Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI sending wrong data - SDK15

Hello,

I'm trying to communicate with another device via I2C. I'm trying to do a simple write but it seems that the TWI NRFX driver is sending wrong data.

I'm just calling nrfx_twi_tx(&m_twi, I2C_ADDR, data, size, false); with some data, but when I get the "DONE" event, the data I see in the interrupt does not match what I wanted to send. I am checking the data in p_event->xfer_desc.p_primary_buf[i] from 0 to length - 1.

This is some debug output for reference:

APP                 : Writing: 01 FE 
TWI                 : Transfer type: XFER_TX.
TWI                 : Transfer buffers length: primary: 2, secondary: 0.
TWI                 : Primary buffer data:
TWI                 :  01 FE                  |..      
TWI                 : Secondary buffer data:
TWI                 :                         |        
TWI                 : tx 01
TWI                 : Function: nrfx_twi_xfer, error code: NRF_SUCCESS.
TWI                 : TWI: Event: NRF_TWI_EVENT_TXDSENT.
TWI                 : tx 00
TWI                 : TWI: Event: NRF_TWI_EVENT_TXDSENT.
TWI                 : TWI: Event: NRF_TWI_EVENT_STOPPED.
TWI                 : Event: EVT_DONE.
APP                 : TXDONE: 00 00 

I added a log just before calling nrf_twi_txd_set:

if (*p_bytes_transferred < length)
{
	NRFX_LOG_INFO("tx %02X", p_data[*p_bytes_transferred]);
    nrf_twi_txd_set(p_twi, p_data[*p_bytes_transferred]);
    ++(*p_bytes_transferred);
}

That's a code snippet from twi_send_byte in nrfx_twi.c

Why could this be happening?

Thanks for your help!

Related