Im not receiving in the correct order means actually im sending two datas(bytes) from my second module.But sometimes the data i send last in 2nd module will received as first in 3rd module and viceversa..Actually the data is a byte which is selected by using a switch.Switch is connected to 14th pin of arduino.
Here is the code of 2nd module.
byte i,j,k=0,reference=27,buttonstate,firstdata=5,temp,tempdata;
int a=0;
void loop()
{
buttonstate=digitalRead(buttonpin);
if(buttonstate==HIGH)
{
k++;
if(k==26)
k=0;
while(digitalRead(buttonpin)==HIGH)
alphadisplay();
convert();
}
if(reference!=k||Serial.available()>0)
{
if(Serial.available()>0)
{
tempdata=Serial.read();
if((tempdata>0)&&(tempdata<25))
{
firstdata=tempdata;
}
else
firstdata;
}
Serial.print(firstdata,BYTE);
forwardserial();
reference=k;
}
alphadisplay();
}
void convert()
{
temp=k;
temp=((k&0x1f)|0x80);
}
convert() is used to identify the data belonging to which module.for 2nd i made MSB as 10,for 3rd 01, for 4th 11..
Here is the code for 3rd module
byte i,j,k=0,reference=27,buttonstate,firstdata,temp,seconddata;
byte tempdata,tempdata1;
int a=0;
void loop()
{
buttonstate=digitalRead(buttonpin);
if(buttonstate==HIGH)
{
k++;
if(k==26)
k=0;
while(digitalRead(buttonpin)==HIGH)
alphadisplay();
convert();
}
if(reference!=k||Serial.available()>0)
{
if(Serial.available()>0)
{
tempdata=Serial.read();
//tempdata1=Serial.read();
//tempdata1=Serial.read();
if((tempdata>0)&&(tempdata<26)||(tempdata>128&&tempdata<154))
{
firstdata=tempdata;
}
else
firstdata;
checkserial();
}
Serial.print(firstdata,BYTE);
Serial.print(seconddata,BYTE);
forwardserial();
reference=k;
}
alphadisplay();
}
void convert()
{
temp=k;
temp=((k&0x1f)|0x40);
}
void checkserial()
{
if((firstdata&0xc0)==0x00)
{
firstdata=firstdata;
}
else if((firstdata&0xc0)==0x80)
//else
{
seconddata=firstdata;
seconddata=(seconddata&0x3f);
}
}
check serial() is used to differentiate the datas(which data which module)..