TFT with 9bit SPI (no C/D), can it be used with Arduino?

Topic created by Jean-Marc Zingg

I bought this SPI TFT, in the hope to use it with ESP8266 (Wemos D1 mini).

https://www.aliexpress.com/item/TIANMA-2-8-inch-37P-SPI-TFT-LCD-Module-ILI9341-Drive-IC-240-320-TM028HDZ25-RGB/32267693877.html

I tried to use it with Adafruit_ILI9341, (Adafruit_ILI9341-dev), but got only white screen.

There is no C/D connection, and I found the link:

which is not for Arduino, but suggests, that the devide uses 9bit SPI (C/D is the 9th bit).

Is there any way to use it with Arduino IDE and library? Help welcome!

UTFT has got drivers for 8-bit SPI and for 9- bit SPI. UTFT has no concept of a hardware SPI bus.
So it will be just as slow with 9-bits as it is with 8-bits.

Note that the device requires 2.8V logic. I would guess that 3.3V logic from a Due or Wemos will be ok.

I have driven an ILI9481 with 9-bit bidirectional. i.e. only CS, SDA, SCK pins.
I use AVR with 3.3V logic. Bit-bash one bit, hardware SPI for 8-bit write, bit-bash for 8-bit reads.

Life is much simpler with 9-bit hardware SPI with an ARM.

Looking at your Ali link, a regular 2.2", 2.4", 2.8" SPI module is cheaper and easier.
Most have an SD cage. Some even have an XPT2046 Touch controller. These certainly have better delivery.

David.

Thank you very much, David, I appreciate your help.

I will look at using UTFT for this device, and need to be more careful for voltage levels ( I used UNO clone for a start).

Some "regular" SPI TFTs for Arduino have not yet arrived.

But the first Raspi TFT that looked promising for Arduino has arrived, and seems also to use 9bit SPI.
Maybe my hope to use it with Arduino IDE is helpless.

https://www.aliexpress.com/item/Electric-Unit-New-High-end-3-5-LCD-Touch-Screen-Display-Module-Board-320x480-RGB-For/32614671903.html

It would spare me the use of a Due or MEGA for the parallel interface, and the need for an additional ESP8266 for my network.

The first one works with UTFT. Thanks a lot!

UTFT myGLCD(ILI9341_S4P,MOSI,SCK,10,NOTINUSE);

I hope that you have used resistors (or level translator chips).

Now compare a regular ILI9341 with ILI9341_due library. You will be gobsmacked !!

David.

david_prentice:
I hope that you have used resistors (or level translator chips).

Now compare a regular ILI9341 with ILI9341_due library. You will be gobsmacked !!

David.

The display survived my first test, connected directly to Arduino UNO.
Now I am more prudent, and for clock speed up to 16MHz I use level converter.

Seriously, 9-bit SPI is incredibly painful. Most microcontrollers can not manage this in hardware.
SAMD, STM32, Kinetis do not have the capability.

SAM3X (as used in a Due) can do 9-bit. Anyway, you still need to change formats on the fly when it comes to reading GRAM.

No, I have never bothered with the level-converter modules. I do have some level-converter modules but I suspect that they get unreliable at high clock rates.

I find it easier to run the whole MCU at 3.3V. You know that the MCU is in charge of data direction, timing etc.

I am constantly amazed by Arduino users' cavalier attitude to logic levels. Some chips and some ports are 5V tolerant as GPIO. The tolerance does not always extend to the pins when they are configured / multiplexed for peripherals.

As far as I know, all the common TFT controllers are NOT 5V tolerant. This does not mean that they fry immediately. But the long term reliability will suffer. Even if the 5V stress was only for a short time.

David.

david_prentice:
Seriously, 9-bit SPI is incredibly painful.

I fully agree. It took me quite some time to achieve correct bit sequence. And I did it only for ESP8266, and have not yet looked at input.

The picture shown is with Wemos D1, the level converter would not be needed for this.
But I keep it to be able to use with Arduino UNO and UTFT.

I have ordered a Wemos D1. It looks fun.

I can only find a 31-page PDF for the ESP8266. Does anyone have a link for a comprehensive English datasheet?

Does the ESP8266 support 9-bit SPI in hardware?

David.

david_prentice:
I have ordered a Wemos D1. It looks fun.

I can only find a 31-page PDF for the ESP8266. Does anyone have a link for a comprehensive English datasheet?

Does the ESP8266 support 9-bit SPI in hardware?

David.

Yes to both.

For the Wemos D1: please note that D5 and D6 are duplicated on the Arduino connector; many shields can't be used directly.

Jean-Marc

void SPI9Class::write(uint8_t data)
{
  while (SPI1CMD & SPIBUSY) {}
  // low byte first, ms bit first!; CMD : dc low -> first bit 0, DATA : dc high -> first bit high
  uint16_t data16 = (data >> 1) | (data << 15) | (digitalRead(_dc) << 7);
  // data16 |= digitalRead(_dc) ? 0x0080 : 0x0000;
  //data16 = 0x0080;
  setDataBits(9);
  SPI1W0 = data16;
  SPI1CMD |= SPIBUSY;
  while (SPI1CMD & SPIBUSY) {}
}

This is the main method of my SPI9Class. Just to give an idea how it works.

It looks as if the ESP8266 can handle 9-bits. I have got a lot of reading to do.

David.

david_prentice:
It looks as if the ESP8266 can handle 9-bits. I have got a lot of reading to do.

David.

It sure can. Maybe I post the initial version of my SPI9Class, a subclass of SPIClass for ESP8266, tomorrow.
It just needs some cleanup.

Jean-Marc

Just finished an initial version. Tested for output only, MSBFIRST, for use with ESP8266 package.

This is "Help Yourself Software", no warranty, no support, no obligations.

In the hope, this may be useful for someone, or inspire additional contributions.

Jean-Marc Zingg

SPI9_TFT_graphicstest_one_lib.zip (22.4 KB)

I just did a first test with a modified Adafruit_ILI9341, source taken from

I would like to check the input function of my SPI9Class. But I don't know how to interpret the values read.

Please tell me if the values read are reasonable. Or some other means to check input function.

Display Power Mode: 0xFE
MADCTL Mode: 0x0
Pixel Format: 0x3
Image Format: 0x0
Self Diagnostic: 0xE0
Benchmark                Time (microseconds)
Screen fill              4778193
Text                     190558
Lines                    1032857
Horiz/Vert Lines         388784
Rectangles (outline)     246547
Rectangles (filled)      9919672
Circles (filled)         1296107
Circles (outline)        723118
Triangles (outline)      262660
Triangles (filled)       3184750
Rounded rects (outline)  393325
Rounded rects (filled)   10768884
Done!

Jean-Marc

Life would be simpler if you did not ask the same question in three different places.

Yes, you can read the ID in most SPI controllers.
Some have regular 8-bit SPI
Some have 9-bit SPI
Some have a single bidirectional SDA pin.

I have attached a sketch. You must have GPIO pins that work. i.e. regular 3.3V logic or level-shifters that really work properly.

I believe that you have ILI9341 with DI, DO pins but no D/C pin.

//char interface = 0;    //regular ST7735, ILI9163
//char interface = HAS_MISO;  //ILI9341 SPI
char interface = HAS_MISO | NINEBITS;  // SPI 
//char interface = NINEBITS | SDA_INPUT;  //ILI9481 SPI

This was originally written for ST7735 style controllers. They have a very small set of "readable" registers. The bit-padding is very messy too!

If you want to read registers with "big" argument lists like GAMMA_P , most ILI9341 libraries can do it via the 0xD9 mechanism.

David.

ST7735_readreg_diag.ino (5.5 KB)

Thank you very much, David.

I tried to get help from wherever and from whomever I could get.

The settings I tried:

#define TFT_MOSI MOSI
#define TFT_MISO MISO
#define TFT_SCK  SCK
#define TFT_SS   D8
#define TFT_DC   D4    // Dummy on TIANMA2.8
#define TFT_RESET D2   // Dummy on TIANMA2.8
#define NINEBITS  (1<<0)
#define SDA_INPUT (1<<1)
#define HAS_MISO  (1<<2)
char *chip = "controller";
//char interface = 0;    //regular ST7735, ILI9163
//char interface = HAS_MISO;  //ILI9341 SPI
//char interface = NINEBITS | SDA_INPUT;  //ILI9481 SPI
char interface = NINEBITS | HAS_MISO; // SDO on TIANMA2.8

The response I got:

data sheet specific calls
controller reg(0x04) = 0x000000
controller reg(0x09) = 0x007FE000
controller reg(0x0A) = 0x0F
controller reg(0x0B) = 0x00
controller reg(0x0C) = 0x07
controller reg(0x0D) = 0x00
controller reg(0x0E) = 0x00
controller reg(0x0F) = 0x00
controller reg(0x2E) = 0x3FFFFF
controller reg(0xA1) = 0xFFFFFFFF
controller reg(0xBF) = 0x00F0F0F0
controller reg(0xD3) = 0x78F0FFFC
controller reg(0xDA) = 0x00
controller reg(0xDB) = 0x00
controller reg(0xDC) = 0x00

I will look at the signal, and try it also with my SPI9Class.

I am VERY wary of any display that does not have a hardware Reset pin.

My ILI9341 produces:

Read registers 8-bit SPI with MISO (+ DC)
data sheet specific calls
controller reg(0x04) = 0x000000
controller reg(0x09) = 0x00610000
controller reg(0x0A) = 0x08
controller reg(0x0B) = 0x00
controller reg(0x0C) = 0x06
controller reg(0x0D) = 0x00
controller reg(0x0E) = 0x00
controller reg(0x0F) = 0x00
controller reg(0x2E) = 0x545454
controller reg(0xA1) = 0xFFFFFFFF
controller reg(0xBF) = 0x00000000
controller reg(0xD3) = 0x41009341
controller reg(0xDA) = 0x00
controller reg(0xDB) = 0x00
controller reg(0xDC) = 0x00

This has little relationship with your output. Note that I apply a Software Reset before I read any register.
So even if the bits might be misaligned, I would still expect a similar bit pattern.

Please confirm that you are actually using an ILI9341.

David.

david_prentice:
I am VERY wary of any display that does not have a hardware Reset pin.
.
.
Please confirm that you are actually using an ILI9341.

David.

Yes, it has a reset pin. I had it connected to the reset of the board, which is sufficient for normal operation.

And no, I don't know if its really a ILI9341, it is under the display. But it works with TFT_ILI9341_ESP and with a modified Adafruit_ILI9341-dev library.

I am grateful for your ST7735_readreg_diag.ino, this will finally confirm the controller in use, verify the input path of my SPI9Class, and let me find out what controller my other SPI 9bit display have.

I will report as soon I have more results. Thank you!

Jean-Marc

I suggest that you connect the TFT_RST pin to a regular GPIO. At least you have proper control that way.

Have you verified the MOSI macro? Is it D7 ?
Do the Wemos pins correspond correctly in Arduino sketches?

Quite honestly, bit-banging GPIO should work in any "Arduino".

David.