int spi_init() { int j; int i; int r; SDHCtype=1; j=5; while(--j) { SPI_CS(0); // Disable CS spi_spin(); puts("SD init...\n"); // puts("SPI Init()\n"); DBG("Activating CS\n"); SPI_CS(1); i=50; while(--i) { if(cmd_reset()==1) // Enable SPI mode { i=1; j=1; } DBG("Sent reset command\n"); if(i==2) { puts("SD card reset failed!\n"); return(0); } } } DBG("Card responded to reset\n"); SDHCtype=is_sdhc(); if(SDHCtype) DBG("SDHC card detected\n"); else // Not SDHC? Set blocksize to 512. { DBG("Sending cmd16\n"); cmd_CMD16(1); } SPI(0xFF); SPI_CS(0); SPI(0xFF); DBG("Init done\n"); return(1); }
int spi_init() { int i; int r; SDHCtype=1; SPI_CS(0); // Disable CS spi_spin(); puts("SPI Init()\n"); DBG("Activating CS\n"); SPI_CS(1); i=8; while(--i) { if(cmd_reset()==1) // Enable SPI mode i=1; DBG("Sent reset command\n"); if(i==2) { DBG("SD card initialization error!\n"); return(0); } } DBG("Card responded to reset\n"); SDHCtype=is_sdhc(); if(SDHCtype) DBG("SDHC card detected\n"); else // If not SDHC, Set blocksize to 512 bytes { DBG("Sending cmd16 (blocksize)\n"); cmd_CMD16(1); } SPI(0xFF); SPI_CS(0); SPI(0xFF); DBG("Init done\n"); return(1); }
int spi_init() { int i; int r; SDHCtype=1; // HW_PER(PER_TIMER_DIV7)=150; // About 350KHz SPI_CS(0); // Disable CS spi_spin(); // puts("Activating CS\n"); SPI_CS(1); i=8; while(--i) { if(cmd_reset()==1) // Enable SPI mode i=1; puts("Sent reset command\n"); if(i==2) { puts("SD card initialization error!\n"); return(0); } } puts("Card responded to reset\n"); SDHCtype=is_sdhc(); if(SDHCtype) puts("SDHC card detected\n"); puts("Sending cmd16\n"); cmd_CMD16(1); SPI(0xFF); SPI_CS(0); SPI(0xFF); puts("Init done\n"); // HW_PER(PER_TIMER_DIV7)=HW_PER(PER_CAP_SPISPEED); return(1); }