SPI PIC 18F4620 and BMP280 (In Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Are the compensation values the same as from sw Spi?
Hi J,
Yes, SWSPI and HWSPI are the same.
However each BMP280 is different, as they are calibrated at the factory.
#11 shows the 'memory map' and the turquoise line shows the CALIBRATION DATA REGISTERS.
It looks as though I made an error from the beginning, and I now see that it should be from [ 0xA1 to 0x88 ] Do you agree?

I have been moving lines around in the [ SSPBUF } section of the program, and now it shows:
almost the same as the earlier SWSPI. (As explained both wrong) but on the right track in the programming sense.
 

Attachments

jjw

Joined Dec 24, 2013
823
No.
How would you get the right results, if they were in wrong order before
Look #11.
It says Calib25-Calib0, 0xA1-0x88
So t1 starts at 0x88
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
No.
How would you get the right results, if they were in wrong order before
Look #11.
It says Calib25-Calib0, 0xA1-0x88
So t1 starts at 0x88
Hi J,
Of course! It's been a long day.
At least the MISO is working at last, which is a step forward.
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
Here is the lattest Alphanumeric file:

I used this to achieve it:
'------------------------------------------------------------------------------------------------------

altmtr = 0
For i = 0 To 26
adr = 0x88 + i
SSPBUF = adr
While Not SSPSTAT.BF
Wend
data = SSPBUF
WaitUs 2
b(i) = data
Next i
altmtr = 1

'Compensation parameters
'Temp coefficents
dummy = b(0)
t1.LB = b(1)
t1.HB = b(2)
t2.LB = b(3)
t2.HB = b(4)
t3.LB = b(5)
t3.HB = b(6)
'pressure coefficients
p1.LB = b(7)
p1.HB = b(8)
p2.LB = b(9)
p2.HB = b(10)
p3.LB = b(11)
p3.HB = b(12)
p4.LB = b(13)
p4.HB = b(14)
p5.LB = b(15)
p5.HB = b(16)
p6.LB = b(17)
p6.HB = b(18)
p7.LB = b(19)
p7.HB = b(20)
p8.LB = b(21)
p8.HB = b(22)
p9.LB = b(23)
p9.HB = b(24)
test = b(25)
test = b(26)
'------------------------------------------------------------------------------------------------------
NOTE: Ive added a couple of READs to the end of the process, to see what'ts there. Previously [ 0XA1 ] wasn't showing, now it shows [ 0 ]
I'm trying to be clear that the correct READings are put in the correct [ B(X) ]
C.
 

Attachments

jjw

Joined Dec 24, 2013
823
I looked at a few values from the beginning and they are the same as from sw Spi.
After the config of BMP280 you can test the calculation.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I looked at a few values from the beginning and they are the same as from sw Spi.
After the config of BMP280 you can test the calculation.
Hi J,
Ok, thanks.
I've added it into the long MAIN program, and at that stage it's showing the same numbers:)

Next I've got to WRITE to the WHITE LINES in #11 MEMORY MAP.

Here's the READ section as above:
'-------------------------------------------------------------------------------------
altmtr = 0
For i = 0 To 26
adr = 0x88 + i
SSPBUF = adr
While Not SSPSTAT.BF
Wend
data = SSPBUF
WaitUs 2
b(i) = data
Next i
altmtr = 1
--------------------------------------------------------------------------------------
HERE is the SWSPI WRITE section:

How do I WRITE? Could you edit the WRITE section from SW to HW please?
--------------------------------------------------------------------------------------
altmtr = 0 '''''''''''''''CHIP SELECT BMP280 ON
SPISend 0x60 ''''''''''''''WRITE 0xe0 RESET ADDR (Try with these OUT first)
SPISend 0xb6 '''''''''''''%10110110 RESET TO 0x00??
altmtr = 1 '''''''''''''''CHIP SELECT BMP280 OFF (Try with these OUT first)
altmtr = 0 ''''''''''''''CHIP SELECT BMP280 ON (Try with these OUT first)
SPISend 0x74 ''''''''''''WRITE 0xF4 Control CTRL_MEAS reg addr
SPISend 0x5f '''''''''''''''''%01011111 T/ON P/ON 't_x2 px16 Normal Mode
altmtr = 1 ''''''''''''''CHIP SELECT BMP280 OFF (Try with these OUT first)
altmtr = 0 '''''''''''''CHIP SELECT BMP280 ON (Try with these OUT first)
SPISend 0x75 ''''''''''''''WRITE 0xF5 Control CONFIG reg addr
'SPISend 0x1c '%00011100 osrs_t 0.5ms Table 11-11R filter x16 table 6
altmtr = 1 'CHIP SELECT BMP280 OFF
--------------------------------------------------------------------------------
C.
 
Last edited:

jjw

Joined Dec 24, 2013
823
Hi J,
Ok, thanks.
I've added it into the long MAIN program, and at that stage it's showing the same numbers:)

Next I've got to WRITE to the WHITE LINES in #11 MEMORY MAP.

Here's the READ section as above:
'-------------------------------------------------------------------------------------
altmtr = 0
For i = 0 To 26
adr = 0x88 + i
SSPBUF = adr
While Not SSPSTAT.BF
Wend
data = SSPBUF
WaitUs 2
b(i) = data
Next i
altmtr = 1
--------------------------------------------------------------------------------------
HERE is the SWSPI WRITE section:

How do I WRITE? Could you edit the WRITE section from SW to HW please?
--------------------------------------------------------------------------------------
altmtr = 0 '''''''''''''''CHIP SELECT BMP280 ON
SPISend 0x60 ''''''''''''''WRITE 0xe0 RESET ADDR (Try with these OUT first)
SPISend 0xb6 '''''''''''''%10110110 RESET TO 0x00??
altmtr = 1 '''''''''''''''CHIP SELECT BMP280 OFF (Try with these OUT first)
altmtr = 0 ''''''''''''''CHIP SELECT BMP280 ON (Try with these OUT first)
SPISend 0x74 ''''''''''''WRITE 0xF4 Control CTRL_MEAS reg addr
SPISend 0x5f '''''''''''''''''%01011111 T/ON P/ON 't_x2 px16 Normal Mode
altmtr = 1 ''''''''''''''CHIP SELECT BMP280 OFF (Try with these OUT first)
altmtr = 0 '''''''''''''CHIP SELECT BMP280 ON (Try with these OUT first)
SPISend 0x75 ''''''''''''''WRITE 0xF5 Control CONFIG reg addr
'SPISend 0x1c '%00011100 osrs_t 0.5ms Table 11-11R filter x16 table 6
altmtr = 1 'CHIP SELECT BMP280 OFF
--------------------------------------------------------------------------------
C.
Similarly as with compensation parameters.

SSPBUF = configuration register write address
While
....
Wend
SSPBUF = configuration data
While
...
Wend
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Similarly as with compensation parameters.

SSPBUF = configuration register write address
While
....
Wend
SSPBUF = configuration data
While
...
Wend
Hi J,
Thanks.
With this:
----------------------------------------------------------------------------------
altmtr = 0 'CHIP SELECT BMP280 ON
SSPBUF = 0x75
While Not SSPSTAT.BF
Wend
SSPBUF = 0x1c
While Not SSPSTAT.BF
Wend
WaitMs 2
altmtr = 1

altmtr = 0 'CHIP SELECT BMP280 ON
SSPBUF = 0x74
While Not SSPSTAT.BF
Wend
SSPBUF = 0x5f
While Not SSPSTAT.BF
Wend
WaitMs 2
altmtr = 1
-----------------------------------------------------------------------------------
Test results show, it's [ -139.83Deg and I'm 14 fathoms deep ]:)
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I don't see anything related to pressure or temperature in the csv file.
Hi J,
No, the CSV file is the alternative to the Digital analyser output. Here it is in case you can read it this time:

I won't get sensible TEMP/PRESS READings till I am certain I'm WRITEing ok.
C
 

Attachments

jjw

Joined Dec 24, 2013
823
The analyser picture is still almost unreadable.
The writing to config registers seems to be ok.
I don't know should they show something in MISO or are they write only.

Edit: they are R/W. You could try to read them after write to check that writing is ok.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
The analyser picture is still almost unreadable.
The writing to config registers seems to be ok.
I don't know should they show something in MISO or are they write only.

Edit: they are R/W. You could try to read them after write to check that writing is ok.
Hi J,
---------------------------------------------------------------------------------------------
altmtr = 0
SSPBUF = 0xf5
While Not SSPSTAT.BF
Wend
dta = SSPBUF
WaitMs 2
altmtr = 1
Hserout "F5 ", #dta, CrLf
------------------------------------------------------------------------------------------
This produces [ 0 ]
C.
 

jjw

Joined Dec 24, 2013
823
Hi J,
---------------------------------------------------------------------------------------------
altmtr = 0
SSPBUF = 0xf5
While Not SSPSTAT.BF
Wend
dta = SSPBUF
WaitMs 2
altmtr = 1
Hserout "F5 ", #dta, CrLf
------------------------------------------------------------------------------------------
This produces [ 0 ]
C.
Did you write data to address 0x75.
To read it, write address 0xF5, then write dummy byte and then should have data in SSPBUF.

I think you can write and read with chipselect on (=0) all the time.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Did you write data to address 0x75.
To read it, write address 0xF5, then write dummy byte and then should have data in SSPBUF.

I think you can write and read with chipselect on (=0) all the time.
Hi J,
Success:)
Here is the CSV. The last 3x lines show [ 0x1c ] WRITE to [ 0x75 ] then [ 0x1c ] when [ 0x75 ] (0xF5 ) is READ.
Thanks.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
This:
------------------------------------------------------------------------------------------------------
'WRITE to 0x75
altmtr = 0 'CHIP SELECT BMP280 ON
SSPBUF = 0x75
While Not SSPSTAT.BF
Wend
SSPBUF = 0x1c
While Not SSPSTAT.BF
Wend
WaitUs 5 '2
SSPBUF = 0x74
While Not SSPSTAT.BF
Wend
SSPBUF = 0x5f
While Not SSPSTAT.BF
Wend
WaitUs 5 '2
altmtr = 1

'READ from 0x75
altmtr = 0
SSPBUF = 0xf5
While Not SSPSTAT.BF
Wend
dta = SSPBUF
WaitMs 5 '2
SSPBUF = 0x88
While Not SSPSTAT.BF
Wend
dta = SSPBUF
WaitUs 5 '2
SSPBUF = 0xf4
While Not SSPSTAT.BF
Wend
dta = SSPBUF
WaitMs 5 '2
SSPBUF = 0x88
While Not SSPSTAT.BF
Wend
dta = SSPBUF
WaitUs 5 '2
altmtr = 1
-------------------------------------------------------------------------------------------------------
produces this:
NOTE: Last line is incorrect
C.
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
Excel clip of your csv, more reader friendly.:)
NOTE: Last line is incorrect
Are you saying all the other values are what you expect.?
E
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
Excel clip of your csv, more reader friendly.:)
NOTE: Last line is incorrect
Are you saying all the other values are what you expect.?
E
Hi E,
Actually the other values are from the earlier 'compensation parameters' READ and some of them are not showing correctly, although on a terminal, they show correctly, perhaps there's an error with the analyser?

The bottom 8x lines show what we are watching: The 2x WRITEs to [ 0x75 and 0x74 ] then READs of the same 2x.
C.
 
Top