Serial Programming question

Arrch:
How about some debug prints?

if(Serial1.available())

{
    sync=Serial1.read();
    if(sync==0x02)
    {
      ...
    }
    else
    {
      Serial.print("The byte I received was not a sync byte: ");
      Serial.println(sync);
    }
  }




It's also worth noting that Serial.available() doesn't return a boolean, it returns a number of bytes in the buffer. The proper way to write it is:



if (Serial.available() > 0)

I will remember those pointers next time. I was using LED on 13 for debugging. I will use debug prints next time.

For now this solved the problem

void setup()
{
  Serial.begin(9600);
  Serial1.begin(300);
}

void loop()
{
  int sync;
  char data,fcs;
  if(Serial1.available())
  {
    sync=Serial1.read();
    //Serial.print(sync);
    if(sync==0xAA)
    {
      while(!Serial1.available());
      data=Serial1.read();
      //fcs=Serial1.read();
      Serial.print(data);
      
    //if((data+fcs)==0)
    //{
     // Serial.print(data);
    //}
    }
    
  }
}

Thank you. I have been struggling with this problem for many hours now. Seeking help here got it solved in minutes

Now I will go on to test the RF receiver and transmitter module