We have found that is a bug in the code at the ADXL345.
It should be called when the sensors as follows:
Code: Select all
// ************************************************************************************************************
// I2C Accelerometer ADXL345
// ************************************************************************************************************
// I2C adress: 0x3A (8bit) 0x1D (7bit)
// Resolution: 10bit (Full range - 14bit, but this is autoscaling 10bit ADC to the range +- 16g)
// principle:
// 1) CS PIN must be linked to VCC to select the I2C mode
// 2) SD0 PIN must be linked to VCC to select the right I2C adress
// 3) bit b00000100 must be set on register 0x2D to read data (only once at the initialization)
// 4) bits b00001011 must be set on register 0x31 to select the data format (only once at the initialization)
// ************************************************************************************************************
#if defined(ADXL345)
void ACC_init () {
delay(10);
i2c_writeReg(ADXL345_ADDRESS,0x2D,1<<3); // register: Power CTRL -- value: Set measure bit 3 on
i2c_writeReg(ADXL345_ADDRESS,0x31,0x0B); // register: DATA_FORMAT -- value: Set bits 3(full range) and 1 0 on (+/- 16g-range)
i2c_writeReg(ADXL345_ADDRESS,0x2C,0x09); // register: BW_RATE -- value: rate=50hz, bw=20hz
acc_1G = 256;
}
void ACC_getADC () {
TWBR = ((16000000L / 400000L) - 16) / 2; // change the I2C clock rate to 400kHz, ADXL435 is ok with this speed
i2c_getSixRawADC(ADXL345_ADDRESS,0x32);
ACC_ORIENTATION( ((rawADC[1]<<8) | rawADC[0])/8 ,
((rawADC[3]<<8) | rawADC[2])/8 ,
((rawADC[5]<<8) | rawADC[4])/8 );
ACC_Common();
}
#endif
There is no "/ 8" in the three lines. If this is added, the copter flying great with the ADXL345.
Can you please add this in the code with future husband?
Thank wolle
http://www.wii-copter.de