Hello everyone,
I’m currently working with a 9DOF Razor IMU (https://www.sparkfun.com/products/10736).
On this board an ADXL345 is connected to an Atmega328. The two units communicate through I2C protocol.
The problem is, when I read the content of a register, say (0x00 = device ID), I get 4 bytes returned instead of one.
The ID of the ADXL345 is defined in the datasheet: ID_ADXL:1110 0101
When I read the register I get;
ID_ADXL: 1111 1111 1111 1111 1111 1111 1110 0101
This is how I read the register;
char id_adxl=0;
id_adxl = i2cRead(adxlAddress, 0x00);
Serial.print("ID_ADXL: ");
Serial.println(id_adxl, BIN);
And this is how i2cRead() is defined;
unsigned char i2cRead(char address, char registerAddress)
{
//This variable will hold the contents read from the i2c device.
unsigned char data=0;
//Send the register address to be read.
Wire.beginTransmission(address);
//Send the Register Address
Wire.write(registerAddress);
//End the communication sequence.
Wire.endTransmission();
//Ask the I2C device for data
Wire.beginTransmission(address);
Wire.requestFrom(address, 1);
//Wait for a response from the I2C device
if(Wire.available()){
//Save the data sent from the I2C device
data = Wire.read();
}
//End the communication sequence.
Wire.endTransmission();
//Return the data read during the operation
return data;
}
I don’t understand how these 3 additional bytes are being read in the register?
The ADXL345 supports fast data transfer mode (400kHz) but my arduino Wire.h library is programmed for normal data transfer (100kHz). I thought this could be the reason.
I tried adding:
Wire.begin();
TWBR = 12;
to enable fast transfer mode, but the error remains.
Any idea what I could be doing wrong?
Thank you for reading this.