Hi Team ,
I am experiencing an issue while reading UART data of 48 bytes continuously with 100usec delay where in we have observed the data is getting lost in between while reading 48bytes.
For Example :
Read 1 : Received Correct 48 Bytes successfully
Read 2 : Received Uncorrect 48 Bytes // Corruption
Read 3 : Received Correct 48 Bytes successfully
Read 4 : Received Uncorrect 48 Bytes // Corruption
Read 5 : Received Correct 48 Bytes successfully
Read 6 : Received Correct 48 Bytes successfully
Read 7 : Received Uncorrect 48 Bytes // Corruption
Read 8 : Received Correct 48 Bytes successfully
Read 9 : Received Correct 48 Bytes successfully
Read 10 : Received Uncorrect 48 Bytes // Corruption
Read 11 : Received Correct 48 Bytes successfully
Read 12 : Received Correct 48 Bytes successfully
Read 13 : Received Correct 48 Bytes successfully
Read 14 : Received Correct 48 Bytes successfully
Note : I did not observe any losses when tried with microcom
Below is my UART Initialization and UART receive / read code snippet
Let me know if i am missing something ? or there is something wrong
Note : UART here refers to CP210x which is a USB → UART Bridge enumerating 3 UARTS
=======> UART INITIALIZATION <=========
void ExtUart_Init(void)
{
uint32_t ret;//,flags;//size_pipe;
fd = le_tty_Open("/dev/ttyUSB1", O_RDWR | O_NOCTTY);
ExtUART_fd=fd;
if(fd<0)
{
LE_ERROR("ECUConnect: EXT_UART SERIAL OPEN FAILED %d",fd);
return;
}
else
{
LE_INFO("ECUConnect: EXT_UART SERIAL OPEN SUCCESS");
}
usleep(100000);
if((ret=le_tty_SetBaudRate(fd,LE_TTY_SPEED_2000000))!=LE_OK)
{
LE_INFO("ECUConnect: Baud rate:%d",GLOB_IRU_CurSettings.UART_1Setting.UART_Baudrate);
LE_ERROR("EXT_UART SETBAUDRATE FAILED ");
LE_INFO("%d",ret);
if(ret==LE_NOT_FOUND)
{
LE_INFO("BRT NOT supported");
}
}
else
{
LE_INFO("ECUConnect: Baud rate:%d",GLOB_IRU_CurSettings.UART_1Setting.UART_Baudrate);
LE_INFO("ECUConnect: EXT_UART SETBAUDRATE SUCCESS");
}
usleep(10000);
if(le_tty_SetFraming(fd,GLOB_IRU_CurSettings.UART_1Setting.parity,GLOB_IRU_CurSettings.UART_1Setting.DataBits,GLOB_IRU_CurSettings.UART_1Setting.stopBits)!=LE_OK)
{
LE_ERROR("ECUConnect: EXT_UART SET_FRAMING FAILED");
}
else
{
LE_INFO("ECUConnect: EXT_UART SET_FRAMING SUCCESS");
}
if(le_tty_SetFlowControl(fd,LE_TTY_FLOW_CONTROL_NONE)!=LE_OK)
{
LE_ERROR("ECUConnect: EXT_UART SET_FLOW CONTROL FAILED");
}
else
{
LE_INFO("ECUConnect: EXT_UART SET_FLOW SUCCESS");
}
if(le_tty_SetRaw(fd,48,UART_READ_TIMEOUT)!=LE_OK)
{
LE_ERROR("ECUConnect: EXT_UART SET_RAW FAILED");
}
else
{
LE_INFO("ECUConnect: EXT_UART SET_RAW SUCCESS");
}
}
===============> UART READ <====================
ret=read(fd, &UART_Recv_Buffer_1,48);
if(ret==48)
{
if((UART_Recv_Buffer_1[0]==0xAA) && (UART_Recv_Buffer_1[1]==0x55) && (UART_Recv_Buffer_1[46]==0x55) && (UART_Recv_Buffer_1[47]==0XAA))
{
//Read successful…
}
else
{
//Read fail…
}
}
Thanks & Regards
- Swapy