Using Arduino Due board cant't read mpl3115 register in Arduino 1.5.5 IDE.

Hi,
I come across a problem when I try to read mpl3115 register using Arduino Due board in Arduino 1.5.5 IDE.

#include <Wire.h>
#define WHO_AM_I 0x0c
#define MPL3115A2_ADDRESS 0x60 // 7-bit I2C address

void setup() {
// put your setup code here, to run once:
int result;
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(0x60);
Wire.write(0x0c); // Address of CTRL_REG1
Wire.endTransmission(true);
Wire.requestFrom(0x60, 1);
result = Wire.read();
Serial.print(result);
}

void loop() {
// put your main code here, to run repeatedly:

}

I guess is that the wire code cant’t send repeated start signal, which is needed by read mpl3115 register.

In \arduino-1.5.5\hardware\arduino\sam\libraries\Wire\Wire.cpp file.

// Originally, ‘endTransmission’ was an f(void) function.
// It has been modified to take one parameter indicating
// whether or not a STOP should be performed on the bus.
// Calling endTransmission(false) allows a sketch to
// perform a repeated start.
//
// WARNING: Nothing in the library keeps track of whether
// the bus tenure has been properly ended with a STOP. It
// is very possible to leave the bus in a hung state if
// no call to endTransmission(true) is made. Some I2C
// devices will behave oddly if they do not see a STOP.
//
uint8_t TwoWire::endTransmission(uint8_t sendStop) {
// transmit buffer (blocking)
TWI_StartWrite(twi, txAddress, 0, 0, txBuffer[0]);
TWI_WaitByteSent(twi, XMIT_TIMEOUT);
int sent = 1;
while (sent < txBufferLength) {
TWI_WriteByte(twi, txBuffer[sent++]);
TWI_WaitByteSent(twi, XMIT_TIMEOUT);
}
TWI_Stop( twi);
TWI_WaitTransferComplete(twi, XMIT_TIMEOUT);

// empty buffer
txBufferLength = 0;

status = MASTER_IDLE;
return sent;
}

The parameter sendStop isn’t used in the function.

Is it right?
what i should do to read mpl3115 register.

I have just been trying to get the MPL3115A2 to work, and running into a similar problem.

A blog post somewhere about 3 years ago reported this problem. It appears that Wire cannot ( or possible previously didn't ) work correctly with the I2C expectations of these devices. The folks who discovered this a couple of years ago wrote a different, alternative I2C library to get around the problem. I downloaded their code but could not get it to work.

Then, it appears that recent versions of Wire actually allow this method to work. So I changed all my code back to Wire, and can't get it to work.

Getting rapidly driven insane here. It seems very difficult to directly correlate what the Wire functions actually do, with the descriptions of the I2C process.

Either my device is broken, or it does not work with any of the diffent versions of I2C and Wire. It does respond with the correct address with the I2C_scanner sketches. Extremely frustrating.

Has anyone else actually got one of these devices to work ?

Serial.begin(9600);
  Wire.beginTransmission(0x60);
  Wire.write(0x0c);  // Address of CTRL_REG1
  Wire.endTransmission(true);
  Wire.requestFrom(0x60, 1);
  result = Wire.read();

I could also point out, that the device register you are accessing here ( 0x0C ) is the “who am I” register and not CTRL_REG1