Hi, Thanks again for your help. I try to modify the common.c file to adapt to my microcontroller. I would like to ask you if the structure is correct (not the single function on the code but the general struscture), because when I built the program I have no problem, but then the code returns error. In particular, init_interface function works correctly, but then init funcrion, set_config function ecc return error -2: communication error static const nrf_drv_twi_t i2c_instance = NRF_DRV_TWI_INSTANCE(0); BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) { int8_t err = nrf_drv_twi_rx(&i2c_instance, reg_addr, reg_data, len); return err; } BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) { int8_t err = nrf_drv_twi_tx(&i2c_instance, reg_addr, reg_data, len, false); return err; } void bme68x_delay_us(uint32_t period, void *intf_ptr) { nrf_delay_us(period); } int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf) { int8_t rslt = BME68X_OK; uint8_t reg_addr; const uint8_t *reg_data; uint32_t len; void *intf_ptr; if (bme != NULL) { /* Bus configuration : I2C */ if (intf == BME68X_I2C_INTF) { printf("I2C Interface\n"); dev_addr = BME68X_I2C_ADDR_LOW; bme->read = bme68x_i2c_read; bme->write = bme68x_i2c_write; bme->intf = BME68X_I2C_INTF; //here I initialize the I2c component const nrf_drv_twi_config_t i2c_instance_config = { .scl = SCL_PIN, .sda = SDA_PIN, .frequency = NRF_TWI_FREQ_100K, .interrupt_priority = 0}; rslt = nrf_drv_twi_init(&i2c_instance, &i2c_instance_config, NULL, NULL); if (rslt) { printf("Error %d: Initialization of I2C connection failed!\n", rslt); } //enable I2c instance nrf_drv_twi_enable(&i2c_instance); } bme->delay_us = bme68x_delay_us; bme->intf_ptr = &dev_addr; bme->amb_temp = 25; /* The ambient temperature in deg C is used for defining the heater temperature */ } else { rslt = BME68X_E_NULL_PTR; } return rslt; } Thanks again
... View more