Skip to main content
vneff
Associate III
November 19, 2024
Solved

Can't get UART Rx interrupt to work

  • November 19, 2024
  • 2 replies
  • 1802 views

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.

Best answer by Saket_Om

Hello @vneff 

Did you implement the USART2_IRQHandler () function as shown below?

 

 

void USART2_IRQHandler(void)
{
 HAL_UART_IRQHandler(&UartHandle);
}

 

 

2 replies

Andrew Neil
Super User
November 19, 2024

@vneff wrote:

I cannot get the RS232 Rx interrupt to work.? 


Before going to interrupts, does polled receiving work?

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.
vneff
vneffAuthor
Associate III
November 19, 2024

Andrew,

 

That was an excellent suggestion. That allowed me to prove that USART2 Rx pin was working.

Thank you.

Saket_OmBest answer
Technical Moderator
November 19, 2024

Hello @vneff 

Did you implement the USART2_IRQHandler () function as shown below?

 

 

void USART2_IRQHandler(void)
{
 HAL_UART_IRQHandler(&UartHandle);
}

 

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
vneff
vneffAuthor
Associate III
November 19, 2024

Saket_Om,

 

That was the problem. Why would the STcube HAL not take of that? Is that a failure of STcubeMX?

mƎALLEm
Technical Moderator
November 19, 2024

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

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.