2019-05-05 04:43 AM
I am using STM32F103C8T6 MCU and STM32CubeMx.
I currently reciving data from UART and printed on PC's serial but it will work only when data terminated by '\n' character.
But what if the data from uart not terminated with '\n'??
Can anybody help??
Please find the code below:
if (huart->Instance == USART2) //current UART
{
if (Rx_indx==0)
{
//for (i=0;i<100;i++)
Rx_Buffer[256] ="\0";
} //clear Rx_Buffer before receiving new data
if (Rx_data[0]!='\n') //if received data different from ascii 13 (enter)
{
Rx_Buffer[Rx_indx++]=Rx_data[0]; //add data to Rx_Buffer
}
else //if received data = 13
{
Rx_Buffer[Rx_indx++] = '\n';
memcpy(Tx_Buffer,Rx_Buffer,Rx_indx);
UART2_print(Tx_Buffer);
Rx_indx=0;
memset(Tx_Buffer, 0, 256);
}
HAL_UART_Receive_DMA(&huart2, Rx_data, 1); //activate UART receive interrupt every time
}
2019-05-05 05:18 AM
check every char you received in mcu when special char(enter ,space, : any terminating char) received then do operation on received data otherwise put char
in to buffer in next position till you don't receive special char .
i am using cool term pc software to watch UART received data and send data to mcu.
2019-05-05 05:20 AM
I already know that man but my question is different....
2019-05-05 06:23 AM
So what would terminate the data in your hypothetical? A different character, intersymbol time, protocol defined length?
Don't do things requiring multiple character times in callback/interrupt.
2019-05-05 07:43 AM
I am asking for communicating with GSM/GPS module SIM7000
whose response is as below:
"\r\n"<response data>"\r\n"