cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt receiving through SPI MISO line

KKIM.6
Senior II

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.

29 REPLIES 29

@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

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.

 

 


@KKIM.6 wrote:

Do you think it is possible to switch functions during operation?


Sure it's possible.

 


@KKIM.6 wrote:

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.


Surely that's irrelevant?

The ADC won't send anything until the Master asks for it?

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.

 

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@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:

https://community.st.com/t5/stm32cubemx-mcus/how-to-have-cubemx-configure-a-peripheral-but-not-enable-it/m-p/761680/highlight/true#M30800

 

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. 

You could also wire two STM32 pins together - use one purely for EXTI, and one purely as MISO ...

 

   STM32
----------+
          |
     EXTI +<---+
          |    |                 ___
     MISO +<---+----------- DOUT/RDY
          |
----------+