Problem using both SPI library and SD library in Arduino UNO program

Hello,

I solved the problem this way.

I had the exact same problem using the Adafruit micro Sd breakout board and Her Max 31855 thermocouple breakout board.

After I had initialized the SD card the thermocouples no longer worked. I had noticed that when it was on my breadboard if I disconnected the clock line the thermocouple boards started working again.

The thermocouples were not on the SPI bus they were on their own buss.

After much headbanging, I tried setting the SPI clock pin as an input after the card was initalized. Then before writing to the card again I set the card back to an output then back to input after writing.

Works like a champ now.

Hope this helps someone else in the future.

I can confirm that I had the same strange results as Dave2Satellite when trying to dump data from an RFID reader to an SD card (both devices sharing SPI). This was resolved for me as well by using the SdFat library he posted a link to above. Setting the slave select (SS) pins HIGH and LOW depending on the module you want to work with just started working after that.

Dear Dave, I have the same problem than you. How do you solve it?
I download the SDFat library, but don't win use the Ethernet Module and the SD Card Module together.
I think in use a pin to turn off and turn on the Ethernet Module.
I do almost all, but nothing yet.

Thanks in advance.

Márcio Araújo.

I ran into same problem of cannot read temp sensor after initializing SD card. I am using the Adafruit Max31855 (PID: 269) and Adafruit Assembled Data Logger For Arduino (PID: 1141). I am controlling them with the Adafruit HUZZAH ESP8266 Breakout (PID: 2471).

I resolved the problem by changing the SPI configuration each time before I read temperature or write data to SD.

#define THERM02_CS 2
#define THERM0_CLK 14 // Fake SPI CLK signal Yellow
#define THERM0_D0 12 // Fake SPI MISO signal Orange

#define DATALOG_CS 16 // for SD on datalogger
#define DATALOG_MOSI 13
#define DATALOG_MISO 12
#define DATALOG_SCK 14

void setupSPIForTempReading() {
pinMode(THERM0_CLK, OUTPUT);
pinMode(THERM0_D0, INPUT);
}

void setupSPIForDataLogger() {
pinMode(DATALOG_MOSI, SPECIAL);
pinMode(DATALOG_SCK, SPECIAL);
pinMode(DATALOG_MISO, SPECIAL);
}

Works great. I read and log temperature.

I do not know if this exact setup will work for Arduino because a different SD library is used with ESP8266:

Used: C:\Users\Mud\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD-master

Digging through the Arduino SD-master would allow you to identify what pinMode to use for Arduino.

Hello all!
Dave, I'm really struggling with a datalogger i'm making for 3 temperature probes (2x PT100 with Max31865 + 1 thermocouple with Max6675.), using an Arduino Uno board.

The three sensors work great together on the SPI bus:

  • PT100_1 - Chip Select on pin 10
  • PT100_2 - Chip Select on pin 9
  • Thermocouple_K - Chip Select pin 8

Also connected the system to Nextion HMI and everything is ok.
The problem is similar to what you experienced with your project, i also want to record on a SD card the measurements from the sensors and i used a SD card module with SPI also:

  • SD Card - Chip Select on pin 7

The card itself i tested and worked fine by itself, but connecting it to the same CLK, SDO, SDI, in paraller with the sensors, i loose the data and the values of the temperatures are all scrambled.

You finished your dialog telling you used the sdFat and it worked with minor changes.
I already tried a lot and i'm not getting there... The sdFat literature info tells that the library supports multiple SPI:

«Support for multiple SPI ports now uses a pointer to a SPIClass object.

See the STM32Test example.

explicit SdFat(SPIClass* spiPort);
\\ or
explicit SdFatEX(SPIClass* spiPort); »

I cheked the STM32Test example but that seems to be made for two SD cards on the same SPI bus...
Am i right?

Would you be so kind to help me? How did you do it on your situation?
If anyone can help me i'm really desperate...
Rafael
1 Like

is it possible for me to connect these sensors using i2c protocol? could anyone help me regarding this?