When communicating with the ADXL355 accelerometer from a Raspberry Pi, i2c works perfectly. However, when I try using SPI the register addresses don't match those in the manual and I need to understand why.
For example, the following code prints the results back from sending 0x00, 0x01, 0x02 and 0x03 which according to the manual (and what I experience when I use i2c) should correspond to DEVID_AD, DEVID_MST, PARTID, and REVID.
#include <bcm2835.h>
#include <stdio.h>
void transfer(char charToTransfer)
{
char buffer[] = { charToTransfer, 0x00};
bcm2835_spi_transfern(buffer, sizeof(buffer));
printf("Rx: %02X \n", buffer[1]);
}
int main(int argc, char **argv)
{
if (!bcm2835_init())
return 1;
bcm2835_spi_begin();
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256);
bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);
transfer(0x00);
transfer(0x01);
transfer(0x02);
transfer(0x03);
bcm2835_spi_end();
return 0;
}
The output from this is
Rx: 00
Rx: AD
Rx: 00
Rx: 1D
whereas it should be
Rx: AD
Rx: 1D
Rx: ED
Rx: 01
Any help would be greatly appreciated as at the moment I can't get data from the accelerometer until I understand why this simple communication isn't working.