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

When EVENTS_ERROR become True ?

Hi. I have troubles. I'm using nRF52 DK and V0.9.0. I'm making program that does TWI communication between MPU9250 what is 9-axis sensor. error is false every time. When it become True? Please help me!

static bool twi_action_wait(nrf_drv_twi_t const * const p_instance)
{
    bool     *error*;
    bool     done;
    uint32_t timeout = 0;
    volatile transfer_t * p_transfer = &(m_cb[p_instance->instance_id].transfer);

    do
    {
        done  = nrf_twi_event_check(p_instance->p_reg, p_transfer->end_event);
        *error* = nrf_twi_event_check(p_instance->p_reg, NRF_TWI_EVENTS_ERROR);
        *error* |= (++timeout < BUSY_LOOP_TIMEOUT) ? false : true;
    } while (!(*error* | done));
    return !*error*;
}

//Question Update at 2/29. It's my program.******************** TWI_main.c

//Question Update at 3/8. It's MPU9150 program.******************** main.c

  • I tested the program, it looks like there is a problem in twi_action_wait of nrf_drv_twi.c. It always caused timeout.

    static bool twi_action_wait(nrf_drv_twi_t const * const p_instance)
    {
        bool     error;
        bool     done;
        uint32_t timeout = 0;
        volatile transfer_t * p_transfer = &(m_cb[p_instance->instance_id].transfer);
    
        do
        {
            done  = nrf_twi_event_check(p_instance->p_reg, p_transfer->end_event);
    	    error = nrf_twi_event_check(p_instance->p_reg, NRF_TWI_EVENTS_ERROR);
            error |= (++timeout < BUSY_LOOP_TIMEOUT) ? false : true;
        } while (!(error | done));
        return !error;
    }
    
  • I looks like you are still using SDK 0.9.0? What nRF52 DK version are you using? Since you get a timeout I would suspect that your MPU of some reason is not responding. Have you double checked the 3 things I listed in my previous answer?

  • I use SDK 0.9.0 and nRF52832.

    Now,I rechecked, Power has been missing! This problem is solved!

    And I have another question.

    About nrf_twi_event_handler of main.c.

    Original main.c was written as following.

    nrf_drv_twi_init(&m_twi_instance, &twi_mpu_9150_config, twi_handler, NULL);

    But the number of arguments of Original's one don't match nRF52's function.

    Because I rewrote as following.

    nrf_drv_twi_init(&m_twi_instance, &twi_mpu_9150_config, NULL);

    With this, "twi_handler" doesn't call this program.

    It caused "twi_tx_done" doesn't change and NRF_ERROR_TIMEOUT mpu9150_write_single.

    What should I do to solve this?

  • Old driver in SDK 0.9.0. nrf_drv_twi_init() parameters:

     * @param[in] p_instance      TWI instance.
     * @param[in] p_config        Initial configuration. If NULL, the default configuration is used.
     * @param[in] event_handler   Event handler provided by the user. If NULL, blocking mode is enabled.
    

    New driver in SDK 11. nrf_drv_twi_init() parameters:

     * @param[in] p_instance      TWI instance.
     * @param[in] p_config        Initial configuration. If NULL, the default configuration is used.
     * @param[in] event_handler   Event handler provided by the user. If NULL, blocking mode is enabled.
     * @param[in] p_context       Context passed to event handler (can be NULL).
    

    If you insist on using the old drivers you should use:

    nrf_drv_twi_init(&m_twi_instance, &twi_mpu_9150_config, twi_handler);
    

    Otherwise the handler will never be called.

  • Thank you Martin Bors-Lind! Due to your efforts,my problems were resolved!

    Thanks for all your help, again. Best Regards.

Related