Reputation: 11
In my application I need to communicate between two MCU in UART. The board used are:
NUCLEO-l4p5zg: Transmitter (TX); STM32MP157A-DK1: Receiver (RX);
The TX lowers the pin to start the communication. When the pin is lowed an interrupt is triggered and the RX enables the reception. (TX lowers the pin PG15 that is the pin PG8 for the RX)
My issue:
The interrupt triggers multiple times instead of once.
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin){
if((HAL_GPIO_ReadPin(port_rx, pin_rx) == 0))
{
HAL_UART_Receive_DMA(uart, (uint8_t *) &rx_data[rx_work], size_pkt);
dbg_cnt++;
}
}
The variable dbg_cnt is saved in the dbg_save_buff and set to zero at the end of the reception.
The dbg_save_buff shows me these values (that change every time I restart the application):
dbg_save_buff = {5, 11, 7, 14, 10, 3, 7, 2, ...}
whereas what i would expect:
dbg_save_buff = {1, 1, 1, 1, 1, 1, 1, 1, ...}
Below the function MX_GPIO_Init
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_Y_GPIO_Port, LED_Y_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = LED_Y_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_Y_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(RX_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI8_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI8_IRQn);
}
What can I do to resolve my issue?
Thank you in advance
Upvotes: 1
Views: 1113
Reputation: 139
In your interrupt handler, you should clear the interrupt flag of this pin:
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
Upvotes: 1