Go Down

Topic: SD Card Write Problem (Read 1 time) previous topic - next topic


I have an Atmega328p chip running at 5V internal 8 MHz. During my tests powered via USB 5V from a USB-TTLSerial adapter. Code is compiled for 8MHz and works well, regarding speed of millis().
I have an SD-Card Adapter with a 3.3V regulator and do signal level shifting from 5V to 3.3V for MOSI, CLK and CS.
They are connected on a breadboard, max 2-3" (<10cm) wires. The 5V power has 47µF + 100nF caps.

I'm working with small FAT16 formatted SD Cards.
Reading works well, but when writing, the cards behave different: One works fine, another one does not: Write always fails.
After running into a write error, I have problems getting that card to be readable again. ( A reset helps usually )
Without writing, reading ia always fine.
I tried with low level access (directly reading/writing empty sectors) using Hardware SPI ( HALF-SPEED ). There's nothing else connected to the SPI lines.

All the cards are doing fine in my computer.

What's more likely : speed issues, power supply issues, signal issues ?


It's perhaps those three all together: speed issues, power supply issues, signal issues.

Do you use a breadboard for the signal level conversion : bad connections.
What is the brand of the card, does it use more power than the others ?


What actual speed are you running the SPI at?  How are you doing the level shifting?
[ I won't respond to messages, use the forum please ]


  Brand : TakeMS 2GB ( some years old, though ) 
  Power consumption: not sure how to measure the actually required power spikes during write. I don't have a real oscilloscope.
     Is analogRead fast enough ? If yes, should I use a second arduino to measure, or dig into how to do this interrupt driven.
  Bad breadboard connections: I understand both reading and writing uses all SPI signals, and reading works well...
Speed: I'm testing based on the Arduino SD library and tried both
     card.init(SPI_HALF_SPEED, chipSelect); // as used in CardInfo.ino example
     and SPI_QUARTER_SPEED. Is it possible to be too slow with my 8MHz board ? 
  LevelShifting : I understand both reading and writing uses all SPI signals, and reading works well...  ;)
     Is there power drawn from the MOSI or CLK line ?
     The adapter provides 10k pullup resistors between its 3.3V regulator and the signal lines,
     so I just added  small reverse diodes to my 5V atmega signals, providing 0.6 .. 3.3 V signal level to the SD card.

Thanks to both for your feedback so far.
More hints ( especially regarding live power measuring, and whether this makes sense ) are very welcome.

My next step will be to cross over the available components
A ) Arduino Uno with Adafruit DataLogger shield ( working )
B ) Standalone 8MHz with LCstudio SD card module ( read only ) 
and see if problem is rather the 8MHz no crystal or the SD card module side


Instead of analogRead() with a second Arduino, I sometimes use a fast optocoupler (with a resistor for the internal led) to the mic input of my computer to measure the noise of a power supply.

The 47uF could be bad. You could place a second capactitor of about 100uF ... 470uF. It might seem odd, but I've seen the craziest unexplainable things with a bad capacitor.
I found a post that is simular: http://arduino.cc/forum/index.php?topic=58643.0

What about this : http://www.adafruit.com/forums/viewtopic.php?f=31&p=146648
It says: "I have heard of issues with accessing SD cards on 8MHz variants"
So the 8MHz might be a problem. But I can't find a good explanation what the problem is with 8MHz.


Thanks, seems an interesting link:

A quote from fa16lib himself:
I find that most older cards work at 8 MHz and almost all older cards work at half speed, 4 MHz.

Many newer cards fail at all speeds with resistor level shifters.  These cards expect very fast SPI signal rise times.  The SD spec requires a rise time of less than 10 ns for all clock speeds under 25 MHz.  It is just not possible to get sharp edges at 8 MHz into the typical capacitance with resistor level shifters.



I was wondering if you were running a +3.3v logic / 8MHz internal clock Arduino circuit...

could you just -not- use the (resistor based) voltage divider and 'direct connect' (so to speak)?

I am trying, and I am not having success.

I have a minimal/breadboard 'Arduino' running @ +3.3v / 8Mhz internal clock  (no crystal/caps)..

successfully flashed bootloader....sketch uploading works every time as well.

With no resistors to stop a 'sharp edge'/fast SPI signal.....  is there another problem?



Thanks for this late response.
Currently my atmega328 runs at 5V, but this is not necessary with 8MHz.

An interesting alternative approach. Thanks !

I just wonder if the 5V->3.3V regulator found on my SD-Card module would be sufficient to supply the atmega328 (plus even a small nokia 5110 ---
except for the backlight).

Up to now the balance between "get it to run safely"  vs. "minimal build" removed the external crystal and relies on a 5V supply only.

The 3.3V for the nokia vcc currently come from a "pseudo regulator" built by a led and a 1k resistor.
Pulling it from the SD-Module was possible as well, but I have the power indicator led anyway.
I would not dare use that to drive my atmega328,  with probably > 20mA, though.

Go Up