2020-05-26 02:42 PM
I'm using a NUCLEO-L053R8 board. I have tried a variety of USART settings including interrupt and DMA, but cannot reliably read unknown string lengths (at 115200 baud).
I want to read either until a certain character is seen, or for a specific period of time.
However, by using the Arduino IDE and running the NUCLEO as an Arduino, I have no problem using the 'serial.read()' function to accomplish the task.
What kind of magic is under the hood in the Arduino code?
2020-05-26 03:03 PM
You can use HAL_UART_Receive() in a manner similar to serial.read. Adjust timeout and size to your use case:
uint8_t c = 0;
if (HAL_UART_Receive(&huart, &c, 1, 1000) == HAL_OK) {
// received character is in c
}
2020-05-26 10:09 PM
Try this one for starting point: https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx
2020-05-27 05:44 AM
Thanks, but that method will loose characters at 115200 baud.
2020-05-27 07:52 AM
> What kind of magic is under the hood in the Arduino code?
Looks like they use some smart heuristic to guess when to stop (timeout?) and their low level code is more efficient than the ST library.
-- pa
2020-05-28 06:34 AM
This is good information. Seems like my biggest issue was that the default clock frequency for an X-CUBE project on the NUCLEO-L053R8 board was 2MHz. Upping that to 30MHz solved the problem.