I'm using a propriety board made by Analog Devices not a Chinese one.
It's connected to the Pi as per RbPi2 to 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); // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default
bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default
char buf[] = { 0x80, 0x00, 0x00, 0x00}; // Read DeviceID of ADXL345
bcm2835_spi_transfern(buf, sizeof(buf));
// buf will now be filled with the data that was read from the 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 ) for 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;
}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 00Same idea with Setup Response.
The two attached oscillograms confirm the responses I get.... Edit: cannot attach 64kb max makes them too small to view.
Are these F2 responses an error code?