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

TWI_XFER is returning NRF_Success but the Data NACK is received

HI,

I'm having a problem when I use the function nrf_drv_twi_xfer. The function returns the error code NRF_SUCCESS, but using the event handler I notice that I'm receiving DATA NACK and the receiving buffer is empty, I didn't recieve a response from the device.

I'm trying to communicate with a CryptoMemory over I2C. In my circuit I have two slaves, a sensor and the cryptomemory, both using the same TWI instance. I have been able to communicate with the sensor without problem using the nrf_drv_twi_tx and nrf_drv_twi_rx functions. 

Reading the Crypto Memory datasheet I think is necessary to work with the Xfer function because it works with commands when in needs an input to give an output. The sensor works different, you can simply write to it or you can just read the register, it's no necessary to indicante a command to have an answer like it does in the Crypto Memory.

I have define my xfer_descriptor like this:

static nrf_drv_twi_xfer_desc_t Cryp_xfer = NRF_DRV_TWI_XFER_DESC_TXRX(Cryp_Addr, tx_cryp, sizeof(tx_cryp), rx_cryp_data, sizeof(rx_cryp_data));

and when  I use the function nrf_drv_twi_xfer is define like this:

err_code1 = nrf_drv_twi_xfer(&m_twi_Acc_Cryp, &Cryp_xfer, flags);

where: 

  • err_code1 is code error returned by the function
  • m_twi_Acc_Cryp is the TWI instance
  • Cryp_xfer is the xfer descriptor above
  • flags is define as NRF_DRV_TWI_FLAG_TX_NO_STOP;

My TWI initialization is using a TWI event handler, so is not in blocking mode. 

What I'm missing? I something configured wrong?

Thanks for your help.

  • Hi Torbjorn,

    Yes, I'm assuming the same, that the crypto memory could NACK if the checksum is no correct.
    I was wondering if the TWI library from the SDK calculates this checksum and added when the functions nrf_drv_twi_tx, nrf_drv_twi_rx and nrf_drv_twi_xfer are used. I wondering this because with the other sensor that I'm using, I use the ...twi_tx and ...twi_rx functions and I don't pass them the count byte neither the checksum bytes, I only pass the array with the info that I want to send and read. I was using the same logic even thought in the other datasheet didn't mention the count byte and the checksum bytes. That's a difference between the datasheets. 

    So in summary my doubt here is if the TWI functions calculates the count and checksum bytes internally and added them when they send the message?

    I still gonna look for some code online that could help to calculate the cheksum of the message and try that option.

    Best regards,

    Julio

  • Hi 

    Using a checksum is not something mandated by the TWI (I2C) specification, this is just something this particular device is doing. In other words, unless you can find a library written specifically for your device then this is something you will have to handle manually on top of the TWI API. 

    Most TWI devices don't bother with checksums, but it makes sense that a module related to crypto would be more concerned about data integrity/corruption.

    Best regards
    Torbjørn

Related