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

TWIM issue (nrf_twim_event_check)

Hi,

I have faced an issue during an I2C read operation. My code stuck in the infinite loop of

while (!nrf_twim_event_check(p_twim, evt_to_wait))
    {
        if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
        {
            NRF_LOG_DEBUG("TWIM: Event: %s.\r\n", (uint32_t)EVT_TO_STR_TWIM(NRF_TWIM_EVENT_ERROR)); 
            nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
            nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
            nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
            evt_to_wait = NRF_TWIM_EVENT_STOPPED;
        }
    }

The issue occurred after I was running my application for the entire day in debug mode, and did a breakpoint to check on some program variables. My code went into softreset and stuck in the aforementioned while loop. Before that the reading operation is smooth. The only way to fix this issue is to perform a hard restart which involves powering down completely and powering up. Is there any way to prevent this or breakout from this loop. Before using the TWIM (with easyDMA), I also have similar issue when I was using the TWI driver. In both cases, the code stuck in a while loop. The SCL pin is held high (normal) but the SDA is held low. FYI: I was porting my application from SDK11 to SDK12. The code worked well in SDK11.

Similar issues have been mentioned before -> devzone.nordicsemi.com/.../ devzone.nordicsemi.com/.../

  • Hi, My code is also stuck in this infinite loop. I have added your posted code //set sensing nrf_gpio_cfg_input(TWI_SCL_M, NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_input(TWI_SDA_M, NRF_GPIO_PIN_PULLUP); before my twi_master_init(); function call, but I am still stuck in the infinite loop. Do you have any suggestions I can try? Thanks

  • Hi Levi,

    I guess a couple of things you can try:

    1. Check if your I2C slave device is holding up the I2C bus. You can try to imitate a stop command before init TWI. Alternatively, you can try to perform a clear bus before init. The latest SDK does not do that by default.
    2. One of the Nordic AFEs offered me the following solution to modify the I2C driver by adding a 4us delay between NRF_GPIO->PIN_CNF[p_config->scl] = SCL_PIN_CONF; NRF_GPIO->PIN_CNF[p_config->sda] = SDA_PIN_CONF; But it didn't resolve my issue unfortunately. Hope it helps you.
  • Here's what I tried:

    1. #define TWI_DEFAULT_CONFIG_CLR_BUS_INIT 1 in sdk_config.h to enable clearing the bus during initialization.
    2. Added the nrf_delay_us(4); where you said to add it.

    No luck so far. It appears my code is getting stuck in my driver function for my TWI sensor and not TWI_init(). Just wanted to make sure we are on the same page. I'll keep digging! Thanks for the help!

Related