|
|
|
|
@ -33,6 +33,7 @@ unsigned char mmc_init ()
|
|
|
|
|
//############################################################################
|
|
|
|
|
{
|
|
|
|
|
unsigned int Timeout = 0;
|
|
|
|
|
uint8_t debug;
|
|
|
|
|
|
|
|
|
|
//Konfiguration des Ports an der die MMC/SD-Karte angeschlossen wurde
|
|
|
|
|
MMC_Direction_REG &=~(1<<SPI_DI); //Setzen von Pin MMC_DI auf Input
|
|
|
|
|
@ -61,7 +62,7 @@ unsigned char mmc_init ()
|
|
|
|
|
|
|
|
|
|
//Sendet Commando CMD0 an MMC/SD-Karte
|
|
|
|
|
unsigned char CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95};
|
|
|
|
|
while(mmc_write_command (CMD) !=1)
|
|
|
|
|
while(mmc_write_command (CMD) != 1)
|
|
|
|
|
{
|
|
|
|
|
if (Timeout++ > 200)
|
|
|
|
|
{
|
|
|
|
|
@ -69,6 +70,7 @@ unsigned char mmc_init ()
|
|
|
|
|
return(1); //Abbruch bei Commando1 (Return Code1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// return(((debug >>1) & 1)+1); //FIXME
|
|
|
|
|
//Sendet Commando CMD1 an MMC/SD-Karte
|
|
|
|
|
Timeout = 0;
|
|
|
|
|
CMD[0] = 0x41;//Commando 1
|
|
|
|
|
@ -151,6 +153,7 @@ unsigned char mmc_read_byte (void)
|
|
|
|
|
#else //Routine für Software SPI
|
|
|
|
|
for(unsigned char a=8; a>0; a--) //das Byte wird Bitweise nacheinander Empangen MSB First
|
|
|
|
|
{
|
|
|
|
|
Byte <<= 1;
|
|
|
|
|
MMC_Write &=~(1<<SPI_Clock); //erzeugt ein Clock Impuls (Low)
|
|
|
|
|
WAIT_HALF_CLOCK;
|
|
|
|
|
|
|
|
|
|
@ -158,7 +161,6 @@ unsigned char mmc_read_byte (void)
|
|
|
|
|
{
|
|
|
|
|
Byte |= 1;
|
|
|
|
|
}
|
|
|
|
|
Byte <<= 1;
|
|
|
|
|
MMC_Write |=(1<<SPI_Clock); //setzt Clock Impuls wieder auf (High)
|
|
|
|
|
WAIT_HALF_CLOCK;
|
|
|
|
|
}
|
|
|
|
|
@ -310,13 +312,13 @@ unsigned char mmc_read_sector (unsigned long addr,unsigned char *Buffer)
|
|
|
|
|
|
|
|
|
|
//############################################################################
|
|
|
|
|
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
|
|
|
|
|
void mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count, unsigned int Bytes)
|
|
|
|
|
uint8_t mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count, unsigned int Bytes)
|
|
|
|
|
//############################################################################
|
|
|
|
|
{
|
|
|
|
|
//Sendet Commando cmd an MMC/SD-Karte
|
|
|
|
|
if (mmc_write_command (cmd) != 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Wartet auf Start Byte von der MMC/SD-Karte (FEh/Start Byte)
|
|
|
|
|
@ -326,7 +328,7 @@ void mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count
|
|
|
|
|
//Lesen des Bolcks (normal 512Bytes) von MMC/SD-Karte
|
|
|
|
|
for (unsigned int a=0;a<Bytes;a++)
|
|
|
|
|
{
|
|
|
|
|
if(Bytes < count) {*Buffer++ = mmc_read_byte();}
|
|
|
|
|
if(a < count) {*Buffer++ = mmc_read_byte();}
|
|
|
|
|
else {mmc_read_byte();}
|
|
|
|
|
}
|
|
|
|
|
//CRC-Byte auslesen
|
|
|
|
|
@ -336,12 +338,12 @@ void mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count
|
|
|
|
|
//set MMC_Chip_Select to high (MMC/SD-Karte Inaktiv)
|
|
|
|
|
MMC_Disable();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//############################################################################
|
|
|
|
|
//Routine zum lesen eines Blocks(512Byte) von der MMC/SD-Karte
|
|
|
|
|
void mmc_read_part(unsigned long addr,unsigned char *Buffer, uint16_t count)
|
|
|
|
|
uint8_t mmc_read_part(unsigned long addr,unsigned char *Buffer, uint16_t count)
|
|
|
|
|
//############################################################################
|
|
|
|
|
{
|
|
|
|
|
//Commando 16 zum lesen eines Blocks von der MMC/SD - Karte
|
|
|
|
|
@ -357,7 +359,7 @@ void mmc_read_part(unsigned long addr,unsigned char *Buffer, uint16_t count)
|
|
|
|
|
cmd[2] = ((addr & 0x00FF0000) >>16 );
|
|
|
|
|
cmd[3] = ((addr & 0x0000FF00) >>8 );
|
|
|
|
|
|
|
|
|
|
mmc_read_block_part(cmd, Buffer, count, 512);
|
|
|
|
|
return mmc_read_block_part(cmd, Buffer, count, 512);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//############################################################################
|
|
|
|
|
|