STM32F103C8 & TFT (ili9325)

Working libraries, libraries being ported and related hardware
golpesar132
Posts: 23
Joined: Mon Jul 10, 2017 1:42 pm

Re: STM32F103C8 & TFT (ili9325)

Post by golpesar132 » Mon Jul 17, 2017 8:54 am

my connection was wrong. this is my response:

Code: Select all

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 00 00	ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 00 00 00	Manufacturer ID
reg(0x0009) 00 00 00 00 00	Status Register
reg(0x000A) 07 70	Get Power Mode
reg(0x000C) 00 00	Get Pixel Format
reg(0x0061) 00 00	RDID1 HX8347-G
reg(0x0062) 00 00	RDID2 HX8347-G
reg(0x0063) 00 00	RDID3 HX8347-G
reg(0x0064) 00 00	RDID1 HX8347-A
reg(0x0065) 00 00	RDID2 HX8347-A
reg(0x0066) 00 00	RDID3 HX8347-A
reg(0x0067) 00 00	RDID Himax HX8347-A
reg(0x0070) 00 00	Panel Himax HX8347-A
reg(0x00A1) 00 00 00 00 00	RD_DDB SSD1963
reg(0x00B0) 00 00	RGB Interface Signal Control
reg(0x00B4) 00 00	Inversion Control
reg(0x00B6) 00 00 00 00 00	Display Control
reg(0x00B7) 00 00	Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00	ILI9481, HX8357-B
reg(0x00C0) 00 00 00 00 00 00 00 00 00	Panel Control
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00	GAMMA
reg(0x00CC) 00 00	Panel Control
reg(0x00D0) 00 00 00	Power Control
reg(0x00D2) 00 00 00 00 00	NVM Read
reg(0x00D3) 00 00 00 00	ILI9341, ILI9488
reg(0x00D4) 00 00 00 00	Novatek ID
reg(0x00DA) 00 00	RDID1
reg(0x00DB) 00 00	RDID2
reg(0x00DC) 00 00	RDID3
reg(0x00E0) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00	GAMMA-P
reg(0x00E1) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00	GAMMA-N
reg(0x00EF) 00 00 00 00 00 00	ILI9327
reg(0x00F2) 00 00 00 00 00 00 00 00 00 00 00 00	Adjust Control 2
reg(0x00F6) 00 00 00 00	Interface Control


this is my code:

Code: Select all

// adapted from LCD_ID_Reader from http://misc.ws/lcd_information
// controllers either read as 16-bit or as a sequence of 8-bit values

//-- Arduino UNO or Mega 2560 Plugged as shield
//-- MAPLEMINI Plugged as shield
#define LCD_WR PA1 //10
#define LCD_RD PA0 //11
#define LCD_RST PB10 //27
#define LCD_CS PA3 //8
#define LCD_RS PA2  //9


#define LCD_D0 PB0
#define LCD_D1 PB1
#define LCD_D2 PB2
#define LCD_D3 PB3
#define LCD_D4 PB4
#define LCD_D5 PB5
#define LCD_D6 PB6
#define LCD_D7 PB7

void setup()
{
    Serial.begin(9600);
    while (!Serial) ;
    Serial.println("Read Registers on MCUFRIEND UNO shield");
    Serial.println("controllers either read as single 16-bit");
    Serial.println("e.g. the ID is at readReg(0)");
    Serial.println("or as a sequence of 8-bit values");
    Serial.println("in special locations (first is dummy)");
    Serial.println("");
    lcdInit();
    lcdReset();      //ensures that controller is in default state
//    for (uint16_t i = 0; i < 256; i++) readReg(i, 7, "f.k"); 
    readReg(0x00, 2, "ID: ILI9320, ILI9325, ILI9335, ...");
    readReg(0x04, 4, "Manufacturer ID");
    readReg(0x09, 5, "Status Register");
    readReg(0x0A, 2, "Get Power Mode");
    readReg(0x0C, 2, "Get Pixel Format");
    readReg(0x61, 2, "RDID1 HX8347-G");
    readReg(0x62, 2, "RDID2 HX8347-G");
    readReg(0x63, 2, "RDID3 HX8347-G");
    readReg(0x64, 2, "RDID1 HX8347-A");
    readReg(0x65, 2, "RDID2 HX8347-A");
    readReg(0x66, 2, "RDID3 HX8347-A");
    readReg(0x67, 2, "RDID Himax HX8347-A");
    readReg(0x70, 2, "Panel Himax HX8347-A");
    readReg(0xA1, 5, "RD_DDB SSD1963");
    readReg(0xB0, 2, "RGB Interface Signal Control");
    readReg(0xB4, 2, "Inversion Control");
    readReg(0xB6, 5, "Display Control");
    readReg(0xB7, 2, "Entry Mode Set");
    readReg(0xBF, 6, "ILI9481, HX8357-B");
    readReg(0xC0, 9, "Panel Control");
    readReg(0xC8, 13, "GAMMA");
    readReg(0xCC, 2, "Panel Control");
    readReg(0xD0, 3, "Power Control");
    readReg(0xD2, 5, "NVM Read");
    readReg(0xD3, 4, "ILI9341, ILI9488");
    readReg(0xD4, 4, "Novatek ID");
    readReg(0xDA, 2, "RDID1");
    readReg(0xDB, 2, "RDID2");
    readReg(0xDC, 2, "RDID3");
    readReg(0xE0, 16, "GAMMA-P");
    readReg(0xE1, 16, "GAMMA-N");
    readReg(0xEF, 6, "ILI9327");
    readReg(0xF2, 12, "Adjust Control 2");
    readReg(0xF6, 4, "Interface Control");
}

void loop() 
{
    // put your main code here, to run repeatedly:

}

void printhex(uint8_t val)
{
    if (val < 0x10) Serial.print("0");
    Serial.print(val, HEX);
}

void readReg(uint16_t reg, uint8_t n, const char *msg)
{
    uint8_t val8;
    lcdReset();
    lcdSetWriteDir();
    lcdWriteCommand(0xB0);     //Command Access Protect
    lcdWriteData(0x00);        //looks wrong
/*
    lcdWriteCommand(0xF6);
    lcdWriteData(0x01);
    lcdWriteData(0x01);
    lcdWriteData(0x03);
*/
    lcdWriteCommand(reg);
    Serial.print("reg(0x");
    printhex(reg >> 8);
    printhex(reg);
    Serial.print(")");
    lcdSetReadDir();
    while (n--) {
        val8 = lcdReadData8();
        Serial.print(" ");
        printhex(val8);
    }
    lcdSetWriteDir();
    Serial.print("\t");
    Serial.println(msg);
}

void lcdInit()
{
    pinMode(LCD_CS, OUTPUT);
    digitalWrite(LCD_CS, HIGH);
    pinMode(LCD_RS, OUTPUT);
    digitalWrite(LCD_RS, HIGH);
    pinMode(LCD_WR, OUTPUT);
    digitalWrite(LCD_WR, HIGH);
    pinMode(LCD_RD, OUTPUT);
    digitalWrite(LCD_RD, HIGH);
    pinMode(LCD_RST, OUTPUT);
    digitalWrite(LCD_RST, HIGH);
}

void lcdReset()
{
    digitalWrite(LCD_RST, LOW);
    delay(2);
    digitalWrite(LCD_RST, HIGH);
    delay(10);             //allow controller to re-start
}

void lcdWrite8(uint16_t data)
{
    digitalWrite(LCD_D0, data & 1);
    digitalWrite(LCD_D1, (data & 2) >> 1);
    digitalWrite(LCD_D2, (data & 4) >> 2);
    digitalWrite(LCD_D3, (data & 8) >> 3);
    digitalWrite(LCD_D4, (data & 16) >> 4);
    digitalWrite(LCD_D5, (data & 32) >> 5);
    digitalWrite(LCD_D6, (data & 64) >> 6);
    digitalWrite(LCD_D7, (data & 128) >> 7);
}

uint16_t lcdRead8()
{
    uint16_t result = digitalRead(LCD_D7);
    result <<= 1;
    result |= digitalRead(LCD_D6);
    result <<= 1;
    result |= digitalRead(LCD_D5);
    result <<= 1;
    result |= digitalRead(LCD_D4);
    result <<= 1;
    result |= digitalRead(LCD_D3);
    result <<= 1;
    result |= digitalRead(LCD_D2);
    result <<= 1;
    result |= digitalRead(LCD_D1);
    result <<= 1;
    result |= digitalRead(LCD_D0);

    return result;
}

void lcdSetWriteDir()
{
    pinMode(LCD_D0, OUTPUT);
    pinMode(LCD_D1, OUTPUT);
    pinMode(LCD_D2, OUTPUT);
    pinMode(LCD_D3, OUTPUT);
    pinMode(LCD_D4, OUTPUT);
    pinMode(LCD_D5, OUTPUT);
    pinMode(LCD_D6, OUTPUT);
    pinMode(LCD_D7, OUTPUT);
}


void lcdSetReadDir()
{
    pinMode(LCD_D0, INPUT);
    pinMode(LCD_D1, INPUT);
    pinMode(LCD_D2, INPUT);
    pinMode(LCD_D3, INPUT);
    pinMode(LCD_D4, INPUT);
    pinMode(LCD_D5, INPUT);
    pinMode(LCD_D6, INPUT);
    pinMode(LCD_D7, INPUT);
}

void lcdWriteData(uint16_t data)
{
    lcdSetWriteDir();
    digitalWrite(LCD_CS, LOW);
    digitalWrite(LCD_RS, HIGH);
    digitalWrite(LCD_RD, HIGH);
    digitalWrite(LCD_WR, HIGH);

    lcdWrite8(data >> 8);

    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);

    lcdWrite8(data);

    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);

    digitalWrite(LCD_CS, HIGH);
}

void lcdWriteCommand(uint16_t command)
{
    lcdSetWriteDir();
    digitalWrite(LCD_CS, LOW);
    digitalWrite(LCD_RS, LOW);
    digitalWrite(LCD_RD, HIGH);
    digitalWrite(LCD_WR, HIGH);
    lcdWrite8(command >> 8);
    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);
    lcdWrite8(command);
    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);
    digitalWrite(LCD_CS, HIGH);
}

uint8_t lcdReadData8()
{
    uint8_t result;
    lcdSetReadDir();
    digitalWrite(LCD_CS, LOW);
    digitalWrite(LCD_RS, HIGH);
    digitalWrite(LCD_RD, HIGH);
    digitalWrite(LCD_WR, HIGH);

    digitalWrite(LCD_RD, LOW);
    delayMicroseconds(10);
    result = lcdRead8();
    digitalWrite(LCD_RD, HIGH);

    delayMicroseconds(10);

    return result;
}


uint16_t lcdReadData16()
{
    uint16_t result;
    result = lcdReadData8() << 8;
    result |= lcdReadData8();
    return result;
}


void lcdWriteRegister(uint16_t addr, uint16_t data)
{
    lcdWriteCommand(addr);
    lcdWriteData(data);
}
this is my connection picture:
viewtopic.php?f=9&t=763&start=150#p31264

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

Re: STM32F103C8 & TFT (ili9325)

Post by david.prentice » Mon Jul 17, 2017 8:56 am

The MCUFRIEND_kbv library is designed for 8-bit Shields. I know that LCD_RD is plugged into Analog #0 pin. Hence my list of #defines in the Readreg sketch.

What panel do you have?
is it a Mcufriend Uno Shield?
Or is it a 16-bit 40-pin module?

The Readreg sketch will work with MIPI controllers even if they use a 16-bit data bus. Because all "commands" operate on 8-bit.
If the ILI9325 has got a 16-bit databus, the readReg sketch will be reading the bits 15..8 of reg(0) all the time. You can re-write the readReg sketch if you want for 16-bit reads and writes.

David.

Edit. From your photo, I see that you have a Uno Shield.
I would not expect any reliable results with jumper wires. If you want to use a Shield, solder Arduino headers and links to your STM32.
If your wiring is correct, the readreg sketch should work fine. The display should work fine.
Last edited by david.prentice on Mon Jul 17, 2017 9:06 am, edited 1 time in total.

golpesar132
Posts: 23
Joined: Mon Jul 10, 2017 1:42 pm

Re: STM32F103C8 & TFT (ili9325)

Post by golpesar132 » Mon Jul 17, 2017 9:00 am

david.prentice wrote:
Mon Jul 17, 2017 8:56 am
The MCUFRIEND_kbv library is designed for 8-bit Shields. I know that LCD_RD is plugged into Analog #0 pin. Hence my list of #defines in the Readreg sketch.

What panel do you have?
is it a Mcufriend Uno Shield?
Or is it a 16-bit 40-pin module?

The Readreg sketch will work with MIPI controllers even if they use a 16-bit data bus. Because all "commands" operate on 8-bit.
If the ILI9325 has got a 16-bit databus, the readReg sketch will be reading the bits 15..8 of reg(0) all the time. You can re-write the readReg sketch if you want for 16-bit reads and writes.

David.
I have Mcufriend Uno Shield and it is 8 bits. I send its picture.
I use this code on arduino uno, and that show me the ID is 9325.

golpesar132
Posts: 23
Joined: Mon Jul 10, 2017 1:42 pm

Re: STM32F103C8 & TFT (ili9325)

Post by golpesar132 » Mon Jul 17, 2017 10:26 am

when I use this code:

Code: Select all

afio_cfg_debug_ports(AFIO_DEBUG_NONE);
instead this:

Code: Select all

afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
the response cahnge to this:

Code: Select all

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 93 26	ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 00 00 00	Manufacturer ID
reg(0x0009) 00 00 00 00 00	Status Register
reg(0x000A) 00 00	Get Power Mode
reg(0x000C) 00 00	Get Pixel Format
reg(0x0061) 00 00	RDID1 HX8347-G
reg(0x0062) 00 00	RDID2 HX8347-G
reg(0x0063) 00 00	RDID3 HX8347-G
reg(0x0064) 00 00	RDID1 HX8347-A
reg(0x0065) 00 00	RDID2 HX8347-A
reg(0x0066) 00 00	RDID3 HX8347-A
reg(0x0067) 00 00	RDID Himax HX8347-A
reg(0x0070) 00 00	Panel Himax HX8347-A
reg(0x00A1) 00 00 00 00 00	RD_DDB SSD1963
reg(0x00B0) 00 00	RGB Interface Signal Control
reg(0x00B4) 00 00	Inversion Control
reg(0x00B6) 00 00 00 00 00	Display Control
reg(0x00B7) 00 00	Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00	ILI9481, HX8357-B
reg(0x00C0) 00 00 00 00 00 00 00 00 00	Panel Control
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00	GAMMA
reg(0x00CC) 00 00	Panel Control
reg(0x00D0) 00 00 00	Power Control
reg(0x00D2) 00 00 00 00 00	NVM Read
reg(0x00D3) 00 00 00 00	ILI9341, ILI9488

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F103C8 & TFT (ili9325)

Post by stevestrong » Mon Jul 17, 2017 11:09 am

golpesar132 wrote:
Mon Jul 17, 2017 7:21 am
thats rigtht. I use below code and all of pins toggle after it.
but it still don't show ant thing on the lcd. why????
Your information is many times confusing:
- how did the pins toggle if you have not used "afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);" before?

Anyway, now that is clear you have an ILI9326, you should be able to use any display lib you want.

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

Re: STM32F103C8 & TFT (ili9325)

Post by david.prentice » Mon Jul 17, 2017 11:28 am

I prefer to use the ST core. However it does not initialise PB4 in its init() code.
The Maple core does.

If MCUFRIEND_kbv is running on the ST core, it enables the PB4 pin.

What is a complete mystery: the Shield returns ID = 0x9325 on a Uno and ID = 0x9326 on MapleMini.

The ILI9326 is a 240x400 with VERY different registers to a 240x320 ILI9325.

From memory, I posted a SPECIAL for golpesar123. So I would expect MCUFRIEND_kbv to work out of the box. Note that you should enable support for ILI9326 and SPFD5420:

Code: Select all

#define SUPPORT_9326_5420
David.

golpesar132
Posts: 23
Joined: Mon Jul 10, 2017 1:42 pm

Re: STM32F103C8 & TFT (ili9325)

Post by golpesar132 » Thu Jul 20, 2017 6:08 pm

Thank you all guys. my problem is solved.
Now I have problem with tftbmp example. after I add the following code to the Adafruit_TFTLCD_8bit_STM32.h file:

Code: Select all

uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
and change the library and pin to this:

Code: Select all

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD_8bit_STM32.h> // Hardware-specific library

#define LCD_CS PA3 // Chip Select goes to Analog 3
#define LCD_CD PA2 // Command/Data goes to Analog 2
#define LCD_WR PA1 // LCD Write goes to Analog 1
#define LCD_RD PA0 // LCD Read goes to Analog 0
#define SD_CS PA4     // Set the chip select line to whatever you use (10 doesnt conflict with the library)

Adafruit_TFTLCD_8bit_STM32 tft;
and copy files woof.bmp and miniwoof.bmp on the sd card. this what show me on the LCD:
Image

what is the problem?? how can I solve it??

a part of serial monitor feedback:

Code: Select all

Found ILI9325 LCD driver
Initializing SD card...OK!

Loading image 'woof.bmp'
File size: 
230456
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 6387 ms

Loading image 'miniwoof.bmp'
File size: 
57654
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 120x160

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F103C8 & TFT (ili9325)

Post by stevestrong » Thu Jul 20, 2017 7:01 pm

Your LCD pin settings in the sketch are not relevant. Only what in the "Adafruit_TFTLCD_8bit_STM32.h" header file is set, is relevant.
So please set there the LCD pins (and the mask values as well).
Also, don´t forget to allocate the LCD_RST pin, it is important that the LCD get reset.

To be sure that the display works correctly, try a simple example, like drawing a red filled rectangle at the coordinates (50, 100) and see if it works.

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

Re: STM32F103C8 & TFT (ili9325)

Post by david.prentice » Thu Jul 20, 2017 7:59 pm

I would start with a bit of honesty. i.e. do you have a 240x320 ILI9325 or a 240x400 ILI9326.

Your photo does look like a 240x320. You did say the ID was reported as 0x9325 on a Uno.
But your earlier message showed LCD_readreg.ino with reg(0) returning 0x9326 on the STM32.

It is very straightforward to render a 24-bit BMP from SD card. Most libraries have examples.
Your SD is obviously working fine. It looks as if your tft.setAddrWindow() or tft.pushColors() is not working properly.

Incidentally, I spent some minutes of my life writing a SPECIAL for you.
It would be nice to get some feedback.

David.

golpesar132
Posts: 23
Joined: Mon Jul 10, 2017 1:42 pm

Re: STM32F103C8 & TFT (ili9325)

Post by golpesar132 » Thu Jul 20, 2017 8:49 pm

sorry guys, if I can't explain good
Your LCD pin settings in the sketch are not relevant. Only what in the "Adafruit_TFTLCD_8bit_STM32.h" header file is set, is relevant.
So please set there the LCD pins (and the mask values as well).
Also, don´t forget to allocate the LCD_RST pin, it is important that the LCD get reset.

To be sure that the display works correctly, try a simple example, like drawing a red filled rectangle at the coordinates (50, 100) and see if it works.
graphicstest example works well and show all rectangle, circles and ....
it means all of my pins connection is correct.
I would start with a bit of honesty. i.e. do you have a 240x320 ILI9325 or a 240x400 ILI9326.

Your photo does look like a 240x320. You did say the ID was reported as 0x9325 on a Uno.
But your earlier message showed LCD_readreg.ino with reg(0) returning 0x9326 on the STM32.
I don't know why I got those feedback a couple of times but the LCD reg is 0x9325 and now the LCD show me that.
It is very straightforward to render a 24-bit BMP from SD card. Most libraries have examples.
Your SD is obviously working fine. It looks as if your tft.setAddrWindow() or tft.pushColors() is not working properly.
I think must be right, tft.pushColors() must have some problem. because I think tft.setAddrWindow() but color don't show correct.
how can i find out that's true and how can i fix it?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests