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.

  • This is strange, the only difference this should make is that the drive is set to S0S1 instead of SOD1. SOD1 should be correct as the pin should only sink current (the pull-up will drive the line to the correct level when the pin is set high/released). Here is the SCL/SDA config:

    #define SCL_PIN_INIT_CONF     ( (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
                                  | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos) \
                                  | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)  \
                                  | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos) \
                                  | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos))
    #define SDA_PIN_INIT_CONF        SCL_PIN_INIT_CONF
    

    And here is the nrf_gpio_cfg_input(..) function:

    __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
    {
        nrf_gpio_cfg(
            pin_number,
            NRF_GPIO_PIN_DIR_INPUT,
            NRF_GPIO_PIN_INPUT_CONNECT,
            pull_config,
            NRF_GPIO_PIN_S0S1,
            NRF_GPIO_PIN_NOSENSE);
    }
    
Reply
  • This is strange, the only difference this should make is that the drive is set to S0S1 instead of SOD1. SOD1 should be correct as the pin should only sink current (the pull-up will drive the line to the correct level when the pin is set high/released). Here is the SCL/SDA config:

    #define SCL_PIN_INIT_CONF     ( (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
                                  | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos) \
                                  | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)  \
                                  | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos) \
                                  | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos))
    #define SDA_PIN_INIT_CONF        SCL_PIN_INIT_CONF
    

    And here is the nrf_gpio_cfg_input(..) function:

    __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
    {
        nrf_gpio_cfg(
            pin_number,
            NRF_GPIO_PIN_DIR_INPUT,
            NRF_GPIO_PIN_INPUT_CONNECT,
            pull_config,
            NRF_GPIO_PIN_S0S1,
            NRF_GPIO_PIN_NOSENSE);
    }
    
Children
No Data
Related