2017-04-27 03:19 AM
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 #spi2017-04-27 05:01 AM
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
2017-04-27 08:26 AM
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.
2017-04-27 09:10 AM
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
2017-04-27 10:26 AM
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.
2017-05-09 05:17 AM
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