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

My microcontroller is STM32WB09TEF7TR.

I thought that it is quite a general method that uses MISO as interrupt input because the company is selling chips.

The only problem is that I don't know the detail method.

If there is any hint, I would appreciate it.

How did you know that my microcontroller,

 

Yes, I'm using STM32WB09TEF7TR.

 I'll read the manual and try to fix code.

Thanks for your reply.

I'll study interrupt-driven SPI and try to modify the code.

Thanks!

I tried to set the MISO pin as the GPIO Interrupt pin in the MX_GPIO_Init(). 

---------------

GPIO_InitStruct.Pin = GPIO_PIN_8; // -> this is actual interrpt pin using MISO pin

GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

------------------

However, once I put the code, the microcontroller is halted even before starting MX_GPIO_Init(). 

I cannot understand why it happened because this halt happened before calling these two functions, MX_GPIO_Init() and MX_SPI_Init().

 

One thing I need to say is that I run the GPIO and SPI initialization code after receiving the command through the Bluetooth LE.

Really situation is hard to understand.

In addition, this is a Bluetooth device. So, I cannot run debug mode....holy.

 

 

 

Sorry. I gave up. :(

I'll use a timer-interrupted SPI. :( 

:(

STM32 is wasting my time a lot.

They should learn how Espressif does.

CubeMX is the source of evil because it generates code that we need to modify :(, which means that we have to understand STM32 itself even though we are not an STM employee.


@KKIM.6 wrote:

I thought that it is quite a general method that uses MISO as interrupt input because the company is selling chips.


No, it's quite unusual.

The company doing this is the maker of the ADC - not the maker of the microcontroller.

They are abusing the standard use of SPI.

Perhaps go to their forum, and ask them how they suggest handling this?

 


@KKIM.6 wrote:

The only problem is that I don't know the detail method.


So do you not have colleagues/supervisors/teachers to help you?

@TDK has said that a single STM32 pin can operate as both an EXTI interrupt input and MISO at the same time.

So, effectively the same as I showed here, but internally within the STM32 on a single pin:

 

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

The only problem with that is to stop the SPI communication from causing EXTI interrupts.

So you'll need something like:

  1. With EXTI enabled, you wait for the DRDY interrupt
  2. When you get a DRDY interrupt, disable further interrupts
  3. Do the SPI transfer
  4. Re-enable the DRDY interrupt
  5. now we're back at 1.

@KKIM.6 wrote:

CubeMX is the source of evil because it generates code that we need to modify .


Clearly, an automated tool cannot cope with every weird corner-case - it has to address the common use cases.

Yours is a wierd corner-case.

 


@KKIM.6 wrote:

we have to understand STM32 itself 


That is true of any microcontroller - and, in fact, any other electronic device.

TDK's comment suggests that the SPI pins can also be used as interrupts.
This was mentioned in a previous thread as well.
 
The problem is that when I try to configure the SPI MISO pin with a GPIO interrupt, the microcontroller freezes, and I cannot determine the cause of this issue.
 
I can understand what you are suggesting.
I've already succeeded in using GPIO, Timer, ADC, and SPI interrupt before. 
Unfortunately, I cannot change the hardware part this time to connect MISO to any GPIO EXIT.
Next time, I can modify the circuit board.
 
During that time, I have to finish the project in another way.
 
 
 

In the case of Espressif, when we write the main() function and build the project, all the necessary components start being set up from that point. Unlike CubeMX, which requires structuring everything beforehand, Espressif’s approach significantly reduces the chances of errors.

Moreover, in modern development, we rely heavily on AI tools like ChatGPT or Gemini. However, explaining CubeMX in text form to ChatGPT is quite challenging. Additionally, when trying to transfer the built code to AI, it’s nearly impossible to upload dozens of pages of code in full.

This essentially means that the CubeMX system is already outdated.

You will understand this once you use Espressif.

With Espressif, you can simply ask ChatGPT to write Wi-Fi code, structure threads within the main() function, and then hit build—at which point, all necessary components are automatically configured.

This level of convenience is something STM should learn from.

 

In addition, why CubeIDE doesn't have a built-in Terminal? Espressif IDE uses the same Eclipse system, but it has a built-in terminal.


@KKIM.6 wrote:

In addition, why CubeIDE doesn't have a built-in Terminal? 


Pretty sure it does.

But I prefer an external terminal anyhow - so have never bothered with it.