SPI PIC 18F4620 and BMP280 (In Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,846
hi,
These are my Mast and Sla Programs, note the Salve regs are preloaded with the binary values 0x1E, 0x24, 0x00, which in Single are 123456.
See the terraterm logs.
E
Hi E,
I appreciate your programs, but perhaps to save more of my confusion, I'll work on the 'memory map' and the order in my last program, which is nearly working, first.
Cheers, C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
Hi E and J,
Result from the latest shuffle round :)
I think you've done it, and I think it's ok. I hope next I can now go down the rest of the MAIN program easily.

I'm using the CODE as #100, with all of the questionable lines included.

Thanks again.
C
 

Attachments

ericgibbs

Joined Jan 29, 2010
21,531
hi,
Can you confirm that you are using the calculations for T & P as shown in example program in the datasheet, if so is it 32 or 64 Bit.??
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
Hi,
The SW HW issue has reared it's ugly head again :(

I'm joing two programs together, by COPY PASTE.
I'm finding that some of the CODE is SW and some HW. I'm alway getting mixed up but I'm talking about using SSPBUF for BYTE/STRING transfer instead of the Oshonsoft method I used previously.

Here is and example of HW? that I need to change, and need some hints how to work it through. It is for an altimeter peripheral, where in this case each BYTE is cycled through.
-------------------------------------------------------------------------------
init_BMP280:
'Compensation parameters
SPICSOn
For i = 0 To 23
altmtr_cs = 0 'CHIP SELECT BMP280 ON
adr = 0x88 + i
SPISend adr
SPIReceive data
b(i) = data
altmtr_cs = 1 'CHIP SELECT BMP280 OFF
Next i
SPICSOff

'Temp coefficents
t1.LB = b(0)
t1.HB = b(1)
t2.LB = b(2)
t2.HB = b(3)
t3.LB = b(4)
t3.HB = b(5)
----------------------------------------------------------
I'm now trying to add the above Altimeter CODE, into previous working SW CODE using this type of CODE. The FULL program is too long to post but, I hope this is enough.
Where do I start?
C.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,531
hi C,
I thought you were using Chip Select 'CS' with multiple HW SPI Slaves, if not, why not.??
E

" An SPI Slave device is selected by its very own CS* (active-low) signal. If the Slave's CS* pin is high, it is required to ignore any clock pulses that go past. If the CS* pin is low, it must clock data in and out as the clock pulses dictate.""
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
hi C,
I thought you were using Chip Select 'CS' with multiple HW SPI Slaves, if not, why not.??
E

" An SPI Slave device is selected by its very own CS* (active-low) signal. If the Slave's CS* pin is high, it is required to ignore any clock pulses that go past. If the CS* pin is low, it must clock data in and out as the clock pulses dictate.""
Hi E,
I have to not think about SW HW, as I get mixed up (Although I've just posted in another SW HW thread, for clarity)

I do use CS e,g, [ altmtr_cs = 0 ], I now think that I need to set this before CALLing a PROCESS or GOSUB with SSPBUF where each BYTE/STRING will be exchanged, as was done in the MASTER-SLAVE thread.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
hi C,
How many Slave peripherals do you have connected to the Master MCU.?
E
Hi E,
Previously, I only had the SLAVE PIC (sucessfully), now I'm adding the BMP280 ALTIMETER peripheral.
In total, there will be the SLAVE PIC plus ALT, COMP, SCREEN. These are the only CS that use SSPBUF
C
 

ericgibbs

Joined Jan 29, 2010
21,531
hi,
If all the peripheral devices have a Chip Select pin, use a Select pin [ from the Master ] for each peripheral to Enable it when you need to communicate with the peripheral device.

The HW SPI is faster than the OSH SW SPI.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
hi,
If all the peripheral devices have a Chip Select pin, use a Select pin [ from the Master ] for each peripheral to Enable it when you need to communicate with the peripheral device.

The HW SPI is faster than the OSH SW SPI.
E
Hi E,
Am I correct that SSPBUF is HW? Hope so!
Now I've got to figure out how to do it. Previously I've used STRINGS [ msg1 = "$COMPDEGM" + "," + str_compdegm + Cr + Lf ]
now I've got to switch to an individual BYTE series.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
him
HW SPI, a copy of an earlier program I sent you,
E
Hi E,
Yes, but it's been modified to work with the FULL program.

In the PROCESS there is a CS/SS for the SLAVE PIC, but now I think I have to SET each CS before CALLING the SPI RD/WR PROCESS.

Then I've got to figure out how to extract each BYTE from the ALTIMETER, which is a slightly different process.

(I hope this is correct, but it is difficult)
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,846
hi C,
It is not for driving your project, it is in answer to your post #129 doubts regarding how to use the HW SPI.....:rolleyes:

E
Hi E,
As I can't post the whole FULL program, I'm going to have to figure it out, and it seems than an anagram of your CODE should work, but needs a bit of working out.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,846
hi,
Small point, using that name for Proc spi_wr_rd() could be confusing.
I would use a separate

Proc spi_wr()

Proc spi_rd()

E
Hi E,
I didn't choose the name 'Proc spi_wr_rd()', but at the time only READ was performed inside that PROCESS?
EDIT: Is it better to CALL 'Proc spi_rd()' then CALL 'Proc spi_wr()' or can RD and WR be in one CALL?
C
 
Last edited:
Top