2023-09-10 08:05 AM - edited 2023-09-13 01:09 AM
I'm trying to port a UART driver from aurdino to STM32. Able to relate all interfaces for aurdino vs STM32 while can't able to map ones for the following
serial.peek()
serial.flush()
Does HAL have an direct interface as peek() to get the next byte of incoming serial data?
Solved! Go to Solution.
2023-09-13 01:39 AM - edited 2023-09-13 01:41 AM
I think you can't still got the data but you can send the DR value to a unit8_t and save it her than you can rewrite this value to the DR after reading.
Best regards.
II
2023-09-10 08:52 AM - edited 2023-09-10 09:04 AM
Hello @darthana
For serial.flush(), I suggest you to use this:
For serial.peek(), I suggest you to use this:
Best regards.
II
2023-09-10 03:05 PM
You'd have to create a buffer for the incoming data so that you could query it.
The STM32 doesn't hold a large number of bytes, and not in a way you can probe/query
2023-09-13 01:07 AM
serial.peek() in arduino provides next byte but without clearing it. So when I use read() later, I can still get the data.
As per my understanding, reading USARTx->DR clears data as well as RXNE flag.
2023-09-13 01:30 AM - edited 2023-09-13 01:41 AM
Yes, reading USARTx->DR clears RXNE flag, so the data (DR content) becomes undefined. You need a software library that saves the new char and returns it later. See also getc & ungetc (available with any decent stdio impl.)
As for flush, see __HAL_USART_SEND_REQ(USART_RXDATA_FLUSH_REQUEST)
2023-09-13 01:39 AM - edited 2023-09-13 01:41 AM
I think you can't still got the data but you can send the DR value to a unit8_t and save it her than you can rewrite this value to the DR after reading.
Best regards.
II