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.2015-09-22 04:05 AM
Hi Mauro,
Q1 & Q2: you are right there is no difference with UART mode @ 8-bit data lengthQ3: no constraints with LIN mode apart of ones mentioned in specification I'd highly recommend to have a look to LIN (local interconnection network) mode paragraph in the USART section of any STM32 reference manual.-Syrine –2017-05-08 11:00 AM
Hi Mauro,
did you ever find a solution for end of message termination over uart? I have a similar problem and LIN mode doesn't appear to do anything, I was hoping it would start a new write to the buffer on being triggered but it doesn't appear to.
I tried initializing the handle with:
HAL_LIN_Init(&UartHandle,UART_LINBREAKDETECTLENGTH_10B);
then calling;
HAL_UART_Receive_IT(&UartHandle,(uint8_t *)buffer,sizebuf);
but no luck or clue. I'm just using a simple bluetooth module and trying to tx commands of different leghths.
Even if I used same size command leghths , they arrive in the buffer as if in a circular buffer !!
my simple bluetooth module just works on any other micro I have used it with without trouble since the end of line is detected.
2017-05-08 01:37 PM
I don't like using this as a message terminator, as there's no way to distinguish it from a real error.
This attitude is wise and prudent. Do you have enough bandwidth to accommodate a CRC?
2017-05-11 09:04 AM
Thanks Syrine,
actually I never had a chance to try it out, since I shifted to other projects.
But I'll keep it in mind.
Mauro
2017-05-11 09:31 AM
Ben,
I never had a chance to experiment with the msg termination over UART by using the Break in LIN mode.
I don't understand your case, though.
You mention you want to transmit commands to a Bluetooth module, but you call HAL_UART_Receive_IT (), which is what you call when you are receiving.
I don't understand what you mean with 'arrive in the buffer as if in a circular buffer'. Can you make an example?
My case with variable msg lengths and Break in LIN mode was a case for the Receiver side, but you appear to be dealing with a Transmitter.
I guess a Receiver would call HAL_UART_Receive_IT () and await for the ISR to call HAL_UART_RxCpltCallback() if no errors occurred, or HAL_UART_ErrorCallback() if any errors occurred, including the Break detection error, which should be treated as a Message Termination case.
Cheers,
Mauro
2017-05-11 11:07 AM
Hi Mauro, thanks for the reply. I should say recieve command, sorry. I am transmitting a command of differnt character leghth from an android app. The bluetooth reciever HC-05 spits out the recieved text over UART.
I am recieving the text over the uart to ARM32F7 with HAL_UART_Receive_IT (); succecfully.
As the text arrives over HAL UART it just fills the buffer in a loop ( circular buffer I think ) This is fine for a console but I just want to copy (uint8_t *)buffer at line break to another buffer and then wait for the next mesage & repeat.
sorry for this begginer question , I'm fairly new to C / arm32. How would I check the HAL_UART_RxCpltCallback(); for a line break ? something like this ?
uint8_t data = HAL_UART_RxCpltCallback();
if ( data != 0 )
{
copy the buffer;
break;
}
2017-05-18 08:17 AM
Ben,
there are some misunderstandings:
My initial question implied that the Transmitter after transmitting the 'line break' also transmits a Break character, which the HAL ISR can recognize and signal by calling HAL_UART_ErrorCallback().
Cheers,
Mauro
2017-05-18 08:19 AM
Probably no, but I'll keep this as an option.
2017-05-23 09:09 AM
Hi Mauro !
Thanks for this in depth answer
' This code can fetch the last received character from the buffer '
probably a stupid question , but how do I read last character received in the buffer if the command messages are different lengths?
I can't predict how long the commands will be so how do I know where in the buffer the last character will be ?
I have something working , but it would be much better just to check for the 0x0A line break !
void USARTx_IRQHandler(void)
{ HAL_UART_IRQHandler(&UartHandle); // receive bytes when they are ready ?? HAL_UART_Receive(&UartHandle,(uint8_t *)bbboxBlueRx,8,1); // RX // get the command name if ( bbboxBlueRx[0] == '♯' ) { for (int a=0; a<7; a++) { if (bbboxBlueRx[a+1] == '@' ) {break;} if (bbboxBlueRx[a+1] == '*' ) {break;} bbboxBlueRxCommand[a] = bbboxBlueRx[a+1]; } BSP_LCD_ClearStringLine(28); BSP_LCD_DisplayStringAtLine(28, (uint8_t *)&bbboxBlueRxCommand); } // get the command value if ( bbboxBlueRx[0] == '@' ) { for (int b=0; b<7; b++) { if (bbboxBlueRx[b+1] == '*' ) {break;} bbboxBlueRxValue[b] = bbboxBlueRx[b+1]; } BSP_LCD_ClearStringLine(30); BSP_LCD_DisplayStringAtLine(30, (uint8_t *)&bbboxBlueRxValue); } UARTbbboxready = 1; // command and value ready to be prcessed flag }