I am attempting to use the SPI2 peripheral on the STM32L471RG microcontroller in order to communicate with the ADS1234 and wanted to run my thoughts past some of you more experienced firmware developers!

Right now I am using the internal clock of the ADC, so I mainly need to focus on the DRDY/DOUT and SCLK pins. I'm going to have an initialize function that configures the other ADC pins.

The reference manual of the STM32L talks about the different modes of SPI that are possible, which leads to my question(s):

1. I am planning on using simplex receive with SPI2 - does this mode sound reasonable based on the ADS1234 interface waveforms?
2. The ADS1234 is 24-bit and the STM32L only goes up to 16-bits in the buffer. My thinking is to configure it for 12-bits and do two transfers, although I'm not sure if this will conflict with anything?
3. Since using the DRDY function is not completely a part of the SPI protocol, I'm wondering how to have this trigger a data transfer. If the DRDY/DOUT pin state goes from high to low (indicating data is ready) should I configure for an interrupt-on-change (IOC) event and then go into completing a transfer?

Below is the data retrieval waveform of the ADS1234.

Thank you for any help. I'm mainly concerned about the logistics of everything.

I would do it completely other way.

1. Set SPI2 MISO pin as GPIO input. Set the EXTI (falling edge) interrupt on this pin
2. In the EXTI interrupt - Disable EXTI, change this pin to the MISO AF, and initiate 3 byte DMA transaction (send 3 dummy bytes as you need to generate clock for the ADS).
3. In the DMA transfer complete interrupt change pin to the GPIO Input. Enable EXTI

Steps 2 & 3 will automatically repeat on every conversion.

• Please excuse my ignorance: what is the AF acronym? – Biff Nov 13 '17 at 20:12
• Alternate Function - ie this port to act as SPI2 MISO. it is set by setting GPIOx MODER register to alternate mode, and setting the AF registers – P__J__ Nov 13 '17 at 20:12
• Ah, understood. – Biff Nov 13 '17 at 20:33
• I should only need DMA for TX, correct? Or should I do full-duplex SPI with DMA1 and two channels for RX and TX? – Biff Nov 14 '17 at 9:53
• @Biff - DMA for RX, TX you can do DMA or not. – P__J__ Nov 14 '17 at 10:46

I am planning on using simplex receive with SPI2 - does this mode sound reasonable based on the ADS1234 interface waveforms?

Yes, you should be able to use a hardware SPI port on the STM32 to communicate with the ADS1234

The ADS1234 is 24-bit and the STM32L only goes up to 16-bits in the buffer. My thinking is to configure it for 12-bits and do two transfers, although I'm not sure if this will conflict with anything?

That will work, you can also set up the buffer for 8 bytes also. At the end of the transfer the buffer will fill up and generate an interrupt (if you set it up that way) which you will need to copy the data out of the buffer before you initiate another transfer.

Since using the DRDY function is not completely a part of the SPI protocol, I'm wondering how to have this trigger a data transfer. If the DRDY/DOUT pin state goes from high to low (indicating data is ready) should I configure for an interrupt-on-change (IOC) event and then go into completing a transfer?

There are two ways you could run the sampling of the ADC1234:

1) initiate an ADC sample and then deterministically wait with a timer or delay the data transfer until you know DRDY has gone low, then initiate a transfer.

2) Do what you suggest and wait for the DRDY to go low with a GPIO port using EXTI on the STM32 then initiate a transfer.

• If I wait for DRDY to go low with an EXTI port, I would effectively be using two pins, correct? One for DOUT and another essentially for DRDY with EXTI, both in parallel? – Biff Nov 13 '17 at 18:13
• @laptop2d EXTI port on the STM32 (not all GPIOS support this) which one do not? EXTI on falling edge (not low level) – P__J__ Nov 13 '17 at 19:28
• Yes, one for DOUT and one for DRDY. Actually I double checked the EXTI statment and I was wrong, I apologize, I will correct the answer – laptop2d Nov 13 '17 at 20:21