Atmel ATmega (ATmega16 / ATmega32) - SD (Secure Digital Card) Flash Memory Extension
This page bases upon the page
Atmel ATmega (ATmega16 / ATmega32) - MMC (Multi Media Card) Flash Memory Extension.
It is easy to interface a SD (Secure Digital Card) with an Atmel ATmega16 (ATmega series) via the SPI (Serial Port Interface).
This is a very handy data logging circuit with lots of memory for data storage.
I2C RAM's or EEPROM's are hardly available at sizes bigger than 256kb, so a solution with a large Flash SD card is not
to beat in both cost effectiveness and storage volume!
Basically a SD card is a MMC card. The commands are the same, the pins are the same, so you can easily replace
the MMC with a SD card. The only change to make is the firmware and that change is only minor:
Instead of checking the return value immediately after sending a command to the card
if (Command(0x51,0,512,0xFF) != 0) {
uart_puts("MMC: read error 1 ");
return 1;
}
we need to loop and check:
uint16_t ix;
char r1 = Command(0x51,0,512,0xFF);
for (ix = 0; ix < 50000; ix++) {
if (r1 == (char)0x00) break;
r1 = SPI(0xFF);
}
if (r1 != (char)0x00) {
uart_puts("MMC: read error 1 ");
return 1;
}
This is the change in the function "int sendmmc(void)".
This was the only change I did and it worked. But to be safe, also implement the loop when sending the
512 byte sector/block write command in "int writeramtommc(void)":
if (Command(0x58,0,512,0xFF) !=0) {
uart_puts("MMC: write error 1 ");
return 1;
}
becomes
uint16_t ix;
char r1 = Command(0x58,0,512,0xFF);
for (ix = 0; ix < 50000; ix++) {
if (r1 == (char)0x00) break;
r1 = SPI(0xFF);
}
if (r1 != (char)0x00) {
uart_puts("MMC: write error 1 ");
return 1;
}
The rest of the code remains unchanged.
Last-Modified: Mon, 18 Jun 2007 17:24:53 GMT