Strange error when programming PIC for BMP280

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I'm programming an 18F46K20 Pic, with a peripheral BMP280 barometer chip.

I'm using Oshonsoft, but in this case using HW SSPBUF DATA exchange.

I have the program READing the BMP280 ok, but this is intermittent, once it fails and shows zero results, it won't work again, until I program and older program first, then the latest prgram again and the latest will always work. This older program is nothing special, and I've compared it with any later working program, but is has some 'magic' about it.

Can anyone tell me how to test what's going on please.
Cheers, Camerart.
 

BobTPH

Joined Jun 5, 2013
8,813
Are you saying that even if you reprogram it with the same program it will not work again?

Have you removed all power and waited long enough fir capacitors to discharge?

Does the barometer chip havre non-volatile storage that the new program might have corrupted?

Bob
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Are you saying that even if you reprogram it with the same program it will not work again?

Have you removed all power and waited long enough fir capacitors to discharge?

Does the barometer chip havre non-volatile storage that the new program might have corrupted?

Bob
Hi B,
Yes, program with working program, is works, turn it OFF/ON and it doesn't work. Program it with the magic program it works, but not as advanced, leave ON, program it with latest program it works, OFF/ON it doesn't work.

2x Different computers, using Pickit3 or Mplab programmer, different cables, same.

Wait long enough for the capacitors to discharge, then what?

Ah, NVM, I wondered what that meant! The BMP280 has an ID, and has NVM parameters for setting up. All programs always READ the ID, and Set up parameters ok.
C
 

BobTPH

Joined Jun 5, 2013
8,813
The fact that it cannot be re-programmed with the same program and behave the same way points to some non-volatile storage being corrupted. It could be in the pic or in the sensor.

My guess is that the old program is setting something non-volatile that the new program relies upon and sometimes clobbers.

Bob
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
The fact that it cannot be re-programmed with the same program and behave the same way points to some non-volatile storage being corrupted. It could be in the pic or in the sensor.

My guess is that the old program is setting something non-volatile that the new program relies upon and sometimes clobbers.

Bob
Hi B,
OK, is NVM where the program is stored?
I've tried searching for where is a PIC ID and factory set DATA is stored, but no luck so far.

There is a WHILE STATUS.3
WEND
The BIT is 0 when the DATA is there.
I tried adding a NOT, and that stalled the program so WHILE seems correct.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Yes

Yes, as well as EEROM on some pics. I think it is more likely settings in your sensor that is the problem. I would compare the code to set it up in the two programs.

Bob
Hi B,
I have found possible differences in both programs, that could matter.

Also There is SSPBUF, in case you don't know this is a buffer. I'm just learning about it, but when it is READ, then a dummy 0 BYTE is sent and is exchnged for DATA. [ Like this: SSPBUF = 0, DATA = SSPBUF ] In the program is a check that DATA is ready, so I SEND a 0 BYTE then READ it, this error is sometimes meaningful DATA or 0. I'm wondering if it could be READing the 0 instead of the meraningful DATA?
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi B,
I've been checking 'everything' and trying small changes to see what's happenings, and always getting odd results.
In the BMP280 initialisation, I start it with a RESET, and noticed a long forgotten comment: 'Is this necessary' I removed it and it appears to have cured the problem. I've tried reprogramming, switching off/on, all good.
Cheers, C.
 

BobTPH

Joined Jun 5, 2013
8,813
What that suggests ti ne is that the old program was setting some persistent (non-volatile) parameter in the chip that is reset to factory default when do the “reset”, I worry that your program is only working now because the setting now remains from the old program. If you were to replace the sensor or build another one, it would not work. I would continue to look at all of the setup done by the old program and make sure it us the same in the new one.

Bob
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
What that suggests ti ne is that the old program was setting some persistent (non-volatile) parameter in the chip that is reset to factory default when do the “reset”, I worry that your program is only working now because the setting now remains from the old program. If you were to replace the sensor or build another one, it would not work. I would continue to look at all of the setup done by the old program and make sure it us the same in the new one.

Bob
Hi B,
I tried a second BMP280. Note different parameter READings and READ = WRITE, which it hasn't been doing.
I'll note what you suggest.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
No need to rewrite.
At first look I did not understand that the picture is about success:)
Morning J,
True, it is now READing the registers. :) You will see that on the diagram, it is READing the compass also. The compass calculation is good, and the results, are lots more consistant than before SSPBUF another :) The TP and PR results are not there yet, so I won't get bored today.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I've am now READing F7 to FC individually, but the D/S strongly advises to READ using BURST, but first I have to sort out the order of using the DATA.
e,g, 0XF7 is Pressure MSB, in the PIC D/S it uses HB LB and 3B, I've tried using the sequence in the OSH programs, but this doen't seem to calculate.

I'm pretty sure it just need puttung in order to work
C
 

ericgibbs

Joined Jan 29, 2010
18,766
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
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
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,



E
Study the above breakdown so that you understand the 'weighting' location of the bytes in LONG add WORD
Hi E,
I'm going to a mate's later who is good at untangling, then we will read your post.

Regarding How can that be correct.? Here is the BMP280 Register map, showing where I got the MSB from. This shows the order to READ the registers, so we have to translate from MSB etc to either HB LB or 3B
Thanks, C.
 

Attachments

jjw

Joined Dec 24, 2013
823
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)
 
Top