Home/Support/Support Forum/Garbage data on Serial Port
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Garbage data on Serial Port

0 votes
Hi,

Currently I am using

wfd ahrsChar = cof_serEgetc();

to read the data. The complete flow is as follows:

flush_buffers();
ser485open(115200); // Set baud rate first
ser485wrFlush(); // Clear Rx and Tx data buffers
ser485rdFlush();
serCflowcontrolOff();
// Initializes serial mode and disables RS-485 transmitter
serMode(0);
// check_Servoes();
memset(&ahrs, 0, sizeof(ahrs));
while(1)
{
parseokay = 1;

costate
{
wfd ahrsChar = cof_serEgetc();
// if((serEread(&ahrsChar,1,1)) > 0)

switch(ahrsMessageByte)
{
case 1:
if(ahrsChar==PREAMBLE1 && ahrsStringCount==0)
{
sensorMessage[ahrsStringCount] = ahrsChar;
ahrsStringCount++;
ahrsMessageByte = 2;
}
break;
case 2:
if(ahrsChar==PREAMBLE2 && ahrsStringCount==1)
{
sensorMessage[ahrsStringCount] = ahrsChar;
ahrsStringCount++;
ahrsMessageByte = 3;
}
else if(ahrsChar==PREAMBLE1)
{
sprintf(buf,"P 2 \n");
}
else
{
ahrsMessageByte = 1;
ahrsStringCount = 0;
// printf("E 2 \n");
}
break;

/// And further processing.

Strange part is first few bytes come ok. After that I start getting bad data. Any help would be greatly appreciated.
Regards
related to an answer for: WHy do I get garbage data on serial port?
asked Mar 2, 2016 in Rabbit Software by siddarth New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
If you remove your "switch(ahrsMessageByte)" section and just dump the hex value of the bytes read, do you see the expected data? If so, there's some problem in how you're processing the bytes. If not, you should focus on the code sending bytes to you, or in monitoring the actual hardware lines to see what data is coming into the Rabbit to confirm it's what you're expecting.
answered Mar 4, 2016 by TomCollins Veteran of the Digi Community (2,305 points)
...