SPI PIC 18F4620 and BMP280 (In Oshonsoft)

jjw

Joined Dec 24, 2013
823
You need the extra read because you don't send the dummy byte after the address inside the loop.

Could you try to read only the last byte, P9 at address 0x9F and print it, should be 23

SSPBUF = 0x9f ' adress of the last byte
While Not SSPSTAT.BF
Wend
' maybe a short delay is needed here?
SSPBUF = 0x00 ' change to 0xFf if 0x00 does not work
While Not SSPSTAT.BF
Wend
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
You need the extra read because you don't send the dummy byte after the address inside the loop.

Could you try to read only the last byte, P9 at address 0x9F and print it, should be 23

SSPBUF = 0x9f ' adress of the last byte
While Not SSPSTAT.BF
Wend
' maybe a short delay is needed here?
SSPBUF = 0x00 ' change to 0xFf if 0x00 does not work
While Not SSPSTAT.BF
Wend
Hi J,
I found that with this: (Note some is commented out)
-----------------------------------------------------------------------------------
altmtr = 0
SSPBUF = 0x9f 'adress of the last byte
While Not SSPSTAT.BF
Wend
WaitUs 2 '' maybe a short delay is needed here?
SSPBUF = 0x00 'change to 0xFf if 0x00 does not work
While Not SSPSTAT.BF
Wend

altmtr = 1

'Compensation parameters
'Temp coefficents
dummy = b(0)
t1.LB = b(1) '0x88
t1.HB = b(2) '0x89
t2.LB = b(3) '0x8a
t2.HB = b(4) '0x8b
t3.LB = b(5) '0x8c
t3.HB = b(6) '0x8d
'pressure coefficients
p1.LB = b(7) '0x8e
p1.HB = b(8) '0x8f
p2.LB = b(9) '0x90
p2.HB = b(10) '0x91
p3.LB = b(11) '0x93
p3.HB = b(12) '0x94
p4.LB = b(13) '0x95
p4.HB = b(14) '0x96
p5.LB = b(15) '0x97
p5.HB = b(16) '0x98
p6.LB = b(17) '0x99
p6.HB = b(18) '0x9a
p7.LB = b(19) '0x9b
p7.HB = b(20) '0x9c
p8.LB = b(21) '0x9d
p8.HB = b(22) '0x9e
p9.LB = b(23) '0x9f
p9.HB = b(24) '0xa0
dummy = b(25)

'Hserout "TI-P9 ", #t1.LB, " ", #t1.HB, " ", #t2.LB, " ", #t2.HB, " ", #t3.LB, " ", #t3.HB, " ", #p1.LB, " ", #p1.HB, " ", #p2.LB, " ", #p2.HB, " ", #p3.LB, " ", #p3.HB, " ", #p4.LB, " ", #p4.HB, " ", #p5.LB, " ", #p5.HB, " ", #p6.LB, " ", #p6.HB, " ", #p7.LB, " ", #p7.HB, " ", #p8.LB, " ", #p8.HB, " ", #p9.LB, " ", #p9.HB, CrLf

Hserout "P9.HB ", #p9.HB, CrLf
-------------------------------------------------------------------------------------------
anything in the address marked in red, gives this result: [ P9.HB = 80 ]
C.
 

jjw

Joined Dec 24, 2013
823
But did you overwrite the separately calculated P.9 in P.9=b(24) ?
Print P.9 immediately before the loop.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
But did you overwrite the separately calculated P.9 in P.9=b(24) ?
Print P.9 immediately before the loop.
Hi J,
I replaced what's in #80 with your suggestion. and the previous [ for and next LOOP ] has been replaced by no LOOP.
As this is in SET-UP, it is before the main LOOP, so no LOOP, simply READ and show.

Any CODE you post, I simply copy, paste and test, I don't tamper with it
C.
 

jjw

Joined Dec 24, 2013
823
Hi J,
I replaced what's in #80 with your suggestion. and the previous [ for and next LOOP ] has been replaced by no LOOP.
As this is in SET-UP, it is before the main LOOP, so no LOOP, simply READ and show.

Any CODE you post, I simply copy, paste and test, I don't tamper with it
C.
Why you then show in #82 P9. HB = b(24)?
Did you write at the of the separate test
P9. HB=SSPBUF
 

jjw

Joined Dec 24, 2013
823
Hi J,
I'm not quite sure what you're asking, but if you want the full T1-3 and P1-9 READ out, then here it is:
C
I asked to get only one value P9. Hb from address 0x9F
with a test in #82:

SSPBUF = 0x9f 'adress of the last byte
While Not SSPSTAT.BF
Wend
WaitUs 2 '' maybe a short delay is needed here?
SSPBUF = 0x00 'change to 0xFF if 0x00 does not work
While Not SSPSTAT.BF
Wend
P9. HB = SSPBUF

Hserout #P9. HB

-----------------

Nothing else.
No loop for b(l)
No P9. HB= something
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I asked to get only one value P9. Hb from address 0x9F
with a test in #82:

SSPBUF = 0x9f 'adress of the last byte
While Not SSPSTAT.BF
Wend
WaitUs 2 '' maybe a short delay is needed here?
SSPBUF = 0x00 'change to 0xFF if 0x00 does not work
While Not SSPSTAT.BF
Wend
P9. HB = SSPBUF

Hserout #P9. HB

-----------------

Nothing else.
No loop for b(l)
No P9. HB= something
Hi J,
Here is the result:
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Show the whole program.
Hi J,
Here is that last FULL program that is working as far as we have got too:

I've left the minimum to give all of the TEMP and PRESS 'parameters'

I've attached an image with slightly different setting, I hope it's a bit clearer.
C
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,766
hi,
If I am reading his code correctly..??

Dim b(24) As Byte 'Altimeter compass

;;;; b(0) thru b(23) .............

'Compensation parameters
altmtr = 0
For i = 0 To 25
adr = 0x88 + i
SSPBUF = adr
While Not SSPSTAT.BF
Wend
b(i) = SSPBUF
WaitUs 2
Next i
 

jjw

Joined Dec 24, 2013
823
Hi J,
Here is that last FULL program that is working as far as we have got too:

I've left the minimum to give all of the TEMP and PRESS 'parameters'

I've attached an image with slightly different setting, I hope it's a bit clearer.
C
Here the last byte is 23, which is the same as from sw Spi.
Does it change randomly?

The analyser image is blurred as usually.
How do you get the image?
Is it a screenshot from PC?
 

jjw

Joined Dec 24, 2013
823
hi,
If I am reading his code correctly..??

Dim b(24) As Byte 'Altimeter compass

;;;; b(0) thru b(23) .............

'Compensation parameters
altmtr = 0
For i = 0 To 25
adr = 0x88 + i
SSPBUF = adr
While Not SSPSTAT.BF
Wend
b(i) = SSPBUF
WaitUs 2
Next i
The data is read out of phase at next address, because there is no dummy write after the address.
That's why the index i is out of bounds.

That is the problem!
Dim b has to be changed to 25.
Strange that the compiler accepts this.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi jjw,
I have had this problem before, the complier accepts it, but does not 'protect' the out of bounds array data and so its over written with the next DIM RAM allocation data in the code.

E

Dim b(24) As Byte 'Altimeter compass
Dim data As Byte 'Altimeter compass
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi E and J,
I think I understand.

Can you clarify a few things here:
------------------------------------------------------------------------------------------------------------------------
'S<S<S<S<S<S<S<S<S<S SHARED COUNTERS AND ARRAYS <S<S<S<S<S<S<S<S<SS
Dim i As Byte 'Altimeter compass (GPS checking )
Dim b(26) As Byte 'Altimeter compass'This number must cover [ 0 to X ] ?
Dim data As Byte 'Altimeter compass
Dim msg1 As String '5110_GPS any msg data will be passed via this string
Symbol dataswitch = LATD.4 'RX 2to1 switch 1=GPS 0=HC-12
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S

'AAAAAAAAAAAAAAAAAAAA BMP280 ALTIMETER AAAAAAAAAAAAAAAAAA
Symbol altmtr = LATD.1 'BMP280 BAROMETER/TEMP
'BMP280 CALC
Dim dummy As Byte
dummy = 0xff
Dim test As Byte
Dim dta As Byte

Dim var1 As Single
Dim var2 As Single
Dim t_fine As Single
Dim t_raw As Long
Dim p_raw As Long
Dim adc_t As Single
Dim adc_p As Single
Dim tp As Single 'TEMP result in CALC
Dim pr As Single 'PRESS result in CALC
Dim strtp As String
Dim strpr As String
Dim adr As Byte 'ADDRESS FOR BMP280
Dim t1 As Word 'Compensation parameters
Dim t2 As Word
Dim t3 As Word
Dim p1 As Word
Dim p2 As Word
Dim p3 As Word
Dim p4 As Word
Dim p5 As Word
Dim p6 As Word
Dim p7 As Word
Dim p8 As Word
Dim p9 As Word
Dim dig_t1 As Single 'Compensation parameters
Dim dig_t2 As Single
Dim dig_t3 As Single
Dim dig_p1 As Single
Dim dig_p2 As Single
Dim dig_p3 As Single
Dim dig_p4 As Single
Dim dig_p5 As Single
Dim dig_p6 As Single
Dim dig_p7 As Single
Dim dig_p8 As Single
Dim dig_p9 As Single

'Compensation parameters
altmtr = 0
For i = 0 To 25
adr = 0x88 + i
SSPBUF = adr
While Not SSPSTAT.BF
Wend
b(i) = SSPBUF
WaitUs 2
Next i

SSPBUF = dummy Is this necessary?

altmtr = 1

'Compensation parameters
'Temp coefficents
dummy = b(0) 'Is this necessary?
t1.LB = b(1) '0x88
t1.HB = b(2) '0x89
t2.LB = b(3) '0x8a
t2.HB = b(4) '0x8b
t3.LB = b(5) '0x8c
t3.HB = b(6) '0x8d
'pressure coefficients
p1.LB = b(7) '0x8e
p1.HB = b(8) '0x8f
p2.LB = b(9) '0x90
p2.HB = b(10) '0x91
p3.LB = b(11) '0x93
p3.HB = b(12) '0x94
p4.LB = b(13) '0x95
p4.HB = b(14) '0x96
p5.LB = b(15) '0x97
p5.HB = b(16) '0x98
p6.LB = b(17) '0x99
p6.HB = b(18) '0x9a
p7.LB = b(19) '0x9b
p7.HB = b(20) '0x9c
p8.LB = b(21) '0x9d
p8.HB = b(22) '0x9e
p9.LB = b(23) '0x9f
p9.HB = b(24) '0xa0
dummy = b(25) Is this necessary?
------------------------------------------------------------------------------------------------------------

The images are 'Screen shot' I'll keep posting them, with different settings. Let me know when they get sharp enough.

EDIT: 010919
C.
 
Last edited:
Top