Hiya All,
Having trouble with the ADXL345 accelerometer communicating via I2C with the new beta library. I am using the ADXL345 library available on the site. With the old mbed library, the device worked perfectly. With the new library all the received communications are incorrect, although nothing else has changed in the main program.
I have seen that a timeout was added to the I2C class, however I'm not sure what effect that would have had.
I have to use the beta library as I'm also using the new DSP algorithms.
Code is as follows:
#include "mbed.h"
#include "ADXL345.h"
int main() {
//set up i2c
ADXL345 acc(p9, p10);
Serial pc(USBTX, USBRX);
pc.baud(115200);
DigitalOut led(LED1);
signed short readings[3];
bool loop = true;
//attempt to get the device ID
pc.printf("Device ID (should be 0xE5 or 229d) : %d\r\n", acc.getDevId());
//attempt to get z axis
pc.printf("Z Axis: %d\r\n", acc.getZAxis());
//get register statuses
char regs[29];
acc.multiByteRead(0x1d, regs, 29);
for (int i=0; i<29; i++) {
pc.printf("Reg %d: %X\r\n", i+29, regs[i]);
}
acc.setPowerControl(8);
while(loop) {
acc.getOutput(readings);
pc.printf("X: %4d\tY: %4d\tZ: %4d\r", readings[0], readings[1], readings[2]);
if (pc.readable()) {
if (pc.getc() == 'q') {
loop = false;
pc.printf("Exited Program\r\n");
}
}
wait_ms(10);
}
}
Any help would be hugely appreciated! Are there any other good I2C libraries hanging around?
Cheers,
Rob
Hiya All, Having trouble with the ADXL345 accelerometer communicating via I2C with the new beta library. I am using the ADXL345 library available on the site. With the old mbed library, the device worked perfectly. With the new library all the received communications are incorrect, although nothing else has changed in the main program.
I have seen that a timeout was added to the I2C class, however I'm not sure what effect that would have had.
I have to use the beta library as I'm also using the new DSP algorithms.
Code is as follows:
Any help would be hugely appreciated! Are there any other good I2C libraries hanging around?
Cheers, Rob