Fairly simple question but I couldn't find any instructions on this. I'm using an STM32G070

I'm interfacing with an ADS1231 which uses DOUT / ~DRDY on the same pin, and I'm wondering if there is a way to use the interrupt pin as an input as well. Essentially what I want to do:

  1. Wait for a falling edge on the DOUT/~DRDY pin (currently configured as EXTI)

[Inside of the ISR:]

  1. Disable interrupts on the pin
  2. Use the pin as an input
  3. Send out the 24 clock signals, reading the DOUT/~DRDY pin after each clock falling edge
  4. Turn the pin back into an interrupt
  5. Exit and wait again

I found an interesting answer in another thread, using the same part (https://electronics.stackexchange.com/a/339742/281491)

I would do it completely other way.

Set SPI2 MISO pin as GPIO input. Set the EXTI (falling edge) interrupt on this pin

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).

In the DMA transfer complete interrupt change pin to the GPIO Input. Enable EXTI

Steps 2 & 3 will automatically repeat on every conversion.

Can anyone elaborate on how I would go about doing the bolded parts, or any other solutions?


  • \$\begingroup\$ Your strategy sounds ok. Its a common technique to enable/disable interrupts on a gpio. Another technique is not to poll or wait for the adc to complete but set up a timer to trigger the conversion then next timer tick read the result and start the next conversion. You normally don’t need to run the adc full speed so set the timer to a value greater than the max conversion time. \$\endgroup\$
    – Kartman
    Commented Apr 7, 2021 at 23:23

2 Answers 2


There are as many ways to do it as people can think of.

Your way will work just fine, although it is not very sophisticated as the MCU will be sitting in the interrupt waiting for the bytes to get transferred before exiting the interrupt. If that is all that is needed, it is simple and effective.

The other solution you found is one of the most complex solutions, although libraries make it easy to do. It simply disables the EXTI interrupt and starts a DMA driven transfer and will immediately exit the interrupt to return do what it was doing. The data is transferred in the background and when the bytes are finished, the transfer complete interrupt will then re-enables the EXTI interrupt.

A solution between these would maybe start an interrupt driven SPI transfer in the EXTI and would re-enable EXTI when bytes are transferred.

There are many other solutions too, just pick one that suita your program flow and gets the job done without adding roo much complexity.


Your approach should work. The approach on the other thread is questionable, IMHO. With 5MHz clock speed using DMA is pointless, considering that MCU is only 64 MHz.

  • 1
    \$\begingroup\$ @Justme 4.8 us, not ms! At 64 MHz it is only 300 MCU cycles. Setting up and processing DMA will take more than that, especially if HAL is used \$\endgroup\$
    – Maple
    Commented Apr 8, 2021 at 6:55
  • \$\begingroup\$ I don't see it being questionable, I think it is extremely sophisticated as an idea, it might just be extremely overkill for a simple situation. Transferring 24 bits at 5 MHz takes 4.8 microseconds, so if the system can handle that, the interrupt can block during the transfer then that is just fine. For some reason you might not want that, and DMA setup will be much faster than 300 MCU cycles. So SPI via interrupts or DMA might suddenly start making sense. It all depends what else the system has to do, how much is the response time, and if asynchronous event-based operations suit better. \$\endgroup\$
    – Justme
    Commented Apr 8, 2021 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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