fork download
  1. //******************************************************************
  2. //Function: to read a single block from SD card
  3. //Arguments: none
  4. //return: unsigned char; will be 0 if no error,
  5. // otherwise the response byte will be sent
  6. //******************************************************************
  7. unsigned char SD_readSingleBlock(unsigned long startBlock)
  8. {
  9. unsigned char response;
  10. unsigned int i, retry=0;
  11.  
  12. response = SD_sendCommand(READ_SINGLE_BLOCK, startBlock<<9); //read a Block command
  13. //block address converted to starting address of 512 byte Block
  14. if(response != 0x00) //check for SD status: 0x00 - OK (No flags set)
  15. return response;
  16.  
  17. SD_CS_ASSERT;
  18.  
  19. while(SPI_receive() != 0xfe) //wait for start block token 0xfe (0x11111110)
  20. if(retry++ > 0xfffe){SD_CS_DEASSERT; return 1;} //return if time-out
  21.  
  22. for(i=0; i<512; i++) //read 512 bytes
  23. buffer[i] = SPI_receive();
  24.  
  25. SPI_receive(); //receive incoming CRC (16-bit), CRC is ignored here
  26. SPI_receive();
  27.  
  28. SPI_receive(); //extra 8 clock pulses
  29. SD_CS_DEASSERT;
  30.  
  31. return 0;
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘SD_readSingleBlock’:
prog.c:12:1: warning: implicit declaration of function ‘SD_sendCommand’ [-Wimplicit-function-declaration]
 response = SD_sendCommand(READ_SINGLE_BLOCK, startBlock<<9); //read a Block command
 ^
prog.c:12:27: error: ‘READ_SINGLE_BLOCK’ undeclared (first use in this function)
 response = SD_sendCommand(READ_SINGLE_BLOCK, startBlock<<9); //read a Block command
                           ^
prog.c:12:27: note: each undeclared identifier is reported only once for each function it appears in
prog.c:17:1: error: ‘SD_CS_ASSERT’ undeclared (first use in this function)
 SD_CS_ASSERT;
 ^
prog.c:19:1: warning: implicit declaration of function ‘SPI_receive’ [-Wimplicit-function-declaration]
 while(SPI_receive() != 0xfe) //wait for start block token 0xfe (0x11111110)
 ^
prog.c:20:24: error: ‘SD_CS_DEASSERT’ undeclared (first use in this function)
   if(retry++ > 0xfffe){SD_CS_DEASSERT; return 1;} //return if time-out
                        ^
prog.c:23:3: error: ‘buffer’ undeclared (first use in this function)
   buffer[i] = SPI_receive();
   ^
stdout
Standard output is empty