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);

    }

 

}

  • Hello again, Jack

    Thank you for providing the additional information. The error code is returned by the call to the nrf_drv_twi_tx function.
    From the function API we can read that:

    The transmission will be stopped when an error occurs. If a transfer is ongoing, the function returns the error code NRF_ERROR_BUSY.

    Which means that you should implement some specific error handling here for the NRF_ERROR_BUSY to trigger when this error code is returned. The most straight-forward one would be to wait and re-try the sending as soon as possible, for example.

    Best regards,
    Karl

  • Hi Karl,

    Thanks a lot for your information and explanation.

    So my problem here is:

    • When the reading period is greater than 50 ms, the function nrf_drv_twi_tx(..) returns success.

    But when the reading period is 50 ms or less, the function nrf_drv_twi_tx(..) function will return the error, NRF_ERROR_BUSY

    So, I have questions:

    • I cannot read faster than 50ms because the nrf_drv_twi_tx(..) function will return the error NRF_ERROR_BUSY when we read faster than 50ms?
    • Or, the nrf_drv_twi_tx(..) function can read faster than 50ms, but my sensor Kx132 cannot be read faster than 50ms?
    • I want to read faster than 50ms on my sensor Kx132. Can you please advise a method that can help me?

    Best,

    Jack

  • Hello Jack,

    Jack Phan said:
    Thanks a lot for your information and explanation.

    No problem at all, I am happy to help! :) 

    Jack Phan said:
    • I cannot read faster than 50ms because the nrf_drv_twi_tx(..) function will return the error NRF_ERROR_BUSY when we read faster than 50ms?
    • Or, the nrf_drv_twi_tx(..) function can read faster than 50ms, but my sensor Kx132 cannot be read faster than 50ms?
    • I want to read faster than 50ms on my sensor Kx132. Can you please advise a method that can help me?

    There is no limitation in the nrfx driver that limits the speed, so we will need to look into what else might be causing this.
    The first thing I would do is to check the datasheet for your sensor, to see if it has any particular requirements for the speed and read/write requests.

    If there is no limitation in the datasheet either we will need to look at why the reads/writes are taking so long - for this we will need to use a logic analyzer to see what is actually happening on the lines.
    From the logic analyzer trace we would be able to see if any of the devices are holding up the transfers from their end, causing the delays.

    Do you have access to a logic analyzer to get these traces?

    Best regards,
    Karl

  • Hi Karl,

    I’ll check the document of the sensor Kx132 and will try to get a signal from my logic analyzer, Saleae, and then will update you.

    I saw an example of Nordic TWI/I2C on the temperature sensor LM75B (examples\peripheral\twi_sensor). Did you have a chance to read this sensor up to 50ms?

    Thanks,

    Jack

  • Hello Jack,

    Jack Phan said:
    I saw an example of Nordic TWI/I2C on the temperature sensor LM75B (examples\peripheral\twi_sensor). Did you have a chance to read this sensor up to 50ms?

    I do not have an LM75B sensor on hand right now to test this, so I have not performed any tested this myself.
    How big is each of your TWI messages, by the way? Just so we can get some reference of the speed you are achieving.

    Jack Phan said:
    I’ll check the document of the sensor Kx132 and will try to get a signal from my logic analyzer, Saleae, and then will update you.

    I look forward to hearing any update! :) 

    Best regards,
    Karl

Related