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

twi_transfer() never exits... s123v3, SDK 12.1.0

I am having trouble with an application where the NRF52832 operates several devices as a TWI master. What is even stranger is that I have been working on this code for a while and only now does it seem to cause a problem - I don't know what I changed that caused the issue. This problem is reproducible across multiple boards and on a Rigado dev board, so I don't think it stems directly from hardware.

I initialize my TWI:

void twi_init (void)
{
  ret_code_t err_code;

const nrf_drv_twi_config_t twi_config = {
   .scl                = 11,
   .sda                = 12,
   .frequency          = NRF_TWI_FREQ_400K,
   .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
   .clear_bus_init     = true
};

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

nrf_drv_twi_enable(&m_twi);
}

And then call it to check the status of a smart battery...

  uint8_t getPctCapacity(nrf_drv_twi_t m_twi)
 {
    uint8_t buf[1];
    uint8_t msg[] = {GET_STATE_OF_CHARGE};
    nrf_drv_twi_tx(&m_twi, BATT_ADR, msg, 1, true);
    nrf_drv_twi_rx(&m_twi, BATT_ADR, buf, 1);
    if (buf[0] > 100) buf[0] = 100;
    return buf[0];
 }

And I get stuck in a loop inside twi_transfer() at nrf_drv_twi.c.

Specifically, my debugger bounces between

(nrf_twi_event_check(p_twi, NRF_TWI_EVENT_RXDREADY))

and

(do_stop_check && nrf_twi_event_check(p_twi, NRF_TWI_EVENT_STOPPED))

Has anyone had any experience with this issue? I get the same results whether or not I am testing on a real board or a dev board with nothing connected to the I2C lines.

Related