2025-01-28 09:53 AM - last edited on 2025-01-28 03:31 PM by Pavel A.
Hi. I'm developing a custom STM32 circuit board.
I'm trying to use an analog-front-end, AD7124-8 ADC chip.
However, this chip generates an interrupt signal through the MISO pin when data is ready.
As you know, once we set SPI in STM32, we cannot use GPIO interrupt callback.
I know somebody already asked about this issue but I want to know if any document solves this problem clearly.
2025-01-28 10:37 AM
@KKIM.6 wrote:I know somebody already asked about this issue but I want to know if any document solves this problem clearly.
Please provide a link to that previous thread.
What was unclear from that previous discussion?
What do you think needs clarifying?
@KKIM.6 wrote:As you know, once we set SPI in STM32, we cannot use GPIO interrupt callback..
So don't set it to SPI until after you've received that interrupt.
Then, when you've done with the SPI, set it back to GPIO with interrupt
2025-01-28 11:40 AM
Do you think it is possible to switch functions during operation?
ADC chip sends data at 20 kHz speed.
I know it is not fast but I'm not sure setting SPI can be so quick.
2025-01-28 11:43 AM
This is the previous thread regarding the SPI pin for external interrupt.
2025-01-28 11:44 AM
2025-01-28 11:45 AM
Because CubeMx dosen't allow two settings for each GPIO pin, I heard that we have to manually change the code.
I want to know detailed instructions if it is.
2025-01-28 11:53 AM
>>Do you think it is possible to switch functions during operation?
Can Cube Auto-Generate this, probably not
But you could create an EXTI and enable/disable this at a register level there, and with GPIO registers.
Perhaps review the STM32's Reference Manual to better understand what the hardware is capable, and the least number of register/bit manipulations to change the behaviour.
https://www.analog.com/en/products/ad7124-8.html
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf
Data sheet suggests it's DOUT/DRDY, which given it's the SLAVE device would presumably be MISO, and you can change the behaviour after you release the #CS
You could also poll the DRDY state via the GPIO->IDR
2025-01-28 12:04 PM - edited 2025-01-28 12:06 PM
@Tesla DeLorean wrote:Can Cube Auto-Generate this, probably not
@KKIM.6 The trouble with Cube is that it groups all the GPIO setup into a single GPIO_Init() function - so you'd have to pull-out the bit that just sets that one pin as EXTI.
The SPI stuff would be easier - you get an SPI_Init(), and an SPI_DeInit().
Would probably be a huge overkill to do a complete init and de-init each time: you could probably pull-out just what needs to change - a lot of stuff (baud rate, SPI Mode, etc) would just say the same.
You can always just look at the Cube-generated code, use it to see what to do, then throw it away and write your own.
You will need to study your chip's Reference Manual to understand what the peripheral registers do.
@KKIM.6 wrote:I heard that we have to manually change the code.
You have to write (or get Cube to generate) code that sets the pin to EXTI, and code that enables SPI - and call them as required.
Note that you can set Cube to generate initialisation code, but not automatically call it at startup:
2025-01-28 12:05 PM
Sorry, my situation is more complex.
The ADC chip doesn't have internal FIFO memory.
So, If I don't read data in time, we will lose data.
In addition, this chip is a multiplexed multi-channel system which means each data is not a data of single channel.
For example, ADC transmits data like ch1 -> ch2 -> ch3 ... -> ch15 and go back to ch1.
So, I need to read the data in a synchronized way if I don't want to miss data.
2025-01-28 12:11 PM
You could also wire two STM32 pins together - use one purely for EXTI, and one purely as MISO ...
STM32 ----------+ | EXTI +<---+ | | ___ MISO +<---+----------- DOUT/RDY | ----------+