NHD-2.8-240320AF-CSXP-FCTP- Can't display the Color background

Comments

5 comments

  • Engineering Support
    Community moderator

    Hi, To display a  red color for background you can use the following code

    #include "tft.h"    // Assuming this file includes all necessary headers for your TFT display

    // RGB565 format for red color
    #define RED 0xF800

    // Function to fill the LCD with a single color
    void LCD_FillScreen(uint16_t color)
    {
        uint16_t x, y;

        for (y = 0; y < LCD_HEIGHT; y++)   // Loop through the height of the screen
        {
            for (x = 0; x < LCD_WIDTH; x++)   // Loop through the width of the screen
            {
                LCD_DrawPixel(x, y, color);   // Draw a pixel with the specified color
            }
        }
    }

    // Example function to initialize the LCD and fill it with red color
    void DisplayRedBackground(void)
    {
        LCD_Init();            // Initialize the LCD (if not already initialized)
        LCD_FillScreen(RED);   // Fill the screen with the red color
    }

     

    and then the main loop in tft.c

     

    int main(void)
    {
        HAL_Init();            // Initialize HAL
        SystemClock_Config();  // Configure system clock
        MX_GPIO_Init();        // Initialize GPIO
        MX_FSMC_Init();        // Initialize FSMC if using parallel communication
        MX_FMPI2C1_Init();     // Initialize I2C if needed

        // Display red background on the LCD
        DisplayRedBackground();

        while(1)
        {
            // Main loop code
        }
    }
    0
  • MEENAKSHI

    Thanks for your reply.

    This time also I got same output.

     

    void LCD_FillScreen(uint16_t color)

    {

    uint16_t x, y;

     

    for (y = 0; y < LCD_HEIGHT; y++) // Loop through the height of the screen

    {

    for (x = 0; x < LCD_WIDTH; x++) // Loop through the width of the screen

    {

    ST7789H2_WritePixel(x, y, color); // Draw a pixel with the specified color

    }

    }

    }

    1
  • Engineering Support
    Community moderator

    Hi,

    Thanks for sharing your update.  Can you confirm if you are able to write to the display?  If you are still seeing an issue, please refer to our example code for this display.  The example code contains the proper initialization sequence as well as a function for filling the screen with a color.

    0
  • MEENAKSHI

    Hi,

    Thanks for your reply. I'm using STM32CubeIDE. But this example is for Arduino.

    0
  • Engineering Support
    Community moderator

    Hi,

    Unfortunately, we do not have example code specifically for the STM32 platform at this time. However, we do offer Arduino code, which you are welcome to use as a reference for your STM32 setup. While we understand that transitioning between platforms can require some adjustments, we are confident that the Arduino code provides a solid starting point.

    That being said, we are unable to allocate engineering resources to review or debug the entirety of your STM32 code. We appreciate your understanding, and if you have any questions about the Arduino reference code or specific aspects of your setup, feel free to reach out, and we'll do our best to assist.

    0

Please sign in to leave a comment.