cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure external interrupt on SPI_MISO pin in STM32H7

RShar.9
Senior

Hello ,

i am using LDC1101 proximity sensor and it data ready interrupt on SPI_MISO pin.

Can any one please tell to how to configure a pin both SPI_MISO and External interrupt.

thanks

7 REPLIES 7
S.Ma
Principal

For STM32L4, you can have EXTI on alternate function like MOSI, MISO, SCK etc..

HAL was not providing this feature, so you need to hack it by controlling the registers directly.

CubeMX and HAL restrict what the HW can do.

We did post and answer this question in this forum, although searching the forum might be tricky.

thanks for the reply, can we do that in stm32h7 also or not.

can you please tell me how to do that, i found nothing about it on forum.

and if i try to enable gpio external interrupt on MISO pin using writing program , will it effect SPI configuration?

EXTI is independent of peripheral signals, it's just a digital input permanently connected to the pin.

I don't know for H7 as I'm focusing on L4 activities currently.

Some extract of the code: (EXTI on SCK rise and fall edge interrupt for STM32L4R5):

void SPIP_EnableSCK_EXTI(SPIP_t* pSPIP) {
// PD1 = SCK
  //void HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init)
  // not portable, complexity up for free, this is a patch to have EXTI on Alternate function...
// DOES NOT WORK AT ALL, MODER=00  GPIO_InitTypeDef GPIO_Init = {GPIO_PIN_1, GPIO_MODE_IT_RISING_FALLING, 0, 0, 0 };
//  HAL_GPIO_Init(GPIOD, &GPIO_Init);
//    SYSCFG->EXTICR[position >> 2] = temp;
  SYSCFG->EXTICR[0] &= ~(0xF<<4);
  SYSCFG->EXTICR[0] |= (3<<4);
  EXTI->IMR1 |= GPIO_PIN_1; // interrupt enable
  EXTI->RTSR1 |= GPIO_PIN_1; // rising sense
  EXTI->FTSR1 |= GPIO_PIN_1; // falling sense
// Above is the ONLY WAY to have EXTI on AF pin.
  __HAL_GPIO_EXTI_CLEAR_IT(pSPIP->pSCK->Init.Pin);
  __HAL_GPIO_EXTI_CLEAR_FLAG(pSPIP->pSCK->Init.Pin);
  //EXTI->IMR1 |= (1<<1);
  HAL_NVIC_SetPriority(EXTI1_IRQn, 1, 0);
  HAL_NVIC_EnableIRQ(EXTI1_IRQn);
}
 
void SPIP_DisableSCK_EXTI(SPIP_t* pSPIP) {
  HAL_NVIC_DisableIRQ(EXTI1_IRQn);  
}
 
void EXTI1_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */
  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
  /* USER CODE BEGIN EXTI0_IRQn 1 */
  /* USER CODE END EXTI0_IRQn 1 */
}

hello

when i am using it in stm32h7 program it's showing many errors.

like "SPIP_t" is undefined

gahelton1
Associate III

I know that this is an old thread, but I have an identical need - that is, have an external interrupt on the MISO line while the SPI is enabled.

Here are a few code snippets from what I have, but for some reason, I cannot get the external interrupt to trigger.

The processor is an STM32F407.

The interrupt is connected to the MISO line (PB4).

The interrupt is to be negative edge triggered.

 //**************************************************
 
 // Configure PB4 (EXTI4) for falling edge trigger
 
 // Enable EXTI4 interrupt in NVIC, but don't enable
 
 // the local ISR enable until we are ready.
 
 //**************************************************
 
 
 
 EXTI->FTSR |= EXTI_FTSR_TR4;
 
 NVIC_EnableIRQ(EXTI4_IRQn);

//*******************************************
// Enable global interrupts
//*******************************************
 
__enable_irq();

	//*******************************
	// Enable external ISR on PB4
	//*******************************
 
	EXTI->IMR |= EXTI_IMR_MR4;

Looking into the EXTI registers, I see that the interrupt is enabled, and falling edge triggered.

0693W00000GWsK8QAL.png 

Of course, I am not using HAL. I don't trust him - you know why.

What am I missing here ?

Thanks in advance.

You have to select the proper port in SYSCFG_EXTICR.

JW