2015-09-01 12:32 AM
Hi everybody,
I am using several flavours of STM32: STM32F407, STM32F030, STM32F071, STM32F303 (soon). Concerning UART, I want to set up a protocol using variable-length messages. In order to minimize the CPU overhead, I want to use the TX with DMA and interrupt at the end of the transmitted message, and RX with DMA and interrupt at the end of the received message.LIN mode
, can you give me some advice? Q1: On the TX side, is there any difference with UART mode @ 8-bit data length? Q2: On the RX side, apart from the Break character handling, is there any difference with UART mode @ 8-bit data length? Q3: Any other caveats or constraints with LIN mode? Best regards, Mauro #stm32-uart-lin-break Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-05-23 09:51 AM
I should also mention I'm trying to use this also. will report back here if I get this working
/* enable RX NOT EMPTY inturrupt on uart */
__HAL_UART_ENABLE_IT(&UartHandle,USART_CR1_RXNEIE);2017-05-25 07:35 AM
Ben,
you must enable RX NOT EMPTY inturrupt on uart, as you suggested:__HAL_UART_ENABLE_IT(&UartHandle,USART_CR1_RXNEIE);
Hence,USARTx_IRQHandler()
will be called upon *each* byte reception on the UART. I suggested you can add your own code in source file stm32f7xx_it.c, inside USARTx_IRQHandler(), between USER CODE BEGIN USART2_IRQn 1 and USER CODE END USART2_IRQn 1. Since USARTx_IRQHandler() will be called upon *each* byte reception on the UART, you know where is the last character received! The HAL functions know where is the next free array position, since they must store the next received character. If you read stm32f7xx_hal_usart.c, inside USART_Receive_IT() you can see that the handle husart contains such pointer. The *last* received character has been stored at (husart->pRxBuffPtr -1). If your UART handle is named UartHandle, then the last received character is*(UartHandle->pRxBuffPtr -1)
. So, you can write something like:if (*(UartHandle->pRxBuffPtr -1) == '\n')
end_of_line_reached = TRUE;
else
end_of_line_reached = FALSE;
You can learn a lot by reading inside the HAL sources.Finally, your function USARTx_IRQHandler() seems way too long for an IRQ handler, which is usually executed at a priority level and therefore delays other lower priority IRQ handlers until it is finished.
Good real time coding requires to do as little as you can inside the IRQ handler, and perform all longer actions which can be delayed (like callingBSP_LCD_ClearStringLine()
andBSP_LCD_DisplayStringAtLine()
)outside the IRQ handler, e.g. in the background scheduler.Cheers,
Mauro