I wanted to store some huge blocks of data in SD card, All the values are stored in a 8 bit buffer. Following is the layman code of what I am doing.
uint8_t buffer; // Contains 8 bit int values from sensor/ ADC
SD_Card_init(); // In SPI mode with FATFs including ".hex" file created
FAT1_write(&fp1, buffer, sizeof(buffer), &bw); // Writing buffer to SD card
I wanted the values written to the file to be in hex.
When I am opening and reading the file through windows. I am not getting the same values as what I am able to see through any hex editor. In notepad it is showing some ascii characters. Following is the program for decoding the values in windows.
uint8_t buffer ;
fp = fopen(“buffer.hex", "r");
if(fp == NULL)
printf("file not found\n");
fread(buffer, 300, 1, fp);
printf("\n%d = %X \n",i, buffer[i]);
Is there any better way to store huge hex values in SD card? as the values being read is different. (initial few values are as expected after that the o/p value changes). I think the problem is something related to ASCII char. as for 8 bit we need 0-255 but if it is converted to ascii then we have 0-127 decimal values defined after that the values are not standard. I don't know exactly what the issue is but initial values being correctly printed is below 127 dec or 0x7F hex values after the 1st occurrence of any hex value in file higher than 0x7F, the values changes till end.
I tried removing some initial values of buffer so that position of 1st occurrence of higher hex value changes. In the o/p again the same thing happened. Kindly help me in resolving this issue.