int main( void ) { WDTCTL = WDTPW + WDTHOLD; //Initialisation of the MMC/SD-card while (status != 0) // if return in not NULL an error did occur and the // MMC/SD-card will be initialized again { status = mmcInit(); timeout++; if (timeout == 150) // Try 50 times till error { //printf ("No MMC/SD-card found!! %x\n", status); break; } } while ((mmcPing() != MMC_SUCCESS)); // Wait till card is inserted // Read the Card Size from the CSD Register cardSize = mmcReadCardSize(); // Clear Sectors on MMC for (i = 0; i < 50; i++) buffer[i] = 1; mmcWriteSector(0, buffer); // write a 50 Byte big block beginning at the (aligned) adress for (i = 0; i < 50; i++) buffer[i] = 0; mmcWriteSector(1, buffer); // write a 50 Byte big block beginning at the (aligned) adress mmcReadSector(0, buffer); // read a size Byte big block beginning at the address. for (i = 0; i < 50; i++) if(buffer[i] != 0) P1OUT |= 0x01; mmcReadSector(1, buffer); // read a size Byte big block beginning at the address. for (i = 0; i < 50; i++) if(buffer[i] != 0) P1OUT |= 0x02; // Write Data to MMC for (i = 0; i < 50; i++) buffer[i] = i; mmcWriteSector(0, buffer); // write a 50 Byte big block beginning at the (aligned) adress for (i = 0; i < 50; i++) buffer[i] = i+64; mmcWriteSector(1, buffer); // write a 50 Byte big block beginning at the (aligned) adress mmcReadSector(0, buffer); // read a size Byte big block beginning at the address. for (i = 0; i < 50; i++) if(buffer[i] != (unsigned char)i) P1OUT |= 0x04; mmcReadSector(1, buffer); // read a size Byte big block beginning at the address. for (i = 0; i < 50; i++) if(buffer[i] != (unsigned char)(i+64)) P1OUT |= 0x08; for (i = 0; i < 50; i++) mmcReadSector(i, buffer); // read a size Byte big block beginning at the address. mmcGoIdle(); // set MMC in Idle mode while (1); }
// Initialize MMC card char mmcInit(void){ //raise CS and MOSI for 80 clock cycles //SendByte(0xff) 10 times with CS high //RAISE CS int i; mmcID = registerComm(&mmcConf); resetUCB0(mmcID); MMC_CS_CONFIG(); //initialization sequence on PowerUp MMC_CS_HIGH(); for(i=0;i<=10;i++) spiSendByte(DUMMY_CHAR); return (mmcGoIdle()); }