Can't get UART Rx interrupt to work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 5:50 AM
I cannot get the RS232 Rx interrupt to work.
I am working with the stm3210c-eval board. I know it is no longer available; but it has a version of the processor that I wish to use and Ethernet support.
I am initiating the receive via:
HAL_UART_Receive_IT( &USART_TDP_Handle, &(USART_TDP_RxBuffer[0]), 1);
The call back function HAL_UART_RxCpltCallback(HAL_UART_RxCpltCallback) is simple:
USART_TDP_ring_Buffer[USART_TDP_ring_Rx_in++] = USART_TDP_RxBuffer[0];
HAL_UART_Receive_IT( &USART_TDP_Handle, &(USART_TDP_RxBuffer[0]), 1 );
BSP_LED_On(LED3);
So, if nothing else the LED should turn on when a byte is received. It does not. I have verified the LED works.
This is my initialization (not that STcubeMX did not initialize the UART Rx pin correctly):
__HAL_RCC_USART2_CLK_ENABLE();
USART_TDP_RX_GPIO_CLK_ENABLE();
USART_TDP_TX_GPIO_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/**USART2 GPIO Configuration
PD5 ------> USART2_TX
PD6 ------> USART2_RX
*/
GPIO_InitStruct.Pin = USART2_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = USART2_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
//GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
__HAL_AFIO_REMAP_USART2_ENABLE();
/* NVIC for USART */
HAL_NVIC_SetPriority(USART2_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USART2_IRQn);
Have I missed something? I have verified that the TTL Rx signal makes to the processor's UART2 Rx pin.
Solved! Go to Solution.
- Labels:
-
Interrupt
-
STM32F1 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 6:27 AM - edited ‎2024-11-19 6:46 AM
Hello @vneff
Did you implement the USART2_IRQHandler () function as shown below?
void USART2_IRQHandler(void)
{
HAL_UART_IRQHandler(&UartHandle);
}
Thanks
Omar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 6:06 AM
@vneff wrote:I cannot get the RS232 Rx interrupt to work.?
Before going to interrupts, does polled receiving work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 6:27 AM - edited ‎2024-11-19 6:46 AM
Hello @vneff
Did you implement the USART2_IRQHandler () function as shown below?
void USART2_IRQHandler(void)
{
HAL_UART_IRQHandler(&UartHandle);
}
Thanks
Omar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 7:43 AM
Andrew,
That was an excellent suggestion. That allowed me to prove that USART2 Rx pin was working.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 7:44 AM
Saket_Om,
That was the problem. Why would the STcube HAL not take of that? Is that a failure of STcubeMX?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 7:46 AM - edited ‎2024-11-19 7:47 AM
@vneff wrote:
That was the problem. Why would the STcube HAL not take of that? Is that a failure of STcubeMX?
Did you activate the NVIC interrupt in CubeMx for USART2?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 7:53 AM
SofLit,
No i did not. I see that would be an issue for Ethernet as well.
If I check those 2, will that screw up my existing code?
STcubeMX does handle the assigned input pins for the STM32F107. Makes them outputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 7:58 AM
So it's not a limitation as you didn't activate the NVIC in CubeMx.
To let CubeMx generate the IRQ handler you need to enable it in NVIC menu:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 8:34 AM
SofLit,
To answer my own question:
f I check those 2, will that screw up my existing code?
Yes, it did wipe out the fixes I had made.to HAL_UART_MspInit & HAL_ETH_MspInit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-11-19 8:47 AM
@vneff wrote:it did wipe out the fixes I had made.to HAL_UART_MspInit & HAL_ETH_MspInit.
It should not change anything that you put in between the USER CODE BEGIN and USER CODE END markers.
Conversely, anything you put outside those markers will get overwritten when the code is re-generated.
