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

TWI Infinate Loop

I asked the following question, TWI Stuck Bus Recovery, last week and got a great answer which I implemented. I tested my implementation by changing the device addresses to see if my system could detect the problem, report it and continue to try and clear the problem. This is all working well.

In order to test physical bus issues I tired grounding the SDA line to see how my implementation would handle this and I was surprised to find my system was stuck in a infinite loop in app_twi.c executing

    while (p_app_twi->internal_transaction_in_progress)
    {
        if (user_function)
        {
            user_function();
        }
    }

What's the best way to implement a timeout or stop this from occurring. I realize that a I2C bus that has SDA grounded isn't likely to occur but our device has a long operating life target and I am trying to be thorough.

Thanks, Darren

  • wouln't it be rather safe to configure the GPIO pin with a pull up rather than testing that this could be grounded by long term wearoff?

    That said, you can do something like this

    app_timer_call_back()
    {
          p_app_twi->internal_transaction_in_progress = false;
    }
    
    start_oneshot_app_timer_with_timeout
    while (p_app_twi->internal_transaction_in_progress)
    {
        if (user_function)
        {
            user_function();
        }
    }
    stop_app_timer
    
  • Aryan,

    Thanks for the reply. Would Nordic consider modifying the SDK in a future release to of the user_function() return an error code that would be tested in the while loop? This why a timeout could be completed implemented in user code.

    Also, I'm not sure what you mean by "rather safe to configure the GPIO pin with a pull up rather than testing that this could be grounded by long term wearoff"

    Thanks, Darren

Related