SPI/DMA issue with kinetis K64 (MK64F12)

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

SPI/DMA issue with kinetis K64 (MK64F12)

963 Views
mikaelelharrar
Contributor III

Hi community,

I'm working on a board with

   - One external ADC which samples the analog voltage at 42 Kilo samples per seconds.

   - Each sample is 12 bytes to read from SPI. My SPI clock work at 15Mhz.

   - SPI channel of my micro (K64) is configured as master, and get a gpio interrupt each time a new sample is ready.

My micro is running free rtos.

To not disturb the execution I decided to use eDMA, to extract the samples from ADC.

For that I exactly copied the example named "espi_dma_transfer_frdmk64" (in initialization).

I have a callback each time the DMA finish the transfer (called from DMA_irq).

At the moment I'm using the gpio interrupt handler to start the DMA transfer (hopefully, this will be triggered directly by the dma if possible).

Problem:

I started a capture during 20 seconds and put some counters in gpio interrupt handler, in dma transfer complete callback, and in start dma tranfer.

I get after 20 seconds:

=> 853526 times the gpio interrupt fired: It is OK because 42000 samples/sec. * 20 seconds => 840000 ~~ 853526

=> 233388 times the DMA complete transfer callback was called => no make sense at all.

=> 640144 times the start DMA function returned "Error Busy flag" (the DMA seems to be busy).

That is mean the DMA transfer take more than 23 us (more than one ADC interval), to transfer 12 bytes only.

How that is it possible ?

How to resolve this problem ?

Please help.

Thanks

Tags (2)
0 Kudos
2 Replies

471 Views
mjbcswitzerland
Specialist V

Hi

You need to use an oscilloscope/logic analyser to check the SPI timing. Depending on the SPI configuration it adds delays between each byte transfer which can be quite long. Once you have seen the timing that you have you can experiment with the SPI pre-scaler settings (which control CS and inter-byte timing) in order to optimise it to your case.

Regards

Mark

0 Kudos

471 Views
mikaelelharrar
Contributor III

Hi Mark,

Thanks for you help. You are right I succedded to save some cycles but unfortunatly it is not enough ... Now my ratio is 1/2 (I can extract data only each 2 interrupt).

0 Kudos