How to setup USART to read unknown string lengths.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-05-26 2: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?
- Labels:
-
STM32L0 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-05-26 3: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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-05-26 10:09 PM
Try this one for starting point: https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-05-27 5:44 AM
Thanks, but that method will loose characters at 115200 baud.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-05-27 7: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-05-28 6: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.
