cancel
Showing results for 
Search instead for 
Did you mean: 

How to send an image located on a USB drive to the display?

MMust.5
Senior II
The USB drive is connected to the STM32F407VGT6, this USB drive contains images, I need to send these images to the display.
 
I already know how to send to the display an array that is located on a USB drive.
I convert the image into an array, for example with the program Image2Lcd Ver3.2 
And I send this array to the display with the following code:

 

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

 

I don't understand now how to send images to the display without conversion.
I need at least an algorithm of actions. I don’t understand what needs to be done in order to send an image to the display without converting the image to an array.
 
1 ACCEPTED SOLUTION

Accepted Solutions

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

8 REPLIES 8

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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,

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?

>>The images will be an array of actual bytes, not hex encodings in ASCII
Ok, sorry, I understand.
I'll try now

I almost succeeded, but for some reason the image is of poor quality and upside down.
When I sent the converted array to the display, the image was not upside down.
The image is 128x160 in size, so in the for loop (128*160)/2
The coordinates were entered correctly, there are no problems with the coordinates.
The "uint32_t byte;" parameter is 32 bit, so I send the data 4 times via SPI.
My SPI1->DR register is 8 bit.
Here I get 4 bytes f_read(&USBHFile, &byte, 4, &k);

 

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?

Pavel A.
Evangelist III

You think a byte is 32 bits? Seriously?

 

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.

Pavel A.
Evangelist III