Multiple SPI commands in single transaction with CS toggle

New project using Nordic platform and I need to send multiple commands (32bit fixed size) to a device quickly using SPI with the CS toggling between each. I just want to confirm this is not something the nRF5340 can do, unlike various STM parts can? It is only one CS hardware transition per transaction?

The Zephyr spi_transceive/write etc command are VERY slow leaving 10s of us between commands.  Using nrfx_spim directly with hardware cs (nrfx_spim_xfer) is faster but still leaves a large gap compared to the speed of the 16Mhz SPI clocked commands.  I have read around on the forums and is using DPPI/timers to trigger the SPI transactions the only option here - just want to confirm before committing to that path? And I can transmit using that option not just recieve?

Many thanks.

  • Hi,

    Yes, that understanding is correct. On the nRF5340, each SPI transfer results in a single CS assertion and de assertion, so it is not possible to generate multiple CS pulses within a single SPI transaction. For applications that require very tight timing between short transfers, the recommended approach is to use the nrfx SPIM API directly and trigger SPI transfers using hardware events (TIMER + DPPI) rather than starting each transfer from software. This can significantly reduces the inter-transfer gap and should work for transmit and receive. As a high level guide, you can proceed as follows:

    1. Use the nrfx SPIM API (instead of the Zephyr SPI API)
    2. Configure a TIMER to generate an event at the required interval
    3. Prepare the SPI transfer using nrfx_spim_xfer() and set the NRFX_SPIM_FLAG_REPEATED_XFER flag.
    4. Obtain the SPIM START task address using nrfx_spim_start_task_address_get()
    5. Use DPPI to connect the TIMER event directly to the SPIM START task.

    Here is the good resource for understanding timer to DPPI connections which shows how timer can toggle the GPIO, instead of toggling a gpio you would connect the timer event to the SPIM START task: timer toggling a GPIO

    And for SPIM usage, this non-blocking nrfx example is a good reference: non-blocking nrfx

    Also make sure you are using SPI master 4 (SPIM4) which supports hardware controlled CS and SPI frequencies up to 32 MHz.

    Best Regards,
    Syed Maysum

Related