Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 2 months ago.
ADXL355
Hi, I am trying to use FRDM-k64f to read the new accelerometer ADXL355. I am referring to the example ADXL345. First, I try to test the SPI communication using below code. Why I always get 0 ?
SPI acc(PTD2,PTD3,PTD1);
DigitalOut cs(PTD0);
Serial pc(USBTX, USBRX);
char buffer[9];
signed short data[3];
float x, y, z;
int deviceID;
char test;
int main() {
cs=1;
acc.format(8,0);
acc.frequency(2000000);
while (1) {
wait(1);
cs=0;
acc.write(0x80|0x01);
deviceID= acc.write(0x00);
pc.printf("partid= %d\r\n",deviceID);
cs=1;
}
Thank you so much.
/media/uploads/cornetlin/adxl354-adxl355_breakout_ug-xxx_july22.pdf /media/uploads/cornetlin/adxl354_355.pdf
2 Answers
8 years, 2 months ago.
Hello Tzu-Hsuan,
acc.format(8,0); acc.frequency(10000000);
write ... acc.write( (address << 1) | 0x00); acc.write(data); ....
read ... acc.write( (address << 1) | 0x01); acc.write(0x00); ....
8 years, 2 months ago.
Hello Tzu-Hsuan,
Referring to the ADXL345 library I think instead of calling
...
acc.format(8,0);
...
acc.write(0x80 | 0x01);
...
you should try to call
...
acc.format(8,3);
...
acc.write(0x80 | (0x00 & 0x3F));
...
or simply
...
acc.format(8,3);
...
acc.write(0x80);
...
Zoltan