TWI bus freeze after several thousand tx/rx cycles

JTLiphardt gravatar image

asked 2017-07-15 03:00:24 +0200

Stian gravatar image

updated 2017-07-17 13:16:49 +0200

I'm periodically polling a TWI sensor with a blocking call, as in

ret_code_t err_code;
m_xfer_done = false;

err_code = nrf_drv_twi_tx(&i2c, address, subAddress, 1, true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false) {};

if (err_code == NRF_SUCCESS) {
        m_xfer_done = false;
        err_code = nrf_drv_twi_rx(&i2c, address, dest, count);
        APP_ERROR_CHECK(err_code);
        while (m_xfer_done == false) {};
};

This works fine about 3000 times, and then comes to grinding halt. I'm reading 8 bytes per nrf_drv_twi_rx. My first guess is running out of memory, but why? I'm just sampling the bus and updating the values of a static unit8_t dest[8].

edit retag flag offensive close delete report spam

Comments

What does the APP_ERROR_CHECK() tell you? Does it ever end up in there with an error code, or is it stuck in the while loop waiting for the m_xfer_done flag?

Stian ( 2017-07-17 13:28:57 +0200 )editconvert to answer

I have no idea why this helps, but all problems vanish when I enable the softdevice. It's weird, since I'm not actually using the softdevice, but all I've done is SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); softdevice_app_ram_start_get(&ram_start); softdevice_enable(&ram_start); and now things are rock-solid. 28,000 data collection and FLASH-write cycles and still going strong....

JTL ( 2017-07-18 20:28:11 +0200 )editconvert to answer