6 years, 4 months ago.

Possible to use DMA for SPI Master read?

Hi all,

I'm trying to use the mbed LPC1768 to receive data over SPI from an ADC, the Texas Instruments ADS1274.

The ADS1274 sends out a signal when new samples are ready. When that happens, the mbed is supposed to generate a clock signal and the ADS1274 will send the data.

I'm using Andy Kirkham's MODDMA library like this:

char buf[NUM_CHANNELS * 3]; // 3 bytes per sample

MODDMA_Config* dma_conf = new MODDMA_Config;

int setup_dma()
    // stolen from moddma example 2
     ->channelNum    ( MODDMA::Channel_0 )
     ->srcMemAddr    ( 0 )
     ->dstMemAddr    ( (uint32_t)buf )
     ->transferSize  ( sizeof(buf) )
     ->transferType  ( MODDMA::p2m )
     ->transferWidth ( MODDMA::word )   // 4 bytes at a time
     ->srcConn       ( MODDMA::SSP0_Rx ) // SSP0: pins 11-13. SSP1: pins 5-7.
     ->dstConn       ( 0 )
     ->dmaLLI        ( 0 )
     ->attach_tc     ( &parse_data ) // called when transferSize is reached
     ->attach_err    ( &dma_error_cb )
    return 0;   // success

When I run dma.Enable(dma_conf); from the main loop, I don't see a clock signal on pin 13. The function parse_data() is never called.

How can I create a clock signal from a DMA transfer?


Kevin Chen

Amador Valley High School Robotics Team

Question relating to:

You first need to ensure the SPI is setup and can read from external device without DMA being used before you try to use DMA. You haven't published enough information to determine if this is the case.

posted by Andy Kirkham 21 Jun 2013

I should add that, assuming the SPI is setup, are you a master? If so you need to "pump out" don't care bytes in order to clock out the data.

For example, when I use DMA for SPI flash devices I send the commands to read a memory section and then setup DMA to send zeros for the number to read using DMA channel_1 and setup DMA_channel_0 to read the incoming stream.

So you need to setup two DMA channels, a lower priority (channel_1) to send zeros or oxff, whatever, that creates the correct number of out-going bytes that matches the number you want to read back. Just before that setup the higher priority (channel_0) to read that number of incoming bytes. Then start the channel_1 transfer, that fires out "don't care" bytes that gets P13 clocking and as the bytes come back channel_0 captures them and stores them as per your setup.

posted by Andy Kirkham 21 Jun 2013
Comment on this question
Be the first to answer this question.

You need to log in to post a question