This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI master and DMA

Using softdevice s132, nRF52832 on a custom board

I don't quite understand how does the SPI work exactly?

I am using it on a battery powered low power sensor application, for this instance I have not set up a SPI event handler, but DMA is enabled.

I am calling nrf_drv_spi_transfer in a function, where I return the recieved data to the function that called it.

The SPI is running at 1mhz - so what is the CPU doing while waiting for the SPI slave to clock in the bytes?

Do I risk that I am working on memory that is not updated from the most recent info from the SPI peripheral device, or is the CPU waiting for the transfer to complete?

Should I set up the SPI event handler and instead signal my app to check the data after the event has indicated SPI transfer event is done - intuitively it seems like a better real-time/low power solution but this may already be sorted and abstracted away in the driver?

Parents
  • Hi,

    If you don't use an event handler the SPI driver is waiting in a while() loop until the transfer is completed and you get an SPI transfer END event.

    In SDK 14 this happens at line 575 in nrf_drv_spi.c:

    if (!p_cb->handler)
    {
        while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_END)){}
        if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
        {
            nrf_gpio_pin_set(p_cb->ss_pin);
        }
    }
    

    So yes, the CPU is waiting for the transfer to complete while wasting time and current. As you say, the point of DMA is to let the CPU sleep or do other things, but you are not actually using DMA if you don't use the SPIM as explained in the Advanced Usage section of the SPI driver documentation.

Reply
  • Hi,

    If you don't use an event handler the SPI driver is waiting in a while() loop until the transfer is completed and you get an SPI transfer END event.

    In SDK 14 this happens at line 575 in nrf_drv_spi.c:

    if (!p_cb->handler)
    {
        while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_END)){}
        if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
        {
            nrf_gpio_pin_set(p_cb->ss_pin);
        }
    }
    

    So yes, the CPU is waiting for the transfer to complete while wasting time and current. As you say, the point of DMA is to let the CPU sleep or do other things, but you are not actually using DMA if you don't use the SPIM as explained in the Advanced Usage section of the SPI driver documentation.

Children
Related