NHD-2.8-240320AF-CSXP-FCTP- Can't display the Color background
I'm using NHD-2.8-240320AF-CSXP-FCTP Display. When I sent a data(display the red background) to display. I display like this -
This is my code and I'm using ST7789h2 driver.
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "st7789h2.h"
#include "stdio.h"
#include "ft6x06.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
CRC_HandleTypeDef hcrc;
FMPI2C_HandleTypeDef hfmpi2c1;
SRAM_HandleTypeDef hsram1;
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_FSMC_Init(void);
static void MX_CRC_Init(void);
static void MX_FMPI2C1_Init(void);
void StartDefaultTask(void *argument);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint16_t RAW_X,RAW_Y;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_FSMC_Init();
MX_CRC_Init();
MX_FMPI2C1_Init();
/* USER CODE BEGIN 2 */
ST7789H2_Init();
LCD_Fill(0xF800, 0, 0, 240, 240);
ft6x06_Init(0x70); // 0x38>>1 = 0x70
ft6x06_TS_Start(0x70);
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize();
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
/* USER CODE END RTOS_EVENTS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if (ft6x06_TS_DetectTouch(0x70))
{
ft6x06_TS_GetXY(0x70, &RAW_X, &RAW_Y);
}
HAL_Delay(100);
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief CRC Initialization Function
* @param None
* @retval None
*/
static void MX_CRC_Init(void)
{
/* USER CODE BEGIN CRC_Init 0 */
/* USER CODE END CRC_Init 0 */
/* USER CODE BEGIN CRC_Init 1 */
/* USER CODE END CRC_Init 1 */
hcrc.Instance = CRC;
if (HAL_CRC_Init(&hcrc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CRC_Init 2 */
/* USER CODE END CRC_Init 2 */
}
/**
* @brief FMPI2C1 Initialization Function
* @param None
* @retval None
*/
static void MX_FMPI2C1_Init(void)
{
/* USER CODE BEGIN FMPI2C1_Init 0 */
/* USER CODE END FMPI2C1_Init 0 */
/* USER CODE BEGIN FMPI2C1_Init 1 */
/* USER CODE END FMPI2C1_Init 1 */
hfmpi2c1.Instance = FMPI2C1;
hfmpi2c1.Init.Timing = 0x00303D5B;
hfmpi2c1.Init.OwnAddress1 = 0;
hfmpi2c1.Init.AddressingMode = FMPI2C_ADDRESSINGMODE_7BIT;
hfmpi2c1.Init.DualAddressMode = FMPI2C_DUALADDRESS_DISABLE;
hfmpi2c1.Init.OwnAddress2 = 0;
hfmpi2c1.Init.OwnAddress2Masks = FMPI2C_OA2_NOMASK;
hfmpi2c1.Init.GeneralCallMode = FMPI2C_GENERALCALL_DISABLE;
hfmpi2c1.Init.NoStretchMode = FMPI2C_NOSTRETCH_DISABLE;
if (HAL_FMPI2C_Init(&hfmpi2c1) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_FMPI2CEx_ConfigAnalogFilter(&hfmpi2c1, FMPI2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FMPI2C1_Init 2 */
/* USER CODE END FMPI2C1_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(BL_CONTROL_GPIO_Port, BL_CONTROL_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, LCD_ENABLE_Pin|TOUCH_RESET_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(MC_LCD_RESET_GPIO_Port, MC_LCD_RESET_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : BL_CONTROL_Pin */
GPIO_InitStruct.Pin = BL_CONTROL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BL_CONTROL_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : TOUCH_INT_Pin */
GPIO_InitStruct.Pin = TOUCH_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(TOUCH_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : LCD_ENABLE_Pin TOUCH_RESET_Pin */
GPIO_InitStruct.Pin = LCD_ENABLE_Pin|TOUCH_RESET_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : MC_LCD_RESET_Pin */
GPIO_InitStruct.Pin = MC_LCD_RESET_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(MC_LCD_RESET_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* FSMC initialization function */
static void MX_FSMC_Init(void)
{
/* USER CODE BEGIN FSMC_Init 0 */
/* USER CODE END FSMC_Init 0 */
FSMC_NORSRAM_TimingTypeDef Timing = {0};
/* USER CODE BEGIN FSMC_Init 1 */
/* USER CODE END FSMC_Init 1 */
/** Perform the SRAM1 memory initialization sequence
*/
hsram1.Instance = FSMC_NORSRAM_DEVICE;
hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
/* hsram1.Init */
hsram1.Init.NSBank = FSMC_NORSRAM_BANK1;
hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
hsram1.Init.ContinuousClock = FSMC_CONTINUOUS_CLOCK_SYNC_ONLY;
hsram1.Init.WriteFifo = FSMC_WRITE_FIFO_ENABLE;
hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE;
/* Timing */
Timing.AddressSetupTime = 3;
Timing.AddressHoldTime = 15;
Timing.DataSetupTime = 4;
Timing.BusTurnAroundDuration = 2;
Timing.CLKDivision = 16;
Timing.DataLatency = 17;
Timing.AccessMode = FSMC_ACCESS_MODE_A;
/* ExtTiming */
if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
{
Error_Handler( );
}
/* USER CODE BEGIN FSMC_Init 2 */
/* FSMC GPIO Configuration */
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Enable GPIO Clocks */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
/* Configure GPIOD pins for FSMC (PD4: RD, PD5: WR, PD7: CS, PD14: D0, PD15: D1, PD0: D2, PD1: D3) */
GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_0 | GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC; // Set to FSMC alternate function
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* Configure GPIOE pins for FSMC (PE7: D4, PE8: D5, PE9: D6, PE10: D7) */
GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* Configure GPIOG pins for FSMC (PG1: D/C, PG5: DIR1, PG7: DIR2) */
GPIO_InitStruct.Pin = GPIO_PIN_1 | GPIO_PIN_5 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
/* USER CODE END FSMC_Init 2 */
}
/* USER CODE BEGIN 4 */
void LCD_Fill(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t width, uint16_t height)
{
for (uint16_t i=0; i<height; i++)
{
ST7789H2_DrawHLine(RGBCode, Xpos, Ypos++, width);
}
}
/* USER CODE END 4 */
/* USER CODE BEGIN Header_StartDefaultTask */
/**
* @brief Function implementing the defaultTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END 5 */
}
/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM3 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM3) {
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
/* USER CODE END Callback 1 */
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/*
* LCD_Controller.c
*
* Created on: Sep 5, 2024
* Author: admin
*/
#include "main.h"
#include "LCD_Controller.h"
#define FMC_BANK1_REG ((uint16_t *) 0x60000000) // Register Address for A0
#define FMC_BANK1_DATA ((uint16_t *) 0x60000002) // Data Address for A0 -> A0<<1 -> 0010
void LCD_IO_WriteReg(uint8_t Reg)
{
*FMC_BANK1_REG = Reg;
}
void LCD_IO_WriteData(uint16_t RegValue)
{
*FMC_BANK1_DATA = RegValue;
}
void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size)
{
for (uint32_t i=0; i<Size; i++)
{
LCD_IO_WriteData(pData[i]);
}
}
uint16_t LCD_IO_ReadData(void)
{
return *FMC_BANK1_DATA;
}
void LCD_IO_Delay(uint32_t delay)
{
HAL_Delay(delay);
}
void LCD_IO_Init(void)
{
HAL_GPIO_WritePin(MC_LCD_RESET_GPIO_Port, MC_LCD_RESET_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LCD_ENABLE_GPIO_Port, LCD_ENABLE_Pin, GPIO_PIN_RESET);
LCD_IO_Delay(5);
// HAL_GPIO_WritePin(BL_CONTROL_GPIO_Port, BL_CONTROL_Pin, GPIO_PIN_RESET);
// LCD_IO_Delay(5);
HAL_GPIO_WritePin(MC_LCD_RESET_GPIO_Port, MC_LCD_RESET_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LCD_ENABLE_GPIO_Port, LCD_ENABLE_Pin, GPIO_PIN_SET);
// HAL_GPIO_WritePin(BL_CONTROL_GPIO_Port, BL_CONTROL_Pin, GPIO_PIN_SET);
}
-
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 -
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 -
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 -
Hi,
Thanks for your reply. I'm using STM32CubeIDE. But this example is for Arduino.
0 -
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.
Comments
5 comments