08-20-2020 11:07 PM - edited 08-20-2020 11:19 PM
What could be the problem, when after power-on reset I get temperature and pressure right, but humidity value is the reset value (0x8000).
The next read returns the reset values for all of them.
The communication looks good (saleae) taken from the BME280 board pins.
Could that be caused by floating CSB? Too frequent reading? Bad oversampling setting? I'm using XinaBox SW1 with threads soldered on the connection pads and DuPonts in the other end. The processor is STM32L425 also running with VCC 1.8V.
It's hard to imagine how that could be power issue, because of the low current consumption compared the 3A output of the power supply.
I'm using 1.8V for Vcc and Vccio, though.
08-21-2020 07:50 PM - edited 08-21-2020 07:51 PM
I mask and OR the bits in the register.
I also took a copy of your humidity compensation function to try, but it also gave zero for that raw value (0x5295).
08-24-2020 10:41 AM - edited 08-24-2020 10:42 AM
#define BME280_ADDR 0xEC // 111011xR
/* registers */
#define BME280_RESET 0xE0
#define BME280_CTRL_HUM 0xF2
#define BME280_STATUS 0xF3
#define BME280_CTRL_MEAS 0xF4
#define BME280_CONFIG 0xF5
#define BME280_PRESS_MSB 0xF7
/* values */
#define BME280_CFG_OSRSH 0x01
#define BME280_CFG_OSRST 0x01
#define BME280_CFG_OSRSP 0x01
#define BME280_CFG_T_SB 0x04 /* every 500 ms */
#define BME280_CFG_FILT 0x00
#define BME280_MODE_NORMAL 0x03
#define BME280_MODE_SLEEP 0x00
#define BME280_MODE_FORCED 0x01
void BME280_init(void)
{
uint8_t tmp;
/* reset */
write_reg(BME280_ADDR, BME280_RESET, 0xB6);
HAL_Delay(2);
tmp = read_reg(BME280_ADDR, BME280_STATUS);
while ((tmp & 0x1) != 0)
{
/* wait until NVM reading is finished */
tmp = read_reg(BME280_ADDR, BME280_STATUS);
}
/* read cal data */
BME280_read_cal_data();
/* configure */
tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 3);
write_reg(BME280_ADDR, BME280_CONFIG, (((BME280_CFG_T_SB & 7) << 5) || ((BME280_CFG_FILT & 7) << 2)));
write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
write_reg(BME280_ADDR, BME280_CTRL_HUM, (BME280_CFG_OSRSH & 7));
write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
}
(The code tag doesn't seem to work.)
08-24-2020 07:29 PM
1. no need to read status bit during sensor reset. you can check the chip id. if chip id matched the desired value, means sensor reset is done sucessfully
2. the correct flow should be as following:
tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 0x00);
write_reg(BME280_ADDR, BME280_CTRL_HUM, (BME280_CFG_OSRSH & 7));
write_reg(BME280_ADDR, BME280_CONFIG, (((BME280_CFG_T_SB & 7) << 5) || ((BME280_CFG_FILT & 7) << 2)));
write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
tmp = ((BME280_CFG_OSRST & 7) << 5) || ((BME280_CFG_OSRSP & 7) << 2) || (BME280_MODE_NORMAL & 3);
write_reg(BME280_ADDR, BME280_CTRL_MEAS,tmp);
when the mode register is changed, the measurement is suppose to start directly. So it is better to set the configuration first, then change the working mode afterwards.
Then you should have the non zero in the ADC register of sensor.
08-25-2020 06:09 AM - edited 08-25-2020 06:36 AM
Instead of polling of chip ID I do:
while ((tmp & 0x1) != 0)
{
/* wait until NVM reading is finished */
tmp = read_reg(BME280_ADDR, BME280_STATUS);
}
Does this: BME280_MODE_NORMAL & 0x00 mean the chip is to put to sleep?
And there is a non-zero value in humidity register(s), but it's such that the compensation algorithm returns zero.
buff[6] uint8_t 0x52 (Hex)
buff[7] uint8_t 0x95 (Hex)
How many bit ADC is used for humidity? The value (0x5295) has 15 bits.
It seems like the result is zeroed at:
var5 = (var5 < 0 ? 0 : var5);
(humidity compensation code from your repo)
08-25-2020 07:09 PM
Yes, if the mode [0:1] shows 0 means sensor is in sleep mode.
But i don't suggest you to check these bits and status bits just after reset sensor. I will recommend you to check chip id instead after power cycle the sensor.
16 bits ADC value are used to calculate humidity.
Can you check again your calibration parameters? And also try to use the latest API from our Github.