I tried to follow the example provided by Bosch, but the self-test still reported errors -5 BME68X_E_SELF_TEST . Since the self-test example provided by Bosch is based on the stm32 F4 platform, I replaced the I2C driver code. i use the NEF52840 microcontroller. The code is as follows.Does anyone know what I did wrong? void twi_BME680_init(void) { ret_code_t err_code; const nrf_drv_twi_config_t twi_BME680_config = { .scl = TWI_BME_SCL_M, .sda = TWI_BME_SDA_M, .frequency = NRF_DRV_TWI_FREQ_100K, .interrupt_priority = APP_IRQ_PRIORITY_HIGH, .clear_bus_init = false }; err_code = nrf_drv_twi_init(&BME680_twi, &twi_BME680_config, NULL, NULL); APP_ERROR_CHECK(err_code); nrf_drv_twi_enable(&BME680_twi); } BME68X_INTF_RET_TYPE bme680_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) { uint8_t device_addr = *(uint8_t*)intf_ptr; (void)intf_ptr; return BME680_write_byte(device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len); } BME68X_INTF_RET_TYPE bme680_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) { uint8_t device_addr = *(uint8_t*)intf_ptr; (void)intf_ptr; return BME680_read_byte(device_addr, reg_addr, reg_data, (uint16_t)len); } void BME_delay_us(uint32_t period, void *intf_ptr) { (void)intf_ptr; nrf_delay_us(period); } void bme680_intf_init() { /* Initialize BME680 structure */ bme680.variant_id = BME68X_VARIANT_GAS_LOW; static Bme_addr = BME68X_I2C_ADDR_LOW;//0x76 bme680.chip_id = BME68X_CHIP_ID; bme680.read = bme680_i2c_read; bme680.write = bme680_i2c_write; bme680.intf = BME68X_I2C_INTF; bme680.delay_us = BME_delay_us; bme680.intf_ptr = &Bme_addr; bme680.amb_temp = 25; } int main(void) { twi_BME680_init();//Initializes the I2C bme680_intf_init(); rslt = bme68x_init(&bme680); /* Initialize BME680 sensor */ bme68x_check_rslt("bme68x_init", rslt); rslt =bme68x_selftest_check(&bme680); bme68x_check_rslt("bme68x_selftest_check", rslt); while(1) {} }
... View more