Error with the faster period of 50ms in I2C/twi reading

 Hello Groups,

I'm trying to send I2C/twi data from nRF52832 using the Nordic development board with nRF Connect SDK 1.9.1.

Based on the sample project ble_app_uart, I read and added the I2C data of the accelerometer KX132 and sending out through the BLE mechanism.

It worked very well with reading and sending I2C data fast to the period, down to 60ms. But when I tried to send faster by setting the period down to 50ms then, I got the error at the function:

   __WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)

At

     NRF_BREAKPOINT_COND;

Any idea on this problem?

Thanks a lot for your time,

Jack

///////// code

// Note: In my application, I need to read the I2C fast to clear the FIFO buffer of the sensor.

#define SENSOR_RATE_MEAS_INTERVAL       APP_TIMER_TICKS(50)

static void application_timers_start(void)                     

{

    ret_code_t err_code;

 

    // Start application timers.

    err_code = app_timer_start(m_sensor_rate_timer_id, SENSOR_RATE_MEAS_INTERVAL, NULL);

    APP_ERROR_CHECK(err_code);

 

}

void twi_init(void)

{

       ret_code_t err_code;

 

       const nrf_drv_twi_config_t twi_sensor_config = {

          .scl = ARDUINO_SCL_PIN,

          .sda = ARDUINO_SDA_PIN,

          .frequency = NRF_DRV_TWI_FREQ_400K,

          .interrupt_priority = APP_IRQ_PRIORITY_HIGH,

          .clear_bus_init = false

       };

 

       err_code = nrf_drv_twi_init(&m_twi, &twi_sensor_config, twi_handler, NULL);

       APP_ERROR_CHECK(err_code);

 

       nrf_drv_twi_enable(&m_twi);

}

 

static void sensor_meas_timeout_handler(void* p_context)  

{

    // prepare data

    uint16_t length = PACKAGE_BLE_MAX_SIZE;

    ret_code_t      err_code;

 

    UNUSED_PARAMETER(p_context);

    kx132ReadFifo();

 

    err_code = ble_nus_data_send(&m_nus, BlePackageData, &length, m_conn_handle);

    if ((err_code != NRF_ERROR_INVALID_STATE) &&

        (err_code != NRF_ERROR_RESOURCES) &&

        (err_code != NRF_ERROR_NOT_FOUND))

    {

        APP_ERROR_CHECK(err_code);

    }

 

}

  • Hi Karl,

    I found the problem.

    The error is busy because it period reads data during the initial sensor setting in the main loop. So I put a flag to wait until the setting is completed.

    Thanks a lot for your time,

    Jack

     

    // ===============

        IsSensorInitReady = true;

        // Enter main loop.

        for (;;)

        {

            idle_state_handle();

        }

     

    // ==============

    static void sensor_meas_timeout_handler(void* p_context)

    {

        if (IsSensorInitReady == false) { return; }

        // prepare data

        uint16_t length = PACKAGE_BLE_MAX_SIZE;

        ret_code_t      err_code;

     

        UNUSED_PARAMETER(p_context);

        kx132ReadFifo();

     

        err_code = ble_nus_data_send(&m_nus, BlePackageData, &length, m_conn_handle);

        if ((err_code != NRF_ERROR_INVALID_STATE) &&

            (err_code != NRF_ERROR_RESOURCES) &&

            (err_code != NRF_ERROR_NOT_FOUND))

        {

            APP_ERROR_CHECK(err_code);

        }

     

    }

  • Hello again, Jack

    I am glad to hear that you were able to resolve the root of this issue - thank you for sharing the solution as well.

    Jack Phan said:
    Thanks a lot for your time,

    It is no problem at all - we are happy to help you!

    Please do not hesitate to open a new ticket if you should encounter any other issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Related