ST7735 based LCDs?

External hardware connected to the STM32 board
User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

ST7735 based LCDs?

Post by Kenjutsu » Wed Aug 12, 2015 9:49 am

Hello everyone,

Has anyone got ST7735 based LCDs working under STM32duino such as this one 1.8 inch 1.8" TFT LCD Display module ST7735S 128x160 51/AVR/STM32/ARM 8/16 bit?
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: ST7735 based LCDs?

Post by madias » Wed Aug 12, 2015 10:40 am

maybe the easiest way is to convert the adafruit library https://github.com/adafruit/Adafruit-ST7735-Library as it was done with all other adafruit tft libs in STM32 library folder. They are all relative similar.

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ST7735 based LCDs?

Post by Kenjutsu » Thu Aug 13, 2015 6:02 am

Thanks, I'll order one and have a look ;)
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

zmemw16
Posts: 1578
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: ST7735 based LCDs?

Post by zmemw16 » Thu Aug 13, 2015 6:45 am

maybe take a look at
https://github.com/PaulStoffregen/Adafr ... t_ST7735.h
that has teensy support, so places you may need to probably change are already marked:-)
have a look at ILI9341_STM32 (builtin) for some typedefs switching as well

and of course
https://github.com/adafruit/Adafruit-ST7735-Library/

i've currently got the constructors and the spi setup wrong in my dedicated stm32 port of PCA8544:-(

is anything defined to help with variants? i.e. 1, 2 or 3 spi setups; modify constructors and / or add an explicit select function?
later i think with default settings in begin()?
hth

stephen

User avatar
FurkanCetin
Posts: 54
Joined: Sat Sep 19, 2015 8:31 pm
Location: Istanbul, TURKEY
Contact:

Re: ST7735 based LCDs?

Post by FurkanCetin » Sun Sep 20, 2015 8:18 am

Hi everyone,

I have been working on my STM32 Smart Watch project and I am satisfied with ST7735S, 1.44' LCD with 128x128 resolution. I examined Adafruit's libraries, as well as Henning Karlsen's UTFT files (They are both very generous contributors about LCD stuff). I also encountered with other works with ST7735 and ILI9340 which were helpful to establish successful SPI communication with LCD.

My board is STM32F103C8, one of the most common one. For now, I want to share the most important parts you may need if it helps. I am planning to create a GitHub rep. for all code. I gladly help you for any question.

You need those in setup:

Code: Select all

  csport    = portOutputRegister(digitalPinToPort(TFT_CS));
  cspinmask = digitalPinToBitMask(TFT_CS);
  dcport    = portOutputRegister(digitalPinToPort(TFT_RS));
  dcpinmask = digitalPinToBitMask(TFT_RS);
  
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV2);



Sending commands and data is handled by those:

Code: Select all

void writeCommand(uint8 c) {
  *dcport &=  ~dcpinmask;
  *csport &=  ~cspinmask;
  
  SPI.write(c);
  
  *csport |= cspinmask;
}

void writeData(uint8 c) {
  *dcport |=  dcpinmask;
  *csport &= ~cspinmask;
  
  SPI.write(c);
  
  *csport |= cspinmask;
}


The rest uses those Command and Data senders. Three fundamental functions you need are those:

Code: Select all

void fillScreen(uint16 color) {

  setAddrWindow(0, 0, TFT_WIDTH - 1, TFT_HEIGHT - 1);

  *dcport |=  dcpinmask;
  *csport &= ~cspinmask;

  SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
  lineBuffer[0] = color;
  SPI.dmaSend(lineBuffer, (65535), 0);
  SPI.dmaSend(lineBuffer, ((TFT_WIDTH * TFT_HEIGHT) - 65535), 0);
  SPI.setDataSize (0);

  *csport |= cspinmask;
}

void setAddrWindow(uint8 x0, uint8 y0, uint8 x1, uint8 y1) {
  writeCommand(ST7735_CASET);
  *dcport |=  dcpinmask;
  *csport &= ~cspinmask;
  SPI.setDataSize (SPI_CR1_DFF);
  SPI.write(x0);
  SPI.write(x1);

  writeCommand(ST7735_RASET);
  *dcport |=  dcpinmask;
  *csport &= ~cspinmask;

  SPI.write(y0);
  SPI.write(y1);
  SPI.setDataSize(0);

  writeCommand(ST7735_RAMWR);
}


void setColor(uint16 color) {
  *dcport |=  dcpinmask;
  *csport &= ~cspinmask;

  SPI.write(color >> 8);
  SPI.write(color);

  *csport |= cspinmask;
}

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ST7735 based LCDs?

Post by Kenjutsu » Fri Oct 30, 2015 12:55 pm

Hello everyone,

My LCD finally arrived from China 8-) I took the Adafruit ST7735 library, and adapted it for the STM32. You can find it here: https://github.com/KenjutsuGH/Adafruit-ST7735-Library

I only tested hardware SPI with the LCD connected as follows:

Code: Select all

SCK --> SCK1 --> PA5
SDA --> MOSI1 --> PA7
A0 --> PA3
RESET --> PA4
CS --> PA2
and graphicstest.ino changed as follows:

Code: Select all

#if defined (__STM32F1__)
  #include <Adafruit_GFX_AS.h>    // Core graphics library
  #define LEDPIN PC13
#endif
#if !defined (__STM32F1__)
  #include <Adafruit_GFX.h>    // Core graphics library
#endif

#include "./Adafruit_ST7735.h" // Hardware-specific library

// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS     PA2
#define TFT_RST    PA4  // you can also connect this to the Arduino reset
                      // in which case, set this #define pin to 0!
#define TFT_DC     PA3

Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ST7735 based LCDs?

Post by Kenjutsu » Tue Nov 03, 2015 1:32 pm

I updated the library with DMA support, as suggested by FurkanCetin and by looking at Adafruit_ILI9341_STM.cpp

To test for any speed improvements, I modified graphicstest.ino to do very simple timing on calling the test functions. Some results:

With HW SPI and no DMA:

Code: Select all

Hello! ST7735 TFT Test
Initialized
48
Benchmark                Time (microseconds)
Draw text                101392
Print Test               1640352
Line Draw Test           891722
Fast Line Draw Test      68545
Draw Rects Test          62890
Test Fill Rects          349202
Test Fill circles        77795
Test Draw Circles        74407
Test Round Rec           196256
Test Triangles           154353
Test Media Buttons       1146629
done
With HW SPI and DMA:

Code: Select all

Hello! ST7735 TFT Test
Initialized
38
Benchmark                Time (microseconds)
Draw text                66547
Print Test               1605677
Line Draw Test           588780
Fast Line Draw Test      43078
Draw Rects Test          42432
Test Fill Rects          97044
Test Fill circles        35953
Test Draw Circles        46549
Test Round Rec           101420
Test Triangles           104518
Test Media Buttons       1102928
done
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

User avatar
ahull
Posts: 1672
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: ST7735 based LCDs?

Post by ahull » Tue Nov 03, 2015 9:48 pm

That's quite an improvement. :D
Improvement.jpg
Improvement.jpg (107.51 KiB) Viewed 4981 times
- Andy Hull -

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ST7735 based LCDs?

Post by Kenjutsu » Wed Nov 04, 2015 4:15 am

ahull wrote:That's quite an improvement. :D
Yes, I was pleasantly surprised as well. 8-) I did realise last night when I went to bed that there are a few places in the code which needs some testing; it will probably fail when using software SPI.

Also, I noticed I might squeeze out a bit more performance and smaller compiled size when using only hardware SPI.

I will modify and test later today and report back here ;)
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ST7735 based LCDs?

Post by Kenjutsu » Wed Nov 04, 2015 12:07 pm

As I suspected, when I added the DMA support, I broke software SPI. This is now fixed
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

Post Reply