[SOLVED] SMT32F103C + ILI9486 TFT not working!

Working libraries, libraries being ported and related hardware
flyboy74
Posts: 231
Joined: Wed Jun 13, 2018 11:02 am

Re: SMT32F103C + ILI9486 TFT not working!

Post by flyboy74 » Tue Oct 30, 2018 8:07 am

ericosowski wrote:
Tue Oct 30, 2018 3:04 am
flyboy74 wrote:
Mon Oct 29, 2018 3:47 am
If you want to sit down and create your own bit-bang code to drive your screen it isn't hard.

The screen will use a 8088 protocol. It works like this, u pull the CS pin low to talk to the screen(same as SPI) then you set the data pins to the data you want to sedn then you pulse the WR pin to get the screen to input the data you have set on the data lines. There is RS (sometimes called DC) pin that chooses whether the data is a command or data to be written to RAM.

To set the data 8 pins at once that are all on the same port and next to each other can be done by just writing the value to the ODR register for that port.

Here is the thread where I was working on a software bit bang viewtopic.php?f=3&t=3967&p=48025&hilit= ... 325#p48025
Thank you flyboy, I intend to go deeper into this subject, I have a 16bit parallel lcl tft 3.5" that I want to make it work, but not now! so your knowledge will be helpfull, but for now I'm needing a quickly solution for this 8bits parallel tft screen.
If you think I can learn something with your code Ill be glad with you share it!

Thank you for your reply and kindness to help!
Ok for your interest I have put the main functions up on github of the project that I posted running on a STM32F407VET board, it uses the FMSC HW peripheral to write to the LCD so not a bit bang as you will need on the bluepill see https://github.com/OutOfTheBots/ili9341_16bit_touch

here is some code from when I used bit bang on a hx8357b screen in 16bit parallel. Something similar to this is what you will need to write for the blue pill. All this code does is setup the screen and continuously write redish coloured pixels to the screen and see the discussion here viewtopic.php?f=3&t=3841&p=47071&hilit=hx8357#p47071

Code: Select all

#include "stm32f4xx.h"
#define RS GPIO_ODR_ODR_0
#define WR GPIO_ODR_ODR_1
#define CS GPIO_ODR_ODR_2
#define RST GPIO_ODR_ODR_3
//used for count down in Delay
__IO uint32_t TimmingDelay;
void SysTick_Handler(void)
{
  if(TimmingDelay !=0)
  {
    TimmingDelay --;
  }
}
void Delay(__IO uint32_t time)
{
  TimmingDelay = time;
  while(TimmingDelay !=0);
}
void Pin_setup(void){
	//enable port D and E
	RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOEEN;
	//Port E is used for parallel data pins
	//set a port E pins to output.
	GPIOE->MODER = 0x55555555;
	//set all port E pins to push pull
	GPIOE->OTYPER = 0;
	//set all port E pins to 100MHz speed
	GPIOE->OSPEEDR =0xFFFFFFFF;
	//Port D is used for RS, WR, CS, RST
	//set needed pins as ouput
	GPIOD->MODER |= GPIO_MODER_MODER0_0 | GPIO_MODER_MODER1_0 | GPIO_MODER_MODER2_0 | GPIO_MODER_MODER3_0;
	//set needed pin to push pull
	GPIOD->OTYPER = 0;
	//set needed pins to 100MHZ;
	GPIOD->OSPEEDR |= 0x000000FF;
	GPIOD->ODR |= RS | WR | CS | RST;
}
void TFT_write_cmd(uint16_t command){
	GPIOD->ODR &= ~RS;
	GPIOD->ODR &= ~CS;
	GPIOD->ODR &= ~WR;
	GPIOE->ODR = command;
	GPIOD->ODR |= WR;
	GPIOD->ODR |= CS;
	GPIOD->ODR |= RS;
}
void TFT_write_data(uint16_t data){
	GPIOD->ODR &= ~CS;
	GPIOD->ODR &= ~WR;
	GPIOE->ODR = data;
	GPIOD->ODR |= WR;
	GPIOD->ODR |= CS;
}
void LCD_setup (void){
	//hardware reset
	GPIOD->ODR &= ~RST;
	Delay(120);
	GPIOD->ODR |= RST;
	Delay(120);
	//software reset
	TFT_write_cmd(0x01);
	Delay(120);
	//sleep out
	TFT_write_cmd(0x11);
	Delay(120);
	//Normal Display Mode On)
	TFT_write_cmd(0x13);
	//Display On
	TFT_write_cmd(0x29);
	//CASET (Column Address Set)
	TFT_write_cmd(0x2A);
	TFT_write_data (0000);
	TFT_write_data (320);
	//PASET (Page Address Set)
	TFT_write_cmd(0x2B);
	TFT_write_data (0000);
	TFT_write_data (480);
	//Exit_idle_mode
	TFT_write_cmd(0x38);
	//Set_pixel_format RGR565 16 bit
	TFT_write_cmd(0x3A);
	TFT_write_data(0b01010101);
	//RAMWR (Memory Write)
	TFT_write_cmd(0x2C);
}
void main(void){
	SysTick_Config(SystemCoreClock/1000);
	Pin_setup();
	LCD_setup();
  // Infinite loop
  while (1)
    {
      //write some redish data to the screen
	  TFT_write_data(0xff00);
    }
}

ericosowski
Posts: 7
Joined: Fri Oct 26, 2018 12:39 pm

Re: SMT32F103C + ILI9486 TFT not working!

Post by ericosowski » Tue Oct 30, 2018 4:27 pm

Hi David,
I assume that the right library is from the link below:
https://github.com/prenticedavid/MCUFRIEND_kbv
I changed the PIN LCD_RD for PB5 port, but I tried with PB0 too and nothing happened.
This ID 0xD3 was returned during one of my many tries to turn it on! And I saw that this ID make reference to ILI9486 in libray's code, but even than it just shows white screen, so I presume that in one moment I wired it right, I'll try again!
I'll reinstall the library via Library Manager and see what happens.
The data pins is default pins PA0~PA7?
Does the pins below must be declared in the sketch header?

Code: Select all

#define LCD_RST PB9
#define LCD_CS PB8
#define LCD_RS PB7
#define LCD_WR PB6
#define LCD_RD PB0

david.prentice
Posts: 163
Joined: Wed Nov 16, 2016 8:52 am

Re: SMT32F103C + ILI9486 TFT not working!

Post by david.prentice » Tue Oct 30, 2018 6:10 pm

The readreg sketch does not use any libraries at all. Only the built-in digitalWrite() and pinMode().

Your Original Post showed readreg working for PB5. Change the wiring to PB0 and the define to PB0. The readreg sketch should give you the same output as in the OP.

It is wise to use the Library Manager to install libraries whenever possible.

Punters often try to put libraries into System folders or random locations. I suggest that you should remove wrongly installed libraries if there is an "official" third party library that is supported by the Manager e.g. Adafruit_GFX, MCUFRIEND_kbv, ...
Then restart the IDE. Install with the Library Manager.

If you ever have a problem, copy-paste the last few lines from the verbose compilation e.g. memory and library use.

David.

ericosowski
Posts: 7
Joined: Fri Oct 26, 2018 12:39 pm

Re: SMT32F103C + ILI9486 TFT not working!

Post by ericosowski » Wed Oct 31, 2018 11:22 am

Hi David,
Good news, I did all the things you said and the TFT started to work, like magic! :D
You are the best!
Thank you very much!

david.prentice
Posts: 163
Joined: Wed Nov 16, 2016 8:52 am

Re: [SOLVED] SMT32F103C + ILI9486 TFT not working!

Post by david.prentice » Wed Oct 31, 2018 1:29 pm

Well done.

The secret is generally to leave the PC and sit down with a nice cup of tea.

Then do one step at a time. Make notes with pencil and paper as you go.

David.

Post Reply