SD card initialised but cannot be read?

Hi all

I have a post for this in the installation section which may be the incorrect place
I am using a 3.2" Itead TFT screen and an ITDB02 v1.1 mega shield and get the message that the card is initialised okay and the type is SD2 but it cannot see the formatting or read the contents.

Can I get some assistance to get it working please as I am stumped.

What kind of SD reader? How is it connected? What code are you running?

Hi Paul

Thanks for the reply. Its a TFT shield and screen kit I bought as a combo some time ago for a project I have only just started.

The screen is an ITDB02-3.2 which has an attached SD card read and the shield is the ITDB02 Mega shield v1.1
Link to TFT and SD reader http://imall.iteadstudio.com/im120419005.html
Using it on an Arduino mega 2560
Compiling on a mac and the only section of the code I believe is relevant follows. The code is huge but none of it refers to the pin setups.
The SD card is a 2GB non SDHC and formatted to FAT16 with several raw files on it for the screens

///Code written by Steve Heitman
///based off original code written by 
///Nick Devan - Touch screen navagation code
///benjaf @ Github&theplantedtank - sunrise/sunset code
 
//#################    REVISION 5.5


//*******Included Libraries*******// 
#include <UTouch.h>
#include <avr/pgmspace.h>
#include <UTFT.h>
#include <tinyFAT.h>
#include <UTFT_tinyFAT.h>
#include <EEPROM.h>
#include <RTClib.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const int chipSelect = 53; 
//********    Declare Touch/LCD/RTC    **********
UTFTtf  myGLCD(ITDB32S, 38, 39, 40, 41);   //sets LCD pins - change to your screen pin-out and aspect
UTouch  myTouch(6,5,4,3,2);     //sets touch pins - change to your set up (default is usually 6,5,4,3,2)
RTC_DS1307 RTC;
 
 
//********   Call Fonts    **********
extern uint8_t arial_bold[];
extern uint8_t Sinclair_S[];
extern uint8_t SevenSegmentFull[];

//*******   Declare 1-Wire for TEMP sensors  ********
#define ONE_WIRE_BUS 2               //sets sensor to pwm pin 2 - Change to your setup

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature tempsensors(&oneWire);

//DS18B20 sensor address' ******change these for your sensors*******
//link provided is a good sketch to get yours
//http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
//I added this link because I found this to be a much easier sketch to use than the Dallas Multiple Example when
//trying to find Address'on a 1 wire bus. 

 DeviceAddress tankTemp = { 0x28, 0x09, 0xD3, 0x07, 0x04, 0x00, 0x00, 0x80 };
 DeviceAddress sumpTemp = { 0x28, 0x48, 0x31, 0x2C, 0x04, 0x00, 0x00, 0x7F };
 DeviceAddress rSinkTemp = {0x28, 0x00, 0x2D, 0x47, 0x04, 0x00, 0x00, 0xF2 };
 DeviceAddress lSinkTemp = {0x28, 0x35, 0xF7, 0x2A, 0x04, 0x00, 0x00, 0x1A };
 /code]

How was the card formatted?

The only way to insure the format complies with the SD association standard is to use their formatter SD Memory Card Formatter for Windows/Mac | SD Association.

Other formats work with Windows, OS X, and Linux but Arduino only supports formats closely related to the standard.

This is necessary since memory is at a premium on Arduino and supporting non-standard formats requires extra program memory.

I did use the SD formatter in the end. I tried 3 options. One was the disk utility on mac but I couldnt find the device name using this method. I then tried the command line option using terminal and sudo diskutil to format it which seemed to be successfull. I also hauled out an old windows laptop to format it.
However the most recent was the SD formatter that you linked to.

I see you are using tinyFAT. Don't use OS X to format SD cards, it put tons of non-standard junk on cards.

Does the standard SD.h library work?

SD.h is based on a four year old version of SdFat and is very buggy since many bug fixes have not been applied. If this does not work try a new version of SdFat.. Google Code Archive - Long-term storage for Google Code Project Hosting..

Try running some of the SdFat examples like QuickStart, SdInfo, and bench.

If these fail, post the error codes.

Also try the SdFat SdFormatter example and post any errors.

No the standard SD library doesnt seem to work however I am not sure if I am setting the chip select pins etc up correctly.

Using SDFAT examples when I run bench I get the following
Free RAM: 6661
Can't access SD card. Do not reformat.
SD errorCode: 0X4,0XFF

SDinfo

type any character to start
cardSize failed
SD errorCode: 0X10
SD errorData: 0XFF

type any character to start

The following code seems to see an sd card however I believe(need confirmation) that the only reason it does is because the pinmode is set to the same as the chip select value which in this case is 53. Should it be set to 53? or the pin mode output set to 53 and chip select to something else?

// UTFT_ViewFont (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the included fonts.
//
// This demo was made for modules with a screen resolution 
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

// set up variables using the SD utility library functions:
#include <SD.h>
#include <tinyFAT.h>
#include <UTFT.h>
#include <UTouch.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 53; 

int x, y;
int bg[] = {
  0, 0, 255};
int fg[] = {
  255, 255, 255};

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT     myGLCD(ITDB32S,38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch   myTouch(6,5,4,3,2);

byte initres;
byte res;
byte input;

void setup()
{ 
START:
  // Initialize serial communication 
  Serial.begin(115200);
  Serial.println("press the ENTER button on your Touch Screen!");
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.setFont(SmallFont);
  myGLCD.print("Initializing SD card...", CENTER, 0);
  pinMode(chipSelect, OUTPUT);/code]

It appears both the TFT screen and the SD are SPI. Are you disabling the TFT SPI before initializing the SD? Which pin on the Mega is the TFT slave select (chip select) connected to? What pin is the SD slave select connected to? If you do not disable the TFT SPI, it will probably interfere with the SD.

The problem seems to be with the SPI bus.

It appears that the LCD has its own bus. I assume none of the LCD pins are connected to SPI pins 50, 51, 52, 53.

Is the touch screen or anything besides the SD connected to the four SPI pins? If you have a second SPI device you need to follow SurferTim.

It appears SD chip select is connected to pin 53. This should be the default pin for the SD begin() call but you could set it explicitly.

The problem could be due to long wires connecting the SPI pins. I have also seen a floating SD chip select pin act like this.

Try running the SdFat examples with a slower SPI clock. In bench change the sd.begin call.

  // initialize the SD card at SPI_FULL_SPEED for best performance.
  // try SPI_HALF_SPEED if bus errors occur.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

I still et the sharing error code at half speed. I will get out my multimeter and go and check my wiring is correct again in case I made a mistake somewhere.

Insure all CS lines are HIGH when you run the SD startup. According to the pinouts on this page, there appear to be three.
http://imall.iteadstudio.com/im120419005.html
CS (for TFT display)
T_CS (for touch)
SD_NSS (for SD)

I looked at this

[ftp://imall.iteadstudio.com/IM120419005_ITDB02_3.2S/SCH_IM120419005_ITDB02_3.2S.pdf]ftp://imall.iteadstudio.com/IM120419005_ITDB02_3.2S/SCH_IM120419005_ITDB02_3.2S.pdf]ftp://imall.iteadstudio.com/IM120419005_ITDB02_3.2S/SCH_IM120419005_ITDB02_3.2S.pdf](ftp://imall.iteadstudio.com/IM120419005_ITDB02_3.2S/SCH_IM120419005_ITDB02_3.2S.pdf)

It appears that there are no level shifters on the SD. SD cards expect 3.3 V levels on SPI. The Mega is 5 V.

See this 5V to 3.3V Mega shield http://imall.iteadstudio.com/im120417024.html

Correct. I am using one of these shields which provides the correct voltage

Starting to think from my testing tht perhaps I have a hardware issue.
Hang tight and I will resolder/ensure the pins are correct and get back to you.

I have attached a photo of the bottom of the shield.
Can someone please confirm the correct wiring for me from the schematics

I have labelled the pins I believe I am checking.
The sd pins don't seem to have any continuity at all with the mega pins I believe they should be connected to.

I think it should be like below
SD Pins Shield Mega
SD-NSS - 38 - 53
SD-SI - 37 - 51
SD-SCK - 36 - 52
SD-SS - 35 - 50

Also. If those pins are correct does the sd card reader need to be powered from 3.3v also or can I solder the correct pins to the appropriate pin on the shield for direct connection to the mega?

Thanks
Steve

I have checked the hardware side and it seems to be mostly correct although I am not certain on the resistor numbering as I have soldered mine now and do not have a blank one for reference.
The resistor numbering on the image I downloaded off the internet is strange
as the attached photo

Mine are connected
Pin 38 - R16/R36(middle 2 resistors) SD-CS
Pin 37 - R15/R35(top 2 resistors) SD-IN
Pin 36 - R14/R34(bottom 2 resistors) SD-CLK
Pin 35 - No resistors

Have also attached the schematic of the resistors

How do you tell from the schematic the correct orientation?
Can I make this all easier by just soldering/wiring the sd card reader outputs to the correct place on the mage?

Catch6C5A.jpg

CatchD658.jpg

Here is a better image of the pins I found.

SurferTim:
Insure all CS lines are HIGH when you run the SD startup. According to the pinouts on this page, there appear to be three.

When running the SD example Tim I am only using 1 and it still doesnt seem to work correctly

Resistor based level shifters are unreliable and don't work with many modern SD cards. Modern SD cards often have edge detectors and the signals provided by resistor dividers are mushy.

The function of the two resistors is to convert the 5V arduino to 3.3V. The larger value of the two resistors should go from ground to the SD. the lower value goes from the Arduino pin to the SD.

The ratio of the resistors should provide the 5V to 3.3V level shift.

nsure all CS lines are HIGH when you run the SD startup. According to the pinouts on this page, there appear to be three.

It appears only the SD card is on the SPI bus so setting chip select high for other devices won't help. The SD libraries handle all levels if the SPI bus is not shared with other devices.