Serial communication problem

Hello Everyone

Im doing a project in which i want to send the data serially through IR.

There are five modules(Duemilanove) and i have to send the data from 1st module to 2nd,1st module data & second module data to 3rd,1st2nd&3rd to 4th module and so on.

Although its working but the order in which i received data in a module is not the same as their sending order. Can anyone help me to suggest a logic so that the data can be received in the same sending order. :frowning:

What's not arriving in order?

1st to 2nd?

2nd to 3rd?

What baud are you trying to use? Are you sure that you are actually receiving something and it isn't just "trash" picked up by the sensor?

Have you tried separating the comms? Just send from 1st to 2nd, 2nd to 3rd without adding data in the packets sent?

if you send a char with a value of 1 (not ascii), you receive 128 on the other side? is that it?

Try posting some software so we can see what you are actually doing and if it might be done wrong.

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)..

Hi all,
I'm interfacing a simulink model with arduino and sending 8bit values (0 to 255) values to and from the arduino. The problem is that I now need to send 10bit values (0 to 1023) to and from the arduino but so far I did not manage to do that.

Any idea?

Thanks.

Two ways. As strings (898 -> '8', '9', '8') or as two bytes. Have simulink break the integer into most significant byte and least significant byte, and send the two bytes. Have the Arduino reassemble the two bytes.

If that proves too difficult, divide the value by 4, and send that value and the remainder. Then, multiply the first value received by 4 and add the second value (the remainder).

Whatever you do, keep in mind that serial data is NOT guaranteed to be delivered.