Try these functions, it might not be exactly want you need though but anyway here:
void sendSerial(long data) {
Serial.begin(9600);
Serial.print(data);
while (Serial.read() != "*") {
;
}
Serial.print("+");
while (Serial.read() != "^") {
;
}
delay(5);
}
long receiveSerial() {
Serial.begin(9600);
long returnData = Serial.read();
Serial.print("*");
while (Serial.read() != "+") {
;
}
Serial.print("^");
return returnData;
}
The function sendSerial() sends the data in the provided parameters, and it waits for a comfirmination before continuing. The function receiveSerial() returns what data sent. This ensures that the processors don't get out of sync.
Hope this helps.