Hello,
I'm working on a project involving the LIS3DH accelerometer and the M0 Adalogger from Adafruit. However, what I need it to do is beyond what I can figure out with their libraries; namely, I need to enable the FIFO and the high-pass filter. I've written a code that works with the UNO for basic SPI communication (just reading the WHO_AM_I register), but it doesn't work with the Adalogger. If I can get the basic SPI to work, I should be able to get the rest of the program going. Thanks for the help!
/*
* WHO AM I?
* The ultimate question for an LIS3DH...
*/
#include <SPI.h>
#define DATAOUT 11 //MOSI
#define DATAIN 12 //MISO
#define SPICLOCK 6 //sck
#define SLAVESELECT 10 //ss
void setup() {
while (!Serial)
Serial.begin(9600);
SPI.begin();
// Set SPI pin modes
pinMode(SPICLOCK, OUTPUT);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SLAVESELECT,OUTPUT);
// Initialize SPI bus settings
SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE3));
digitalWrite(SLAVESELECT, HIGH); //disable device
// Write to CTRL_REG1 to take out of power down mode
digitalWrite(SLAVESELECT, LOW); //enable device
SPI.transfer(0x20);
SPI.transfer(0x8F);
digitalWrite(SLAVESELECT, HIGH);
// Read and print WHO_AM_I register
digitalWrite(SLAVESELECT, LOW); //enable device
// WHO_AM_I address with bit 0 set to "1" as the LIS3DH read command
SPI.transfer(0x8F);
uint8_t deviceid = SPI.transfer(0x00);
digitalWrite(SLAVESELECT, HIGH);
SPI.endTransaction();
Serial.println(deviceid, HEX);
}
void loop() {
// put your main code here, to run repeatedly:
}
The datasheet and application note for the LIS3DH can be found here: