I'm trying to read a Micro SDmicroSD block. But I don't know why it doesn't work.
I do:
CS_UP;
for(uint8_t i = 0; i <14; i++){ /*send* Send 74+ clocks */
spi_tranceiver(0xff);
}
_delay_ms(1); /*wait* 1ms*Wait 1 ms */
//CS_UP;
/*initizalize* MicroInitizalize SD*microSD */
put_string("Go to idle state\n");
while (Reset_Card() != 0x01); // Go to idle state
;
put_string("Send IF COND\n");
while (Send_CMD8() != 0x01); // SEND IF COND
;
put_string("Send ACMD41 and CMD55\n");
for (int i = 0; i<100; i++)
while ( Send_CMD55() && Send_ACMD41())
;
setBlockLen(); // setSet block read in 512 bytes
CS_DOWN;
put_string("\nConfigure finished correctly\n");
And then I just call:
readSingleBlock(0x00, &buf)
readSingleBlock is defined as follows:
uint8_t readSingleBlock ( uint32_t block_address, unsigned char *buf )
{
int i;
block_address = block_address << 9;
CS_UP;
while ( 0x00 != sdsc_command ( READ_SINGLE_BLOCK, block_address))
) ) ;
while ( 0xfe != spi_rx () )
;
for ( i = 0; i < 512; i ++ ){
//buf [ i ] = spi_rx();
put_int(spi_rx());
put_string("\n");
}
spi_rx spi_rx();
spi_rx spi_rx();
CS_DOWN;
//for (i = 0; i<512; i++) put_int(buf[i]);
The problem is that the printout is:
0 0 0 ..(zeros).. 128 255 255 255 12 255 255 255 0 8 0 0 0 72 59 ..(zeros).. 85 170
Did somebody encounter this problem?
Do you have some suggestions?
Thanks!