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 12:15 PM
Thanks for your reply.
I am currently modifying the internal code by referring to the build code for the GPIO interrupt callback generated by CubeMX.
If you have an example video, website, or document for this and can share it, I would greatly appreciate it.
2025-01-28 12:21 PM
> 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.
2025-01-28 12:25 PM
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.
2025-01-28 12:29 PM
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.
2025-01-28 12:39 PM
@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.
2025-01-28 12:40 PM
>>If you have an example video, website, or document for this and can share it, I would greatly appreciate it.
That's usually not how the world works, perhaps you have a colleague or supervisor with more experience who can walk you through the task. Most of the rest of us have jobs doing unrelated tasks.
From post it's not clear WHICH STM32 you're talking about.
As TDK indicates you might be able to use EXTI regardless of the SPI usage, as the pin is already an INPUT.
You're likely having to drive #CS LOW and HIGH manually now, so you can either implicitly check the DRDY state at that point or re-engage EXTI on the pin.
Pull a copy of the Reference Manual (RM) for your STM32 and read the Chapters on the GPIO Peripheral and it's registers, and those of the EXTI
The HAL code is going to do a lot of modification, whereas all you need to do is change a handful of bits/register to flip the operational state or mode from one type of behaviour to another.
2025-01-28 12:41 PM
@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.
2025-01-28 12:45 PM
>>Here if I put the below part, the Microcontroller will be frozen. / If I remove this part, the microcontroller work very well.
Ok, this suggests it's stuck in a interrupt storm / loop, where it exits, the interrupt isn't really cleared, and it re-enters, continuously
You'll likely need to cycle between various phases of the transfer, and mode changes on the signals, in different callback functions. ie between SPI transfer, completion, and back to EXTI
2025-01-28 12:47 PM - edited 2025-01-28 12:48 PM
You haven't specified which chip you're using. "STM32" is woefully insufficient. The method will vary based on it.
Use a single HAL_GPIO_Init call on the pin setting both the AF and the EXTI.
Probably something like GPIO_InitStruct.Mode = MODE_AF | EXTI_IT | TRIGGER_FALLING.
Registers in GPIO, EXTI and SYSCFG are generally relevant here if you want to do it through there after it's already initialized as an SPI pin.
Edit: looks like you're on the H7, the above should work.
2025-01-28 12:48 PM
If STM32WB09, Reference Manual https://www.st.com/resource/en/reference_manual/rm0505-ultralow-power-wireless-32bit-mcu-armbased-cortexm0-with-bluetooth-low-energy-and-24-ghz-radio-solution-stmicroelectronics.pdf