cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get UART Rx interrupt to work

vneff
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello @vneff 

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

 

 

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

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

View solution in original post

7 REPLIES 7
Andrew Neil
Evangelist III

@vneff wrote:

I cannot get the RS232 Rx interrupt to work.? 


Before going to interrupts, does polled receiving work?

Saket_Om
ST Employee

Hello @vneff 

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

 

 

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

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Andrew,

 

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

Thank you.

Saket_Om,

 

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


@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 on "Accept as Solution" on the reply which solved your issue or answered your question.

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.

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:

SofLit_0-1732031929027.png

 

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