Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
1158 Discussions

read bitmap from sdcard de2 nios2

Honored Contributor II

hi. i want to read a bitmap image from my sdcard. i was able to write to sdcard as in the tutorial. my source code for reading is as follows: 

# include <stdio.h># include <system.h># include <altera_up_sd_card_avalon_interface.h> 

# pragma pack(2) 


typedef struct{ 

unsigned short int type; /* Magic identifier */ 

unsigned int size; /* File size in bytes */ 

unsigned short int reserved1, reserved2; 

unsigned int offset; /* Offset to image data, bytes */ 

} BMPFileHeader; 


typedef struct{ 

unsigned int size; /* Header size in bytes */ 

int width,height; /* Width and height of image */ 

unsigned short int planes; /* Number of colour planes */ 

unsigned short int bits; /* Bits per pixel */ 

unsigned int compression; /* Compression type */ 

unsigned int imagesize; /* Image size in bytes */ 

int xresolution,yresolution; /* Pixels per meter */ 

unsigned int ncolours; /* Number of colours */ 

unsigned int importantcolours; /* Important colours */ 

} BMPInfoHeader; 



short int sd_fileh; 

short int header; 

int x; 

int main() 

printf("SD Card Access Test\n"); 


alt_up_sd_card_dev *sd_card_dev = alt_up_sd_card_open_dev(SD_CARD_NAME); 


if(sd_card_dev != 0) 



printf("Card is FAT16\n"); 


printf("Card is not FAT16\n"); 


sd_fileh = alt_up_sd_card_fopen("pic.bmp", false); 


if (sd_fileh < 0) 

printf("Problem creating file. Error %i", sd_fileh); 


printf("SD Accessed Successfully, reading BMP image..."); 


header = (unsigned char)(alt_up_sd_card_read(sd_fileh)); 

printf("Size: %ld\n", sizeof(BMPFileHeader)); 




printf("Closing File..."); 





return 0; 


it builds without errors and the sd card was accessed successfully but the returned bitmap size was wrong. please guide me in correcting my code especially in the reading part. im not familiar with c. thanks in advance!
0 Kudos
0 Replies