Skip to main content
cjaya.1
Associate III
September 26, 2022
Question

I am having difficulty receiving data on USART2. It is receiving one character when I use HAL_UART_Receive_IT interrupts. I am trying to receive some characters from ADUCM360 USART.

  • September 26, 2022
  • 6 replies
  • 3135 views

I can see transmitting characters from ADUCM360 to STM32.But it does not capture the incoming characters from STM32 using interrupts. Any help on this very much appreciated. Thank you

This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
September 26, 2022

Most STM32 have one interrupt per character.And then selectively call-back once the whole request is serviced.

Would suggest managing in-bound data into your own buffers, to handle later, and resubmit the receive requests.

The HAL is a bit of an ugly mess in this regard. Avoid doing any complex or blocking work in the interrupt handlers, or the call-backs they call.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
cjaya.1
cjaya.1Author
Associate III
September 26, 2022

Thank you for the reply.

"Most STM32 have one interrupt per character.And then selectively call-back once the whole request is serviced"

How do I do that because I can see only character on the STM32 data register when it is in interrupt service routine (UARTHandler) before the call back.

cjaya.1
cjaya.1Author
Associate III
September 26, 2022

also, I try using HAL_UART_Receive_DMA but its still receiving one character when I call it.

Tesla DeLorean
Guru
September 27, 2022

You've basically posted the same question 3 times, and not identified what STM32 you're talking about, there's like a hundred at this point.

Don't view the peripheral in the debugger, it reading the data register will clear the status.

If you get an overrun you need to clear that, perhaps look at the Reference Manual for the part you're using.

For an STM32L0 notionally

 if (USART_RS232->ISR & USART_ISR_ORE) // Overrun Error
 USART_RS232->ICR = USART_ICR_ORECF;
 if (USART_RS232->ISR & USART_ISR_NE) // Noise Err
 USART_RS232->ICR = USART_ICR_NCF;
 if (USART_RS232->ISR & USART_ISR_FE) // Framing Error
 USART_RS232->ICR = USART_ICR_FECF;

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
cjaya.1
cjaya.1Author
Associate III
October 3, 2022

Thank you for the reply. I am still having problem. Like you said I am clearing out the Overrun error by reading the DR. I am using STM32F405RGT6 device but I couldnt find any reference material how to clear the Overrun error.

So on the USART2_IRQHandler, this is my code

void USART2_IRQHandler(void)
{
 uint32_t status = USART2->SR;
 
if(status & USART_SR_RXNE)
 {
 c = USART->DR;
 
 if( i < 30)
 Receive[i++] = c; 
 }
else if (status & USART_SR_ORE)
 {
 c = USART->DR;
 if( i< 30)
 Receive[i++] = c;
 CountRx2Overrun++;
 }
}

Can you point to me what I am doing wrong. Thank you

EEbyKarl
Visitor II
October 5, 2022

You need to call HAL_UART_Receive_IT() after each interrupt after you read the character out of the register, which then enables interrupt again for the next character.

cjaya.1
cjaya.1Author
Associate III
October 5, 2022

Thank you for the reply. So on the USART2_IRQHandler() inside, I should call back HAL_UART_Receive_IT(). Is that right?

EEbyKarl
Visitor II
October 5, 2022

Yes, that is correct.

AScha.3
Super User
October 14, 2022

HAL_UART_Receive_IT(&huart2, (uint8_t*)ch, 1); -- need pointer here ->

HAL_UART_Receive_IT(&huart2, &ch, 1);

"If you feel a post has answered your question, please click ""Accept as Solution""."
cjaya.1
cjaya.1Author
Associate III
October 15, 2022

Thank you for all of your replies. after increasing the buffer size. I am able to receive 19 strings. But the 19 strings I received is static. It needs to be change every time i receive. Every time I receive it should be different set of data. Is something I need to reset the buffer everytime I receive and the buffer pointer. Any thoughts about this.