Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
1079 Discussions

University SD CARD IP reads nothing

Honored Contributor I


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))); 



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

if (Read_Sector_Data(0, 0)) 



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.
0 Kudos
0 Replies