Strange error when programming PIC for BMP280

jjw

Joined Dec 24, 2013
823
Hi,
Clip from Manual:
.HW,.LW,.3B,.4B,
High word (composed by bytes 3 and 2) and low word (composed by bytes 1 and 0) of a Long (Single) variable can be addressed by .HW and .LW extensions. Byte 0 can be addressed by .LB and byte 1 by .HB extensions. The third and the fourth byte of Long and Single variables can be addressed by .3B and .4B extensions. Individual bits can be addressed by .0, .1, ..., .3
A Long (Single) variable can be addressed by .HW and .LW
Clip end.

The .HW can be accessed by .HB and .LB or .3B and .2B
The .LW can be accessed by .HB and .LB or .1B and .0B
So a LONG variable can be seen as

.HW [ .HB & .LB] + .LW[ .HB & .LB] or .3B .2B .1B .0B

Example:
Dim along as LONG
Dim hword as WORD
Dim lword as WORD
Dim hbyte as BYTE
Dim lbyte as BYTE
Set:
along= 0x12345678
hword =0x1234
lword = 0x5678
hbyte of hword = 0x12
lbyte of hword = 0x34
hbyte of lword = 0x56
lbyte of lword = 0x78

So this is the location of the BYTE
hword = 0x1234
lword = 0x5678
.3B = 0x12
.2B = 0x34
.1B = 0x56
.0B = 0x78

Your post says: Pressure MSB, in the PIC D/S it uses HB LB and 3B,

How can that be correct.?

E
Study the above breakdown so that you understand the 'weighting' location of the bytes in LONG add WORD
I did not find .1B and .0B in the manual ( web site), but .3B, .HB , .LB work in a long variable.
There is an example where a byte is read from a long using .LB
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
You have ( had ) these right in the old working program.
For example the pressure:

Dim p_raw as long
...
p_raw.3B = periph_rd(0xF9)
p_raw.HB = periph_rd(0xF8)
p_raw.LB = periph_rd(0xF7)
Hi J,
Yes, I used these to start with, but the result was wrong. We will go through it all again this afternoon. (Some of the variables have changed name)
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
From an earlier suggestion READ ALTMTR registers is done with this [ p_raw.LB = periph_rd_alt(0xf7) ]

The best we have achieved so far is with this CODE, that uses an older READ method, copied from a working TP and PR good program:

The attached CODE gives consistent, but incorrect READings, where if I warm the sensor up, the TP number goes down.

NOTE: the ALT SHOW line in the JPG, may not be worded correctly!
NOTE: The D/S says to use Burst mode READ which could be the problem?
C
Code:
''READ ALTMTR BMP280
'Proc read_altmtr()

''READ three bytes of pressure:'DAVE's
'altmtr_cs = 0
'p_raw.3B = periph_rd_alt(0xf9)
'altmtr_cs = 1
'altmtr_cs = 0
'p_raw.HB = periph_rd_alt(0xf8)
'altmtr_cs = 1
'altmtr_cs = 0
'p_raw.LB = periph_rd_alt(0xf7)
'altmtr_cs = 1
'altmtr_cs = 0
'p_raw = ShiftRight(p_raw, 4)
'altmtr_cs = 1
'adc_p = p_raw

''READ three bytes of temperature:
'altmtr_cs = 0
't_raw.3B = periph_rd_alt(0xfc)
'altmtr_cs = 1
'altmtr_cs = 0
't_raw.HB = periph_rd_alt(0xfb)
'altmtr_cs = 1
'altmtr_cs = 0
't_raw.LB = periph_rd_alt(0xfa)
'altmtr_cs = 1
't_raw = ShiftRight(t_raw, 4)
'adc_t = t_raw

    Toggle rled  '[yled]
  

    't_raw.LB = b(2)  'Altimeter TEMPERATURE  [[[ PREVIOUS VALUES  ]]]
    't_raw.HB = b(1)  'Altimeter
    't_raw.3B = b(0)  'Altimeter
    't_raw = ShiftRight(t_raw, 4)
    'adc_t = t_raw
    'p_raw.LB = b(2)  'ba Altimeter Pressure
    'p_raw.HB = b(1)  'ba Altimeter
    'p_raw.3B = b(0)  'ba Altimeter
    'p_raw = ShiftRight(p_raw, 4)
    'adc_p = p_raw
'###########ADDED#######################
Proc read_altmtr()

altmtr_cs = 1  'ADDED!!!!!!!!!!!!!!!

    For i = 0 To 2  'Altimeter TEMPERATURE
    Toggle rled
        altmtr_cs = 0  'CHIP SELECT BMP280 ON
        rd_adr = 0xfa + i  '7A=WRITE FA=READ Altimeter
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd = SSPBUF
        b(i) = periph_rd  'data  'Altimeter
        altmtr_cs = 1  'CHIP SELECT BMP280 OFF
    Next i  'ia altimeter
      
    t_raw.LB = b(2)  'Altimeter TEMPERATURE
    t_raw.HB = b(1)  'Altimeter
    t_raw.3B = b(0)  'Altimeter
    t_raw = ShiftRight(t_raw, 4)
    adc_t = t_raw

    For i = 0 To 2  'Altimeter TEMPERATURE
        altmtr_cs = 0  'CHIP SELECT BMP280 ON
        rd_adr = 0xf7 + i  '00=WRITE 80=READ Altimeter
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd = SSPBUF
        b(i) = periph_rd  'data  'Altimeter
        altmtr_cs = 1  'CHIP SELECT BMP280 OFF
    Next i  'ia altimeter

    p_raw.LB = b(2)  'ba Altimeter TEMPERATURE
    p_raw.HB = b(1)  'ba Altimeter
    p_raw.3B = b(0)  'ba Altimeter
    p_raw = ShiftRight(p_raw, 4)
    adc_p = p_raw

Call calca()  'ALTMTR BMP280

    strtp = #tp
    strpr = #pr

End Proc                                       

'@@@@@@@@@@@@@@@@FROM 190921 1001 TP PR CORRECT @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'read_BMP280:
    'SPICSOn
    'For i = 0 To 2  'Altimeter TEMPERATURE
        'altmtr_cs = 0  'CHIP SELECT BMP280 ON
        'adr = 0xfa + i  '00=WRITE 80=READ Altimeter
        'SPISend adr
        'SPIReceive data  'dataa Altimeter
        'b(i) = data  'Altimeter
        'altmtr_cs = 1  'CHIP SELECT BMP280 OFF
    'Next i  'ia altimeter

    't_raw.LB = b(2)  'Altimeter TEMPERATURE
    't_raw.HB = b(1)  'Altimeter
    't_raw.3B = b(0)  'Altimeter
    't_raw = ShiftRight(t_raw, 4)
    'adc_t = t_raw

    'For i = 0 To 2  'Altimeter PRESSURE
        'altmtr_cs = 0  'CHIP SELECT BMP280 ON
        'adr = 0xf7 + i  '00=WRITE 80=READ altimeter
        'SPISend adr
        'SPIReceive data  'altimeter
        'b(i) = data  'Altimeter
        'altmtr_cs = 1  'CHIP SELECT BMP280 OFF
        'Next i  'Altimeter
    'SPICSOff

    'p_raw.LB = b(2)  'ba Altimeter TEMPERATURE
    'p_raw.HB = b(1)  'ba Altimeter
    'p_raw.3B = b(0)  'ba Altimeter
    'p_raw = ShiftRight(p_raw, 4)
    'adc_p = p_raw

    'Gosub calca

    'strtp = #tp
    'strpr = #pr
'Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'###########ADDED########################
  
  
'Call calca()  'ALTMTR BMP280

    'strtp = #tp
    'strpr = #pr


'End Proc
 

Attachments

jjw

Joined Dec 24, 2013
823
Hi,
From an earlier suggestion READ ALTMTR registers is done with this [ p_raw.LB = periph_rd_alt(0xf7) ]

The best we have achieved so far is with this CODE, that uses an older READ method, copied from a working TP and PR good program:

The attached CODE gives consistent, but incorrect READings, where if I warm the sensor up, the TP number goes down.

NOTE: the ALT SHOW line in the JPG, may not be worded correctly!
NOTE: The D/S says to use Burst mode READ which could be the problem?
C
Code:
''READ ALTMTR BMP280
'Proc read_altmtr()

''READ three bytes of pressure:'DAVE's
'altmtr_cs = 0
'p_raw.3B = periph_rd_alt(0xf9)
'altmtr_cs = 1
'altmtr_cs = 0
'p_raw.HB = periph_rd_alt(0xf8)
'altmtr_cs = 1
'altmtr_cs = 0
'p_raw.LB = periph_rd_alt(0xf7)
'altmtr_cs = 1
'altmtr_cs = 0
'p_raw = ShiftRight(p_raw, 4)
'altmtr_cs = 1
'adc_p = p_raw

''READ three bytes of temperature:
'altmtr_cs = 0
't_raw.3B = periph_rd_alt(0xfc)
'altmtr_cs = 1
'altmtr_cs = 0
't_raw.HB = periph_rd_alt(0xfb)
'altmtr_cs = 1
'altmtr_cs = 0
't_raw.LB = periph_rd_alt(0xfa)
'altmtr_cs = 1
't_raw = ShiftRight(t_raw, 4)
'adc_t = t_raw

    Toggle rled  '[yled]
 

    't_raw.LB = b(2)  'Altimeter TEMPERATURE  [[[ PREVIOUS VALUES  ]]]
    't_raw.HB = b(1)  'Altimeter
    't_raw.3B = b(0)  'Altimeter
    't_raw = ShiftRight(t_raw, 4)
    'adc_t = t_raw
    'p_raw.LB = b(2)  'ba Altimeter Pressure
    'p_raw.HB = b(1)  'ba Altimeter
    'p_raw.3B = b(0)  'ba Altimeter
    'p_raw = ShiftRight(p_raw, 4)
    'adc_p = p_raw
'###########ADDED#######################
Proc read_altmtr()

altmtr_cs = 1  'ADDED!!!!!!!!!!!!!!!

    For i = 0 To 2  'Altimeter TEMPERATURE
    Toggle rled
        altmtr_cs = 0  'CHIP SELECT BMP280 ON
        rd_adr = 0xfa + i  '7A=WRITE FA=READ Altimeter
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd = SSPBUF
        b(i) = periph_rd  'data  'Altimeter
        altmtr_cs = 1  'CHIP SELECT BMP280 OFF
    Next i  'ia altimeter
     
    t_raw.LB = b(2)  'Altimeter TEMPERATURE
    t_raw.HB = b(1)  'Altimeter
    t_raw.3B = b(0)  'Altimeter
    t_raw = ShiftRight(t_raw, 4)
    adc_t = t_raw

    For i = 0 To 2  'Altimeter TEMPERATURE
        altmtr_cs = 0  'CHIP SELECT BMP280 ON
        rd_adr = 0xf7 + i  '00=WRITE 80=READ Altimeter
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd = SSPBUF
        b(i) = periph_rd  'data  'Altimeter
        altmtr_cs = 1  'CHIP SELECT BMP280 OFF
    Next i  'ia altimeter

    p_raw.LB = b(2)  'ba Altimeter TEMPERATURE
    p_raw.HB = b(1)  'ba Altimeter
    p_raw.3B = b(0)  'ba Altimeter
    p_raw = ShiftRight(p_raw, 4)
    adc_p = p_raw

Call calca()  'ALTMTR BMP280

    strtp = #tp
    strpr = #pr

End Proc                                      

'@@@@@@@@@@@@@@@@FROM 190921 1001 TP PR CORRECT @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'read_BMP280:
    'SPICSOn
    'For i = 0 To 2  'Altimeter TEMPERATURE
        'altmtr_cs = 0  'CHIP SELECT BMP280 ON
        'adr = 0xfa + i  '00=WRITE 80=READ Altimeter
        'SPISend adr
        'SPIReceive data  'dataa Altimeter
        'b(i) = data  'Altimeter
        'altmtr_cs = 1  'CHIP SELECT BMP280 OFF
    'Next i  'ia altimeter

    't_raw.LB = b(2)  'Altimeter TEMPERATURE
    't_raw.HB = b(1)  'Altimeter
    't_raw.3B = b(0)  'Altimeter
    't_raw = ShiftRight(t_raw, 4)
    'adc_t = t_raw

    'For i = 0 To 2  'Altimeter PRESSURE
        'altmtr_cs = 0  'CHIP SELECT BMP280 ON
        'adr = 0xf7 + i  '00=WRITE 80=READ altimeter
        'SPISend adr
        'SPIReceive data  'altimeter
        'b(i) = data  'Altimeter
        'altmtr_cs = 1  'CHIP SELECT BMP280 OFF
        'Next i  'Altimeter
    'SPICSOff

    'p_raw.LB = b(2)  'ba Altimeter TEMPERATURE
    'p_raw.HB = b(1)  'ba Altimeter
    'p_raw.3B = b(0)  'ba Altimeter
    'p_raw = ShiftRight(p_raw, 4)
    'adc_p = p_raw

    'Gosub calca

    'strtp = #tp
    'strpr = #pr
'Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'###########ADDED########################
 
 
'Call calca()  'ALTMTR BMP280

    'strtp = #tp
    'strpr = #pr


'End Proc
The old program did not use the burst mode and worked, so it is not reason.
Show the calca and the trimming parameters.

This has an extra step:
periph_rd = SSPBUF
b(i) = periph_rd
Replace with b(I)=SSPBUF
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
Am I correct that both XLSB BYTEs contain a fixed setting, so should be 1,2,4,8 or 16 and not change?
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
The old program did not use the burst mode and worked, so it is not reason.
Show the calca and the trimming parameters.

This has an extra step:
periph_rd = SSPBUF
b(i) = periph_rd
Replace with b(I)=SSPBUF
Hi J,
Is this correct: Replace with b(I)=SSPBUF ?
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
b( i ) of course.
Hi J,
Good! I use more read and write than copy and paste as i used to, so you've improved my habits:)
C.

COMP PAR:
Comp PAR =216
Comp PAR =167
Comp PAR =50
Comp PAR =116
Comp PAR =171
Comp PAR =208
Comp PAR =46
Comp PAR =207
Comp PAR =249
Comp PAR =140
Comp PAR =248
Comp PAR =112
Comp PAR =0
Comp PAR =55
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =51
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =96
Code:
'ALTITUDE TEMP CALC
Proc calca()  'ALTMTR BMP280
    'Calculate temperature
    var1 = ((adc_t / 16384 - (dig_t1 / 1024))) * dig_t2
    var2 = (((adc_t) / 131072 - (dig_t1) / 8192) * (adc_t / 131072 - dig_t1 / 8192) * dig_t3)
    t_fine = var1 + var2
    tp = (var1 + var2) / 5120
    'Calculate pressure
    var1 = t_fine / 2 - 64000
    var2 = var1 * var1 * dig_p6 / 32768
    var2 = var2 + var1 * dig_p5 * 2
    var2 = var2 / 4 + dig_p4 * 65536
    var1 = ((dig_p3) * var1 * var1 / 524288 + dig_p2 * var1) / 524288
    var1 = (1 + var1 / 32768) * dig_p1
    pr = 1048576 - adc_p
    pr = (pr - (var2 / 4096)) * 6250 / var1
    var1 = dig_p9 * pr * pr / 2147483648
    var2 = pr * dig_p8 / 32768
    pr = pr + (var1 + var2 + dig_p7) / 16
End Proc
 

jjw

Joined Dec 24, 2013
823
Hi J,
Good! I use more read and write than copy and paste as i used to, so you've improved my habits:)
C.

COMP PAR:
Comp PAR =216
Comp PAR =167
Comp PAR =50
Comp PAR =116
Comp PAR =171
Comp PAR =208
Comp PAR =46
Comp PAR =207
Comp PAR =249
Comp PAR =140
Comp PAR =248
Comp PAR =112
Comp PAR =0
Comp PAR =55
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =51
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =96
Code:
'ALTITUDE TEMP CALC
Proc calca()  'ALTMTR BMP280
    'Calculate temperature
    var1 = ((adc_t / 16384 - (dig_t1 / 1024))) * dig_t2
    var2 = (((adc_t) / 131072 - (dig_t1) / 8192) * (adc_t / 131072 - dig_t1 / 8192) * dig_t3)
    t_fine = var1 + var2
    tp = (var1 + var2) / 5120
    'Calculate pressure
    var1 = t_fine / 2 - 64000
    var2 = var1 * var1 * dig_p6 / 32768
    var2 = var2 + var1 * dig_p5 * 2
    var2 = var2 / 4 + dig_p4 * 65536
    var1 = ((dig_p3) * var1 * var1 / 524288 + dig_p2 * var1) / 524288
    var1 = (1 + var1 / 32768) * dig_p1
    pr = 1048576 - adc_p
    pr = (pr - (var2 / 4096)) * 6250 / var1
    var1 = dig_p9 * pr * pr / 2147483648
    var2 = pr * dig_p8 / 32768
    pr = pr + (var1 + var2 + dig_p7) / 16
End Proc
I mean the single values dig_ti etc.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
I mean the single values dig_ti etc.
Hi J,
Here they are:
C
Code:
Proc init_altmtr_comppar()  'READ and SET Compensation parameters

        For i = 0 To 23
        rd_adr = 0x88 + i  '00=WRITE 80=READ
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd_alt = SSPBUF
        b(i) = periph_rd_alt
    Next i

'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)
    p2.LB = b(8)
    p2.HB = b(9)
    p3.LB = b(10)
    p3.HB = b(11)
    p4.LB = b(12)
    p4.HB = b(13)
    p5.LB = b(14)
    p5.HB = b(15)
    p6.LB = b(16)
    p6.HB = b(17)
    p7.LB = b(18)
    p7.HB = b(19)
    p8.LB = b(20)
    p8.HB = b(21)
    p9.LB = b(22)
    p9.HB = b(23)
'convert to singles with sign
    dig_t1 = t1
    dig_t2 = t2
    If dig_t2 > 32767 Then
        dig_t2 = dig_t2 - 65536
    Endif
    dig_t3 = t3
    If dig_t3 > 32767 Then
        dig_t3 = dig_t3 - 65536
    Endif
    dig_p1 = p1
    dig_p2 = p2
    If dig_p2 > 32767 Then
        dig_p2 = dig_p2 - 65536
    Endif
    dig_p3 = p3
    If dig_p3 > 32767 Then
        dig_p3 = dig_p3 - 65536
    Endif
    dig_p4 = p4
    If dig_p4 > 32767 Then
        dig_p4 = dig_p4 - 65536
    Endif
    dig_p5 = p5
    If dig_p5 > 32767 Then
        dig_p5 = dig_p5 - 65536
    Endif
    dig_p6 = p6
    If dig_p6 > 32767 Then
        dig_p6 = dig_p6 - 65536
    Endif
    dig_p7 = p7
    If dig_p7 > 32767 Then
        dig_p7 = dig_p7 - 65536
    Endif
    dig_p8 = p8
    If dig_p8 > 32767 Then
        dig_p8 = dig_p8 - 65536
    Endif
    dig_p9 = p9
        If dig_p9 > 32767 Then
    dig_p9 = dig_p9 - 65536
    Endif

End Proc
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
The old program did not use the burst mode and worked, so it is not reason.
Hi J,
I hoping for Burst READ eventually. Since burst READing the Compass, the output is much more stable, as previously I had a 250 averaging routine to smooth it, and now it is within a couple of degrees.
C
 

jjw

Joined Dec 24, 2013
823
Hi J,
Here they are:
C
Code:
Proc init_altmtr_comppar()  'READ and SET Compensation parameters

        For i = 0 To 23
        rd_adr = 0x88 + i  '00=WRITE 80=READ
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd_alt = SSPBUF
        b(i) = periph_rd_alt
    Next i

'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)
    p2.LB = b(8)
    p2.HB = b(9)
    p3.LB = b(10)
    p3.HB = b(11)
    p4.LB = b(12)
    p4.HB = b(13)
    p5.LB = b(14)
    p5.HB = b(15)
    p6.LB = b(16)
    p6.HB = b(17)
    p7.LB = b(18)
    p7.HB = b(19)
    p8.LB = b(20)
    p8.HB = b(21)
    p9.LB = b(22)
    p9.HB = b(23)
'convert to singles with sign
    dig_t1 = t1
    dig_t2 = t2
    If dig_t2 > 32767 Then
        dig_t2 = dig_t2 - 65536
    Endif
    dig_t3 = t3
    If dig_t3 > 32767 Then
        dig_t3 = dig_t3 - 65536
    Endif
    dig_p1 = p1
    dig_p2 = p2
    If dig_p2 > 32767 Then
        dig_p2 = dig_p2 - 65536
    Endif
    dig_p3 = p3
    If dig_p3 > 32767 Then
        dig_p3 = dig_p3 - 65536
    Endif
    dig_p4 = p4
    If dig_p4 > 32767 Then
        dig_p4 = dig_p4 - 65536
    Endif
    dig_p5 = p5
    If dig_p5 > 32767 Then
        dig_p5 = dig_p5 - 65536
    Endif
    dig_p6 = p6
    If dig_p6 > 32767 Then
        dig_p6 = dig_p6 - 65536
    Endif
    dig_p7 = p7
    If dig_p7 > 32767 Then
        dig_p7 = dig_p7 - 65536
    Endif
    dig_p8 = p8
    If dig_p8 > 32767 Then
        dig_p8 = dig_p8 - 65536
    Endif
    dig_p9 = p9
        If dig_p9 > 32767 Then
    dig_p9 = dig_p9 - 65536
    Endif

End Proc
Hi J,
Here they are:
C
Code:
Proc init_altmtr_comppar()  'READ and SET Compensation parameters

        For i = 0 To 23
        rd_adr = 0x88 + i  '00=WRITE 80=READ
        WaitUs 1
        SSPBUF = rd_adr
        While Not SSPSTAT.BF
        Wend
        WaitUs 1
        SSPBUF = 0  'Dummy BYTE
        While Not SSPSTAT.BF
        Wend
        periph_rd_alt = SSPBUF
        b(i) = periph_rd_alt
    Next i

'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)
    p2.LB = b(8)
    p2.HB = b(9)
    p3.LB = b(10)
    p3.HB = b(11)
    p4.LB = b(12)
    p4.HB = b(13)
    p5.LB = b(14)
    p5.HB = b(15)
    p6.LB = b(16)
    p6.HB = b(17)
    p7.LB = b(18)
    p7.HB = b(19)
    p8.LB = b(20)
    p8.HB = b(21)
    p9.LB = b(22)
    p9.HB = b(23)
'convert to singles with sign
    dig_t1 = t1
    dig_t2 = t2
    If dig_t2 > 32767 Then
        dig_t2 = dig_t2 - 65536
    Endif
    dig_t3 = t3
    If dig_t3 > 32767 Then
        dig_t3 = dig_t3 - 65536
    Endif
    dig_p1 = p1
    dig_p2 = p2
    If dig_p2 > 32767 Then
        dig_p2 = dig_p2 - 65536
    Endif
    dig_p3 = p3
    If dig_p3 > 32767 Then
        dig_p3 = dig_p3 - 65536
    Endif
    dig_p4 = p4
    If dig_p4 > 32767 Then
        dig_p4 = dig_p4 - 65536
    Endif
    dig_p5 = p5
    If dig_p5 > 32767 Then
        dig_p5 = dig_p5 - 65536
    Endif
    dig_p6 = p6
    If dig_p6 > 32767 Then
        dig_p6 = dig_p6 - 65536
    Endif
    dig_p7 = p7
    If dig_p7 > 32767 Then
        dig_p7 = dig_p7 - 65536
    Endif
    dig_p8 = p8
    If dig_p8 > 32767 Then
        dig_p8 = dig_p8 - 65536
    Endif
    dig_p9 = p9
        If dig_p9 > 32767 Then
    dig_p9 = dig_p9 - 65536
    Endif

End Proc
Could you print them and the raw values of t and p.
I would then calculate the temperature and pressure.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Could you print them and the raw values of t and p.
I would then calculate the temperature and pressure.
Hi J,
Can you clarify 'them' in your sentence please.
EDIT: The DIG values are calculated each time using the [ convert to singles with sign ] section of the CODE in #32


The RAW values are in the link #24 shows them in ALT SHOW. e,g, P_MSB = P_RAW.3B
C.
 
Last edited:

jjw

Joined Dec 24, 2013
823
Hi J,
Can you clarify 'them' in your sentence please.
EDIT: The DIG values are calculated each time using the [ convert to singles with sign ] section of the CODE in #32


The RAW values are in the link #24 shows them in ALT SHOW. e,g, P_MSB = P_RAW.3B
C.
You must have the values of dig_t1... dig_p1...
and t_raw, p_raw, when you calculate the temperature and pressure.
Print the actual values .
I don't want to dig bytes from #29 ( param= ...) or .3B .HB .LB
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
You must have the values of dig_t1... dig_p1...
and t_raw, p_raw, when you calculate the temperature and pressure.
Print the actual values .
I don't want to dig bytes from #29 ( param= ...) or .3B .HB .LB
Hi J,
Is this it?
C
Code:
READY
ALT SHOW  ID 0x58 88  =88  CTRL_MEAS B7 or 183 =183  CONFIG 0x10 or 16  =16

T1  =42968
T2  =29746
T3  =53419
P1  =53038
P2  =36089
P3  =28920
P4  =14080
P5  =0
P6  =0
P7  =51
P8  =0
P9  =24576
DIG_T1  =42968.00
DIG_T2  =29746.00
DIG_T3  =-12117.00
DIG_P1  =53038.00
DIG_P2  =-29447.00
DIG_P3  =28920.00
DIG_p4  =14080.00
DIG_P5  =0.00
DIG_P6  =0.00
DIG_P7  =51.00
DIG_P8  =0.00
DIG_P9  =24576.00
Comp PAR =216
Comp PAR =167
Comp PAR =50
Comp PAR =116
Comp PAR =171
Comp PAR =208
Comp PAR =46
Comp PAR =207
Comp PAR =249
Comp PAR =140
Comp PAR =248
Comp PAR =112
Comp PAR =0
Comp PAR =55
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =51
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =96
ALT SHOW P_MSB =15 - P_LSB =255 - P_XLSB =255 - T_MSB =15 - T_LSB =255 - T_XLSB =255
TP=  110.08  PR=  -33244.80
COMPASS SHOW  72   153   1   51   0   77   0   113   1   16
COMP DEG  283.94

ALT SHOW P_MSB =15 - P_LSB =255 - P_XLSB =255 - T_MSB =15 - T_LSB =255 - T_XLSB =255
TP=  110.08  PR=  -33244.80
COMPASS SHOW  72   153   1   55   0   83   0   111   1   16
COMP DEG  286.81

ALT SHOW P_MSB =15 - P_LSB =255 - P_XLSB =255 - T_MSB =15 - T_LSB =255 - T_XLSB =255
TP=  110.08  PR=  -33244.80
COMPASS SHOW  72   153   1   57   0   87   0   107   1   16
COMP DEG  288.72
 

jjw

Joined Dec 24, 2013
823
X
Hi J,
Is this it?
C
Code:
READY
ALT SHOW  ID 0x58 88  =88  CTRL_MEAS B7 or 183 =183  CONFIG 0x10 or 16  =16

T1  =42968
T2  =29746
T3  =53419
P1  =53038
P2  =36089
P3  =28920
P4  =14080
P5  =0
P6  =0
P7  =51
P8  =0
P9  =24576
DIG_T1  =42968.00
DIG_T2  =29746.00
DIG_T3  =-12117.00
DIG_P1  =53038.00
DIG_P2  =-29447.00
DIG_P3  =28920.00
DIG_p4  =14080.00
DIG_P5  =0.00
DIG_P6  =0.00
DIG_P7  =51.00
DIG_P8  =0.00
DIG_P9  =24576.00
Comp PAR =216
Comp PAR =167
Comp PAR =50
Comp PAR =116
Comp PAR =171
Comp PAR =208
Comp PAR =46
Comp PAR =207
Comp PAR =249
Comp PAR =140
Comp PAR =248
Comp PAR =112
Comp PAR =0
Comp PAR =55
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =51
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =0
Comp PAR =96
ALT SHOW P_MSB =15 - P_LSB =255 - P_XLSB =255 - T_MSB =15 - T_LSB =255 - T_XLSB =255
TP=  110.08  PR=  -33244.80
COMPASS SHOW  72   153   1   51   0   77   0   113   1   16
COMP DEG  283.94

ALT SHOW P_MSB =15 - P_LSB =255 - P_XLSB =255 - T_MSB =15 - T_LSB =255 - T_XLSB =255
TP=  110.08  PR=  -33244.80
COMPASS SHOW  72   153   1   55   0   83   0   111   1   16
COMP DEG  286.81

ALT SHOW P_MSB =15 - P_LSB =255 - P_XLSB =255 - T_MSB =15 - T_LSB =255 - T_XLSB =255
TP=  110.08  PR=  -33244.80
COMPASS SHOW  72   153   1   57   0   87   0   107   1   16
COMP DEG  288.72
XLSB is clearly wrong in pressure and temperature because it should be between 0-240. Probably also lsb which is always 255.
Do you switch CS of the compass off, when measuring BMP280.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
X

XLSB is clearly wrong in pressure and temperature because it should be between 0-240. Probably also lsb which is always 255.
Do you switch CS of the compass off, when measuring BMP280.
Hi J,
In #24 the commented out sections, plus many more were tested, and there are so many combinations.

again, I've tried switching CS ON/OFF in many tests. From memory, in the working program they weren't switched ON/OFF between READs.

I've had a suspicion that XLSB and LB are the wrong way round. At the moment they are the same as the OSH working program.
C.
 
Top