Hello
I have nRF52832 custom board and have BME280 sensor connected to I2C/TWI
Whatever I do I get same reading (for 3 different sensors)
I'm constantly reading same values
Fullscreen
1
2
3
4
<00> info>app: TWI device detected at address 0x76
<00> debug> app: Pressure 64275
<00> debug> app: Temperature 2239
<00> debug> app: Humidity 96241
and here is my I2C/TWI init
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void twi_init(void)
{
ret_code_t err_code;
const nrfx_twim_config_t i2c_config =
{
.scl = I2C_SCL_PIN,
.sda = I2C_SDA_PIN,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY,
.hold_bus_uninit = NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT
};
err_code = nrfx_twim_init(&i2c, &i2c_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
if (NRF_SUCCESS == err_code)
{
nrfx_twim_enable(&i2c);
}
}
also I2C read and write methods
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int8_t twi_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
ret_code_t err_code;
const nrfx_twim_xfer_desc_t xfer_desc = NRFX_TWIM_XFER_DESC_TXRX(id, ®_addr, sizeof(reg_addr), data, len);
err_code = nrfx_twim_xfer(&i2c, &xfer_desc, 0);
return (err_code == NRF_SUCCESS) ? 0 : -1;
}
int8_t twi_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
ret_code_t err_code;
const nrfx_twim_xfer_desc_t xfer_desc = NRFX_TWIM_XFER_DESC_TX(id, data, len);
err_code = nrfx_twim_xfer(&i2c, &xfer_desc, 0);
return (err_code == NRF_SUCCESS) ? 0 : -1;
}
and finally BME280 reading
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bme280_data_t twi_bme280_read()
{
int8_t rslt = BME280_OK;
uint8_t settings_sel;
bme280_data_t ret;
bme280.settings.osr_h = BME280_OVERSAMPLING_1X;
bme280.settings.osr_p = BME280_OVERSAMPLING_16X;
bme280.settings.osr_t = BME280_OVERSAMPLING_2X;
bme280.settings.filter = BME280_FILTER_COEFF_16;
bme280.settings.standby_time = BME280_STANDBY_TIME_62_5_MS;
settings_sel = BME280_OSR_PRESS_SEL;
settings_sel |= BME280_OSR_TEMP_SEL;
settings_sel |= BME280_OSR_HUM_SEL;
settings_sel |= BME280_STANDBY_SEL;
settings_sel |= BME280_FILTER_SEL;
rslt = bme280_set_sensor_settings(settings_sel, &bme280);
if (rslt != BME280_OK) {
NRF_LOG_DEBUG("bme280_set_sensor_settings (%d).", rslt);
If anyone can help me what I'm doing wrong
I'm going in circles and can't figure it out, but when connect to Arduino sensor works
so is not hardware as is detected on I2C bus (as you can see in log)