Trouble interpreting air flow sensor output

Hello,

I’m having a problem interpreting the output from an air flow sensor.

I’m using an Arduino Mega 2560, Arduino 1.0.4 and Windows XP. The sensor is a Sensirion EM1 air flow sensor, part #EM1NV4R0V_1A.
The spec sheet is here: http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/GasFlow/Sensirion_Gas_Flow_EM1_Datasheet_V3.pdf
It’s also an attachment below.

Per the spec sheet (Page 7) The measurement values are provided as a 16 bit signed integer in binary format with 2 bytes synchronization preceding.
sync 0x7F
sync 0x7F
MSB
LSB

In addition, The received value is a 16 bit signed integer in the two’s complement representation. The calibrated data is multiplied by a constant factor and then rounded to the next smaller integer in order to transfer also fractions of a unit through the integer protocol.

The air flow value should be 60.00 and I get 53.99

Here’s my code:

 int incomingByte1 = 0; //1st sync byte
 int incomingByte2 = 0;  // 2nd sync byte
 int msb = 0; //most significant byte of data
 int lsb = 0;  // least significant byte of data
 int measurementBit = 0; // declare variable to hold 16 bit signed integer in binary format
 int FlowScaleFactorDivision = 128; // declare variable for the flow scale factor of 1/128 ln/min 
 float ActualMeasurement = 0.0;

void loop() {
    if (Serial2.available()>=4) {
    incomingByte1 = Serial2.read();
    incomingByte2 = Serial2.read();
    msb = Serial2.read();
    lsb = Serial2.read();
      
   if (incomingByte1 == syncbyte && incomingByte2 == syncbyte && msb != syncbyte); {
     measurementBit = msb + (lsb<<8); 
     ActualMeasurement = measurementBit / FlowScaleFactorDivision; 
     Serial.println(ActualMeasurement);

Any thoughts?

Regards,
Mark

Sensirion_Gas_Flow_EM1_Datasheet_V3-1.pdf (329 KB)

Try changing this:
measurementBit = msb + (lsb<<8);
to:
measurementBit = (msb<<8) | lsb;

Or even better, to this:

measurementBit = word( msb, lsb);

I tried both of the following:

measurementBit = (msb<<8) | lsb;

measurementBit = word( msb, lsb);

and the result is 254 instead of 30.
Any other things I could be doing incorrectly?

Regards,
Mark