Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[nRF5 SDK v16.0.0] Error when operating SPI and I2C simultaneously

Hi there,

When I operate SPI and I2C simultaneously on nRF52832, an error has occurred.

Could you please teach me how to solve an error?

I use an attached "main.c".

The below process is executed when operating SPI and I2C simultaneously.

1) When Raspberry Pi as I2C master reads nRF52832 as I2C slave,

    TWIS_EVT_READ_REQ is active in function "twis_event_handler" on line 358 and

    function "ees_readBegin" is executed.

2) When function "sensor_update" is executed in function "ees_readBegin"  on line 213,

    nRF52832 reads pressure and temperature from external 5 pressure sensors by SPI.

3) When function "spi_read_acc" is executed in function "sensor_update" on line 1171,

    nRF52832 reads pressure and temperature from external 5 pressure sensors by SPI,

    and read pressure and temperature is stored to "m_manufac_data".

    Then data of "m_manufac_data" is copied to "i2c_spi_data".

4) When I run on debug mode, function "nrf_drv_spi_transfer" in function "spi_read_acc" on line 938

     is executed and an error has occurred like an attached "error_messeage.png".

     However, when I run on normal mode, function "ees_readEnd" on line 238 is executed,

     and Raspberry Pi as I2C master reads the unexpected value of pressure and temperature.

Best regards,

Yasuyuki

04316.main.c

Parents
  • Hi,

    The error code (0x11 - 17 - NRF_ERROR_BUSY) means that the previous transfer is not completed.

    Have you tested without your timeout code?

    while (1)
    {
    //    nrf_delay_us(SPI_WAIT_TIME_UNIT);   // (1/4M)*(49*8)clk = 100usec
        if (spi_xfer_done) {
            memcpy(data, &m_rx_buf[1], dataLen);
            break;
        }
    //    if (SPI_WAIT_MAX_BURST < waitCnt++) {
    //        memset(data, 0, dataLen);
    //        break;
    //    }
    }

    Since you are calling the SPI transfer function from the TWIS handler, which runs at APP_IRQ_PRIORITY_HIGH, the SPI interrupt handler (running at APP_IRQ_PRIORITY_LOW) will be blocked from executing and completing the transfer. I would recommend you to schedule the SPI transfer outside of the event handler, either using the application scheduler library, or by setting a flag in the event handler and check the flag in main-loop. Alternatively, you need to increase the SPI priority above the priority of the TWIS event handler, to allow the SPI interrupt handler to preempt the TWIS handler and complete the SPI transfers.

    Best regards,
    Jørgen

Reply
  • Hi,

    The error code (0x11 - 17 - NRF_ERROR_BUSY) means that the previous transfer is not completed.

    Have you tested without your timeout code?

    while (1)
    {
    //    nrf_delay_us(SPI_WAIT_TIME_UNIT);   // (1/4M)*(49*8)clk = 100usec
        if (spi_xfer_done) {
            memcpy(data, &m_rx_buf[1], dataLen);
            break;
        }
    //    if (SPI_WAIT_MAX_BURST < waitCnt++) {
    //        memset(data, 0, dataLen);
    //        break;
    //    }
    }

    Since you are calling the SPI transfer function from the TWIS handler, which runs at APP_IRQ_PRIORITY_HIGH, the SPI interrupt handler (running at APP_IRQ_PRIORITY_LOW) will be blocked from executing and completing the transfer. I would recommend you to schedule the SPI transfer outside of the event handler, either using the application scheduler library, or by setting a flag in the event handler and check the flag in main-loop. Alternatively, you need to increase the SPI priority above the priority of the TWIS event handler, to allow the SPI interrupt handler to preempt the TWIS handler and complete the SPI transfers.

    Best regards,
    Jørgen

Children
No Data
Related