Garbage data on Serial Port

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 

");
}
else
{
ahrsMessageByte = 1;
ahrsStringCount = 0;
// printf("E 2
");
}
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

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.