expert_vision
Junior Member level 3
- Joined
- Dec 5, 2012
- Messages
- 26
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,283
- Activity points
- 1,506
I am data logging my uC on a microSD card and everything is fine on the physical circuit.
In Proteus though, everything is fine to the point when I send READ_SINGLE_BLOCK.
So it goes in SPI mode at command GO_IDLE_STATE by responding 0x01 and initializations (SEND_OP_COND twice, CRC_ON_OFF OFF and SET_BLOCK_LEN 512 -- all respond 0x00) is fine too. Then I send READ_SINGLE_BLOCK at 0 and I receive 0x00, but data token 0xfe never comes, all I receive is 0xff.
The MMC image I use is the one in:
C:\Program Files (x86)\Labcenter Electronics\Proteus 7 Professional\SAMPLES\VSM for USB\PICDEM FS USB\MSD\disk.bin
I tried other images too.
Again, the physical circuit works fine, is Proteus the one causing trouble.
Here is the SD_readSingleBlock function:
In Proteus it gets stuck in the while loop waiting for 0xfe.
In Proteus though, everything is fine to the point when I send READ_SINGLE_BLOCK.
So it goes in SPI mode at command GO_IDLE_STATE by responding 0x01 and initializations (SEND_OP_COND twice, CRC_ON_OFF OFF and SET_BLOCK_LEN 512 -- all respond 0x00) is fine too. Then I send READ_SINGLE_BLOCK at 0 and I receive 0x00, but data token 0xfe never comes, all I receive is 0xff.
The MMC image I use is the one in:
C:\Program Files (x86)\Labcenter Electronics\Proteus 7 Professional\SAMPLES\VSM for USB\PICDEM FS USB\MSD\disk.bin
I tried other images too.
Again, the physical circuit works fine, is Proteus the one causing trouble.
Here is the SD_readSingleBlock function:
Code:
//******************************************************************
//Function: to read a single block from SD card
//Arguments: none
//return: unsigned char; will be 0 if no error,
// otherwise the response byte will be sent
//******************************************************************
unsigned char SD_readSingleBlock(unsigned long startBlock)
{
unsigned char response;
unsigned int i, retry=0;
response = SD_sendCommand(READ_SINGLE_BLOCK, startBlock<<9); //read a Block command
//block address converted to starting address of 512 byte Block
if(response != 0x00) //check for SD status: 0x00 - OK (No flags set)
return response;
PORTD = 5;
SD_CS_ASSERT;
retry = 0;
while((SPI_receive()) != 0xfe) //wait for start block token 0xfe (0x11111110)
if(retry++ > 0xfffe){SD_CS_DEASSERT; return 1;} //return if time-out
for(i=0; i<512; i++) //read 512 bytes
buffer[i] = SPI_receive();
SPI_receive(); //receive incoming CRC (16-bit), CRC is ignored here
SPI_receive();
SPI_receive(); //extra 8 clock pulses
SD_CS_DEASSERT;
return 0;
}
In Proteus it gets stuck in the while loop waiting for 0xfe.