Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Same spi code runs on nrf52840 but does not run on nrf52832

Hello.

I am developing an SPI FIFO reading  program with a accelerometer. with sdk17.1.0 

It runs well on nrf52840 devkit but it stuck at nrf52832 devkit.

And I found this thread and disabled SPI0_USE_EASY_DMA, then it runs on nrf52832,

but the spi transfer speed is much slower than which is on nrf52840 devkit. (Which will cause data loss)

The nRF52840 program and the nRF52832 program have exactly the same code, with the spi instance set to 0. (Of course, there are some differences in the c_preprocessor_definitions)

The spi transfer code is showed below

uint8_t SpiInOut (stmdev_ctx_t* spi_ctx, uint8_t outData)
{
    uint32_t err_code;
    uint8_t inData ;
    
    if ((spi_ctx == NULL) || (&(spi_ctx->spi_handle) == NULL))
    {
        APP_ERROR_CHECK_BOOL (false);
    }

    err_code = nrf_drv_spi_transfer (&(spi_ctx->spi_handle), &outData, 1, &inData, 1);
    APP_ERROR_CHECK(err_code);

    return inData;
}

int32_t SpiWriteRegisters(void* handle, uint8_t reg, const uint8_t* buffer, uint16_t len)
{
    UNUSED_PARAMETER(handle);

    GpioWrite(&iis3dwb_.spi.Nss, 0);
    SpiInOut(&iis3dwb_.spi, reg);
    for(uint16_t i = 0; i < len; i++)
    {
        SpiInOut(&iis3dwb_.spi, buffer[i]);
    }
    GpioWrite(&iis3dwb_.spi.Nss, 1);

    return 0;
}

int32_t SpiReadRegisters(void* handle, uint8_t reg, uint8_t* buffer, uint16_t len)
{
    UNUSED_PARAMETER(handle);
    
    // Set first bit to 1;
    reg |= 0x80;
    GpioWrite(&iis3dwb_.spi.Nss, 0);
    SpiInOut(&iis3dwb_.spi, reg);
    
    for(uint16_t i = 0; i < len; i++)
    {
        buffer[i] = SpiInOut(&iis3dwb_.spi, 0);
    }

    GpioWrite(&iis3dwb_.spi.Nss, 1);

    return 0;
}

Parents Reply Children
  • Thanks for your reply.

    So while using nRF52832, adopting the SPIM peripheral (with SPI0_USE_EASY_DMA enabled) and applying Errata 58's work around, I can theoretically achieve the same transfer speeds as on the nRF52840?

    If so, is this way above a robust way to solve this problem, or I should just choose nRF52840 for relatively high-speed SPI transaction?

  • Hi,

    Yes, the workaround is effective, so with it you can do 1 byte transfers while DMA is enabled. The main thing when using it is tha tyou need to check for every transaction how large it is, and endable ble workaround before a 1 bye transaction, and disable it after (it will cause problems for multi byte transactions).

    There are other good reasons for choosing the nRF52840, but this particular issue whould be managable on the nRF52832 as well.

Related