HSEROUT intermittent working OSHONSOFT

Thread Starter

camerart

Joined Feb 25, 2013
3,257
Hi,
This morning has been a bit of a blur!
It's possible, I've got something to work, I'll have a break, then re-check;)

I searched for BMP280 Burst READ, but couldn't find much about it, does this look like BURST READ?

Here is a section of CODE and the Terminal view.
C
Code:
main:  '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

rd_adr = 0xf7  '0xF7 press_msb_adr
press_msb_dta = read_dta(rd_adr)
rd_adr = 0xf8  '0xF8 press_msb_adr
press_lsb_dta = read_dta(rd_adr)
rd_adr = 0xf9  '0xF9 press_msb_adr
press_xlsb_dta = read_dta(rd_adr)
rd_adr = 0xfa  '0xFA press_msb_adr
temp_msb_dta = read_dta(rd_adr)
rd_adr = 0xfb  '0xFB press_msb_adr
temp_lsb_dta = read_dta(rd_adr)
rd_adr = 0xfc  '0xFC press_msb_adr
temp_xlsb_dta = read_dta(rd_adr)

Toggle rled
WaitMs 100

Hserout "press_msb_dta  ", #press_msb_dta, CrLf
Hserout "press_lsb_dta  ", #press_lsb_dta, CrLf
Hserout "press_xlsb_dta  ", #press_xlsb_dta, CrLf, CrLf
Hserout "temp_msb_dta  ", #temp_msb_dta, CrLf
Hserout "temp_lsb_dta  ", #temp_lsb_dta, CrLf
Hserout "temp_xlsb_dta  ", #temp_xlsb_dta, CrLf, CrLf


Goto main
   
End                                              

'----------- PERIPHERAL UTILITIES  -------------
'HC-12 INITIALISATION
init_HC12:
                                    'PRESS BUTTON (OR RADSET)
    radset = RADIO_COMMAND_MODE  'SET HC-12 COMMAND ON
    Hserout "AT+C002", CrLf  '433.800
    radset = RADIO_DATA_MODE  'SET HC-12 RUN ON
    Return
'------------------

Proc spi_init()  'looks like straight from the datasheet
'4620
TRISC.3 = 0  'SCK to Slave
TRISC.4 = 1  'MISO
TRISC.5 = 0  'MOSI

'MODE 0,0
SSPSTAT.SMP = 0  'Input data sampled at middle of data output time
SSPSTAT.CKE = 0  '1 Output data changes on clock transition from idle to active
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 = 1  '[1]  'Clock Idle high, Active low [Clock Idle Low, Active High]
SSPCON1.SSPM3 = 0  '0010 = SPI Master mode, clock = FOSC/64
SSPCON1.SSPM2 = 0
SSPCON1.SSPM1 = 1
SSPCON1.SSPM0 = 0

End Proc                                        

Proc write_dta()
altmtr_cs = 0
WaitUs 1
    SSPBUF = wr_adr
    While Not SSPSTAT.BF
    Wend
WaitUs 1
    SSPBUF = wr_byte
    While Not SSPSTAT.BF
    Wend
altmtr_cs = 1

End Proc                                        

Function read_dta(rd_adr As Byte) As Byte
altmtr_cs = 0
WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
WaitUs 1
    SSPBUF = rd_byte
    While Not SSPSTAT.BF
    Wend
    read_dta = SSPBUF
altmtr_cs = 1

End Function
 

Attachments

jjw

Joined Dec 24, 2013
798
SSPSTAT.BF = 0 <--- .BF is read only
It will be zeroed when SSPBUF is read?

I think in burst read you write the first address once and do continuos reads.The address is incremented automatically.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,257
SSPSTAT.BF = 0 <--- .BF is read only
It will be zeroed when SSPBUF is read?

I think in burst read you write the first address once and do continuos reads.The address is incremented automatically.
Hi J,
I got a bit diverted by this: https://github.com/BoschSensortec/BMP2-Sensor-API/ I read that there was an error and this should be the latest, but I can't read it fully.

I've changed the CODE, trying to get BURST READ, here:
NOTE: Now the C/S is at the beginning and at the end of all of the READ registers.
I'm not sure how to READ the Regiters as shown in the D/S.
C
Code:
main:  '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Toggle rled
WaitMs 1000

'READ [Function read_BMP280]'????????????????????????
Call Function read_BMP280()  '???????????????????????????????
Hserout "press_msb_dta  ", #press_msb_dta, CrLf
Hserout "press_lsb_dta  ", #press_lsb_dta, CrLf
Hserout "press_xlsb_dta  ", #press_xlsb_dta, CrLf, CrLf
Hserout "temp_msb_dta  ", #temp_msb_dta, CrLf
Hserout "temp_lsb_dta  ", #temp_lsb_dta, CrLf
Hserout "temp_xlsb_dta  ", #temp_xlsb_dta, CrLf, CrLf

Goto main
   
End                                              

'----------- PERIPHERAL UTILITIES  -------------
'HC-12 INITIALISATION
init_HC12:
                                    'PRESS BUTTON (OR RADSET)
    radset = RADIO_COMMAND_MODE  'SET HC-12 COMMAND ON
    Hserout "AT+C002", CrLf  '433.800
    radset = RADIO_DATA_MODE  'SET HC-12 RUN ON
    Return
'------------------

Proc spi_init()  'looks like straight from the datasheet
'4620
TRISC.3 = 0  'SCK to Slave
TRISC.4 = 1  'MISO
TRISC.5 = 0  'MOSI

'MODE 0,0
SSPSTAT.SMP = 0  'Input data sampled at middle of data output time
SSPSTAT.CKE = 0  '1 Output data changes on clock transition from idle to active
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 = 1  '[1]  'Clock Idle high, Active low [Clock Idle Low, Active High]
SSPCON1.SSPM3 = 0  '0010 = SPI Master mode, clock = FOSC/64
SSPCON1.SSPM2 = 0
SSPCON1.SSPM1 = 1
SSPCON1.SSPM0 = 0

End Proc                                        

Proc write_dta()
altmtr_cs = 0
WaitUs 1
    SSPBUF = wr_adr
    While Not SSPSTAT.BF
    Wend
WaitUs 1
    SSPBUF = wr_byte
    While Not SSPSTAT.BF
    Wend
altmtr_cs = 1

End Proc                                        

Function read_dta(rd_adr As Byte) As Byte
altmtr_cs = 0
WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
WaitUs 1
    SSPBUF = rd_byte
    While Not SSPSTAT.BF
    Wend
    read_dta = SSPBUF
altmtr_cs = 1

End Function                                    

Function read_BMP280(rd_adr As Byte) As Byte

altmtr_cs = 0

rd_adr = 0xf7  '0xF7 press_msb_adr
press_msb_dta = read_dta(rd_adr)
'rd_adr = 0xf8  '0xF8 press_msb_adr
press_lsb_dta = read_dta(rd_adr)
'rd_adr = 0xf9  '0xF9 press_msb_adr
press_xlsb_dta = read_dta(rd_adr)
'rd_adr = 0xfa  '0xFA press_msb_adr
temp_msb_dta = read_dta(rd_adr)
'rd_adr = 0xfb  '0xFB press_msb_adr
temp_lsb_dta = read_dta(rd_adr)
'rd_adr = 0xfc  '0xFC press_msb_adr
temp_xlsb_dta = read_dta(rd_adr)

WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
WaitUs 1
    SSPBUF = rd_byte
    While Not SSPSTAT.BF
    Wend
    read_dta = SSPBUF
   
altmtr_cs = 1

End Function
 

Thread Starter

camerart

Joined Feb 25, 2013
3,257
Hi,
In #23 I have [ Function read_BMP280 ] I think this may be wrong, am I correct?
Does a FUNCTION only give out 1x READing, where I'm trying to get 6x READings.
What to do?
C
 

jjw

Joined Dec 24, 2013
798
SSPSTAT.BF has to be cleared before sending.

You had a working version with Oshonsoft SPI functions.
Replace:
SPISend adr -> SPI_write(adr)
SPISend data -> SPI_write(data)
SPIReceive data -> SPI_read(data)
where SPI_write, SPI_read are functions or procedures using hardware SPI.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,257
SSPSTAT.BF has to be cleared before sending.

You had a working version with Oshonsoft SPI functions.
Replace:
SPISend adr -> SPI_write(adr)
SPISend data -> SPI_write(data)
SPIReceive data -> SPI_read(data)
where SPI_write, SPI_read are functions or procedures using hardware SPI.
Hi J,
You have totally floored me.
I always get mixed up between HW and SW, and I don't even know which type Oshonsoft use, but Here's a link from 2019: https://forum.allaboutcircuits.com/...mp280-in-oshonsoft.162449/page-3#post-1426015
Where I'm sure I started adopting the SSPBUF method of getting DATA, are you saying that I should go back and start again using the Oshonsoft SPI method?
:(
C.
 

jjw

Joined Dec 24, 2013
798
No, I mean that you can replace the Oshonsoft Basic language functions, which don't use the SSPBUF.
If I remember correctly you had a working version of a BMP280, which used Oshonsoft functions SPISend, SPIReceive, but did not have a working program using SSPBUF.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,257
Hi J,

No, I mean that you can replace the Oshonsoft Basic language functions, which don't use the SSPBUF.
If I remember correctly you had a working version of a BMP280, which used Oshonsoft functions SPISend, SPIReceive, but did not have a working program using SSPBUF.
Hi J,
Yes, I have been almost there for a a couple of times, but as I can't remember what paths I took to get here, I had better carry on down this one for a while, till I give in, to any suggestions.
So alongward and upward:)
C
 

ericgibbs

Joined Jan 29, 2010
16,741
hi C,
For reference only,
More bugs in the IDE.. 18F2321
No Hserout , No ADC ...

Avoid using this PIC type until Vlad fixes these problems

E
 
Top