2019-03-21 06:20 AM
Hello,
I'm designing an application where a PCB with STM32F031C6 has to receive a minimum of 5 bytes via an half-duplex communication. Transmission is delimited by special character, ASCII is used. Ideally, the transmission would be composed by 3 data bytes and 2 delimiters (minimum).
I don't properly understand if the HAL_UART_Receive_IT function suits my interest (i see it works with n° of bytes) and, more importantly, how the HAL_UART_Error_Callback is triggered.
I don't understand the so-called "half transfer" callbacks too.
The documentation is not helping me, i already read some PDFs...
Anyone who understood enough to explain it to me?
Thank you in advance,
Mirco
Solved! Go to Solution.
2019-03-21 10:07 AM
More importantly, understand that every byte received generates an interrupt. The IRQ Handler calls into the HAL, and when the HAL accumulates the data length you requested it calls your routine.
This is unduly circuitous in my opinion, and you'd be well advised just to service the UART in IRQ the same way people have done for a quarter century.
The Half/Complete Transfer is a DMA terminology used where the buffer length described to the DMA controller is split in two to provide a ping-pong method to access the inactive half of the buffer.
2019-03-21 09:48 AM
In order to receive variable length data, or data that may arrive at any time, you need to either create your own interrupt-driven code, or use the HAL_UART_Receive_DMA() function, with the DMA configured for circular mode. You then ignore the half transfer complete and full transfer complete interrupts. There have been several threads on this forum about this. Try searching for UART and DMA.
Warning: When using the HAL_UART_Receive_DMA() function, the HAL code will disable the receiver if the serial port reports ANY error. You need to add code to the error callback to re-start the receive function. Or edit the HAL UART code directly to keep the receive function going on error.
2019-03-21 10:01 AM
Uart is easy to handle with low layer. First, use interrupt for receiving byte by byte like it is done on most 8 bit mcu. In the interrupt, check for your end character, and set a flag for main loop to process the message and block any further incoming. Next, use hw feature to detect the end character, finally, manage a rolling buffer fifo to keep accepting incoming bytes while main loop is still processing any received messages. Later you might consider using dma cycling a buffer and check every 1msec.
2019-03-21 10:07 AM
More importantly, understand that every byte received generates an interrupt. The IRQ Handler calls into the HAL, and when the HAL accumulates the data length you requested it calls your routine.
This is unduly circuitous in my opinion, and you'd be well advised just to service the UART in IRQ the same way people have done for a quarter century.
The Half/Complete Transfer is a DMA terminology used where the buffer length described to the DMA controller is split in two to provide a ping-pong method to access the inactive half of the buffer.
2019-03-22 12:12 AM
I will probably stick with the classic method as you both said, placing the code in the stmxxx_it.c routine.
2019-03-22 12:12 AM
Thank you for the explanation!
2019-03-22 12:13 AM
Thanks! What do you mean by "use hw feature to detect the end character"? Which hw feature?