void mmc_init(void) // Komplettinitialisierung der MMC-Karte { unsigned char ucindex=0,in,shdn=1; // lokale Zählervariable unsigned int mmc_defekt; // Zählervariable zur MMC-Erkennung shdn = CHECKBIT(PORTB,PORTPIN4); //Shutdown Card-Translater if (shdn!=0x00) // Überprüfung auf SHDN { SETBIT(PORTB,PORTPIN0); // SS --> CS MMC inaktiv "1" SPCR=0x5C; // SPI enabled for(ucindex=0; ucindex<10; ucindex++) { SPDR = 0xFF; // DummyClocks werden gesendet delay_spi(8); // delay wegen Nachladen des Registers if(SPSR == 0x40) // Daten sind sonst falsch ucindex--; } CLEARBIT(PORTB,PORTPIN0); // SS wird low -> CS MMC aktiv "0" delay_spi(4); // auf MMC-SPI-Access delay_spi(4); SPDR = 0x40; // Command 0 bis CRC delay_spi(4); for(ucindex=0; ucindex<4; ucindex++) { SPDR = 0x00; // 0x00 (4x Dummy ) wird gesendet delay_spi(4); if(SPSR == 0x40) // WCOL Write Collision Flag wird abge- ucindex--; // fragt--> Befehl wird wiederholt } SPDR = 0x95; // CRC delay_spi(4); SPDR = 0xFF; delay_spi(4); // Wartet auf "valid response" SPDR = 0xFF; in = 0xFF; // In-Register wird auf 0xFF gesetzt delay_spi(4); do { mmc_defekt++; SPDR = 0x41; // Command 1 bis CRC delay_spi(4); for(ucindex=0; ucindex<4; ucindex++) { SPDR = 0x00; // DummyClock delay_spi(4); // Daten sind sonst falsch, if(SPSR == 0x40) // da Registerfehlermeldung ucindex--; } SPDR = 0xFF; // CRC delay_spi(4); SPDR = 0xFF; delay_spi(4); // Wait for valid response SPDR = 0xFF; delay_spi(4); in = SPDR; // SPDR wird nach in-Register eingelesen delay_spi(4); SPDR = 0xFF; // DummyClock delay_spi(4); if ( mmc_defekt == 0xFFFF ) // Abbruch, da keine oder fehlerhafte MMC { Schreibe("MMC fehlt ",1); Schreibe("oder defekt !! ",2); break; } } // solange bis response von while (in>0x00); // Cmd1 = 0x00 !!! } // Initialisierung fertig } void mmc_cmd25(void) // Multiple Block Write bei MMCKarte { unsigned char in=1; { SPDR = 0x59; // Command 25 bis CRC delay_spi(4); SPDR = 0x00; // Adresse zum Schreibbeginn -> 0x00000000 delay_spi(4); SPDR = 0x00; delay_spi(4); SPDR = 0x00; delay_spi(4); SPDR = 0x00; delay_spi(4); // Ende Adresse SPDR = 0xFF; // CRC und Stopp Bit delay_spi(4); do // NCR Dummy clocks .... { SPDR = 0xFF; delay_spi(4); in = SPDR; // ... und einlesen... } while(in > 0x00); // ...bis response = 0x00 } SPDR = 0xFF; // Nwr-Time Dummy clock delay_spi(4); }