This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

52810, LIS3DH, i2c using TWI, got NRF_ERROR_DRV_TWI_ERR_ANACK while calling nrf_drv_twi_tx

52810, LIS3DH, I call nrf_drv_twi_tx got NRF_ERROR_DRV_TWI_ERR_ANACK return using  either TWI/ or  TWIM . Here is my code:

const nrf_drv_twi_config_t config = {
.scl = TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER,
.sda = TWI_MASTER_CONFIG_DATA_PIN_NUMBER,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH, 
.clear_bus_init = true
};

err_code = nrf_drv_twi_init(&m_twi, &config, NULL, NULL);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&m_twi);

uint8_t buf[7];

buf[0] = WHO_AM_I;

nrf_drv_twi_tx(&m_twi, LIS3DH_ACC_I2C_SAD_H, buf[0], 1, false);

Please help me out, thanks a lot.

  • Hello,

    Here is  an exempt from the Infocenter documentation for the TWI driver, regarding this particular error:

    NRFX_ERROR_DRV_TWI_ERR_ANACK - Negative acknowledgement (NACK) is received after sending the address in polling mode.

    So, it seems your TWI slave is sending a NACK. You should check what your slave datasheet says about this.
    Based on the code you have provided, there is not much more I can say about this.

    uint8_t buf[7];

    buf[0] = WHO_AM_I;

    nrf_drv_twi_tx(&m_twi, LIS3DH_ACC_I2C_SAD_H, buf[0], 1, false);

    This might not work as you intend. I will assume your WHO_AM_I string is a single byte, which also means that the remaining 6 bytes of your buf array is randomly initialized. You then proceed with nrf_drv_twi_tx(which is deprecated, by the way) for sending only the first byte of the array. If this what you intended to do?

    Also, is there a particular reason why you are using the legacy layer of the TWI driver?

    You can read more about the available TWI functionality and usage in the TWI API Reference.

    Best regards,
    Karl

  • Thanks. I got those code from the SDK examples. I have checked out the link you shared, but still don't know how to code without using the legacy layer. Can you please share me some code that uses the up to date TWI drivers? That will be great help!

Related