2023-11-15 10:47 AM - edited 2023-11-15 10:53 AM
char line[100];
uint32_t Num;
while(f_gets(line, 2, &USBHFile))
{
if(line[0] == 'x' || line[0] == 'X')
{
char hex[10]={"0x"};
f_gets(line, 3, &USBHFile);
strcat(hex,line);
Num=strtol(hex, NULL, 16);
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = Num;
while(!(SPI1->SR & SPI_SR_TXE));
}
}
Solved! Go to Solution.
2023-11-15 11:08 AM
The images will be an array of actual bytes, not hex encodings in ASCII, and might be in a graphics file format like JPEG or BMP.
A BMP file can describe several different bit/colour depths, and usually in a raster line format.
You'd read data with f_read(), or on a PC with fread(). Suggest you get a File View or File Manager were you can inspect and understand the byte level content as in the file, and as read directly into memory.
2023-11-15 11:08 AM
The images will be an array of actual bytes, not hex encodings in ASCII, and might be in a graphics file format like JPEG or BMP.
A BMP file can describe several different bit/colour depths, and usually in a raster line format.
You'd read data with f_read(), or on a PC with fread(). Suggest you get a File View or File Manager were you can inspect and understand the byte level content as in the file, and as read directly into memory.
2023-11-15 11:16 AM
If I now convert the image to an array then get this type of data in a text file:
0XC6,0X10,0XC6,0X10,0X86,0X10,0XC6,0X10,0XC6,0X10,0XC6,0X10,0XC7,0X10,0XC7,0X10, 0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,
I read a text file with the function
f_gets(line, 2, &USBHFile)
I can also read the image using the f_gets function and get the same data type?
0XC6,0X10,0XC6,0X10,0X86,0X10,0XC6,0X10,0XC6,0X10,0XC6,0X10,0XC7,0X10,0XC7,0X10, 0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,0XC7,0X10,
2023-11-15 11:23 AM - edited 2023-11-15 11:24 AM
I tried, it doesn't work. Maybe I'm opening the image incorrectly?
I opened the text file like this:
f_open(&USBHFile, "image.txt", FA_READ);
I tried to open the image like this:
f_open(&USBHFile, "5_16.bmp", FA_READ);
Maybe this is wrong?
2023-11-15 11:28 AM
>>The images will be an array of actual bytes, not hex encodings in ASCII
Ok, sorry, I understand.
I'll try now
2023-11-15 12:31 PM - edited 2023-11-15 12:38 PM
TFT_SetCursorPosition(0,0,127,159);
f_open(&USBHFile, "5_16.bmp", FA_READ);
uint32_t byte;
unsigned int k;
for(int i=0; i<(128*160)/2;i++)
{
f_read(&USBHFile, &byte, 4, &k);
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = byte>>24;
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = byte>>16;
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = byte>>8;
while(!(SPI1->SR & SPI_SR_TXE));
SPI1->DR = byte&0xFF;
while(!(SPI1->SR & SPI_SR_TXE));
}
Am I doing something wrong?
2023-11-15 02:13 PM
You think a byte is 32 bits? Seriously?
2023-11-15 02:18 PM - edited 2023-11-15 02:30 PM
uint32_t byte;
32 bits== 4 bytes
No, of course not, I didn't think so.
The variable name is probably just wrong.
If I thought so, I wouldn't shift the bits in the "byte" variable
SPI1->DR = byte>>24;
I only needed one byte from the "byte" variable, so I called it that.
My SPI1->DR register is 8 bit.
2023-11-15 02:55 PM