Device conflict using SPI interface

I’m trying to make a weather station which can log data to an SD card. All went well until I tried to add a timestamp to the datalog file. I have cut the program to the bone and find that it functions fine provided:

1.) The SD Card is not in the socket… OR

2.) Remove the reference to ReadTimeDate() at line 168 with the SD Card present.

Some details, I’m using Arduino 1.6.5, the project uses an Arduino Pro Mini (5v, 16MHz), DS3234 RTC chip, the SD Card and DS3234 are both using a 3.3v local regulated supply, additionally the SD Card CS, SCK, and MOSI lines are buffered with a CD4050 chip. I have scoped the CS lines using 2-probes to verify that they are not active (low) at the same time.

The code to talk to the RTC is from “http://www.l8ter.com/?p=375

Any suggestions welcome.

SensorEvalTimeOnly.ino (11.8 KB)

  #include  <SD.h>              //  only here for FreeRam function  uses about 750 bytes

Isn’t that comment complete nonsense?

      if (b==2)
        b=B00000010;
      else if (b==1)
        b=B00000001;

If b is 2, set b to 2. If b is 1, set b to 1.

Exactly why is THAT necessary?

What RTC are you using? Most are I2C devices. If using the SPI RTC causes problems, get an I2C RTC.

All went well until I tried to add a timestamp

You forgot to describe the problem.

additionally the SD Card CS, SCK, and MOSI lines are buffered with a CD4050 chip

Why the buffer chip? A bidirectional level converter would make more sense, as would using a 3.3V Arduino. Please post a hand-drawn wiring diagram.

We recommend to get all the parts working individually before putting them together. Have you separately been able to read and write to the RTC without problems?

SD cards have been known to Not release the MISO line. Try adding one gate of a buffer like 74HC125 on MISO coming back from the SD, with it's OE/ driven by CS going to the SD card.

Thank You @CrossRoads. I added a switch made from 2-BSS84 P-MOS controlled by the SD Card CS line to isolate the SD Card.

The real joy came when I defined the SCK line as an output with an initial state of LOW in the set-up and it started to function as expected. See #3 of this post: https://forum.arduino.cc/index.php?topic=109630.0

Any body here know of a list of similar mis-behaving SPI devices?

SDCardDataSwitch.pdf (4.8 KB)