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

understanding SPI with easy DMA

Hi!

I want to understand different in use with DMA and w/o DMA in the SPI.

I explore example SPI from SDK examples and see that enabled SPI and SPIM together.

But at this case what 

spi_event_handler

handled?

SPI works with DMA? If I don't want to work with DMA? What should I do? 

  • Hi Mikhail

    There is no reason not to use DMA in the nRF52832. 

    The reason we support both is that the older nRF51 devices did not support DMA in the SPIM interface, and the driver was designed to support operation both with and without DMA. 

    All the nRF52 devices support DMA in the SPIM interface, and using DMA ensures less CPU utilization and lower current consumption, so I would recommend using it at all times. 

    Best regards
    Torbjørn

  • Hi! Thanks.

    I understand that should use DMA in the nRF52. 

    But DMA means SPIM? Or means NRFX?

    Could you explane me in the above screenshot, in the your example SPI, for what needs three SPI declarations?

    - NRFX SPIM

    - NRFX SPI

    - SPI enabled

    If I only need to use SPI master with DMA, which settings in the sdk_config.h should I enable?

    Which instance should use in those settings for DMA use?

    Why in this example used instance from just SPI?

    And in a code I use this instance

    #define SPI_INSTANCE  0 /**< SPI instance index. */
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */

    Therefore, for use DMA with SPI master, how should minimum configure sdk_config.h and wich instance should enable?

  • Hi Mikhail

    The SPIM interface uses DMA, that is correct. The older SPI interface did not have DMA. 

    The reason the peripheral configuration is a bit confusing is that the older nrf_drv_spi driver (accessed through SPI_ENABLED) was later on replaced by the nrfx drivers, and to avoid having to rewrite all the examples the nrf_drv_spi implementation was changed to only forward the calls to the nrfx implementation. 

    It is possible to call the nrfx API directly, but in general it is easier to keep the nrf_drv_spi interface on top, and just use nrfx under the hood. 

    There is no need to enable NRFX_SPIM_ENABLED or NRFX_SPI_ENABLED. As long as you enable SPI_ENABLED, and enable SPIx_USE_EASY_DMA for any instance that you use, the nrfx_spim driver will be enabled automatically, and DMA will be used:


    Best regards
    Torbjørn

  • Thanks. Therefore, for use SPI DMA should I enable NRFX_SPIM, NRFX_SPI and SPI_ENABLED with USE_EASY_DMA?

    Means, should enable those 3 things? All together. 

  • Hi 

    Sorry, it seems my screenshot was a bit confusing. 

    It is enough to only enable SPI_ENABLED, as shown here:

    Enabling NRFX_SPI_ENABLED and NRFX_SPIM_ENABLED should not do any harm, but is not necessary. They will be enabled automatically as needed by the SPI_ENABLED settings. 

    Best regards
    Torbjørn

Related