I'm trying to read a microSD block. But I don't know why it doesn't work.
I do:
CS_UP;
for(uint8_t i = 0; i <14; i++){ /* Send 74+ clocks */
spi_tranceiver(0xff);
}
_delay_ms(1); /* Wait 1 ms */
//CS_UP;
/* Initizalize 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(); // Set 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();
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?
Peter Mortensen
4373 silver badges12 bronze badges
asked Nov 22, 2016 at 3:03
-
Please add, which printout you were expecting. Also please post, how many zeroes are printed out at the respective parts of the output. This makes it easier to trace down the problem.Ariser– Ariser2016年11月22日 09:46:14 +00:00Commented Nov 22, 2016 at 9:46
-
And now we're equating "AVR" with "Arduino"? What the hell?Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2016年11月23日 16:50:13 +00:00Commented Nov 23, 2016 at 16:50
-
I use Arduino Mega Board. But I don't use Arduino Language programming.Emmanuel Arias– Emmanuel Arias2016年11月24日 01:15:04 +00:00Commented Nov 24, 2016 at 1:15
1 Answer 1
I formated the SD card, and then work correctly
Thanks!
answered Nov 23, 2016 at 14:15