Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

STM32 and LCDTFT and Micro SD card Adaptor

Alireza770717

Junior Member level 3
Junior Member level 3
Joined
Nov 21, 2023
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
154
Hello friends, I successfully installed the LCD library with STM32F103C8T6 microcontroller along with a separate SD card. Now I have a problem with displaying the image. Do you think I chose the wrong type of microcontroller?


Main.c file attached
 

Attachments

  • main.zip
    2.8 KB · Views: 105
Hello!
I successfully installed the LCD library with STM32F103C8T6

- We don't know where this library comes from
- We don't have access to the wiring
- We don't have access to your LCD documentation.
- We don't know what "a problem with displaying the image" means.
-> Does it display anything? Is it completely black? Can you initialize it? Can you get a uniform background but nothing else?
Are you trying to display characters and they don't display well?

Etc, etc...

Dora.
 
Hello!


- We don't know where this library comes from
- We don't have access to the wiring
- We don't have access to your LCD documentation.
- We don't know what "a problem with displaying the image" means.
-> Does it display anything? Is it completely black? Can you initialize it? Can you get a uniform background but nothing else?
Are you trying to display characters and they don't display well?

Etc, etc...

Dora.
https://github.com/martnak/STM32-ILI9341/blob/master/Src/ILI9341/ILI9341_Touchscreen.c
library LCD


https://01001000.xyz/2020-08-09-Tutorial-STM32CubeIDE-SD-card/

library SD Card



photo9413913952.jpg


From the SD card, I can display text on the LCD, but the image is displayed in a partially colored way.
with communication SPI

Please help me thanks
 
Hello!

I checked your lcd library.
You are aware that it's a library for the touch panel only, right?
I mean, you cannot write a character with this library, not even a white background, nothing.
You can just read the position of where you press on the screen.

Beside this, you were saying you have "installed" the library. What I see is plain C code,
there is nothing to install. What did you do exactly?

rom the SD card, I can display text on the LCD,

Where do you see text on the image you posted? Did you write the "YL / 16"?

but the image is displayed in a partially colored way.

Where do you see an image. What do you mean by "partially colored way"?

Beside this, before messing with the SD card, you should solve the LCD first. Then when
it works, add the SD card. Or the other way around. I would start with the LCD as it
allows you to write error messages.

Dora.
 
Hello!

I checked your lcd library.
You are aware that it's a library for the touch panel only, right?
I mean, you cannot write a character with this library, not even a white background, nothing.
You can just read the position of where you press on the screen.

Beside this, you were saying you have "installed" the library. What I see is plain C code,
there is nothing to install. What did you do exactly?


Where do you see text on the image you posted? Did you write the "YL / 16"?


Where do you see an image. What do you mean by "partially colored way"?

Beside this, before messing with the SD card, you should solve the LCD first. Then when
it works, add the SD card. Or the other way around. I would start with the LCD as it
allows you to write error messages.
Hello, have good time
Yes, you are right. This library is related to the touch LCD, but I made some changes and was able to display text. The photo I posted earlier is related to the problem of displaying the image. However, I was able to display a photo above the screen, but there are still some problems.
 

Attachments

  • photo9443937490.jpg
    photo9443937490.jpg
    168.2 KB · Views: 118
Hello!

Yes, you are right. This library is related to the touch LCD, but I made some changes and was able to display text.

So what you are saying is that the code you posted does not correspond to the problem you have?
Beside this, what you are saying is a bit scary: you modified the LCD touch screen program to display something?
(I hope not).
You should NEVER do that. The touch.c (whatever the name) should NOT display anything. If you do that, nobody
is ever going to hire you.

Let's do thing in the right sequence:
- Can you display a white screen, or a screen of a uniform color?
- Can you write a dot of another color on that screen?

As long as you cannot say yes to both of these questions, don't write anything else, don't mess with images,
don't mess with the SD card. And don't write these functions in touch.c, but in display.c.

Dora.
 
Hello!



So what you are saying is that the code you posted does not correspond to the problem you have?
Beside this, what you are saying is a bit scary: you modified the LCD touch screen program to display something?
(I hope not).
You should NEVER do that. The touch.c (whatever the name) should NOT display anything. If you do that, nobody
is ever going to hire you.

Let's do thing in the right sequence:
- Can you display a white screen, or a screen of a uniform color?
- Can you write a dot of another color on that screen?

As long as you cannot say yes to both of these questions, don't write anything else, don't mess with images,
don't mess with the SD card. And don't write these functions in touch.c, but in display.c.

Dora.
Hi,

After a few days, I was able to display images on the TFT LCD display in such a way that it reads and displays the image in BMP format from the SD card. My problem was with coding and how to put the image in RAM, which I was mistakenly putting the hex code in RAM. My next problem is with the refresh rate of the page, which is low. What solutions do you suggest?



main.c



thank you
--- Updated ---

C:
FATFS fs;  // file system
FIL file; // File
FILINFO fno;
FRESULT fresult;  // result
UINT br, bw;  // File read/write count

/**** capacity related *****/
FATFS *pfs;
DWORD fre_clust;
uint32_t total, free_space;

int displayImage(const char* fname) {
//    UART_Printf("Openning %s...\r\n", fname);
    FIL file;
    FRESULT res = f_open(&file, fname, FA_READ);
    if(res != FR_OK) {
        LCD_ShowString(0,10,"f_open() failed, res = %d\r\n",RED,WHITE,16,0);
        return -1;
    }

    LCD_ShowString(0,30,"File opened, reading...\r\n",RED,WHITE,16,0);

    unsigned int bytesRead;
    uint8_t header[34];
    res = f_read(&file, header, sizeof(header), &bytesRead);
    if(res != FR_OK) {
         LCD_ShowString(0,50,"f_read() failed, res = %d\r\n",RED,WHITE,16,0);
        f_close(&file);
        return -2;
    }

    if((header[0] != 0x42) || (header[1] != 0x4D)) {
         LCD_ShowString(0,90,"Wrong BMP signature: 0x%02X 0x%02X\r\n",RED,WHITE,16,0);
        f_close(&file);
        return -3;
    }

    uint32_t imageOffset = header[10] | (header[11] << 8) | (header[12] << 16) | (header[13] << 24);
    uint32_t imageWidth = header[18] | (header[19] << 8) | (header[20] << 16) | (header[21] << 24);
    uint32_t imageHeight = header[22] | (header[23] << 8) | (header[24] << 16) | (header[25] << 24);
    uint16_t imagePlanes = header[26] | (header[27] << 8);
    uint16_t imageBitsPerPixel = header[28] | (header[29] << 8);
    uint32_t imageCompression = header[30] | (header[31] << 8) | (header[32] << 16) | (header[33] << 24);


    snprintf(buff, sizeof(buff), "Pixels offset: %lu\r\n ", imageOffset);
    LCD_ShowString(0,110,buff,RED,WHITE,16,0);
    snprintf(buff, sizeof(buff), "WxH: %lux%lu\r\n ", imageWidth, imageHeight);
    LCD_ShowString(0,130,buff,RED,WHITE,16,0);
    snprintf(buff, sizeof(buff), "Planes: %d\r\n ", imagePlanes);
    LCD_ShowString(0,150,buff,RED,WHITE,16,0);
    snprintf(buff, sizeof(buff), "Bits per pixel: %d\r\n ", imageBitsPerPixel);
    LCD_ShowString(0,170,buff,RED,WHITE,16,0);
    snprintf(buff, sizeof(buff), "Compression: %ld\r\n ", imageCompression);
    LCD_ShowString(0,190,buff,RED,WHITE,16,0);

    if((imageWidth != LCD_H) || (imageHeight != LCD_W)) {
//        UART_Printf("Wrong BMP size, %dx%d expected\r\n", ST7735_WIDTH, ST7735_HEIGHT);
        LCD_ShowString(0,210,"Wrong BMP size, %dx%d expected\r\n",RED,WHITE,16,0);
        f_close(&file);
        return -4;
    }

    if((imagePlanes != 1) || (imageBitsPerPixel != 24) || (imageCompression != 0)) {
        LCD_ShowString(0,230,"Unsupported image format\r\n",RED,WHITE,16,0);
        f_close(&file);
        return -5;
    }

    res = f_lseek(&file, imageOffset);
    if(res != FR_OK) {

        snprintf(buff, sizeof(buff), "f_lseek() failed, res = %d\r\n ", res);
        LCD_ShowString(0,250,buff,RED,WHITE,16,0);
        f_close(&file);
        return -6;
    }

    // row size is aligned to 4 bytes
    uint8_t imageRow[(LCD_H * 3 + 3) & ~3];
    for(uint32_t y = 0; y < imageHeight; y++) {
        uint32_t rowIdx = 0;
        res = f_read(&file, imageRow, sizeof(imageRow), &bytesRead);
        if(res != FR_OK) {
            snprintf(buff, sizeof(buff), "f_read() failed, res = %d\r\n", res);
            LCD_ShowString(0,270,buff,RED,WHITE,16,0);
            f_close(&file);
            return -7;
        }

        for(uint32_t x = 0; x < imageWidth; x++) {
            uint8_t b = imageRow[rowIdx++];
            uint8_t g = imageRow[rowIdx++];
            uint8_t r = imageRow[rowIdx++];
            uint16_t color565 = COLOR565(r, g, b);
            LCD_DrawPoint(x,imageHeight - y - 1,color565);
        }
    }

    res = f_close(&file);
    if(res != FR_OK) {
//        UART_Printf("f_close() failed, res = %d\r\n", res);
        snprintf(buff, sizeof(buff), "f_close() failed, res = %d\r\n", res);
        LCD_ShowString(0,290,buff,RED,WHITE,16,0);
        return -8;
    }

    return 0;
}












LCD_Init();


   LCD_Fill(0,0,240,320,WHITE);


    FRESULT res = f_mount(&fs, "", 0);
    if(res != FR_OK) {
    //      UART_Printf("f_mount() failed, res = %d\r\n", res);
        snprintf(buff, sizeof(buff), "f_mount() failed, res = %d\r\n", res);
        LCD_ShowString(0,310,buff,RED,WHITE,16,0);
        return -2;
    }
    LCD_ShowString(0,330,"f_mount() done!\r\n",RED,WHITE,16,0);






 while (1)
  {
          displayImage("1.bmp");
          displayImage("2.bmp");
          displayImage("3.bmp");
          displayImage("4.bmp");
          displayImage("11.bmp");
          displayImage("22.bmp");
 }
 
Last edited:
Hello!

Frame rate is low doesn't mean much. Let's put numbers: what rate do you need?
What rate do you have?

Dora.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top