Hello, i search since a week for this problem.
I have a Arduino mega with a SD-card shield, a ADLX345 (accelerometer) , a MAX 31855 (thermocouple) and a RTC DS3234. All on the SPI Bus !
It’s a dataLogger on a car’s ECU, I send the ECU’s data on Bluetooth and I stores them on SD card.
Everything works well (Bluetooth, hour, thermocouple and accelerometer) but when I activate the recording on the SD card, RTC and accelerometer no longer work (data is false). Thermocouple and SD card works very well so the SPI bus is not disturbed. I checked the various CS, they are all to 1. I changed the SD Library to the library SDfat but the problem remains the same.
I hope someone can help me.
DashBoard_V2.ino (26.3 KB)
The problem may be that the SD uses SPI mode zero. I see you use SPI_MODE3 for other devices.
New versions of SdFat set the SPI mode to zero before every access to the SPI bus.
SD.h initializes the SPI bus to mode zero also. Some versions of SD.h may also set the SPI mode to zero before access. I wrote the five year old version of SdFat used in SD.h but it has been modified lately so I don't know what your version does.
OK, thanks for your answer.
I use the last SDfat library, i can check inside the library but if it uses the Mode 0, can I change something ? (I have to learn the difference between the modes.)
I use the last SDfat library, i can check inside the library but if it uses the Mode 0, can I change something ?
The SD libraries use mode 0. You can't change this since SD cards require mode 0.
Just fix your software to set mode 3 before accessing your SPI devices. The new SdFat will change the mode to zero when it needs to.
Here are the four SPI modes. The diagrams are labeled by polarity and phase. The table below relate mode to CPOL and CPHA
Mode vs polarity and phase
Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
Thanks a lot, exactly what I did before your answer. I put a mode 3 before use ADLX and RTC. Now my program works perfectly.
This forum is very nice !