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

Related