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.
1087 Discussions

DE2 cannot open a file in the SD card

Honored Contributor II

The function alt_up_sd_card_find_first works perfectly, which can help me print out all the file names in the SD card. (So I think it's not any formatting and size problem of the SD card. It's 2GB and FAT16 anyways.) 


But when I call alt_up_sd_card_fopen, it returns me -1, so I can't open, create, and write a file. 


Below is my simple code of creating a text file, and print out all the file names: 


alt_up_sd_card_dev *device_reference = NULL; 

int connected = 0; 

char* fileName; 

device_reference = alt_up_sd_card_open_dev(SD_CARD_NAME); 



short int handler; 

char buffer[10000] = "Testing Testing\0"; 

int index = 0; 



if (device_reference != NULL) { 





handler = alt_up_sd_card_fopen("test2.txt", false); 

if (handler >= 0){ 

while (buffer[index] != '\0'){ 

alt_up_sd_card_write(handler, buffer[index]); index++;} 


else printf("cannot open file: %d\n",handler); 

while (1) { 

if ((connected == 0) && (alt_up_sd_card_is_Present())) { 

printf("Card connected. \n"); 

printf("fat16: %d",alt_up_sd_card_is_FAT16()); 

if (alt_up_sd_card_is_FAT16()) { 

printf("FAT16 file system detected. \n"); 




printf("Files detected: \n"); 


printf("%s \n",fileName); 


else if (alt_up_sd_card_find_first("",fileName)== -1) 

printf("No files. \n"); 

} else { 

printf("Unknown file system. \n"); 

connected = 1; 

} else if ((connected == 1) && (alt_up_sd_card_is_Present() 

== false)) { 

printf("Card disconnected. \n"); 

connected = 0; 



I found a similar thread about this issue. 

But I had the interface already... I don't know why it's still nothing changes??? 


Please help, thanks
0 Kudos
0 Replies