cancel
Showing results for 
Search instead for 
Did you mean: 

External ADC with 18bits using SPI with DMA

Simon Schmid
Associate
Posted on April 27, 2017 at 12:19

Hi,

I'm currently investigating how to efficiently connect an 18bit ADC (

http://www.analog.com/media/en/technical-documentation/data-sheets/AD7691.pdf

) to an STM32L432KC microcontroller. The ADC uses SPI to transmit the data. Preferrably I'd like to use DMA to keep the load low.

Unfortunately I haven't found much information about how to setup DMA with SPI frames larger than 16bit. I think the biggest problem is that I only get one busy indicator (interrupt) before the transmission of the 18bits (see attached timing diagram), so I can't trigger two 9bit DMA transfers from the SPI peripheral easily.

Could you give me any pointers how to read out the ADC efficiently? Maybe there's a way to 'abuse' the SAI or timer to generate two 9bit DMA transfers?

Thanks in advance

Simon

#external-adc #dma #adc #spi
5 REPLIES 5
Posted on April 27, 2017 at 14:01

18x 16-bit words is the same a 16x 18-bit words, you'll just have to fish the bits out of the input buffer.

9x 16-bit is 8x 18-bit

If your devices expects CS to bang up and down for each word, then that's going to be much more difficult to do. Perhaps have the STM32 think it is the slave and generate the CLK and CS with a TIM 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on April 27, 2017 at 15:26

Thanks for your reply, the device has a conversion trigger pin to start a conversion. The device expects SCLK to be provided by the microcontroller to clock out the conversion result.

After the conversion is done, the device automatically starts to clock out the 18bits synchronized to SCLK. There's an  busy indicator to mark the start of a transfer of 18 consecutive bits:

In either mode, the AD7691 offers the option of forcing a start bit in front of the data bits. This start bit can be used as a busy signal indicator to interrupt the digital host and trigger the data reading. Otherwise, without a busy indicator, the user must timeout the maximum conversion time prior to readback.

The busy indicator however is optional and the data could be clocked out immediately.

The problem is I can't start a new conversion until all 18bits have been clocked out. The simple solution would be an interrupt service routine on the busy indicator and read two 9bit frames but this will use up a lot of processor time, hence I'm looking for a DMA solution to do batch processing.

Posted on April 27, 2017 at 18:10

I'd set a timer's ARR to tCYC (and more, as appropriate), one compare channel to output the conversion trigger onto a pin, i.e. timed just slightly after 0, other compare timed to fire after tCONV and third delayed 9 SPI clocks after the second. The latter two set then to trigger the DMA into SPI-Tx, set to 9 bits. The DMA from SPI-Rx triggered then from SPI itself. Easy-peasy 😉

JW

Posted on April 27, 2017 at 17:26

The parts aren't well suited to each other.

If the STM32 acts as a slave it will just make progress as the clock appears. Some of the TIM can be used to generate pulse trains, basically one-pulse-mode with repetition. Alternatively you can drive GPIO with DMA via a pattern buffer, and TIM.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Andrew Clifford
Associate
Posted on May 09, 2017 at 14:17

Hi Simon, did you manage to get it working? I am interested because I am shortly going to be trying to do exactly the same thing!

Thanks,

Andrew