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

TWI read with 32 bits register address return all zeros

Hi all,

Using the nrf52832 TWI, I am trying to interract with a sensor through I2C.

On the same board, I am successfully able to exchange data with an accelerometer (8bit register adress) using I2C, but when I am trying to exchange with the other devices which uses 32 bits adress, the TWI_perform only returns 0 on the ret_buffer. Though on the oscilloscope I can see that the device is responding normally to my request.

Here's my function : 

uint32_t igo_hal_i2c_buf_read(uint8_t i2c_id, uint8_t* buf, uint32_t len, uint8_t* ret_buf)
{
   nrf_twi_mngr_transfer_t transfers[2];

   transfers[0].p_data = buf;
   transfers[0].length = 4;
   transfers[0].operation = NRF_TWI_MNGR_WRITE_OP(i2c_id);
   transfers[0].flags = NRF_TWI_MNGR_NO_STOP;

   transfers[1].p_data = ret_buf;
   transfers[1].length = len;
   transfers[1].operation = NRF_TWI_MNGR_READ_OP(i2c_id);
   transfers[1].flags = 0;

   twi_perform(&g_twi_bus_config[CONFIG_WWR_TWI_BUS], transfers, ARRAY_SIZE(transfers))
}

Please note that twi_perform does return NRF_SUCCESS!

Do you have any idea why the ret_buffer is always NULL while the I2C exchange is ok as I can decode it on my oscilloscope?

Thanks in advance!

Sylvain

Parents
  • Hi,

    • What value is the parameters that you pass to twi_perform?
    • Where do you call the function from? For example, Is it called multiple times in a loop? And are you calling it from interrupt context?

    regards

    Jared 

  • Hi Jared,

    Here's the parameters I use

    - i2c_id : is my i2c_slave address

    - buf => uint8_t buf[4] = {0x12,0x34,0x56,0x78}

    - len = 4

    - ret_buf => uint8_t ret_buf[4] = {0,0,0,0}

    - CONFIG_WWR_TWI_BUS = 0 as I use the primary TWI Bus

    /**@brief Configuration of TWI buses. */
    const nrf_drv_twi_config_t g_twi_bus_config[] = {
    .frequency = (nrf_twi_frequency_t)26738688,//100k
    .interrupt_priority = TWI_DEFAULT_CONFIG_IRQ_PRIORITY,
    .clear_bus_init = TWI_DEFAULT_CONFIG_CLR_BUS_INIT,
    .hold_bus_uninit = CONFIG_TWI0_UP_IN_SYSOFF_STATE,
    .scl = mysclpin,
    .sda = mysdapin,
    },
    };

    I call the function during when I initializes all my components/sensors so it is not called in an interrupt callback, it is also not called multiples times

    As I was saying, on a hardware point of view it seems to work fine, the only thing is that ret_buff does not return as it should.

    Thanks for the support,

    Sylvain

  • Hi Sylvain,

    It isn't apparent from the code or your description what the cause of the issue is. I suggest using the debugger and setting a breakpoint in transaction_end_signal() in nrf_twi_mngr.c and see what the p_user_data points to when you receive data.

    regards

    Jared

  • Hi Jared,

    I have p_user_data = 0x00000001 when transaction_end_signal() is called and it switches to 0x00000000 when exiting transaction_end_signal() 

    Best regards,

    Sylvain

Reply Children
Related