2022-07-20 11:21 AM
Shouldn't just the RXNE flag trigger with this code? or does the outgoing transmit message also generate an RXNE flag?
Thanks!
Solved! Go to Solution.
2022-07-21 12:55 PM
A good example of how "helpful" the HAL is...
There is a decent USART example:
2022-07-20 03:43 PM
With HAL you are supposed to use it's callbacks.
A hardware loop or a half-duplex mode with receiving not turned off while transmitting will result in receiving everything that is transmitted.
2022-07-20 04:49 PM
Thanks for replying, no hardware loop and full duplex, so I don't believe that's the issue.
2022-07-20 08:47 PM
Are you using the cubemx generated HAL, API or building your own? - I'd recommend not using the cubemx generated HAL, their ISR's are massively bloated and takes up too much time. Anyway, regarding your issue, if you're trying to check if there's a byte pending to be read in the RX register then you should be checking the RXNE bit in the ISR register something like below.
if (READ_BIT(uart_ptr->Instance->ISR, USART_ISR_RXNE)) {
// read it, so that RXNE is cleared by the hardware
char byte = uart_ptr->Instance->RDR;
}
And you're using the wrong macro. The __HAL_UART_GET_IT_SOURCE macro doesn't give you the source of an interrupt trigger but instead lets you check if the interrupts for TX or RX are enabled or disabled in the control registers.
2022-07-21 12:28 PM
Thank you very much- that makes a lot of sense, I didn't realise that the macro was the wrong one. I was trying to use a mixture of HAL and my own interrupt, I want to trigger an interrupt whenever a byte is received and once detected use the HAL routine to handle it. You are right, the HAL serial interrupt is bloated, is there better example code for UART handling?
2022-07-21 12:55 PM
A good example of how "helpful" the HAL is...
There is a decent USART example:
2022-07-24 06:49 AM
I managed to understand the reason for the RX interrupt, it was pretty simple, basic logic, the processor is communicating with a device and the device returns a character when it receives one , so that triggers the interrupt - pretty basic mistake on my part. I got the HAL routines running but they don't seem to be fast enough to receive a string at 115k. So I'll have to wade through setting registers by hand. Thank you very much for the example code Piranha, much appreciated.