Issues with i2c when using Wire.Available()

I am working on a project which requires communication from an Arduino Due (Master) and an FDC2214Q1 C to D IC (Slave), but there is some variability as to whether the code works or not depending on seemingly random variables.

I have narrowed the issue to the function I am using to read 2 bytes from the slave. The code is pretty standard, and is as followed:

// Read 2 byte from the FDC at 'address'
uint16_t FDC2214::read16FDC(uint16_t address) {
    uint16_t data;

    Wire.endTransmission(false); //restart
    Wire.requestFrom(_i2caddr, (uint8_t) 2);

    while (!Wire.available());
	    data =;
	    data <<= 8;

    while (!Wire.available());
	    data |=;
	    Wire.endTransmission(true); //end

    return data;

The code seems to get hung up sometimes on while (!Wire.available()) and if I simply remove that step, I never get the correct Device ID.

However, if I simply unplug the DUE and close the Serial Monitor and replug in and upload, it works. I just kind of upload and disconnect a few times and open and close the Serial Monitor and sometimes it works great, other times it gets hung up?

Any ideas what could be causing such and issue?

Code library from: FDC2214/FDC2214.cpp at master · zharijs/FDC2214 · GitHub

Please, simply execute the following codes to read 2-byte data from an I2C Slave.

Wire.beginTransmission(slaveAdress); //queuing the slave address
Wire.write(regAddress); //queuing the register address/pointing regsiter
byte busStatus = Wire.endTransmission(); //transmit all queued data and bring STOP condition on I2C Bus
if(busStatus != 0x00)
   Serial.print("Transmission Error....!");//transmissiion error wait here for ever

Wire.requestFrom(slaveAddress, 2);     //this is looping code; when 2-byte has arrived, the loop terminates
byte x1 =;   //read the first byte from FIFO Buffer
byte x2 = (x1 <<8)|;   //16-bit data is formed
Serial.print(x2, HEX); //show data

Thank you for the advice, I will give this a shot and update you as to whether or not it is working!

Instead of waiting for a byte, reading it, waiting for another byte, and reading it, wait for two bytes, then read them both.

The available() method does NOT return true or false, so you shouldn't use it like it does. It returns the number of bytes available to read.

   while(Wire.available() < 2)
      // Twiddle thumbs
   byte a =;
   byte b =;

Thanks for the note, and I have now realized that indeed your interpretation is the correct one. I have made the necessary modifications to get it to work. Right now I am actually getting pretty good runs based off of @GolamMostafa's code! I really appreciate both of yours advice.

Could you write your solution here on fdc2214.cpp?