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.