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