SdFormatter.ino reports error: write MBR SD error: 13,0

Hi all,

I just pulled the sdfatlib from github master today, and found that the SdFormatter.ino cannot format my SD card. I am using Arduino Uno R3.

The SD card can be formatted using official SDFormatter V4.0 on my desktop. If I create folders and files on my desktop, all the card folders / file names read from QuickStart.ino is correct as well (attached at the end of the thread).

Any ideas? Thanks!


Output from SdFormatter.ino

This program can erase and/or format SD/SDHC cards.

Erase uses the card's fast flash erase command. Flash erase sets all data to 0X00 for most cards and 0XFF for a few vendor's cards.

Cards larger than 2 GB will be formatted FAT32 and smaller cards will be formatted FAT16.

Warning, all data on the card will be erased. Enter 'Y' to continue: Y

Options are: E - erase the card and skip formatting. F - erase and then format the card. (recommended) Q - quick format the card without erase.

Enter option: F Card Size: 1910 MB, (MB = 1,048,576 bytes)

Erasing ............... All data set to 0x00 Erase done

Formatting Blocks/Cluster: 64 FAT16 error: write MBR SD error: 13,0

Output from QuickStart.ino

SPI pins: MISO: 12 MOSI: 11 SCK: 13 SS: 10

Be sure to edit DISABLE_CHIP_SELECT if you have a second SPI device. For example, with the Ethernet shield, DISABLE_CHIP_SELECT should be set to 10 to disable the Ethernet controller.

SD chip select is the key hardware option. Common values are: Arduino Ethernet shield, pin 4 Sparkfun SD shield, pin 8 Adafruit SD shields and modules, pin 10

Enter the chip select pin number: 10

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

Card successfully initialized.

Card size: 2003 MB (MB = 1,000,000 bytes)

Volume is FAT16, Cluster size (bytes): 32768

Files found (date time size name): 2015-05-08 17:49:00 0 test1/ 2015-05-08 17:49:02 0 test2/ 2015-05-08 17:49:06 0 test.txt

Success! Type any character to restart.


I tried to use AnalogBinLogger.ino, and it failed (no surprises given the previous post):

FreeRam: 1117

type: c - convert file to csv d - dump data to Serial e - overrun error details r - record ADC data

Sample pins: 0 1 2 3 4 ADC bits: 10 ADC clock kHz: 500 Sample Rate: 5000.00 Sample interval usec: 200.0000 Creating new file error: createContiguous failed SD errorCode: 0X13,0X0

However, the official SD library data logger (Example-SD-Datalogger) worked, which seems to indicate that the wiring is correct.

(I changed SS from 4 to 10)

Initializing SD card...card initialized. 384,360,342 356,351,344 345,342,339 338,335,334

And here is the output from Examples-SD-CardInfo.ino to show that the logging was successful:

Initializing SD card...Wiring is correct and a card is present.

Card type: SD1

Volume type is FAT16

Volume size (bytes): 2002452480 Volume size (Kbytes): 1955520 Volume size (Mbytes): 1909

Files found on the card (name, date and size in bytes): DATALOG.TXT 2000-01-01 01:00:00 5005

Any ideas on where I could continue my next step in debugging would be appreciated. Thanks!

You won't see write errors with the SD.h Datalogger example since it does not check for errors.


SD.h is just a wrapper for an old version of SdFat but it uses half speed SPI, 4 MHz. The SD.h Datalogger example logs data at a fairly slow rate since it echos to Serial.

AnalogBinLogger uses full speed SPI, 8 MHz, and writes lots of data at a high rate. It checks every operation for errors.

SdFormatter runs at 4 MHz but also writes lots of data and checks for errors.

You may have marginal SPI wiring or a problem with your SD shield/module.

What SD shield/module are you using?

Hi Bill,

First of all, thank you for your reply!

You are right that it might be due to the cheap SD module that I am using. I am using this one, that I bought from ebay for less than a dollar. I will be getting an Ethernet shield tomorrow, so I will post back here as soon as I can test it with that.

So far,

1) I tried swapping a couple of modules but they report a similar error. It looks like an incompatibility issue for the design of the module, rather than a hardware problem for the module.

2) My current wiring with an Arduino Uno is: GND to GND, 3.3V to 3.3V, CS to 10, MOSI to 11, SCK to 13 and MISO to 12. Looks right to me...

Anyway, I will report back after I try the Ethernet shield. Thanks again for your input!


Your module is known for problems. It does not have proper 5V to 3.3V SPI level shifters.

The SD on the Ethernet shield should work better.


Thank you again for your response!

  1. Good news: I got the code working! It turned out to be really my bad - I was experimenting with a cheap Arduino clone ($3), called DCCduino, that replaced 16u2 (16 MHz) with CH340G (12 MHz). When I went back to official Arduino Uno R3, it worked just out of the box. I apologize for forgetting to mention this cheap copy.

  2. That said, the board with CH340G shouldn’t interfere with the clocking of SPI I assume… Because that is only the serial communication part, right? Plus, I am sure that the board itself does not have hard-ware problem since I tried a couple of them and they gave me the same result.

  3. I understand that cheap boards maybe totally a mess, yet I am interested to look into it a little bit more, because I am trying to make a cheap DAQ box with fs >16 kHz :slight_smile: So, I plan to try to dig into some of the sdfatlib code by myself later, to see whether I can find a fix.

Thanks again for your help Bill! I really appreciate your time. And, also, when I got it working, the analog data logger is really working like a charm - really high sampling frequency for only less than 50 dollars of equipment!


Edit on 2015/05/14 21:13 EDST

Well, first of all, pin 13 on Mega would be pin 9 on Uno, which is not used...

Any both pin 9 and pin 13 works alright on the CH340G based Arduino Uno. Hmm. I'd have look into it more.

A quick update:

I found this post mentioning an interesting pin behavior:

One thing to be careful for though is the bootloader, most the time the Chinese vendor had written a custom bootloader which may make certain pins behave funny. e.g. a common thing is for pin 13 (the default led ) is permanently high.

This is what I encounter. I think this is related because I use pin 13 as SCK. I will update using "Edit" in this post after I find more out.

I understand that cheap boards maybe totally a mess, yet I am interested to look into it a little bit more, because I am trying to make a cheap DAQ box with fs >16 kHz :) So, I plan to try to dig into some of the sdfatlib code by myself later, to see whether I can find a fix.

Part of the problem is the SD module. It won't work with some SD cards or Arduino clones.

There are many ways to fix your SD module. The problem is hardware so modifying SdFat won't do it.

Search for LC Studio SD card.

There are lots of low cost SD modules on ebay that work without modification.

Here is one for $1.31.

There are also many low cost Arduino clones that work well. Spend $0.50 more because you will continue to have problems with junk.

Hi Bill,

Thanks one more time for your response!

Actually now it works perfectly with the official Arduino Uno! The formatting is successful, the data writing has no problem. I used the 3.3 V directly rather than the 5 V. Therefore, I think the problem with the SD module should be resolved.

The error still happens if I am using an unofficial Arduino Uno, based on CH340G rather than 16u2. I wonder how this may change how sdfatlib behave.


The problem is lack of level shifters so it will still be flaky. I have had dozens of users think they fixed this module then have problems later.

Well at least you saved $0.50.

The Arduino outputs 5V SPI and SD cards may work but you are depending on the SD cards input protection to saturate the pins 50 ma output and produce 3.3 V.

Hi Bill,

Oh OK I see what you mean! You are saying that even though the official Arduino Uno works with that module, it might be just be I am lucky; the module itself is problematic so the output is unstable. If I try to use another module, this problem might just go away.

Thanks - I ordered those modules, and am patiently waiting for them to arrive :)


Dear all,

Just a quick update - thanks! The new CATALEX module for micro SD works perfectly. It should be the notorious LC STUDIO module level shift error that is causing the problem before.

I am waiting for a module for standard SD from here to arrive, so I can have a working module with standard SD.

If anyone knows about a cheap and working SD module for standard SD card (not LC STUDIO ones), I'd be more than happy to know!

Have a great day,