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.

  • You only need it if you want to do multiple transfers triggered on some sort of event and don't want to use the CPU to set up each transfer. Such events can be generated by timers, external signals, etc. If you only need one transfer at the time I suggest that you just enable the event handler and let the CPU sleep until the event handler wakes it up after starting a transfer.

    We don't have any good examples in the SDK, but I posted an example in the comment section here that might be useful.

Reply
  • You only need it if you want to do multiple transfers triggered on some sort of event and don't want to use the CPU to set up each transfer. Such events can be generated by timers, external signals, etc. If you only need one transfer at the time I suggest that you just enable the event handler and let the CPU sleep until the event handler wakes it up after starting a transfer.

    We don't have any good examples in the SDK, but I posted an example in the comment section here that might be useful.

Children
Related