2021-12-13 11:11 AM
Hello Everyone!
Couple days ago, I tried to interface STM32F030R8T6 dev. board with TFT display like on the picture with ILI9486 driver.
One year ago, I interfaced the same TFT with FPGA de board and everything was fine.
With STM32 I tried to interface in 16-bit mode.
This display doesn't has the RDX pin for reading from it. Only Write Operations.
Below my code, which I've started and stuck with strange display behaviour.
Problem is with colors.
When I set Red Backcolor, the display is shows it as almost Black color.
Green Color it shows as dark Green and Blue Color it shows correct.
So all colors which are close to red, slowly become darker.
I've tried to do Display Inversion mode Command, but it turned everything to Brighter color.
The Blue Color it turned to yellow, Green and Yellow turned to Purple Color, White Color turned to Orange.
I understand, I did something wrong, but cannot find where.
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* 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 ---------------------------------------------------------*/
TIM_HandleTypeDef htim16;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM16_Init(void);
/* USER CODE BEGIN PFP */
void TFT_Send_A_2Byte_To_TFT_DataPins(uint32_t character)
{
HAL_GPIO_WritePin(TFT_D0_GPIO_Port, TFT_D0_Pin, character & 0b0000000000000001);
HAL_GPIO_WritePin(TFT_D1_GPIO_Port, TFT_D1_Pin, character & 0b0000000000000010);
HAL_GPIO_WritePin(TFT_D2_GPIO_Port, TFT_D2_Pin, character & 0b0000000000000100);
HAL_GPIO_WritePin(TFT_D3_GPIO_Port, TFT_D3_Pin, character & 0b0000000000001000);
HAL_GPIO_WritePin(TFT_D4_GPIO_Port, TFT_D4_Pin, character & 0b0000000000010000);
HAL_GPIO_WritePin(TFT_D5_GPIO_Port, TFT_D5_Pin, character & 0b0000000000100000);
HAL_GPIO_WritePin(TFT_D6_GPIO_Port, TFT_D6_Pin, character & 0b0000000001000000);
HAL_GPIO_WritePin(TFT_D7_GPIO_Port, TFT_D7_Pin, character & 0b0000000010000000);
HAL_GPIO_WritePin(TFT_D8_GPIO_Port, TFT_D8_Pin, character & 0b0000000100000000);
HAL_GPIO_WritePin(TFT_D9_GPIO_Port, TFT_D9_Pin, character & 0b0000001000000000);
HAL_GPIO_WritePin(TFT_D10_GPIO_Port, TFT_D10_Pin, character & 0b0000010000000000);
HAL_GPIO_WritePin(TFT_D11_GPIO_Port, TFT_D11_Pin, character & 0b0000100000000000);
HAL_GPIO_WritePin(TFT_D12_GPIO_Port, TFT_D12_Pin, character & 0b0001000000000000);
HAL_GPIO_WritePin(TFT_D13_GPIO_Port, TFT_D13_Pin, character & 0b0010000000000000);
HAL_GPIO_WritePin(TFT_D14_GPIO_Port, TFT_D14_Pin, character & 0b0100000000000000);
HAL_GPIO_WritePin(TFT_D15_GPIO_Port, TFT_D15_Pin, character & 0b1000000000000000);
}
void WRX(TIM_HandleTypeDef *htim,char start_stop) //1-start generation for tft operation;0-complete stop;
{ //*** min delay time is 3us *******
if(start_stop)
{ HAL_GPIO_TogglePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin);
Delay_us(&htim16, 3);
}
}
void Write_Command(uint32_t Command)
{
HAL_GPIO_WritePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin, 1);
HAL_GPIO_WritePin(TFT_RESX_GPIO_Port, TFT_RESX_Pin, 1);
HAL_GPIO_WritePin(TFT_CSX_GPIO_Port, TFT_CSX_Pin, 0);
HAL_GPIO_WritePin(TFT_DCX_GPIO_Port, TFT_DCX_Pin, 0);
HAL_GPIO_WritePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin, 0);
TFT_Send_A_2Byte_To_TFT_DataPins(Command);
HAL_GPIO_WritePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin, 1);
}
void Write_Data(uint32_t Data)
{
HAL_GPIO_WritePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin, 1);
HAL_GPIO_WritePin(TFT_RESX_GPIO_Port, TFT_RESX_Pin, 1);
HAL_GPIO_WritePin(TFT_CSX_GPIO_Port, TFT_CSX_Pin, 0);
HAL_GPIO_WritePin(TFT_DCX_GPIO_Port, TFT_DCX_Pin, 1);
HAL_GPIO_WritePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin, 0);
TFT_Send_A_2Byte_To_TFT_DataPins(Data);
HAL_GPIO_WritePin(TFT_WRX_GPIO_Port, TFT_WRX_Pin, 1);
}
void Initialization()
{ //******* Reset tft driver ***************
HAL_GPIO_WritePin(TFT_RESX_GPIO_Port, TFT_RESX_Pin, 1);
HAL_Delay(1);
HAL_GPIO_WritePin(TFT_RESX_GPIO_Port, TFT_RESX_Pin, 0);
HAL_Delay(10); // Delay 10ms // This delay time is necessary
HAL_GPIO_WritePin(TFT_RESX_GPIO_Port, TFT_RESX_Pin, 1);
HAL_Delay(120);
//************* Start Initial Sequence **********//
Write_Command(0xF2);
Write_Data(0x18);
Write_Data(0xA3);
Write_Data(0x12);
Write_Data(0x02);
Write_Data(0xB2);
Write_Data(0x12);
Write_Data(0xFF);
Write_Data(0x10);
Write_Data(0x00);
Write_Command(0xF1);
Write_Data(0x36);
Write_Data(0xA4);
Write_Command(0xF8);
Write_Data(0x21);
Write_Data(0x04);
Write_Command(0xF9);
Write_Data(0x00);
Write_Data(0x08);
Write_Command(0x36); //Memory Access Control
Write_Data(0x08);
Write_Command(0xB4); //Display Inversion Control
Write_Data(0x00);
Write_Command(0xC1); //Power Control 2
Write_Data(0x41);
//Write_Data(0x00);
Write_Command(0xC5); //VCOM Control
Write_Data(0x08); //is used to set factor to generate VCOM voltage from the reference voltage VREG2OUT.
Write_Command(0xC0); //Power Control 1
Write_Data(0x0D);
Write_Data(0x0D);
Write_Command(0xC2); //Power Control 3
Write_Data(0x00);
Write_Command(0xE0); // PGAMCTRL (Positive Gamma Control)
Write_Data(0x0F);
Write_Data(0x24);
Write_Data(0x1C);
Write_Data(0x0A);
Write_Data(0x0F);
Write_Data(0x08);
Write_Data(0x43);
Write_Data(0x88);
Write_Data(0x32);
Write_Data(0x0F);
Write_Data(0x10);
Write_Data(0x06);
Write_Data(0x0F);
Write_Data(0x07);
Write_Data(0x00);
Write_Command(0xE1); // NGAMCTRL (Negative Gamma Control)
Write_Data(0x0F);
Write_Data(0x38);
Write_Data(0x30);
Write_Data(0x09);
Write_Data(0x0F);
Write_Data(0x0F);
Write_Data(0x4E);
Write_Data(0x77);
Write_Data(0x3C);
Write_Data(0x07);
Write_Data(0x10);
Write_Data(0x05);
Write_Data(0x23);
Write_Data(0x1B);
Write_Data(0x00);
Write_Command(0xE2); // Digital Gamma Control 1
Write_Data(0x0F);
Write_Data(0x32);
Write_Data(0x2E);
Write_Data(0x0B);
Write_Data(0x0D);
Write_Data(0x05);
Write_Data(0x47);
Write_Data(0x75);
Write_Data(0x37);
Write_Data(0x06);
Write_Data(0x10);
Write_Data(0x03);
Write_Data(0x24);
Write_Data(0x20);
Write_Data(0x00);
Write_Command(0xB6); //Display Function Control
Write_Data(0x00);
Write_Data(0x22); //0x42=Rotation 180 degrees //0x22
Write_Data(0x3B);
Write_Command(0x20); // Display Inversion OFF
//Write_Data(0xC8); //C8???
Write_Command(0x3A); // Interface Pixel Format
Write_Data(0x55);
Write_Command(0x2A); // Column Address Set
Write_Data(0x00);
Write_Data(0x00);
Write_Data(0x01);
Write_Data(0x3F);
Write_Command(0x2B); // Page Address Set
Write_Data(0x00);
Write_Data(0x00);
Write_Data(0x01);
Write_Data(0xDF);
Write_Command(0x11); //Sleep out
HAL_Delay(120);
Write_Command(0x38); //Idle Mode Off
Write_Command(0x13); //Normal Mode On
Write_Command(0x29); // Display ON
}
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* 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_TIM16_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start(&htim16);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
Initialization();
Write_Command(0x2C); // Memory Write
HAL_Delay(1);
for(int i=0;i<(480);i++)
{
for(int j=0;j<320;j++)
{
if(i==360)
{
Write_Data(0xFFFF); //White Color
}
if(i==240)
{
Write_Data(0x07E0); //Green Color
}
if(i==120)
{
Write_Data(0xFFE0); //Yellow Color
}
if(j==160)
{
Write_Data(0x0001F); //Blue Color
}
else
{
Write_Data(0xF800); //Red Color
}
}
}
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Did Anyone meet such problem before?
Will apreciate your replies!!!
Thanks in advance.
Solved! Go to Solution.
2021-12-21 07:51 AM
You made at least one mistake:
void TFT_Send_A_2Byte_To_TFT_DataPins(uint32_t character)
{
HAL_GPIO_WritePin(TFT_D0_GPIO_Port, TFT_D0_Pin, character & 0b0000000000000001);
HAL_GPIO_WritePin(TFT_D1_GPIO_Port, TFT_D1_Pin, character & 0b0000000000000010);
...
}
should be more like (you forgot to move the bit to position 0 after masking):
void TFT_Send_A_2Byte_To_TFT_DataPins(uint32_t character)
{
HAL_GPIO_WritePin(TFT_D0_GPIO_Port, TFT_D0_Pin, (character & 0b0000000000000001)>>0 );
HAL_GPIO_WritePin(TFT_D1_GPIO_Port, TFT_D1_Pin, (character & 0b0000000000000010)>>1 );
...
}
Please try it out and let us know.
Regards
/Peter
2021-12-21 07:51 AM
You made at least one mistake:
void TFT_Send_A_2Byte_To_TFT_DataPins(uint32_t character)
{
HAL_GPIO_WritePin(TFT_D0_GPIO_Port, TFT_D0_Pin, character & 0b0000000000000001);
HAL_GPIO_WritePin(TFT_D1_GPIO_Port, TFT_D1_Pin, character & 0b0000000000000010);
...
}
should be more like (you forgot to move the bit to position 0 after masking):
void TFT_Send_A_2Byte_To_TFT_DataPins(uint32_t character)
{
HAL_GPIO_WritePin(TFT_D0_GPIO_Port, TFT_D0_Pin, (character & 0b0000000000000001)>>0 );
HAL_GPIO_WritePin(TFT_D1_GPIO_Port, TFT_D1_Pin, (character & 0b0000000000000010)>>1 );
...
}
Please try it out and let us know.
Regards
/Peter
2021-12-21 11:41 AM
Dear Peter!
Thanks a lot!
That's was the reason.
Simply overlooked the shifts after masking.
Now, it's operate as should be. All colors are available.
I thought, it were either mistake in missed ili9486 commands or some time issues, but the reason was simplier.
So, the problem is solved.
Once again, Thank you, Peter.
2022-05-30 11:00 PM
../Core/Src/main.c(56): error: #18: expected a ")"
HAL_GPIO_WritePin(TFT_D0_GPIO_Port, TFT_D0_Pin, (character & 0b0000000000000001) >> 0);
why this Error?
2022-05-31 05:46 AM
Your error message says that a ) is missing.
Where exactly the ) is missing, no one can say without the whole source code.