SPI PIC 18F4620 and BMP280 (In Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I'm having great difficulty understanding how PROCEDURES work, and a mate of mine has volunteered to explain one to one. (Does he know what he's getting himself into) :)

So for now I'll carry on without them.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I had a quick lesson in PROCEDURES, FUNCTIONS and INCLUDES yesterday.
Some of it must have gone in, as I made a working PROCEDURE today.
PIC1 SENDS test DATA to PIC2 which returns different test DATA. I can print it on a computer terminal, from the MAIN LOOP.
There are many loose ends, so I'll still go for lessons ;)
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I've attached the GPS, to the PCB and when the signal wire is disconnected and shown on a terminal it show correctly NMEA sentences.
When I connect it to the DATA switch input, it shows, see attched:
I'm tracing it through, and the CODE is all over the place, but can anyone let me know what they think causes this, please?
It's possible that two signals are being mixed!
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi,
A circuit showing the DATA switch and a Code clip would help.:rolleyes:
E
Hi E,
It's difficult to show the relevant CODE,as it's scattered in various places, here's the actual switch section. I've tried ON/OFF, but it's a bit tricky.
Here's the PCB (7)
I didn't want to get too detailed, at the moment anyway, more of a general what could cause it question.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi E,
It's difficult to show the relevant CODE,as it's scattered in various places, here's the actual switch section. I've tried ON/OFF, but it's a bit tricky.
Here's the PCB (7)
I didn't want to get too detailed, at the moment anyway, more of a general what could cause it question.
C
Hi E,
I've manually switched the DATASW to a none input PIN in the CODE, and it's now working, so the GPS DATA is now at the SWITCH PIN, just got to do something with the SWITCH.
Quite a few things have changed, since getting SPI to work between PIC1 and 2, so the program has to be reorganised.
Cheers, E.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi, PCB7

I've moved from the Oshonsoft version of SPI, to the SSPBUF exchange version.
The MASTER PIC is not exchanging DATA with the SLAVE PIC ok.

Next I'm trying to get the first peripheral to work. (ALTIMETER BMP280)
I'm sending the REGISTER address to the SLAVE expecting the DATA of that REGISTER to return, but it's not working.
Any ideas?
C

Code:
'BMP280 UTILITIES
'Initialize BMP280
Proc init_BMP280()  'init_BMP280  ':
Symbol altmtr_cs = LATD.3  'BMP280 BAROMETER/TEMP [ Moved from GLOBAL SYMBOL needs setting for each PROC instance (Perhaps use INCLUDE?)]]

adr = 0x88

'Compensation parameters
WaitUs 10
    For i = 0 To 23
        
            altmtr_cs = 0  'CHIP SELECT BMP280 ON

            SSPBUF = adr  'SPISend adr
            
            While Not SSPSTAT.BF  'If buffer empty do nothing
            Wend

            data = SSPBUF  'SPIReceive data
            WaitUs 2

            b(i) = data
            adr = adr + i
            
            altmtr_cs = 1  'CHIP SELECT BMP280 OFF
            
    Next i

If adr = 0xa1 Then adr = 0x88  '(poss 0x9f)

'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)
'pressure coefficients
    p1.LB = b(6)
    p1.HB = b(7)
 

Attachments

jjw

Joined Dec 24, 2013
823
Show the SPI_init() for the BMP280.
I would first try to read the id byte from BMP280.
If you send an address to read from, you get the data on the next write to BM280.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Show the SPI_init() for the BMP280.
I would first try to read the ident byte from BMP280.
If you send an address to read from, you get the data on the next write to BM280.
Hi J,
First attempt failed, I'll keep trying.
I'm only trying the BMP280 peripheral, so no PIC2.
C
Code:
Proc spi_init()  'looks like straight from the datasheet

'4620
'PORTA.4 = 0  'SS Sets SS PIN on PIC2 [[MOVED to PIC2 SPECIFIC CALL ]]
PORTD.3 = 0  'BMP280_cs
TRISC.3 = 0  'clk to Slave
TRISC.4 = 1  'sdi from slave
TRISC.5 = 0  'sdo to slave

'MODE 0,0

SSPSTAT.SMP = 0  'sample a mid data
SSPSTAT.CKE = 1
SSPSTAT.5 = 0  'I2C only
SSPSTAT.4 = 0  'I2C only
SSPSTAT.3 = 0  'I2C only
SSPSTAT.2 = 0  'I2C only
SSPSTAT.1 = 0  'I2C only
SSPSTAT.BF = 0  'If SSPBUF=1=Full

SSPCON1.WCOL = 0  'Collision detect
SSPCON1.SSPOV = 0  'Overflow
SSPCON1.SSPEN = 1  'Configure SCK,SD0,SDI,/SS
SSPCON1.CKP = 0  'Clock Idle Low, Active High
SSPCON1.SSPM3 = 0  '0010 = SPI Master Mode Fosc/64
SSPCON1.SSPM2 = 0
SSPCON1.SSPM1 = 1
SSPCON1.SSPM0 = 0

End Proc
 

jjw

Joined Dec 24, 2013
823
#167 tries to read the calibration data from BMP280.
I mean measurement control and configuration of the BMP280.
You had a working version with Oshonsoft SPIsend, SPIreceive functions.
Try to read the ID byte from BMP280. If it works then copy the rest from the old working program.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
#167 tries to read the calibration data from BMP280.
I mean measurement control and configuration of the BMP280.
You had a working version with Oshonsoft SPIsend, SPIreceive functions.
Try to read the ID byte from BMP280. If it works then copy the rest from the old working program.
Hi J,
Yes, I have old working versions using the Oshonsoft SPIsend, SPIreceive functions, but I've been changing it all over to the SSPBUF exchange method.
I have a working SSPBUF program between PIC1 (MASTER) and PIC2 )SLAVE1), where they exchange counting DATA, and now I've moved on to the next peripheral BMP280 (SLAVE2), and am trying to also use the SSPBUF method.
First as you suggest, I'm trying to READ the ID from it.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I've come to the painful conlusion that I've got to go back in time, to an earlier working old PCB and programs :(

PCB5 still has the Transmitter GPS and all of the peripherals, and used to work (I've used it for testing) apart from (I think) it.
It doesn't have the SPI connection to PIC2 but has a SERIAL connection back tothe DATASW, instead.
I'll get this working as it did before I updated the PCBS, then change each peripheral to a PROCEDURE, which should transfer to PCB7.

I may be some timeo_O
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I've now got an older program version to work after temporarily fixing PCB5. There is no SPI between the 2x PICs, and it's not perfect, but no matter for now.
Working on MASTER PIC1 18F46K20:
Radio
GPS
Compass
Altimeter
Joysticks.
NEXT:
The Compass and Altimeter SPI is Oshonsofts SPICSON/OFF method and I've got to change it to the SSPBUF method.
Each section has to be moved into PROCEDURES, FUNCTIONS and INCLUDES.

Which one should I do first?
C.
 

ericgibbs

Joined Jan 29, 2010
18,848
hi C,
Even this short test code fails.
E
Code:
Define SIMULATION_WAITMS_VALUE = 1  'Comment in for SIM out for PIC

'----------- SYSTEM CONFIG  --------------------
'PIC Config
Define CONFIG1L = 0x00
Define CONFIG1H = 0x02  '8=INT  2=EXT
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x81  'Set for HVP
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
Define CLOCK_FREQUENCY = 8


'Set up UART and RX interrupt for immediate use
Hseropen 9600  'does a basic config of TX and RX including BAUDCON, SPEN, CREN, TXEN etc.
Hserout "TEST", CrLf

End
 

ericgibbs

Joined Jan 29, 2010
18,848
hi C,
Checking the asm code, shows that the correct code has been compiled.
When it stops and I set the TXI bit using the IDE , the program just runs thru the TEST message, but no UART print out.
Ask Vlad.
E
 

Attachments

Top