Spark Logic

8-bit|16-bit parallell ILI9341

andreas_ferm

Good day everyone, I’m all new to stm32 and have previously only done smaller projects on arduiono boards, mostly using already-finished libraries.

Now I reached a point where my programmings skills lack, so instead of optimizing my code i started to look at maple mini and thought it would be excellent to also add a “nice” GUI to my project.

I ended up ordering a chinese 3.2″ tft+touch+sd card combo, but what i didn’t know or think of beforehand was to check the connectivity needed (i just read here and saw all the included libraries for the aforementioned display controller), but all of them are using SPI. So the display came in the mail and i became aware that it didn’t have any SPI interface, (at least not for the display, only for the touch and sd card)

Are there any working options that is available to use with stm32duino? What would be my best chance of getting this to work? (i was initially thinking about going for a MEGA, but choose the maple mini clone as i was impressed with the various tft demos i’ve seen )

I’ve tried looking through “all” of the internet, but have only found small pointers, and none of the really targeted for stm32duino. (i found one post where someone had posted an utft version with support for stm32, which was based on some teensy port, but it was also done for SPI only, and i couldn’t find any ILI9341 tft ‘drivers’ for parallel communication… well there was one for an ILI9481 but i’m not sure if that can be used in direct replacement.

Anyone has a similar display and has it working with a maple mini?

Thanks!
Andreas

Replies20

VadimEL Sat Aug 13, 2016 1:44 pm

I try to learn ARM sorry if I ask stupid questions.
stm32f103c8t6 does not have the PC1, this is a mistake?
maybe PA1 ?

Pito Sat Aug 13, 2016 1:59 pm

No PC1, but PC13,14,15

VadimEL Sat Aug 13, 2016 2:16 pm

Pito Ok, I need to change data bus pin PC1 to PC13 ? in functions called write8(), setWriteDataBus()

Pito Sat Aug 13, 2016 2:44 pm

change PC1 to PA1

VadimEL Sat Aug 13, 2016 5:23 pm

i think it’s a mistake, and nothing to change??????.
//#define TFT_DATA GPIOA

void Adafruit_ILI9341_8bit_STM::setWriteDataBus(void)
{
//set the pins to output mode
//not required to mask and assign, because all pins of bus are set together
TFT_DATA->regs->CRL = 0x33333333;
//each pin is configured by four bits, and 0b0011 or 0x3 means output mode (same as pinmode())
}

konczakp Mon Aug 15, 2016 11:49 am

Hi,

Yes Spfd5408 2.4” TFT screen is working with maple mini and blue pill very well. You have to read this topic carefully because everything is here also with a way of connecting tft to stm32 and also what to change and how in the libraries. Few posts earlier I posted everything You need to get this working (also with working sketch example) For example here is how to modify library http://www.stm32duino.com/viewtopic.php … 110#p16273 and below is an example from cologne86. This should help You to get this working.

VadimEL Mon Aug 15, 2016 6:32 pm

konczakp
I change in Adafruit_ILI9341_8bit_STM.h
#define TFT_CNTRL GPIOA
#define TFT_DATA GPIOB
#define TFT_RD PA0
#define TFT_WR PA1
#define TFT_RS PA2
#define TFT_CS PA3
#define TFT_RST PA8
and
TFT_CNTRL->regs->CRL = (TFT_CNTRL->regs->CRL & 0xFFFF0000) | 0x00003333;
in Adafruit_ILI9341_8bit_STM.cpp
======================================================
connect
111.jpg
111.jpg (157.91 KiB) Viewed 720 times

cologne86 Mon Aug 15, 2016 8:12 pm

hi vadim,

here is what i have right now, works for my ili9341 and almost works for the ili9328/ili9325 (slower and doesnt work in landscape reverse)
with pb8-pb15 as d0-d7

i dont exactly remember what i have modified but it should still run with good performance for the ili9341

i have also added a pushcolors function for displaying sdcard stuff faster

.h
/*
See rights and use declaration in License.h
This library has been modified for the Maple Mini
*/

#ifndef _ADAFRUIT_ILI9341H_
#define _ADAFRUIT_ILI9341H_

#include "Arduino.h"
#include "Print.h"
#include <Adafruit_GFX.h>
#include <avr/pgmspace.h>

#define TFTLCD_DELAY 0xFF

#define ILI9341_TFTWIDTH 240
#define ILI9341_TFTHEIGHT 320

#define ILI9341_NOP 0x00
#define ILI9341_SWRESET 0x01
#define ILI9341_RDDIDIF 0x04
#define ILI9341_RDDID 0xD3
#define ILI9341_RDDST 0x09

#define ILI9341_SLPIN 0x10
#define ILI9341_SLPOUT 0x11
#define ILI9341_PTLON 0x12
#define ILI9341_NORON 0x13

#define ILI9341_RDMODE 0x0A
#define ILI9341_RDMADCTL 0x0B
#define ILI9341_RDPIXFMT 0x0C
#define ILI9341_RDIMGFMT 0x0D
#define ILI9341_RDDSM 0x0E
#define ILI9341_RDSELFDIAG 0x0F

#define ILI9341_INVOFF 0x20
#define ILI9341_INVON 0x21
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPOFF 0x28
#define ILI9341_DISPON 0x29

#define ILI9341_CASET 0x2A
#define ILI9341_PASET 0x2B
#define ILI9341_RAMWR 0x2C
#define ILI9341_RGBSET 0x2D
#define ILI9341_RAMRD 0x2E

#define ILI9341_PTLAR 0x30
#define ILI9341_VSCRDEF 0x33
#define ILI9341_TEOFF 0x34
#define ILI9341_TEON 0x35
#define ILI9341_MADCTL 0x36
#define ILI9341_VSCRSADD 0x37
#define ILI9341_IDMOFF 0x38
#define ILI9341_IDMON 0x39
#define ILI9341_PIXFMT 0x3A

#define ILI9341_FRMCTR1 0xB1
#define ILI9341_FRMCTR2 0xB2
#define ILI9341_FRMCTR3 0xB3
#define ILI9341_INVCTR 0xB4
#define ILI9341_PRCTR 0xB5
#define ILI9341_DFUNCTR 0xB6
#define ILI9341_ETMOD 0xB7

#define ILI9341_PWCTR1 0xC0
#define ILI9341_PWCTR2 0xC1
#define ILI9341_PWCTR3 0xC2
#define ILI9341_PWCTR4 0xC3
#define ILI9341_PWCTR5 0xC4
#define ILI9341_VMCTR1 0xC5
#define ILI9341_VMCTR2 0xC7
#define ILI9341_PWCTRLA 0xCB
#define ILI9341_PWCTRLB 0xCF

#define ILI9341_RDID1 0xDA
#define ILI9341_RDID2 0xDB
#define ILI9341_RDID3 0xDC
#define ILI9341_RDID4 0xD3

#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1
#define ILI9341_DGAMCTRL1 0xE2
#define ILI9341_DGAMCTRL2 0xE3
#define ILI9341_TCTRLA 0xE8
#define ILI9341_TCTRLB 0xEA
#define ILI9341_PWRSEQ 0xED

#define ILI9341_EN3GAM 0xF2
#define ILI9341_IFCTL 0xF6
#define ILI9341_PUMP 0xF7

#define ILI9341_MADCTL_MV BIT(5)
#define ILI9341_MADCTL_MX BIT(6)
#define ILI9341_MADCTL_MY BIT(7)

#define ILI932X_START_OSC 0x00
#define ILI932X_DRIV_OUT_CTRL 0x01
#define ILI932X_DRIV_WAV_CTRL 0x02
#define ILI932X_ENTRY_MOD 0x03
#define ILI932X_RESIZE_CTRL 0x04
#define ILI932X_DISP_CTRL1 0x07
#define ILI932X_DISP_CTRL2 0x08
#define ILI932X_DISP_CTRL3 0x09
#define ILI932X_DISP_CTRL4 0x0A
#define ILI932X_RGB_DISP_IF_CTRL1 0x0C
#define ILI932X_FRM_MARKER_POS 0x0D
#define ILI932X_RGB_DISP_IF_CTRL2 0x0F
#define ILI932X_POW_CTRL1 0x10
#define ILI932X_POW_CTRL2 0x11
#define ILI932X_POW_CTRL3 0x12
#define ILI932X_POW_CTRL4 0x13
#define ILI932X_GRAM_HOR_AD 0x20
#define ILI932X_GRAM_VER_AD 0x21
#define ILI932X_RW_GRAM 0x22
#define ILI932X_POW_CTRL7 0x29
#define ILI932X_FRM_RATE_COL_CTRL 0x2B
#define ILI932X_GAMMA_CTRL1 0x30
#define ILI932X_GAMMA_CTRL2 0x31
#define ILI932X_GAMMA_CTRL3 0x32
#define ILI932X_GAMMA_CTRL4 0x35
#define ILI932X_GAMMA_CTRL5 0x36
#define ILI932X_GAMMA_CTRL6 0x37
#define ILI932X_GAMMA_CTRL7 0x38
#define ILI932X_GAMMA_CTRL8 0x39
#define ILI932X_GAMMA_CTRL9 0x3C
#define ILI932X_GAMMA_CTRL10 0x3D
#define ILI932X_HOR_START_AD 0x50
#define ILI932X_HOR_END_AD 0x51
#define ILI932X_VER_START_AD 0x52
#define ILI932X_VER_END_AD 0x53
#define ILI932X_GATE_SCAN_CTRL1 0x60
#define ILI932X_GATE_SCAN_CTRL2 0x61
#define ILI932X_GATE_SCAN_CTRL3 0x62
#define ILI932X_PART_IMG1_DISP_POS 0x80
#define ILI932X_PART_IMG1_START_AD 0x81
#define ILI932X_PART_IMG1_END_AD 0x82
#define ILI932X_PART_IMG2_DISP_POS 0x83
#define ILI932X_PART_IMG2_START_AD 0x84
#define ILI932X_PART_IMG2_END_AD 0x85
#define ILI932X_PANEL_IF_CTRL1 0x90
#define ILI932X_PANEL_IF_CTRL2 0x92
#define ILI932X_PANEL_IF_CTRL3 0x93
#define ILI932X_PANEL_IF_CTRL4 0x95
#define ILI932X_PANEL_IF_CTRL5 0x97
#define ILI932X_PANEL_IF_CTRL6 0x98
/*
#define ILI9341_PWCTR6 0xFC

*/

// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F

/*
Define pins and Output Data Registers
*/

//Port data |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
//Pin stm32 |PA7|PA6|PA5|PA4|PA3|PA2|PC1|PA0|
//Control pins |RD |WR |RS |CS |RST|
//Pin stm32 |PB4|PB5|PB6|PB7|PB8|
#define TFT_CNTRL GPIOA
#define TFT_DATA GPIOB
#define TFT_RD PA0
#define TFT_WR PA1
#define TFT_RS PA2
#define TFT_CS PA3
#define TFT_RST PA8
#define TFT_RD_MASK digitalPinToBitMask(TFT_RD)
#define TFT_WR_MASK digitalPinToBitMask(TFT_WR)
#define TFT_RS_MASK digitalPinToBitMask(TFT_RS)
#define TFT_CS_MASK digitalPinToBitMask(TFT_CS)

#define RD_ACTIVE TFT_CNTRL->regs->BRR = TFT_RD_MASK
#define RD_IDLE TFT_CNTRL->regs->BSRR = TFT_RD_MASK
#define WR_ACTIVE TFT_CNTRL->regs->BRR = TFT_WR_MASK
#define WR_IDLE TFT_CNTRL->regs->BSRR = TFT_WR_MASK
#define CD_COMMAND TFT_CNTRL->regs->BRR = TFT_RS_MASK
#define CD_DATA TFT_CNTRL->regs->BSRR = TFT_RS_MASK
#define CS_ACTIVE TFT_CNTRL->regs->BRR = TFT_CS_MASK
#define CS_IDLE TFT_CNTRL->regs->BSRR = TFT_CS_MASK

#ifndef RD_STROBE
#define RD_STROBE {RD_ACTIVE; RD_IDLE;}
#endif
#define WR_STROBE { WR_ACTIVE; WR_IDLE; }
#define swap(a, b) { int16_t t = a; a = b; b = t; }

//Set pins to the 8 bit number
#define write8special(c) { TFT_DATA->regs->BSRR = ((~c)<<24) | ((c)<<8); WR_STROBE; }

class Adafruit_ILI9341_8bit_STM : public Adafruit_GFX {

public:

Adafruit_ILI9341_8bit_STM(void);

void begin(void),
begin(uint16_t id),
setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
pushColors(uint16_t *data, uint8_t len, boolean first),
pushColors(uint8_t *data, uint8_t len, boolean first),
pushColor(uint16_t color),
fillScreen(uint16_t color),
#if defined (__STM32F1__)
drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1, uint16_t color),
#endif
drawPixel(int16_t x, int16_t y, uint16_t color),
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color),
setRotation(uint8_t r),
write8(uint8_t),
writedata(uint8_t d),
writecommand(uint8_t c),
invertDisplay(boolean i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);

/* These are not for current use, 8-bit protocol only! */
//uint8_t readdata(void),
uint8_t readcommand8(uint8_t reg);
uint32_t readID(void);
uint8_t driver;

private:
uint8_t tabcolor;
uint8_t read8(void);
void setReadDataBus(void),
setWriteDataBus(void),
commandList(uint8_t *addr),
flood(uint16_t color, uint32_t len),
writeRegister16(uint16_t a,uint16_t d) ;

#if defined (__STM32F1__)
uint16_t lineBuffer[ILI9341_TFTHEIGHT]; // DMA buffer. 16bit color data per pixel
#endif
};

#endif //endif of the header file

konczakp Tue Aug 16, 2016 12:13 pm

@VadimEL
In my opinion You have a hardware problem. Have You got another screen to try? One of my screens was similar to Yours. Try to connect as it should be and gently squeeze with your fingers screen to the board in different areas while reseting the stm32 board. Check if something will happen. In my situation when I have squeezed on the left bottom corner it was working. There was some soldering problem. For me this doesn’t look as a library problem. When I had a problem with library it was only blinking or white screen on nothing else. Removing one data pin means that You are not transfering all info to the tft. Of course I might be wrong in this case.

@cologne86
inverted picture on the screen means that there is different chip and there is a need for different initialization for this screen in the library or different library.

By the way:

Anyone has got library for the eagle software ? I need it to prepare a board

VadimEL Tue Aug 16, 2016 3:15 pm

konczakp it work well on https://github.com/JoaoLopesF/SPFD5408/.
I code program on atmel(arduino), but flash program memory is out.
I buy logic analyzer tomorrow and compare signals.
sorry my english bad :mrgreen: I hope you understand what i writing.

================================================================
in atmel(arduino) inicialization

else if (id == 0x9341) {

uint16_t a, d;
driver = ID_9341;
CS_ACTIVE;

writeRegister8(ILI9341_SOFTRESET, 0); //softreset == 0x01
delay(50);
writeRegister8(ILI9341_DISPLAYOFF, 0); //0x28

writeRegister8(ILI9341_POWERCONTROL1, 0x23);// команда 0xC0 а потом данные 0x23
writeRegister8(ILI9341_POWERCONTROL2, 0x10);//команда 0xC1 а данные 0x10
writeRegister16(ILI9341_VCOMCONTROL1, 0x2B2B);//0xC5
writeRegister8(ILI9341_VCOMCONTROL2, 0xC0);//0xC7
writeRegister8(ILI9341_MEMCONTROL, ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR);
writeRegister8(ILI9341_PIXELFORMAT, 0x55);
writeRegister16(ILI9341_FRAMECONTROL, 0x001B);

writeRegister8(ILI9341_ENTRYMODE, 0x07); //0xB7
/* writeRegister32(ILI9341_DISPLAYFUNC, 0x0A822700);*/

writeRegister8(ILI9341_SLEEPOUT, 0);
delay(150);
writeRegister8(ILI9341_DISPLAYON, 0); //ILI9341_DISPLAYON 0x29
delay(500);
// *** SPFD5408 change -- Begin
// Not tested yet
//writeRegister8(ILI9341_INVERTOFF, 0);
//delay(500);
// *** SPFD5408 change -- End
setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1);
return;

VadimEL Thu Aug 18, 2016 7:12 pm

Ok. it works now on spfd5408 2.4 TFT

//Port data |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
//Pin stm32 |PA7|PA6|PA5|PA4|PA3|PA2|PA1|PA0|
//Control pins |RD |WR |RS |CS |RST|
//Pin stm32 |PB4|PB5|PB6|PB7|PB15|

http://ifolder.com.ua/p6dz77ur9lq5.html


//инициализация НОВАЯ
void Adafruit_ILI9341_8bit_STM::begin(void) {

// toggle RST low to reset TFT_RST это PB8
if (TFT_RST > 0)
{
digitalWrite(TFT_RST, HIGH);
delay(5);
digitalWrite(TFT_RST, LOW);
delay(20);
digitalWrite(TFT_RST, HIGH);
delay(150);
}

//reset();

writecommand(0x01); //softreset == 0x01
writedata(0x00);

delay(50);

writecommand(0x28); //ILI9341_DISPLAYOFF //0x28
writedata(0x00); //

writecommand(ILI9341_PWCTR1); //Power control
writedata(0x23); //VRH[5:0]

writecommand(ILI9341_PWCTR2); //Power control
writedata(0x10); //SAP[2:0];BT[3:0]

//0x2B2B == 10 1011 0010 1011
writecommand(ILI9341_VMCTR1); //VCM control 0xC5
//изменил
// writedata(0x3e); //
// writedata(0x28);

writedata(0x2B);
writedata(0x2B);

writecommand(ILI9341_VMCTR2); //VCM control2 0xC7
//изменил
//writedata(0x86); //--
writedata(0xC0);

writecommand(ILI9341_MADCTL); //ILI9341_MEMCONTROL == 0x36 Memory Access Control //0x36
//ILI9341_MADCTL_MY | ILI9341_MADCTL_MY 0x80 == 10000000
// ILI9341_MADCTL_BGR 0x08 == 1000
//10001000== 88
//заменил
// writedata(0x48);
writedata(0x88);

writecommand(ILI9341_PIXFMT); //0x3A
writedata(0x55);

writecommand(ILI9341_FRMCTR1);//0xB1
// 0x001B==11011

// writedata(0x00);
// writedata(0x18);

//изменил
writedata(0x00);
writedata(0x1B);

// writecommand(ILI9341_DFUNCTR); // 0xB6 Display Function Control
//writedata(0x08);
//writedata(0x82);
//writedata(0x27);

//writecommand(0xF2); // 3Gamma Function Disable
//writedata(0x00);

//writecommand(ILI9341_GAMMASET); //0x26 Gamma curve selected
//writedata(0x01);

//writecommand(ILI9341_GMCTRP1); // 0xE0 Set Gamma
//writedata(0x0F);
//writedata(0x31);
//writedata(0x2B);
//writedata(0x0C);
//writedata(0x0E);
//writedata(0x08);
//writedata(0x4E);
//writedata(0xF1);
//writedata(0x37);
//writedata(0x07);
//writedata(0x10);
//writedata(0x03);
//writedata(0x0E);
//writedata(0x09);
//writedata(0x00);

//writecommand(ILI9341_GMCTRN1); // 0xE1 Set Gamma ILI9341_GMCTRN1 0xE1
//writedata(0x00);
//writedata(0x0E);
//writedata(0x14);
//writedata(0x03);
//writedata(0x11);
//writedata(0x07);
//writedata(0x31);
//writedata(0xC1);
//writedata(0x48);
//writedata(0x08);
//writedata(0x0F);
//writedata(0x0C);
//writedata(0x31);
//writedata(0x36);
//writedata(0x0F);

// delay(150);

//ILI9341_ENTRYMODE
writecommand(0xB7);
writedata(0x07);

delay(150);
writecommand(ILI9341_SLPOUT); //Exit Sleep
delay(500);
writecommand(ILI9341_DISPON); //Display on 0x29

digitalWrite(PB7, HIGH);
digitalWrite(PB5, HIGH);
digitalWrite(PB4, HIGH);

digitalWrite(PB8, LOW);
delay(100);
digitalWrite(PB8, HIGH);

// Data transfer sync
digitalWrite(PB7, LOW);

digitalWrite(PB6, LOW);
writecommand(0x00);
for(uint8_t i=0; i<3; i++) writecommand(0x00); // Three extra 0x00s
digitalWrite(PB7, HIGH);

}

VadimEL Wed Aug 24, 2016 8:41 pm

stevestrong wrote:cologne86 wrote:I connected both.

cologne86 Wed Aug 31, 2016 9:32 am

in my case there is a ams1117 drop down regulator on the lcds pcb, so it works with only 5v connected for both

stevestrong Wed Aug 31, 2016 9:46 am

cologne86 wrote:in my case there is a ams1117 drop down regulator on the lcds pcb, so it works with only 5v connected for both

VadimEL Wed Aug 31, 2016 12:09 pm

but not in my case.
Image
power supply only 3.3V =)

stevestrong Wed Aug 31, 2016 1:40 pm

It’s strange, the on-board 3.3V regulator supplies the transceivers and the LCD, but not the SD card. This is identical with my board.
Now I have to double check why the SD card sketch worked in my case without 3.3V pin connected…

But meanwhile I have bigger problems, the LCD only works with slow toggling signals, and I don’t know why.
One thing is that the filtering capacitors are missing from my LCD board.
The other thing is that the LCD works with faster toggling if the LCD is disassembled so that the flexible cable is straight (not bent).
Anyone an idea why?

VadimEL Wed Aug 31, 2016 8:02 pm

stevestrong what is ” slow toggling signals”
did you put delay, after “tft.command”, or what? =)
———————-
i do not have problem with toggling signals.
But problem with disconnecting maple com port after using tft.command. :?

stevestrong Thu Sep 01, 2016 8:41 am

Slow toggling means bit toggling using digitalWrite() function.

konczakp Thu Sep 01, 2016 9:24 am

@VadimEL
If You resolve Your problem with serial disconnection after tft call please post here what to do. Check if it is happening when You call
tft.setTextSize(1);

Sign in to reply