Skip to main content
KKIM.6
Senior
January 28, 2025
Question

Interrupt receiving through SPI MISO line

  • January 28, 2025
  • 3 replies
  • 2999 views

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.

3 replies

Andrew Neil
Super User
January 28, 2025

@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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
KKIM.6
KKIM.6Author
Senior
January 28, 2025

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.

 

 

Andrew Neil
Super User
January 28, 2025

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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
January 28, 2025

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

 

 STM32
----------+
 |
 EXTI +<---+
 | | ___
 MISO +<---+----------- DOUT/RDY
 |
----------+
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
KKIM.6
KKIM.6Author
Senior
January 28, 2025

Thanks for your reply.

 

Unfortunately, we have already ordered hardware (circuit board).

So, we have to make it work within a single MISO with interrupt.

I'm trying to set PA8 (MISO pin) as the GPIO interrupt pin but the microcontroller is frozen at the GPIO setting step.

I'm not sure this is the right way to set up MISO as a GPIO interrupt.

That's why I need a clear example document for this.

 

Below is my GPIO_Init() code.

 

void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

 

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOB_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

 

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(PSW_GPIO_Port, PSW_Pin, GPIO_PIN_RESET);

 

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOA, SYNC_Pin|CS_Pin, GPIO_PIN_RESET);

 

/*RT DEBUG GPIO_Init */

RT_DEBUG_GPIO_Init();

 

/*Configure GPIO pin : PSW_Pin */

GPIO_InitStruct.Pin = PSW_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(PSW_GPIO_Port, &GPIO_InitStruct);

 

/*Configure GPIO pins : SYNC_Pin CS_Pin */

GPIO_InitStruct.Pin = SYNC_Pin|CS_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

/*Configure GPIO pin : PA0 */

GPIO_InitStruct.Pin = GPIO_PIN_0; // -> this is dummy interrupt pin

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

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

 

/**/

LL_PWR_SetNoPullB(LL_PWR_GPIO_BIT_0);

 

/**/

LL_PWR_SetNoPullA(LL_PWR_GPIO_BIT_2|LL_PWR_GPIO_BIT_9);

 

/* EXTI interrupt init*/

HAL_NVIC_SetPriority(GPIOA_IRQn, 1, 0);

HAL_NVIC_EnableIRQ(GPIOA_IRQn);

}

 

 

Here if I put the below part, the Microcontroller will be frozen.

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

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

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

If I remove this part, the microcontroller work very well.

Andrew Neil
Super User
January 28, 2025

@KKIM.6 wrote:

Unfortunately, we have already ordered hardware (circuit board)..


Always best to prove your design before committing to custom hardware!

Please see How to insert source code for how to properly post source code.

You can edit your post to re-do it.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User
January 28, 2025

> As you know, once we set SPI in STM32, we cannot use GPIO interrupt callback.

Not true. It can be configured as SPI_MOSI and a EXTI interrupt at the same time.

"If you feel a post has answered your question, please click ""Accept as Solution""."
KKIM.6
KKIM.6Author
Senior
January 28, 2025

Thanks for your reply, once I can solve the problem, I'll accept it as a solution.

Unfortunately, I don't know how to activate SPI and MISO callback simultaneously now. 

So, I need more assistance.

 

Andrew Neil
Super User
January 28, 2025

@KKIM.6 wrote:

I don't know how to activate SPI and MISO callback simultaneously now.


That's not two separate things - that's just interrupt-driven SPI.

Plenty of examples in Cube.

But start a separate thread for that - it's a different question.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.