BME280 Sensor

JohnInTX

Joined Jun 26, 2012
4,014
Have you seen this thread?
https://forum.allaboutcircuits.com/threads/bmp280-digital-pressure-sensor.167356/

If you look at the bottom of this page, there are also other references to the BME280.

The pressures, temperatures etc. are loaded with continuously updated values placed in addressable registers.
Setup and reading those pressures and temperatures is accomplished by reading and writing the registers.

A single read or write transaction is framed by the CSB/ chip select (for SPI) and can read or write multiple registers in one transaction.

To write one register requires two bytes, a control byte with the register address and RW=0 followed by the value to be written into the register.
Each register write requires 2 bytes, a control byte and a data byte.
Multiple registers can be written in the same transaction but each register still requires the two bytes, control byte with register address and the data byte. There is no auto-increment of register addresses.

To read one or more registers, a control byte is sent with the register address to read and RW=1.
The next byte is the addressed register's value.
Clocking in more bytes will read the next contiguous register - the address auto increments.

That's about it.
 
Last edited:

Thread Starter

champ1

Joined Jun 4, 2018
119
The pressures, temperatures etc. are loaded with continuously updated values placed in addressable registers.
Setup and reading those pressures and temperatures is accomplished by reading and writing the registers.

A single read or write transaction is framed by the CSB/ chip select (for SPI) and can read or write multiple registers in one transaction.

That's about it.
1583115375933.png

To write one register requires two bytes, a control byte with the register address and RW=0 followed by the value to be written into the register.
Each register write requires 2 bytes, a control byte and a data byte.
page 27 in datasheet

Register Name : hum_lsb, Register Address : 0xFE
Register Name : hum_msb , Register Address : 0xFD

so now we will send two bytes (control byte = 01110100 = 0x74 and register address = 0xFE)

To read one or more registers, a control byte is sent with the register address to read and RW=1.
so now we will send two bytes to read sensor (control byte = 11110100 = 0xF4 and Register Address : 0xFE)
 

JohnInTX

Joined Jun 26, 2012
4,014
so now we will send two bytes (control byte = 01110100 = 0x74 and register address = 0xFE)
The control byte contains the register address, you don't send a second byte to address a register. The second byte contains register data. Look at the bits in the control byte in the figure you posted above.

Edit: note that the register address in the control byte is only 7 bits. The MSbit is the read/write control bit. The register address always assumes the most significant bit is 1 so 0x74 is really addressing register 0xF4.
Control byte:
0x74 writes register F4h
0xF4 reads register F4h
 
Last edited:

Thread Starter

champ1

Joined Jun 4, 2018
119
The control byte contains the register address, you don't send a second byte to address a register. The second byte contains register data.
To write register "ctrl_meas" requires two bytes, control byte and a data byte. Page 29 Table 23, 24,and 25

Control byte = 0xF4
data byte = ?

SPI_SEND (0xF4, data byte)

What will be register data for register "ctrl_meas" ?
 

Thread Starter

champ1

Joined Jun 4, 2018
119
hi Champ,
Register 0xF4 does not measure a parameter it sets the data options for the device.
Ref d/s clip.
1583141194261.png
When MCU transmitting data What would be Data byte [b7 to b0] ?
When MCU Receiving data What would be Data byte [b15 to b8] ?
 

ericgibbs

Joined Jan 29, 2010
9,871
hi,
The data is 16 bits, split into two 8 bit bytes, high byte and low byte of a 16 bit Word.
Is this what you are asking.?
E
 

Thread Starter

champ1

Joined Jun 4, 2018
119
hi,
The data is 16 bits, split into two 8 bit bytes, high byte and low byte of a 16 bit Word.
Is this what you are asking.?
E
length of data byte is 16 bits What the value should I send to data byte register to write register (hum_lsb, hum_msb )
 

LesJones

Joined Jan 8, 2017
2,611
The registers hum_lsb & hum_msb (Humidity registers) are read only so you cannot write to them. If you look at the table on the datasheet just below the table you posted in post #3 you will see whiche register you can write to. There is a lot of information on the data sheet that you need to read to understand how to read the data from the registers and display the information. If you only want the humidity reading that is much simpler than temperature an pressure readings. I am working on reading the data from a BMP280 (Which is similar.) with a PIC12F1840. As the data sheet only gives details of the calculations in terms of a "C" program I am having difficulty as I don't understand "C"

Les.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
9,871
hi champ,
I see that you are referring to the Humidity regs, as Les points out these are READ only.
Read 0XFD and 0XFE. ie: High 8 bit byte and Low 8 bit byte, to a 16bit WORD.

E
 

jjw

Joined Dec 24, 2013
539
The registers hum_lsb & hum_msb (Humidity registers) are read only so you cannot write to them. If you look at the table on the datasheet just below the table you posted in post #3 you will see whiche register you can write to. There is a lot of information on the data sheet that you need to read to understand how to read the data from the registers and display the information. If you only want the humidity reading that is much simpler than temperature an pressure readings. I am working on reading the data from a BMP280 (Which is similar.) with a PIC12F1840. As the data sheet only gives details of the calculations in terms of a "C" program I am having difficulty as I don't understand "C"

Les.
I have converted a BMP280 Python program from GitHub to Oshonsoft Basic.
It is a barebones calculation of temperature and pressure without setup.
I could post it here, if you are interested.
The original Python program is somewhere in Electrotech Online, year 2018?
 

LesJones

Joined Jan 8, 2017
2,611
Hi jjw,
Thanks for the offer but your comment about Python prompted me to search for the BMP280 with the Raspberry Pi. Although I know even less about Python than "C" I found a Python program and the calculations were more understandable than the "C" programs on the data sheet. I think I have probably guessed wrongly how "C" deals with the sign bit when shifting signed numbers. For a right shift if the most significant bit was set was set I set the carry bit in the status register instead of clearing it. For a left shift I assume that the sign bit is not changed. so for a 32 bit number bit 31 is not changed but bit 30 is lost. I have also assumed that zero is shifted into bit 0. I have the temperature calculation working correctly but the pressure calculation is giving incorrect results. One thing that did catch me out is that the 2 byte correction values are stored in the reverse sequence to the raw temperature and pressure values. (The least significant byte is stored in the lower register address.

Les.
 

LesJones

Joined Jan 8, 2017
2,611
Thanks for the offer but the problem is now solved. I missed typing a line of code which loads the required value into the configuration register so the config register was left at some random value
Code:
;Write config register
    MOVLW    0x40        ; Value to be written to BMP config register
    MOVFW   BMP_Wdata       ;This was the line I missed out. ****
    MOVLW    Conf_reg    ;Config register address (0xF5)
    Call    Write_BMP280
This is the device. It communicates using an HC-12 transceiver. To get a reading I just transmit it's address (It's address is #A) and it responds with an ASCII string giving the temperature and pressure readings I have other remote sensors some with DHT22s reading temperature and humidity and some with IN219s reading voltage and current.
This is the BMP280 unit.

IMG_1674.JPGIt uses a PIC12F1840.

Les.
 

camerart

Joined Feb 25, 2013
1,937
Thanks for the offer but the problem is now solved. I missed typing a line of code which loads the required value into the configuration register so the config register was left at some random value
Code:
;Write config register
    MOVLW    0x40        ; Value to be written to BMP config register
    MOVFW   BMP_Wdata       ;This was the line I missed out. ****
    MOVLW    Conf_reg    ;Config register address (0xF5)
    Call    Write_BMP280
This is the device. It communicates using an HC-12 transceiver. To get a reading I just transmit it's address (It's address is #A) and it responds with an ASCII string giving the temperature and pressure readings I have other remote sensors some with DHT22s reading temperature and humidity and some with IN219s reading voltage and current.
This is the BMP280 unit.

View attachment 204645It uses a PIC12F1840.

Les.
Hi L,
A neat solution.
C.
 
Top