xbee arduino transmission not stable

Hi, I am trying to send x, y, z co-ordinates from an arduino connected to an accelerometer to another over xbees :-

Here’s the code :-
Sender

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>


// Assign a unique ID to accelerometer
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
// Declare the variables for Co-ordinates

int8_t x;
int8_t y;
int8_t z;

char HEAD = 'H';
char TAIL = 'T';

void setup() 
{
  Serial.begin(9600);
  
  // Initialize the accelerometer sensor
  
  if(!accel.begin()) {
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
  
  accel.setRange(ADXL345_RANGE_16_G);
}

void loop()
{
  sensors_event_t event; 
  accel.getEvent(&event);
	
  // Getting the x, y, z co-ordinates from accelerometer truncating the floating point value
  x = (event.acceleration.x * 100) / 100;
  y = (event.acceleration.y * 100) / 100; 
  z = (event.acceleration.z * 100) / 100; 
        
  
  
  Serial.write(HEAD);
  Serial.write(x);
  Serial.write(y);
  Serial.write(z);
  Serial.write(TAIL);

  delay(50);
}

Reciever

int8_t x;
int8_t y;
int8_t z;

char HEAD = 'H';
char TAIL = 'T';

void setup()
{
    Serial.begin(9600);
    pinMode(13, OUTPUT);

}

void loop()  

{
    
  while(Serial.available()) {
    
    if(Serial.read() == HEAD) {
      x = Serial.read();
      y = Serial.read();
      z = Serial.read();
      
      // Toggle the LED
      digitalWrite(13, !digitalRead(13));
  
      if(Serial.read() == TAIL) {
        break;
      }
    
    }
     
  }
  
  delay(50);
}

The LED on the reciever is not blinking in a uniform manner. When I print x, y, z values I get negative ones on occaision which I’ve read somewhere indicate no data is coming through. Looking at it gives an impression that break in transmission is periodic.

  // Getting the x, y, z co-ordinates from accelerometer
  x = (event.acceleration.x * 100) / 100;
  y = (event.acceleration.y * 100) / 100; 
  z = (event.acceleration.z * 100) / 100;

WTF? Why are you multiplying by 100 and then dividing by 100? What do you expect that to accomplish?

  while(Serial.available()) {
    
    if(Serial.read() == HEAD) {
      x = Serial.read();
      y = Serial.read();
      z = Serial.read();

If at least one byte has arrived, read all 4 of them. Does that REALLY seem like a good idea?

WTF? Why are you multiplying by 100 and then dividing by 100? What do you expect that to accomplish?

That's to truncate the two decimal place floating point value in 'event.accleration.x' . I've edited my post

If at least one byte has arrived, read all 4 of them. Does that REALLY seem like a good idea?

Yeah what you say does make sense. But if I read 4 values instead of 3 why should it affect the transmission?

anath2: That's to truncate the two decimal place floating point value in 'event.accleration.x' . I've edited my post

but:

int8_t x;

try Serial.print(x) and look at your result.

anath2: Yeah what you say does make sense. But if I read 4 values instead of 3 why should it affect the transmission?

what if less than 4 have arrived?... serial is slow-ish.

try something like this:

int x;
int y;
int z;
int myNumber;
byte message;
char HEAD = 'H';
//char TAIL = 'T';

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop()  

{ 
  if (Serial.available() > 3) 
  {
    if (Serial.peek() == 'H') 
    {
      char dump = Serial.read();//toss the header
      x = (Serial.read() - '0');
      y = (Serial.read() - '0');
      z = (Serial.read() - '0');
      myNumber = x * 100 + y * 10 + z ;
      message = 1;
    }
    else
    {
      char dump = Serial.read();//throw away non-header
    }
    if (message)
    {
      Serial.println(x);
      Serial.println(y);
      Serial.println(z);
      Serial.println(myNumber);
      digitalWrite(13, !digitalRead(13));
      message = 0;
    }
  }
}

has no error checking for numbers, though