nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

TWI comunication to read/write register

Hi,

I'm using nRF52832 with BME688 Bosch sensor. I'm using APIs that are provided by Bosch, but I have to adapt them to nRF52832 microcontroller.

In particular, I'm not sure if the comunication with TWI is correct.

I write this two functions to read and write Bosch's registers

BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
    uint8_t dev_addr = *(uint8_t*)intf_ptr; 
    ret_code_t ret_code;
    ret_code = nrf_drv_twi_tx(&i2c_instance, dev_addr, &reg_addr,1,false);
    if(ret_code != NRF_SUCCESS)
    {
            return ret_code;
    }
    ret_code = nrf_drv_twi_rx(&i2c_instance,dev_addr, reg_data, len);
    return ret_code;
}

BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
    uint8_t dev_addr = *(uint8_t*)intf_ptr;
    ret_code_t ret_code;
    ret_code = nrf_drv_twi_tx(&i2c_instance, dev_addr, reg_data, len , false); 
    return ret_code;
}

The compiler does not get any error, but then the code does not work as I would like.

Are there any error in my functions or are they correct?

Thanks for helping

Parents Reply Children
No Data
Related