Strange error when programming PIC for BMP280

jjw

Joined Dec 24, 2013
823
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.
In #24 the xlsb has ok values for temperature and pressure and change between measurements which is normal.
What has been changed after it?
#37 looks like it is not measuring at all.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
In #24 the xlsb has ok values for temperature and pressure and change between measurements which is normal.
What has been changed after it?
#37 looks like it is not measuring at all.
Hi J,
I think this is the program in #24 READings in JPG (before your suggestion)

The first change was your suggestion in #24, the program uses a FUNCTION, I changed it from peripheral to DATA as suggestion

I'll go back to this one, before your suggestion, with correct READings, and change it if you suggest. This one has no CS between each batch of 3x REG READs
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,830
I have not seen periph_rd_alt function.
Hi J,
I forgot! I make lots of changes to solve these puzzles.

I added 2x extra FUNCTIONs over time. Later I will try to minimise them by consolidation later.

Here are the FUNCTIONs:
C
Code:
Function rd_nxt_reg() As Byte
WaitUs 1
    SSPBUF = 0
    While Not SSPSTAT.BF
    Wend
    rd_nxt_reg = SSPBUF
End Function                                     
'-------------------------------SPI FUNCTIONS-------------------------------------------------
Function periph_wr(wr_adr As Byte, wr_data As Byte) As Byte

WaitUs 1  '/// maybe not needed
SSPBUF = wr_adr
While Not SSPSTAT.BF  'PIC
Wend
WaitUs 1
SSPBUF = wr_data
While Not SSPSTAT.BF  'PIC
Wend

End Function                                     

Function periph_rd(rd_adr As Byte) As Byte
WaitUs 1
SSPBUF = rd_adr
While SSPSTAT.BF  'PIC
Wend
WaitUs 1
SSPBUF = 0  'Dummy BYTE
While Not SSPSTAT.BF  'PIC
Wend
periph_rd = SSPBUF

'While drdy_pin  'ADDED??????????????????????????
'Wend

End Function                                     

'############################################'******ADDED**************?????????
Function periph_rd_alt(rd_adr As Byte) As Byte

'WaitUs 1
SSPBUF = rd_adr
While Not SSPSTAT.BF  'PIC
Wend
'WaitUs 1'Below
While STATUS.3  'Must have this or WAIT
Wend

SSPBUF = 0  'Dummy BYTE
While Not SSPSTAT.BF  'PIC
Wend
periph_rd_alt = SSPBUF

End Function                                     
'#######################################
 

Beau Schwabe

Joined Nov 7, 2019
186
This sounds like the OSCCON register is not being initialized in your code. This has bit me a few times on other processors where now I make it a habit to force the oscillator to run the way I want it to.

Here is what happens: When you program the device "NEW" everything works as you expect. If you are powering from the PicKit3 or some other programmers, and you reset the micro. The micro 'sees' this as a conditional reset that puts it into a default clock mode of 1MHz.

See page #28 and #33 of the datasheet... (Note #3)
Reference: https://ww1.microchip.com/downloads/en/DeviceDoc/40001303H.pdf

1633201578267.png
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
This sounds like the OSCCON register is not being initialized in your code. This has bit me a few times on other processors where now I make it a habit to force the oscillator to run the way I want it to.

Here is what happens: When you program the device "NEW" everything works as you expect. If you are powering from the PicKit3 or some other programmers, and you reset the micro. The micro 'sees' this as a conditional reset that puts it into a default clock mode of 1MHz.

See page #28 and #33 of the datasheet... (Note #3)
Reference: https://ww1.microchip.com/downloads/en/DeviceDoc/40001303H.pdf

View attachment 249345
Hi B,
This has caught me out as well, so I changed to Crystal oscillator, and I'm pretty sure no need for OSCCON.
Thanks,
C.
 

Beau Schwabe

Joined Nov 7, 2019
186
Hi B,
This has caught me out as well, so I changed to Crystal oscillator, and I'm pretty sure no need for OSCCON.
Thanks,
C.
External crystal or not, a Power ON reset will put the micro in a low power 'safe mode' of 1MHz ... See OSCCON on page #57 Table 4-4 of the PDF.

All you need to do is force OSCCON to the value you want at the beginning of your program in your initialization section.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
External crystal or not, a Power ON reset will put the micro in a low power 'safe mode' of 1MHz ... See OSCCON on page #57 Table 4-4 of the PDF.

All you need to do is force OSCCON to the value you want at the beginning of your program in your initialization section.
Hi B,
I looked into the OSCCON section of the D/S (different Page No) it's quite a mine field, so I'll have to come back to it later, unless you can give me the settings for OSCCON, and I'll add it in, thanks.
It also mentions RESET, which can be different depending, since removing my RESET things have improved.

My programmer has a simulator, with settings that make the clock run slower so we can watch, I occasionally leave this on slow, so I added ON/OFF LED ealry in the program, so I see a 1Sec switch, and know it's set correctly.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
I searched a little bit and found that you had 2 years ago a program using SSPBUF with sensible results.
https://forum.allaboutcircuits.com/...0-and-bmp280-in-oshonsoft.162449/post-1427699

Maybe you should check the SSPSTAT, SSPCONFIG1 and BMP280 setup from that program ( msg #100 in that thread )
Hi E,
I found the program. I've changed a lot of things since then (a bit tidier) also the PCB has changed, so quite a big job to get it onto this PCB.
I checked SSPSTAT CKE=1 CKP=0 the opposite of today. Today's settings match the D/S.
SSPCONFIG1 L=same H=0x02 Today H=0x06 Crystal +PLL = 32MHz
DEFINE Clock frequency = 8 Today =32

Did I miss anything?
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
External crystal or not, a Power ON reset will put the micro in a low power 'safe mode' of 1MHz ... See OSCCON on page #57 Table 4-4 of the PDF.

All you need to do is force OSCCON to the value you want at the beginning of your program in your initialization section.
Hi B,
I've had another look, but I don't see any reference to the external crystal in the OSCCON area of the D/S. Are you sure it relates to a XTL?
C
 

jjw

Joined Dec 24, 2013
823
Hi E,
I found the program. I've changed a lot of things since then (a bit tidier) also the PCB has changed, so quite a big job to get it onto this PCB.
I checked SSPSTAT CKE=1 CKP=0 the opposite of today. Today's settings match the D/S.
SSPCONFIG1 L=same H=0x02 Today H=0x06 Crystal +PLL = 32MHz
DEFINE Clock frequency = 8 Today =32

Did I miss anything?
C.
What does this mean: SSPCONFIG1 L=same H=0x02 ?
"Settings match the D/S" which D/S ?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
What does this mean: SSPCONFIG1 L=same H=0x02 ?
"Settings match the D/S" which D/S ?
Hi J,I sShould have been clearer!

2019 PROG Looking at the Oshonsoft manual, not D/S
SSPSTAT.CKE=1
SSPSTAT.CKP=0
CONFIG1L = 0x00
CONFIG1H = 0x02'EXT 8MHz
DEFINE CLOCK FREQUENCY 8

2021 PROG
SSPSTAT.CKE=0
SSPSTAT.CKP=1
CONFIG1L = 0x00
CONFIG1H = 0x06'EXT 8MHz + PLL = 32MHz
DEFINE CLOCK FREQUENCY 32
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi E,
This looks like before I switched to Crystal control, and used OSCCON.

Over time I try not to go back to older programs, if I can avoid it, as changes especially those small ones, can get overwritten. Now I try to fix today's program, as best as I can. (or should I say we)
Having said that I have the FULL program that this program will be intergrated with, but that's more structure related.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
I did say this error was intermittent! Today all of the tests have worked? 183+183

I'm still getting the same results as previous posts, trying different ideas.
I'm now trying BURST READ.
Here is the Multiple BYTE READ Figure 11, but it shows 0xF6 as the Control BYTE. It is shown for I2C and I found a reference to it is with an earler module BMP180, could this be left over from that, or is it correct?
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
It's possible that I've got it to BURST READ ALT? The JPGshows.
The TP and PR are still incorrect.

Is the JPG easier to read, than previously mentioned?
C
 

Attachments

Top