Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

University SD CARD IP reads nothing

Hi,

I added the altera_up_avalon_sd_card_interface into nios system.The SD card can be detected, and the READ_BLOCK command can be executed but no data be written in SD_CARD_BUFFER.Following is the code:

---------------------------------------------------------

device_reference = alt_up_sd_card_open_dev(SD_CARD_NAME);

if(device_reference == NULL) printf("SD Card was not found.\n");

if (device_reference != NULL)

{

fprintf(fp,"\n write_read from %x\n",SD_CARD_BASE);

for(i=0;i<512;i++)(*((volatile unsigned char *)SD_CARD_BUFFER(SD_CARD_BASE, i)))=i & 0xff;

for(i=0;i<512;i++)bb[i]=(*((volatile unsigned char *)SD_CARD_BUFFER(SD_CARD_BASE, i)));

for(i=0;i<64;i++)

fprintf(fp,"%2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",bb[8*i],bb[8*i+1],bb[8*i+2],bb[8*i+3],bb[8*i+4],bb[8*i+5],bb[8*i+6],bb[8*i+7]);

fprintf(fp,"write_read ok\n\n");

if (Read_Sector_Data(0, 0))

{

for(i=0;i<64;i++)

fprintf(fp,"%2x,%2x,%2x,%2x,%2x,%2x,%2x,%2x\n",bb[8*i],bb[8*i+1],bb[8*i+2],bb[8*i+3],bb[8*i+4],bb[8*i+5],bb[8*i+6],bb[8*i+7]);

fprintf(fp,"read_sector ok\n\n");

}

}

-------------------------------------------------------------

Where Read_Sector_Data() coming from "altera_up_sd_card_avalon_interface.c" as following:

---------------------------------------------------------------

bool Read_Sector_Data(int sector_index, int partition_offset)

// This function reads a sector at the specified address on the SD Card.

{

bool result = false;

if (alt_up_sd_card_is_Present())

{

short int reg_state = 0xff;

/* Write data to the SD card if the current buffer is out of date. */

if (current_sector_modified)

{

if (Write_Sector_Data(current_sector_index, 0) == false)

{

return false;

}

}

/* Multiply sector offset by sector size to get the address. Sector size is 512. Also,

* the SD card reads data in 512 byte chunks, so the address must be a multiple of 512. */

*command_argument_register = (sector_index + partition_offset)*512;

*command_register = CMD_READ_BLOCK;

do {

reg_state = *aux_status_register;

} while ((reg_state & 0x04)!=0);

// Make sure the request did not time out.

if ((reg_state & 0x10) == 0)

{

result = true;

current_sector_modified = false;

current_sector_index = sector_index+partition_offset;

}

}

return result;

}

--------------------------------------------------------------------------

The strange thing is that the data in SD_CARD_BUFFER after READ_BLOCK were same as the data in SD_CARD_BUFFER before READ_BLOCK.

Looking for your help.

Thanks in advance.
No RepliesBe the first to reply