Tutorials
nRF52840 SPI FIFO Reads: Count the Command Byte in EasyDMA
Published · Updated
For a conventional full-duplex four-wire SPI FIFO read, the first received byte coincides with the outbound command. Your raw DMA buffer and your payload can start at different offsets.
Map the transaction at the wire

For four whole FIFO words you want 28 payload bytes. With one command byte and no additional protocol dummy phase, clock 29 bytes while chip select stays active. On a raw nRF52840 SPIM action, TXD.MAXCNT can be one and RXD.MAXCNT 29. EasyDMA transmits ORC for the remaining clocks. Allocate the buffers in accessible data RAM and hold them until the transaction is complete.
The received byte at index zero is exchanged during the command. In this raw transaction, FIFO payload is RX[1:29]. Some drivers implement command and receive phases with scatter/gather buffers, so compare the driver contract with the actual capture before applying an offset in the application.
Prove the 29-byte transaction before scaling up
![TX: one command: RX[0] is command exchange. 4 FIFO words: 28 bytes at RX[1:29]. 29 total bytes at 4 MHz: 58 microseconds of clock time](https://fpga.io/wp-content/uploads/2026/11/logger-20261123-04.png)
Capture CS, SCK, MOSI and MISO on one read. Label the command exchange and the four seven-byte groups. Confirm the configured SPI mode and range against the LSM6DSOX and host documentation. Match tag bytes at raw positions 1, 8, 15 and 22. Reject an incomplete transfer and re-establish the FIFO read boundary before decoding again.
Estimate payload read time separately from software overhead. At an illustrative 4 MHz SCK, the 232 serial clocks take 58 µs. CS setup/hold and gaps, earlier status reads, scheduling latency and any driver retries extend total service time. Keep DMA length within the selected peripheral instance and driver limits, then validate the exact nRF52840 silicon revision and errata.
If the trace decodes correctly and the application still sees invalid tags, dump DMA memory before queue handoff. If the DMA dump is right while the decoder output is wrong, check the data pointer, buffer ownership and lifetime before retuning SCK.
For 28 FIFO bytes, should the raw receive buffer be 28 bytes?
For this single full-duplex transfer it needs 29 bytes. The driver API may expose only the 28-byte payload.
Show the three-step example
![TX: one command: RX[0] is command exchange. 4 FIFO words: 28 bytes at RX[1:29]. 29 total bytes at 4 MHz: 58 microseconds of clock time](https://fpga.io/wp-content/uploads/2026/11/logger-20261123-04.gif)
TX: one command: RX[0] is command exchange. 4 FIFO words: 28 bytes at RX[1:29]. 29 total bytes at 4 MHz: 58 microseconds of clock time.
LSM6DSOX device documentation · nRF52840 host documentation · FIFO watermark and service-time budget · Motion logger project and storage worksheet · Check SPI mode against the first bit
Bring one CS-to-CS capture, the DMA offsets and counts, and the first raw buffer before parser handoff. Prepare an engineering review.
References
Nordic nRF52840 SPIM and ST AN5272 section 9.8 · ST AN5272 FIFO retrieval.
Back to Tutorials