1
\$\begingroup\$

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.

ADS1234 data retrieval

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Please excuse my ignorance: what is the AF acronym? \$\endgroup\$ – Biff Nov 13 '17 at 20:12
  • \$\begingroup\$ 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 \$\endgroup\$ – P__J__ Nov 13 '17 at 20:12
  • \$\begingroup\$ Ah, understood. \$\endgroup\$ – Biff Nov 13 '17 at 20:33
  • \$\begingroup\$ I should only need DMA for TX, correct? Or should I do full-duplex SPI with DMA1 and two channels for RX and TX? \$\endgroup\$ – Biff Nov 14 '17 at 9:53
  • \$\begingroup\$ @Biff - DMA for RX, TX you can do DMA or not. \$\endgroup\$ – P__J__ Nov 14 '17 at 10:46
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – Biff Nov 13 '17 at 18:13
  • \$\begingroup\$ @laptop2d EXTI port on the STM32 (not all GPIOS support this) which one do not? EXTI on falling edge (not low level) \$\endgroup\$ – P__J__ Nov 13 '17 at 19:28
  • \$\begingroup\$ 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 \$\endgroup\$ – Voltage Spike Nov 13 '17 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.