But now I encountered some problem within an embedded project, I want to share the solution with you.Continuously receive data using interrupts on UART is complicated (or even impossible) in HAL.
Most approaches I found crawling the internet are using the LL library to achieve this and many discussions around HAL do not end in satisfaction. Some work around the problems with dirty approaches (e.g. HAL code itself), other step back from interrupt and use a polling approach. Instead, it offers functions to receive a special amount of data using a non-blocking interrupt approach, handling all the difficulties with tracking the state in the instance stucture (huartX) and entering a callback for the diverse states of the receptiontransmission, e.g. HALUARTRxCpltCallback(UARTHandleTypeDef huart) or void HALUARTRxHalfCpltCallback(UARTHandleTypeDef huart). Dont use the high level receive functions at all for the continuous RX behaviour, since you do not want to receive a special amount of data but be called at each reception. I did not try during transmit, but it seems not disturbing anything. If you plan to use the HALUARTReceiveIT functions in parallel, you could try to put your code below the handler. I did not test it, but there is a good chance that it works.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |