Go Down

Topic: SD Card Module - Pull-Up Resistors and Decoupling Capacitor? (Read 745 times) previous topic - next topic

Tbdanny

I'm trying to get the below SD Card reader module working with an Arduino Mega 2560:





However, I'm having some problems getting it to work reliably.  After doing a bit of googling and reading about it, I've found some threads on this forum that mention that a 10uF or higher ceramic disc capacitor is needed across the power supply, as well as 10K pull-up resistors on the CS, MOSI, SCK and MISO pins.  However, I have a few questions about the details of how these are connected.


The SD card module has connections for +3.3V, +5V, GND, as well as the four pins mentioned above.  So with this in mind, I'd like to ask:

  • Should both the +3.3V and the +5V both be connected to those pins on the Arduino?  Currently, I've only got the +5v hooked up to that supply from the Arduino.
  • Should the 10k pull-up resistors go between the CS, MOSI, SCK and MISO pins and +3.3V or between those pins and +5V?


ShermanP

I've posted about this before:

https://forum.arduino.cc/index.php?topic=623299.0

but I still believe that this type of module is not a good design for 5V Arduinos.  SD cards are 3.3V devices, which means they must be powered by 3.3V, and their SCLK, MOSI and CS input pins should be fed with 3.3V signals from the Arduino.  Your module provides 3.3V power through the 3.3V voltage regulator, but it appears that the other three lines simply have inline resistors that limit current when the incoming 5V from the Arduino exceeds the permitted voltage on the SD card pins.

So far as I can tell, virtually all full size SD card modules use this design, so it appears they work, at least most of the time.  But I don't see how they could be reliable with a wide variety of SD cards.  A better design would have a voltage translator chip in addition to the regulator.  That type of circuit is more typical of microSD modules.  I don't know why this difference exists since I believe SD and microSD are electronically the same.

As to your questions, I believe you definitely should not connect both power pins.  I think the best one to use is probably the 5V line, which would drive the 3.3V regulator on the module.

I don't know what to suggest for pullup resistors since SCLK, MOSI and CS are already 5V coming out of the Arduino.  So it's not clear what purpose any pullup would have on those lines.  MISO is coming out of the SD card at 3.3V, but I think all 5V Arduinos would still read that as a high.  But if you do use a pullup on that one, it would be to 5V.  But please wait for more responses here before you do anything.  My understanding of all of this is not good, as you can tell.


Tbdanny

Thanks for the link.  I took a look at that thread, and the 3.3V-5V level shifter (translator chip) does appear to be missing from my board.

There's a couple of reasons why I picked this particular module, mainly from a design point of view.  This is actually going into a controller for my model railroad, to drive an automatic scheduling system.  Basically, the controller reads the schedule off a CSV file on the card, then puts that up on a screen on the train layout, one train at a time.  As such, I'd like to have the SD card accessible from outside the unit, rather than opening it up each time I want to change the schedule.  Furthermore, the smallest card I have is a 2GB full-size SD card, with my smallest micro-SD being 8GB.  Given that the schedule file is only a few hundred KB at most, it seems a waste to use an 8GB card for this.

As such, is it possible to put a 3.3V-5V level shifter between the SCK, SC, MISO and MOSI pins, or would it be better to just get a micro SD card reader like the one in your post?

ShermanP

I think adding a level shifter chip just complicates things.  Where would you put it?  And if things from China are available to you in Oz for about the same cost as in the US, a microSD module with level shifter would only cost a couple bucks.

It also appears you can get 128, 256 or 512MB microSD cards for a buck or two from those same sources.

But please understand - modules just like yours appear to be the standard design for full-size SD cards used with 5V MCUs.  The fact that I don't think the design is right doesn't mean there's really anything wrong with them, or that switching to a level-shifter design would solve your problems.  But it might be worth the small investment to find out if it would.

I've ordered a module like yours to play with and test, but it's several weeks away.  I want to trace out the circuit, and also see if it works as well for me as my microSD module.

Tbdanny

Well, I've just tried the level shifter, putting it inline between the Arduino's SCI pins and the SD card reader.  No luck.

It may be the standard design, but the fact is that when correctly wired and using an example straight from the code library, it just plain doesn't work for me.

I've found some of the MicroSD card modules that appear to be similar to the ones in your post: https://www.ebay.com.au/itm/283179556019.  I'll see how those go when they get in.

ShermanP

I would have expected the level shifter to work.  So the problem may be somewhere else.  Can you measure the voltage on the output pin of the 3.3V regulator on your module?

In your first post you said you had trouble getting this to work "reliably".  I assume that means it works well enough that you know the pins, etc., are connected correctly.

Tbdanny

#6
Jul 09, 2019, 10:11 pm Last Edit: Jul 09, 2019, 10:53 pm by Tbdanny Reason: Information update.
I've just done that measurement across the voltage regulator.  I'm getting 0v between GND and VOut, and 0.15v (approx) between GND and VIn.  This is powered from the Arduino via USB.

I think we've found the source of the problem.  I've got a couple of spare modules, so I'll do the same test on those and see how it goes.

UPDATE:

I've just tried with another SD card module.  I tested the voltage regulator chip on it, and that was good.  However, upon testing it, I got the following results:

Code: [Select]

SdFat version: 10100

Assuming the SD is the only SPI device.
Edit DISABLE_CHIP_SELECT to disable another device.

Assuming the SD chip select pin is: 53
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start

init time: 125 ms

Card type: SDHC

Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Version: 8.0
Serial number: 0XE4951B5D
Manufacturing date: 8/2011

cardSize: 15931.54 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
OCR: 0XC0FF8000

SD Partition Table
part,boot,type,start,length
1,0X0,0XC,8192,31108096
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0
error:
File System initialization failed.

SD errorCode: 0X30,0XFF

type any character to start
error: cardBegin failed
SD errorCode: 0X43,0X1

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF

type any character to start

SdFat version: 10100

Assuming the SD is the only SPI device.
Edit DISABLE_CHIP_SELECT to disable another device.

Assuming the SD chip select pin is: 53
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF

type any character to start
error: cardBegin failed
SD errorCode: 0X25,0XFF


Aside from the first few error messages, it's exactly the same as before.  I'm going to try it with the logic level converters in place.

I did check the voltage output from the regulator chip afterwards, and it was giving me 3.3 and 5 where expected.

Tbdanny

I just tried it with the logic level converter, and no luck.  I guess I'll have to wait for those Micro-SD with built-in LLC to come in.

ShermanP

This is really strange because it obviously is communicating successfully in the beginning.

It's curious that it only fails when trying to deal with the file system.  What program are you running to do this test?  Is it possible the software is a bit out of date and just can't deal with cards this big?  Have you tried the CardInfo example in the SD library?

If it fails at exactly this point every time, it may just be a software issue.

Tbdanny

I'm using the SDFat library, which I understand is a more up-to-date version of the SD library.  I've tried it with cards that are 2GB, 8GB and 16GB, all with more or less the same results.

I will try the SD library, and see how that goes.

UPDATE:

I tried it with the SD library, and the same thing happened.  Just 'initialization failed'.

At this point, I'm starting to question whether I actually need an SD card.  The idea was that I would load three files onto it - one is a schedule, and one a set of rules for the generation of extra trains.  The third file would be a 'save' file, which would contain details of which day and train the schedule was up to.

Most of this information could be hard-coded into the sketch itself.  My main worry is that I don't want to keep having to open up the model train controller and extract the Arduino each time I want to update the schedule.  As such, plan B is to have a USB cable going to the Arduino, with the plug out the back of the case.  Then I can just plug that in if I need to update the code.

Tbdanny

Since my last update, I've done a bit of experimentation.  I realised that the one common factor that I hadn't yet checked was the Arduino itself.  All tests had been done off the one mega.  I had a Uno and a Sparkfun Redboard spare, so I tested with both of them.  The initial results were promising.  It failed on the first go, but worked every time after that if I waited for a second or two between performing each test.

I tried changing the SdFat library, replacing the SPI_FULL_SPEED parameter with SPI_HALF_SPEED.  This seemed to make the SdInfo sketch work reliably.  It showed the info for each card, on both the Uno and the Redboard.  However, it only worked for the 8GB SDHC card.  Not the 2GB cards (FAT16), or the 16GB SDHC cards.

With this in mind, I tried the ReadWrite example, to test if it could write a file to the card and read it.  This is where it gets interesting.  When I ran the sketch, it apparently didn't have any errors, and wrote to the file properly.  But when it went to show the contents it had read back from the file, it only showed blank lines.  At least, this is what I saw from the serial monitor.

To check what was on the SD card, I put it into my laptop and checked it.  When I opened it in file explorer, I was greeted by this:



At this point, I realised it still wasn't quite working.

ShermanP

I'm running Arduino v1.8.8 and using a generic Nano (5V) which uses the CH340G USB adapter chip.  And I still only have the microSD module with the level shifting chip.  CS is pin 10.

I ran the ReadWrite example from the SD library, with the CS pin changed from 4 to 10 on line 36.  I tested it with a 256MB microSD card (FAT16, 16K clusters) and a 4GB microSDHC card (FAT32, 32K clusters).  Both cards had been formatted with the SD Formatter program from the SD association (as per the sticky post here).

ReadWrite worked perfectly in all cases, including hitting the Nano's reset button, which just wrote another line to TEST.TXT.  The file is normal when read on my computer, and there's no corruption to any other files on the card.

In the end, you aren't going to know whether your module is at fault until the other one arrives.  I think it's premature to abandon using an SD card until you've tested the new module.  If it still doesn't work, then I really wouldn't know what to suggest.  You're trying multiple SD cards and multiple Arduinos, and assuming the cards are formatted properly, and there's nothing wrong with IDE v1.8.9 (if that's what you're using), and you are selecting the right Board, Processor, Port, etc., then it should all work.

Tbdanny

Yep.  I suspect it's the fact it uses resistors for pull-down on the logic.  I found another thread, here https://forum.arduino.cc/index.php?topic=58643.0 that covers it.  The micro-SD modules are due to arrive in a day or so, so I'll see how I go with those.

ShermanP

The module I had ordered arrived yesterday.  I traced out the circuit, and have posted a new "warning" thread on these modules:

https://forum.arduino.cc/index.php?topic=626295.0

The bottom line is that the resistors are 10K pullup resistors to 3.3V, and they do nothing to prevent the full 5V from being presented to the SD card's pins, with no current limiting.  I was going to test this module to see whether it worked or not as a replacement for my microSD modules that work perfectly.  But frankly, I'm afraid to do that.

What bothers me is that yours should have worked with the level-shifter IC.  If it doesn't, there's a possibility that something has been damaged.


Tbdanny

Sherman,

I've checked the SD cards I tested in that module, and they fortunately appear to be undamaged.  Same for the pins on the Arduino Uno, the Sparkfun Redboard and the Arduino Mega.

The micro-SD card readers have arrived, and I've hooked one up to the Uno and the Mega.  Following this, all tests have worked successfully.

Go Up