ADXL345 Bad Response? - Raspberry Pi Forums


rbpi2 adxl345.jpg
hardware connection
rbpi2 adxl345.jpg (57.82 kib) viewed 986 times
hi, i'm using pi2 try , gather accelerometer data analog devices adxl345.
i'm using propriety board made analog devices not chinese one.
it's connected pi per rbpi2 adxl345.jpg attached.
i'm running this

code: select all

#include <bcm2835.h> #include <stdio.h>  int main(int argc, char **argv) {          if (!bcm2835_init())         return 1;          bcm2835_spi_begin();     bcm2835_spi_setbitorder(bcm2835_spi_bit_order_msbfirst);      // default     bcm2835_spi_setdatamode(bcm2835_spi_mode0);                   // default     bcm2835_spi_setclockdivider(bcm2835_spi_clock_divider_65536); // default     bcm2835_spi_chipselect(bcm2835_spi_cs0);                      // default     bcm2835_spi_setchipselectpolarity(bcm2835_spi_cs0, low);      // default          char buf[] = { 0x80, 0x00, 0x00, 0x00}; // read deviceid of adxl345     bcm2835_spi_transfern(buf, sizeof(buf));     // buf filled data read slave     printf("device id: %02x %02x %02x %02x \n", buf[0], buf[1], buf[2], buf[3]);  //    delay(1000);      char buf2[] = { 0x2d, 0x02, 0x00}; // setup 0x2d ( power_ctl reg ) measure     bcm2835_spi_transfern(buf2, sizeof(buf2)); // (b7 reset == write)     printf("setup response is: %02x %02x %02x %02x \n", buf2[3], buf2[2], buf2[1]);      delay(1000);      char buf3[] = { 0xb2, 0x00, 0x00}; // read x0 reg 0x32 (b7 set == read)     bcm2835_spi_transfern(buf3, sizeof(buf3));     printf("x axis is: %02x %02x %02x \n", buf3[3], buf3[2], buf3[1]);  //    delay(1000);      bcm2835_spi_end();     return 0; }
response is

code: select all

~/projects/adxl $ sudo ./spix device id: 00 00 00 00 setup response is: f2 f2 f2 f2 x axia is: 00 00 00
made read device id 4 byte buffer assuming missing something.
same idea setup response.
2 attached oscillograms confirm responses get.... edit: cannot attach 64kb max makes them small view.

these f2 responses error code?

any appreciated here.

have faulty unit or code bad somewhere?


raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code