Using SDFat Library and an External ADC on the same SPI interface for low power.

Hello all,

I am trying to communicate with two different devices on the single Teensy3.1 SPI interface, i.e. an ADC (ADS1220) and a micro SD card, using the SDFat library for it's SD idle/sleep capabilities. Currently, I have a working program that uses the simpler SD library to initialize and read the SD card, then I initialize the ADC, while making the chipselect on the SD card high. Just a little background, the SD card stores about 30 different bitmaps for the LCD display and the ADC is a high precision 24-bit, low offset voltage unit that is used to sample small amplified measurements from a strain gage wheatstone bridge circuit. Before each ADC read sample, I change the SPI mode from mode0, while working with the SD card, to mode1, to work with the ADC. The ADC is able to read accurate voltage measurements from the circuit during conversions, then once the user inputs a display change the ADC will momentarily stop conversions and then the SD card is read for bitmaps. My only issue is that the SD card is not allowed to sleep with the SD library I am using and draws way too much current, this is a major problem since my project is battery powered. I have read all of the SD low power posts from:; I am also unable to cycle the power on the SD card to save power, since the SD library will not let me reinitialize the SD card.

What I am striving to do is use the superior SDFat library with its low power idle capabilities instead of the simpler SD library. I have altered my program to use the SDFat library in exchange for the SD library. While the SD card works perfectly, the ADC however does not function properly. What I have discovered is that once the SDFat library initializes the SD card, it changes the teensy3.1 SPI settings for optimized use with the SD card, however I do not know how to change these SPI settings back to default values during ADC conversions, then once the program needs to read the SD card again revert back to the SDFat SPI settings for the card.

The only wall hindering me from solving this issue is my lack of knowledge on the architecture of the SDFat library and how it alters the SPI interface with the Teensy3.1 microcontroller. I have been searching through the C++ files to find any changes in the SPI interface, but the only program I can clearly see changes in is with the SdSpiArduino.cpp program, which changes the SPI mode and divisor. These are the only SPI changes I make while working with the other SD library and that setup works, however when doing the same with the SDFat library chaos ensues. It is my understanding that the SD library is a derivative of the SDFat library, therefore theoretically this should work on either..

Any help on this matter will be greatly appreciated!


Ok, for anyone who is interested in this post, I have solved my issue. The neat thing about the SDFat Library is that it was programmed so well and there is a switch to force the library to only use the standard Arduino SPI interface. In my scenerio, I am switching the Arduino SPI settings, mode0 & mode1, before using the respective device. The SDFat Library has an implementation that uses the native on-board SPI interface for supported microcontrollers to speed up data transfer rates between the controller and the SD card. I am not skilled enough to alter the native SPI interface for the Teensy3.1 microcontroller as I have also not been able to find any documentation on it. So after finding this switch, I was able to disable the use of the native SPI setting changes which was ultimately corrupting communication with the ADC.

In the SdFatConfig.h header, look for Set USE_ARDUINO_SPI_LIBRARY nonzero to force use of Arduino Standard * SPI library. This will override native and software SPI for all boards. */


In conclusion, you should be able to use any number of SPI devices with the SD card on the same SPI bus with this method.

Hello Jake, on Teensy 3.1 & Adafr 2.8" TFT LCD Shield w/Touchscreen there is microSC card existing on the back. May I ask how did you connect Teensy to microSD? which pins on Teensy? I have Teensy with screen and touch running is there any problems with using micro SD ? Thanks Mike