K64: How to Initiate 2-frame SPI transfer from DMA?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K64: How to Initiate 2-frame SPI transfer from DMA?

782 Views
davenadler
Senior Contributor I

As part of a set of DMA processing that generates various excitation and control signals, we need to initiate an SPI master transfer of two 16-bit words. The SPI slave device actually has a single 18-bit frame, so we'll just use two 16-bit frames from K64 (16-bit is maximum length K64 SPI supports for master transfer), and ignore the extra 14 bits clocked in on receive.

First try: SPI2 has a 1-deep FIFO, and the documentation implies that a frame is immediately moved from FIFO to shift register if you write to PUSHR while SPI is not running (while shift register is empty). So, I though just use DMA to write two 32-bit words to PUSHR (first should immediately transfer into shift register, second sits in FIFO til first is shifted out). Unfortunately, 2nd word is ignored and I only see one 16-bit transfer on the scope, aarrggg... Note: SPI DMA request is used to transfer RX data into a buffer; this part works OK (except only first 16-bits of data ever received).

So, how to start a two-word transfer to SPI via DMA (no ISRs etc, DMA only)?

Thanks in advance for any help,
Best Regards, Dave

Labels (1)
Tags (2)
0 Kudos
2 Replies

435 Views
Jonathan_Iglesias
NXP TechSupport
NXP TechSupport

Hi Dave Nadler,

Please check the KSDK for K64  in boards>frdmk64f>driver_examples>dspi>edma_transfer

 there is an example.  soy you can see the process.

Welcome to MCUXpresso | MCUXpresso Config Tools 

Please let me know if you have more questions.

have a great day

BR

Jonathan

0 Kudos

435 Views
davenadler
Senior Contributor I

Thanks Jonathan, but unfortunately I had previously read this example and it is quite unhelpful. SPI is a full-duplex device, and this example seems to use two separate SPI peripherals, each in half-duplex! My use-case is a far more typical SPI scenario (in fact, required for two different SPI peripherals in a current project) as follows:

On a DMA request, send 2 words to SPI1 while simultaneously receiving 2 words from SPI1 into a buffer. Sometime later, on the next DMA request, again send (the same) 2 control words while receiving the next 2 words into the next sequential positions in the buffer. Repeat the process until the buffer is filled up (for example 1024 two-word transfers completed). DMA requests come from either a timer or a DMA-link.

This is an extremely common use case for reading an SPI sensor, ADC, etc on a timer - unlike the rather strange example.

Thanks in advance for any help,
Best Regards, Dave

0 Kudos