2017-01-24 06:27 AM
Hi all
I'd like to use UART to receive soe fixed length datas, ex.'1234567890'.
uint8_t buff[10];
hal_uart_receive_it(&huart, buff, 10); or
hal_uart_receive_dma(&huart, buff, 10);
How should I do and then make sure the buff contain '1234567890' every time, not '5678901234' or other situation.
Thank you in advance.
2017-01-24 07:23 AM
Hi
paker.earth
,I advice you to have a look at the 'UART' examples provided by ST.
Depending on your STM32 device, download the convenient package. The 'UART' examples could be found under: STM32Cube_FW_F...\Projects\STM32F....\Examples\UART May this help youKhouloud.
2017-01-24 07:32 AM
You'd need some flexibility in your code to be able to resynchronize to the data stream if you lost bytes or came in mid stream. ie realize you have 4 bytes of your packet in the first receive, and you need only get 6 more to complete it.
2017-01-24 07:32 AM
The device that you are using is asynchronous by design, there is no data framing at the byte level.
Your options are to put framing bytes (STX/ETX) around your data and use those to delineate your data or put an idle period between your data packets. Arrange for the idle time to be longer than one packet, then use DMA with interrupts along with a timer interrupt. If the packet is too short, the timer will fire in the gap between packets, picking off a short packet. If you get a reasonable amount of data, the DMA transfer will give you an interrupt and you can kill the timer.
If you have an unstated requirement that you can't change the data stream by adding framing or idle periods, you're basically screwed. You will have to look at the data, figure out what is missing and use short DMA requests to try and get back into sync, but you have lost data. That's probably not okay.
A