Incorrect bluetooth values after tranmission.

Hello,

I’m currently receiving incorrect values when sending two bytes via an HM-11 modules. I’m receiving data on both ends. However the data is not the same when comparing the HEX values from each. I basically just want to transmit a 16bit value between modules.

Here is my receiving code to view the output. I’m using Serial2 to transmit the data between modules.

   if(Serial2.available()>=2) //&& Serial3.available()>=6)
   {

      Serial2.readBytes(rightInput,2);
//      Serial3.readBytes(leftInput,6);
      Serial2.write(0x00);
      rightMSB = ((rightInput[0] << 8) & 0xFF00) | (rightInput[1] & 0x00FF);
//      dacRight.setVoltage(rightVoltage, false);
      Serial.print(rightInput[0], HEX);
      Serial.print("\t");
      Serial.println(rightInput[1], HEX);
      Serial.flush();

Here is the sending data. Its reading the data from a ADS1114 then sending the bytes via bluetooth where its processed.

 if(Wire.available() == 2)
{
outputData[0] = Wire.read();//MSB
outputData[1] = Wire.read();//LSB
if(Serial.available()>=1)
  {        
  Serial.write(outputData, 2);
  Serial.flush();
  Serial.read();
  }
}

Thanks

1) Post your full code (at least somewhere), not just snippets because I cannot tell what datatype rightInput is or if rightMSB is a signed int or what and I don't fancy guessing.

2)

 if(Wire.available() == 2)
{
outputData[0] = Wire.read();//MSB
outputData[1] = Wire.read();//LSB
if(Serial.available()>=1)

Be careful here, first, if you have 3+ bytes in the buffer then this code will never execute, and second, if you have 2 bytes the program will read both of them and "if(Serial.available()>=1)" will be false. You either need to wait for the next byte to come in (up to a certain timeout) or check "if(Wire.available() >= 3)".