LIS3DH 3-axis accelerometer w/ Adafruit Data Logging Shield

Dear arduino makers,

I am a neewbie in this arduino topic and now I have started my first project. It is about data logging and vibration measuring. I bought an Arduino 101, an Adafruit LIS3DH accelerometer and an Adafruit Data Logging Shield with on-board RTC.

The RTC on the shield communicates by PIN A4 and A5, the SD card reader and the accelerometer are communicating with the arduino by SPI (PIN D11, D12 and D13). ChipSelect (CS) for SD reader is PIN D10, CS for the LIS3DH is PIN D8 (see my code).

You can see the wiring on this picture: Wiring Arduino 101/DataLoggingShield

The code of my project so far you can download here: ProjectCode
I took an code example (lighttemplogger) of the Adafruit Data Logging Shield and the “acceldemo” code from the LIS3DH library and fused them together by editing them fitting my needs.

Now there is a problem in the code bacause of that it isn’t quite working, yet. Maybe someone of you can help me with this issue.
When you see the code there are two parts which I took out by comment. They are about checking the SD card and the logfile if working/already existing. The first part about checking the SD card is the main problem I think. If I take it out you can see the result on one this picture: LIS3DH is working. The values of the LIS3DH get written together with millis and the date/time of the RTC into the serial monitor BUT afterwards you won’t find the LOGGERnn.txt on the SD card. So something is wrong with the comunication to the SD card. AND while the code is running the green LED (LED1 of the Data Logging Shield) is not working as coded in the loop.
On the other hand, if I put in both parts the logfile will be created an written on same as in the serial monitor BUT the communication with the LIS3DH is not working well baecause the values written in the logfile and the serial monitor are alwas 0.00 on all three axis (x,y,z).

The problem must be something about the chipSelect (CS) of the SD card and the LIS3DH not working the same time. Do you have a solution/idea to fix this problem? I am not very familiar with the SPI communication. Maybe something is wrong here?

Thank you very much for every hint. :slight_smile:

According to ST community

You need to disable the I2C on LIS3DH with a non documented feature of the LIS3DH in order to share SPI bus.

"Miroslav B Moderator
Jul 8, 2016 5:03 PM
To use LIS3DH on shared SPI bus it is necessary to disable the I2C.
It can be done applying following sequence after each device power on.

a = read(0x17)
write(0x17, (0x80 OR a))

Best regards