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/.../

Parents
  • I think I have fixed the issue by manually configure the I2C pins for input sensing with internal pull up (code below) before initializing the driver. However, more testings are required.

    //set sensing
    nrf_gpio_cfg_input(TWI_SCL_M, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(TWI_SDA_M, NRF_GPIO_PIN_PULLUP);
    

    I have also found out that the while-loop stuck is a rare occurrence, so it was a little difficult for me to replicate the issue. The only way for me to replicate it was through running my application with constant I2C read for the entire day, and while it's reading, I will reset and reflash in my softdevice, boot-loader and upload my application. After that, the device will hang if I uploaded a version without the manual config (even soft reset will not get me out of the loop).

    Edit: I have confirmed that after I did this, I don't experience any issue with my TWI. If anyone can offer me a good explanation, that would be great. Thank you in advance.

  • Yeah, that's a little strange but I have actually placed the manual pin config before my TWI init. The reason for doing that (which might be a little silly) was actually just me trying to pull the TWI pins high before TWI init, since I suspect the reason for the stuck is because my SDA wasn't pulled up for some reason after the TWI init (SDA was low during the stuck). Also to note that I was relying on the internal pullups.

Reply
  • Yeah, that's a little strange but I have actually placed the manual pin config before my TWI init. The reason for doing that (which might be a little silly) was actually just me trying to pull the TWI pins high before TWI init, since I suspect the reason for the stuck is because my SDA wasn't pulled up for some reason after the TWI init (SDA was low during the stuck). Also to note that I was relying on the internal pullups.

Children
No Data
Related