(SOLVED) SdFat + TFT + DUE works only with pc connection

Hello everyone,

I am using a TFT with a SD card reader and SdFat library on a DUE.

It runs perfectly while connected to my pc with open serial monitor and shows images.

The problem: as soon as I disconnect the DUE from my pc, the code won't work. It fails at the initialization in this line:

if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

and also if I use:

sd.begin(chipSelect, SPI_HALF_SPEED);

Any idea at this point where I have to look at?
Maybe comment in the library all lines that output something to the serial monitor?

Thank you!


How are you powering the Due when the usb is disconnected?

The DUE is powered by a DC/DC converter with 12V at the VIN pin.
The TFT with the SD card reader is powered with 3.3V from the DUE, a second DC/DC delivers 5V for backlight.

Just as a test, do you have a 7.5v or 9v wall wart you can try it with? Rating of 1A is best.

I have a Mega 2560, and with any shields attached, the onboard regulator has problems using 12v on Vin. I use a 7.5v wall wart, and it works much better.

edit: And what seems to work better than anything is a USB 5v 1A phone charger.

I don't think it is the voltage regulator, since the TFT and other components work perfectly. I use 24V input which is converted to 12V (max. current 3A).

I still think it is something about printing information to the serial monitor, for example error information or initialization information is printed.

But I will try what you suggest!

The SD card requires a lot of power to read and write. My code has no problem sending data over the serial monitor when using the SD card as long as I don't overload the voltage regulator.

The SD card read or write can use 100ma.

I measured the 3.3 V pin, there is no drop in voltage. Also the DUE is able to deliver 800mA on the 3.3V pin.

Even if there is no SD card attached, the code will not run past this part:
sd.begin(chipSelect, SPI_HALF_SPEED); (maybe because of an initialization error?)

You may have to ask fat16lib about that, or hope he reads this and replies. That is his library you are using, so he would be the one to know.

edit: I don't know what SPI_HALF_SPEED value is. The SD begin function for the Due sets the SPI clock divider to 21. That gives a bus speed of 4MHz. Maybe try a Serial.println(SPI_HALF_SPEED); and see what value it displays.

Here I am again.
I tried also sd.begin(chipSelect, 21); which works with USB connection, but not without.

The "chipSelect" is not really existing, since I control the chip select via MCP23017. But it still works with connected USB cable. Maybe the problem is located somewhere there...

I have tried different clock speeds (SPI_HALF_SPEED is 21MHz), but no change.

I think I will write a mail to fat16lib@sbcglobal.net.

This is very strange to me, because it works perfectly with USB connection :frowning: :frowning:

I test SdFat on Due with power supplied by an external 9V supply. I don't have your hardware so I can't help with your problem since my tests with external power work.

The "chipSelect" is not really existing, since I control the chip select via MCP23017.

What does this mean? You must allow SdFat to control chip select for reliable operation.

SD cards require SPI clocks occasionally with chip select high. During initialization, a minimum of 74 clock cycles must be provided with chip select high. An SD card requires clocks after chip select is high to release MISO.

Often SdFat does not access the card during calls since data is cached and buffered. Cycling chip select in these cases probably is OK but may change the state of the card.

You might want to try the Arduino SPI library which is slower. Edit SdFatConfig.h like this:


SdFat will not print error data to Serial unless you call a version of these functions:


You must allow SdFat to control chip select for reliable operation.

That was it, I thought I could control the chip select myself. All I/Os of my DUE are beeing used, so I decided to use one of the MCP23017 attached to it to control the chip select. Manually I have set the pin to low before sd access and to high after. But that does not work.

I could change some pins so the chip select is now attached to the DUE and it works perfectly.

There are two MCP3208 ADCs also on the SPI. Their chip selects are still controlled manually.

Thank you both for your help!