Hi Guys,
I've downloaded v1.5.3 IDE thinking that all the I2C bugs would have been ironed out...
I have the following code which works fine on the MEGA board but not on my due board. I'm using a ADXL345 acceleration sensor and just reading the z-axis for testing purposes. The error starts to occur when I flip the sensor around to the negative z-axis. As you can see from the data below it reads the data OK in the positive direction but when flipped it gives me a large meaningless number. When using I2C the DUE does not appear to handle negative numbers or is it just the way I have coded it?
158
153
143
133
126
126
118
113
96
69
61
35
32
2
65508
65468
65452
65429
65391
65372
65341
65335
65305
65297
65282
65314
65352
65397
Here is my code.
#include <Wire.h>
const int ADXL345_I2C_ADDRESS = 0x53;
int POWER_CTL = 0x2D;
int DATA_FORMAT = 0x31;
int DATAZ0 = 0x36;
int DATAZ1 = 0x37;
void setup()
{
Wire.begin();
Serial.begin(9600);
ADXL345_setup(DATA_FORMAT, 0x08);
ADXL345_setup(POWER_CTL, 0x08);
}
void loop()
{
Serial.println(ADXL345_read());
delay(250);
}
void ADXL345_setup(int I2C_address, int configVal)
{
Wire.beginTransmission(ADXL345_I2C_ADDRESS);
Wire.write(I2C_address);
Wire.write(configVal);
Wire.endTransmission();
}
int ADXL345_read()
{
Wire.beginTransmission(ADXL345_I2C_ADDRESS);
Wire.write(DATAZ0);
Wire.endTransmission();
Wire.requestFrom(ADXL345_I2C_ADDRESS, 2);
byte LSB_z = Wire.read();
byte MSB_z = Wire.read();
return ((int)MSB_z << 8) | LSB_z;
}
Any help in this area would be much appreciated. Before anybody asks I have accounted for the DUE's internal pull-ups...