if ( send_cmd ( CMD0, 0 ) == 1 ) { /* Enter Idle state */
if ( send_cmd ( CMD8, 0x1AA ) == 1 ) { /* SDC Ver2+ */
for ( n = 0; n < 4; n++ ) ocr[n] = rcvr_spi (); /* Get trailng data of R7 resp */
if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) { /* The card can work at vdd range of 2.7-3.6V */
send_cmd ( CRC_ON_OFF, 0 ); // no checking CRC, redundant
while ( send_cmd ( ACMD41, 1UL << 30 ) ); /* ACMD41 with HCS bit */
wdttime ( SDTIME ); // wait for card to init
SSP1CON1 = SSP1CON1 & 0xf0; // set to full speed
// SSP1CON1bits.SSPM0=1; // set to fosc/16
if ( send_cmd ( CMD58, 0 ) == 0 ) { /* Check CCS bit in the OCR */
for ( n = 0; n < 4; n++ )
ocr[n] = rcvr_spi ();
SDC0.sdtype = ( ocr[0] & 0x40 ) ? 6 : 2;
}
}
} else { /* SDC Ver1 or MMC */
if ( send_cmd ( ACMD41, 0 ) <= 1 ) {
SDC0.sdtype = 2;
cmd = ACMD41; /* SDC */
} else {
SDC0.sdtype = 1;
cmd = CMD1; /* MMC */
}
while ( send_cmd ( cmd, 0 ) ); /* Wait for leaving idle state */
if ( send_cmd ( CMD16, 512 ) == 0 ); /* Select R/W block length */
}