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

Parents
  • 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
    
Reply
  • 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
    
Children
No Data
Related