ST7735 TFT Display

Last post
37 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

Teaching myself AVRs and AVR-GCC... (still)
My setup is ATMEGA328P 16Mhz on an Arduino Uno.

I just got this bit of kit:
http://www.hobbytronics.co.uk/arduino/arduino-shields/arduino-tft-shield

Featuring a 128 x 160 18 bit colour TFT screen driven by a ST7735, connected in 4 wire SPI mode.

I've converted a driver I found on the interweb to avr-gcc and it works.

I'm bit-banging the SPI for the moment but will be using the hardware SPI at some point.

However, according to my very basic calculations, it should only take ~140mS to fill the screen with coloured pixels because, looking at the dis-assembly, there's 110 instructions to set a single pixel plus 288 instructions for the loops.

(20480 x 110) x 62nS = ~139mS

where 62nS = 1 over 16 Million.

However, it takes about 2 seconds for the display to update.

Can anyone shed any light on this?

I can post the code if it's not obvious.

Any help is highly appreciated...

Many thanks.
Darren.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The calculation certainly looks correct given your numbers. It is difficult to say anything more without seeing the code.

Martin Jay McKee

As with most things in engineering, the answer is an unabashed, "It depends."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

120x160 = 19200 pixels

If you are writing a single colour to the whole screen:
~ 20 SPI bytes to set up screen window.
+ 19200 x 2 bytes to write a single 16-bit colour to each pixel.

The same numbers apply for blitting a pattern from disk or RAM.

Your Arduino can do 8MHz SPI (1us per byte). So the theoretical fillScreen() is 39ms.

Note that the AVR SPI is pants. You can't write continuously without gaps.
If you use the AVR USART_MSPI, you can achieve the theoretical.

Quite honestly, 19k pixels never have a speed problem. A regular ILI9320 240x320 has 77k pixels, and there are some big 7" TFT displays with massive numbers of pixels. An AVR is noticeably slow.

Bit-banging SPI via Arduino digitalWrite() will make you cry. Even if you use optimised ASM, you can't get near the hardware speeds.

Oh, and if you write each pixel with drawPixel(), it will be about 9 16-bit SPIs per pixel.

Numbers are guesswork. I may verify them later.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the help. Here's the code.

ST7735.c:

#include 
#include 
#include 
#include "ST7735.h"

#define  cbi(sfr, bit) (sfr &= ~_BV(bit))
#define  sbi(sfr, bit) (sfr |= _BV(bit))
#define  tbi(a, b) ((a) & (1<<(b)))

void Tick(uint16_t i)
{
	while(--i);
}

void TFTIOInit()
{
	/* CLK   = Output
	 * DOUT  = Output
	 * CS    = Output
	 * RS    = Output
	 * BL    = Output
	 *
	 */

	sbi(TFT_CLK_DDR, TFT_CLK_PIN);
	sbi(TFT_DOUT_DDR, TFT_DOUT_PIN);
	sbi(TFT_CS_DDR, TFT_CS_PIN);
	sbi(TFT_RS_DDR, TFT_RS_PIN);
	sbi(TFT_BL_DDR, TFT_BL_PIN);

	sbi(TFT_CS_PORT, TFT_CS_PIN);
	cbi(TFT_CLK_PORT, TFT_CLK_PIN);
	cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
	cbi(TFT_RS_PORT, TFT_RS_PIN);
	cbi(TFT_BL_PORT, TFT_BL_PIN);

	return;
}

void TFTBackLight(bool state)
{
	if(state) sbi(TFT_BL_PORT, TFT_BL_PIN);
	else cbi(TFT_BL_PORT, TFT_BL_PIN);
}

void TFTWriteCmd(uint8_t command)
{
	uint8_t i = 8;

	cbi(TFT_CS_PORT, TFT_CS_PIN);	/* Setup Chip Select */
	cbi(TFT_RS_PORT, TFT_RS_PIN);	/* R/S = 0 for Command */

	while(1) {
		i--;
		if tbi(command, i) sbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
		else cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);

		cbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Setup the Clock */
		sbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Reset the Clock */
		if(i == 0)break;
	}

	sbi(TFT_CS_PORT, TFT_CS_PIN);	/* Deselect Chip Select */

	return;
}

void TFTWriteData(uint8_t data)
{
	uint8_t i = 8;

	cbi(TFT_CS_PORT, TFT_CS_PIN);	/* Setup Chip Select */
	sbi(TFT_RS_PORT, TFT_RS_PIN);	/* R/S = 1 for Command */

	while(1) {
			i--;
			if tbi(data, i) sbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
			else cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);

			cbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Setup the Clock */
			sbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Reset the Clock */
			if(i == 0)break;
	}

	sbi(TFT_CS_PORT, TFT_CS_PIN);	/* Deselect Chip Select */

	return;
}

void TFTInit()
{

	TFTIOInit();

	TFTWriteCmd(ST7735_SWRESET); // software reset
	Tick(50);
	TFTWriteCmd(ST7735_SLPOUT);  // out of sleep mode
	Tick(500);

	TFTWriteCmd(ST7735_COLMOD);  // set color mode
	TFTWriteData(0x05);          // 16-bit color
	Tick(10);

	TFTWriteCmd(ST7735_FRMCTR1); // frame rate control
	TFTWriteData(0x00);          // fastest refresh
	TFTWriteData(0x06);          // 6 lines front porch
	TFTWriteData(0x03);          // 3 lines backporch
	Tick(10);

	TFTWriteCmd(ST7735_MADCTL);  // memory access control (directions)
	TFTWriteData(0xC8);          // row address/col address, bottom to top refresh

	TFTWriteCmd(ST7735_DISSET5); // display settings #5
	TFTWriteData(0x15);          // 1 clock cycle nonoverlap, 2 cycle gate rise, 3 cycle oscil. equalize
	TFTWriteData(0x02);          // fix on VTL

	TFTWriteCmd(ST7735_INVCTR);  // display inversion control
	TFTWriteData(0x0);           // line inversion
/*
	TFTWriteCmd(ST7735_PWCTR1);  // power control
	TFTWriteData(0x02);          // GVDD = 4.7V
	TFTWriteData(0x70);          // 1.0uA
	Tick(10);
	TFTWriteCmd(ST7735_PWCTR2);  // power control
	TFTWriteData(0x05);          // VGH = 14.7V, VGL = -7.35V
	TFTWriteCmd(ST7735_PWCTR3);  // power control
	TFTWriteData(0x01);          // Opamp current small
	TFTWriteData(0x02);          // Boost frequency


	TFTWriteCmd(ST7735_VMCTR1);  // power control
	TFTWriteData(0x3C);          // VCOMH = 4V
	TFTWriteData(0x38);          // VCOML = -1.1V
	Tick(10);

	TFTWriteCmd(ST7735_PWCTR6);  // power control
	TFTWriteData(0x11);
	TFTWriteData(0x15);
*/
	TFTWriteCmd(ST7735_GMCTRP1);
	TFTWriteData(0x09);
	TFTWriteData(0x16);
	TFTWriteData(0x09);
	TFTWriteData(0x20);
	TFTWriteData(0x21);
	TFTWriteData(0x1B);
	TFTWriteData(0x13);
	TFTWriteData(0x19);
	TFTWriteData(0x17);
	TFTWriteData(0x15);
	TFTWriteData(0x1E);
	TFTWriteData(0x2B);
	TFTWriteData(0x04);
	TFTWriteData(0x05);
	TFTWriteData(0x02);
	TFTWriteData(0x0E);
	TFTWriteCmd(ST7735_GMCTRN1);
	TFTWriteData(0x0B);
	TFTWriteData(0x14);
	TFTWriteData(0x08);
	TFTWriteData(0x1E);
	TFTWriteData(0x22);
	TFTWriteData(0x1D);
	TFTWriteData(0x18);
	TFTWriteData(0x1E);
	TFTWriteData(0x1B);
	TFTWriteData(0x1A);
	TFTWriteData(0x24);
	TFTWriteData(0x2B);
	TFTWriteData(0x06);
	TFTWriteData(0x06);
	TFTWriteData(0x02);
	TFTWriteData(0x0F);
	Tick(10);
/*
	TFTWriteCmd(ST7735_CASET);	/* Set window area X
	TFTWriteData(0x00);
	TFTWriteData(0x02);
	TFTWriteData(0x00);
	TFTWriteData(0x81);

	TFTWriteCmd(ST7735_RASET);	/* Set window area Y
	TFTWriteData(0x00);
	TFTWriteData(0x02);
	TFTWriteData(0x00);
	TFTWriteData(0x81);
*/
	TFTWriteCmd(ST7735_NORON);   // normal display on
	Tick(10);

	TFTWriteCmd(ST7735_DISPON);
	Tick(500);

	TFTBackLight(1);

}

void TFTSetWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
{
	TFTWriteCmd(ST7735_CASET);   /* col address command */
	TFTWriteData(0x00);
	TFTWriteData(x0);          /* X Start */
	TFTWriteData(0x00);
	TFTWriteData(x1);          /* X end */

	TFTWriteCmd(ST7735_RASET);   /* row address command */
	TFTWriteData(0x00);
	TFTWriteData(y0);          /* Y Start */
	TFTWriteData(0x00);
	TFTWriteData(y1);          /* Y end */
}

void TFTPixel(uint16_t x, uint16_t y, uint16_t color)
{
	TFTSetWindow(x, y, x , y);
	TFTWriteCmd(ST7735_RAMWR);		/* RAM Access */
	TFTWriteData(color >> 8);
	TFTWriteData(color);
}

st7735.h:

#ifndef ST7735_H_
#define ST7735_H_

#include 

#define TFT_CLK_PORT	PORTB
#define TFT_CLK_PIN		5
#define TFT_CLK_DDR		DDRB
#define TFT_DOUT_PORT	PORTB
#define TFT_DOUT_PIN	3
#define TFT_DOUT_DDR	DDRB
#define TFT_CS_PORT		PORTB
#define TFT_CS_PIN		2
#define TFT_CS_DDR		DDRB
#define TFT_RS_PORT		PORTB
#define TFT_RS_PIN		0
#define TFT_RS_DDR		DDRB
#define TFT_BL_PORT		PORTB
#define TFT_BL_PIN		1
#define TFT_BL_DDR		DDRB

#define ST7735_NOP      (0x0)
#define ST7735_SWRESET  (0x01)
#define ST7735_SLPIN    (0x10)
#define ST7735_SLPOUT   (0x11)
#define ST7735_PTLON    (0x12)
#define ST7735_NORON    (0x13)
#define ST7735_INVOFF   (0x20)
#define ST7735_INVON    (0x21)
#define ST7735_DISPON   (0x29)
#define ST7735_CASET    (0x2A)
#define ST7735_RASET    (0x2B)
#define ST7735_RAMWR    (0x2C)
#define ST7735_COLMOD   (0x3A)
#define ST7735_MADCTL   (0x36)
#define ST7735_FRMCTR1  (0xB1)
#define ST7735_INVCTR   (0xB4)
#define ST7735_DISSET5  (0xB6)
#define ST7735_PWCTR1   (0xC0)
#define ST7735_PWCTR2   (0xC1)
#define ST7735_PWCTR3   (0xC2)
#define ST7735_VMCTR1   (0xC5)
#define ST7735_PWCTR6   (0xFC)
#define ST7735_GMCTRP1  (0xE0)
#define ST7735_GMCTRN1  (0xE1)

void Tick(uint16_t i);
void TFTBackLight(bool state);
void TFTWriteCmd(uint8_t command);
void TFTWriteData(uint8_t data);
void TFTInit();
void TFTIOInit();
void TFTSetWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
void TFTPixel(uint16_t x, uint16_t y, uint16_t color);

#endif /* ST7735_H_ */

testtft.c:

#include 
#include 
#include "ST7735.h"

int main()
{

	int x, y, z;

	TFTInit();

	TFTSetWindow(0, 0, 128, 160);

for(z = 0; z < 65535; z=z+100) {

	for(y = 0; y < 160; y++) {
		for(x = 0; x < 128; x++) {
			TFTPixel(x, y, z);
		}
	}

}

	while(1) {
		//TFTBackLight(0);
		//_delay_ms(3000);
		//TFTBackLight(1);
		//_delay_ms(3000);
	}



}


Thanks for looking.

Regards,
Darren.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are bit-bashing the SPI. From memory, you can only get about 2MHz throughput with that C.

You are also writing each Pixel individually. i.e. setting X, Y
The whole point of the TFT controllers is that you can set a rectangular "window". Then blit each pixel with the 16-bit colour.

I presume that your shield came with example code. I presume that the shield pins default to the SPI pins. e.g. you get 'slow' and 'fast' examples from Adafruit.

Adafruit have excellent libraries.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David. Many thanks.

I'm going to convert to SPI hardware mode and do window access. I'll get back to you.

Forgive me for being dense but how do you arrive at 2meg for bit banging?

Thanks for your help.
Darren.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just built your project. (a few changes for my hardware and compiler)
It is certainly SLOW !

Add a blit function:

void TFTblit(uint16_t color, uint16_t len)
{
    uint16_t mask;

    TFTWriteCmd(ST7735_RAMWR);  /* RAM Access */

    cbi(TFT_CS_PORT, TFT_CS_PIN);       /* Setup Chip Select */
    sbi(TFT_RS_PORT, TFT_RS_PIN);       /* R/S = 1 for Data */

    while (len--) {
        for (mask = 0x8000; mask != 0; mask >>= 1) {
            if (color & mask)
                sbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
            else
                cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);

            cbi(TFT_CLK_PORT, TFT_CLK_PIN);     /* Setup the Clock */
            sbi(TFT_CLK_PORT, TFT_CLK_PIN);     /* Reset the Clock */
        }
    }

    sbi(TFT_CS_PORT, TFT_CS_PIN);       /* Deselect Chip Select */

    return;
}

or simply extend your drawPixel() to write multiple.

void TFTPixelrpt(uint16_t x, uint16_t y, uint16_t color, uint16_t len)
{
   TFTSetWindow(x, y, 127, 159);
   TFTWriteCmd(ST7735_RAMWR);      /* RAM Access */
   while (len--) {
      TFTWriteData(color >> 8);
      TFTWriteData(color);
   }
}

The blit method is preferable. You can draw filled rectangles of any size. (determined by setWindow() coordinates)

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Done the blit mode - certainly makes a difference

Still bit bashing - having trouble getting it to work with hardware mode - the display just sits there doing nothing but it's not getting stuck at the check the byte transmitted while loop for a change.

Might need help with this after I've tried a few other things.

Regards,
Darren

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Darren,
I have a few questions. Regarding the Bit-Banging:
even if you optimize your code 100% , you still need to make sure that the system clock IS actually 16MHZ (check prescalers etc.)
Also You might have some fuses wrong... like CLK/8, or clock source. SO have you actually verified that the core is runing @16MHz?

About the HW spi now, are you using some ASF or other Library? Could it be that the CS is not set correctly, and the LCD is never selected? Have you got any means of checking the actuall pin levels while sending SPI?

Alex

There are 10 kinds of people... those who digg binary and those who don't

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay, I give up!

The h/w SPI isn't working... the display just sits there but the signals are still clocking away.

Can anyone shed some light?

#include 
#include 
#include 
#include "ST7735.h"

#define  cbi(sfr, bit) (sfr &= ~_BV(bit))
#define  sbi(sfr, bit) (sfr |= _BV(bit))
#define  tbi(a, b) ((a) & (1<<(b)))

void Tick(uint16_t i)
{
	while(--i);
}

void TFTIOInit()
{
	/* CLK   = Output
	 * DOUT  = Output
	 * CS    = Output
	 * RS    = Output
	 * BL    = Output
	 *
	 */

	sbi(TFT_CLK_DDR, TFT_CLK_PIN);
	sbi(TFT_DOUT_DDR, TFT_DOUT_PIN);
	sbi(TFT_CS_DDR, TFT_CS_PIN);
	sbi(TFT_RS_DDR, TFT_RS_PIN);
	sbi(TFT_BL_DDR, TFT_BL_PIN);
	cbi(PORTB, PINB4);

	sbi(TFT_CS_PORT, TFT_CS_PIN);
	//cbi(TFT_CLK_PORT, TFT_CLK_PIN);
	//cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
	cbi(TFT_RS_PORT, TFT_RS_PIN);
	cbi(TFT_BL_PORT, TFT_BL_PIN);

	return;
}

void TFTSPIInit()
{
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
	//SPSR = (1<<SPI2X);
}

void TFTBackLight(bool state)
{
	if(state) sbi(TFT_BL_PORT, TFT_BL_PIN);
	else cbi(TFT_BL_PORT, TFT_BL_PIN);
}


void TFTWriteCmdBB(uint8_t command)
{
	uint8_t i = 8;

	cbi(TFT_CS_PORT, TFT_CS_PIN);	/* Setup Chip Select */
	cbi(TFT_RS_PORT, TFT_RS_PIN);	/* R/S = 0 for Command */

	while(1) {
		i--;
		if tbi(command, i) sbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
		else cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);

		cbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Setup the Clock */
		sbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Reset the Clock */
		if(i == 0)break;
	}

	sbi(TFT_CS_PORT, TFT_CS_PIN);	/* Deselect Chip Select */

	return;
}

void TFTWriteDataBB(uint8_t data)
{
	uint8_t i = 8;

	cbi(TFT_CS_PORT, TFT_CS_PIN);	/* Setup Chip Select */
	sbi(TFT_RS_PORT, TFT_RS_PIN);	/* R/S = 1 for Command */

	while(1) {
			i--;
		 	if tbi(data, i) sbi(TFT_DOUT_PORT, TFT_DOUT_PIN);
			else cbi(TFT_DOUT_PORT, TFT_DOUT_PIN);

			cbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Setup the Clock */
			sbi(TFT_CLK_PORT, TFT_CLK_PIN);		/* Reset the Clock */
			if(i == 0)break;
	}

	sbi(TFT_CS_PORT, TFT_CS_PIN);	/* Deselect Chip Select */

	return;
}

void TFTWriteCmd(uint8_t command)
{
	cbi(TFT_CS_PORT, TFT_CS_PIN);	/* Setup Chip Select */
	sbi(TFT_RS_PORT, TFT_RS_PIN);	/* R/S = 1 for Command */

	Tick(10);
	SPDR = command;
	while(!(SPSR & (1<<SPIF)));
	Tick(10);
	sbi(TFT_CS_PORT, TFT_CS_PIN);	/* reset Chip Select */

	return;
}

void TFTWriteData(uint8_t data)
{
	cbi(TFT_CS_PORT, TFT_CS_PIN);	/* Setup Chip Select */
	cbi(TFT_RS_PORT, TFT_RS_PIN);	/* R/S = 0 for data */

	Tick(10);
	SPDR = data;
	while(!(SPSR & (1<<SPIF)));
	Tick(10);
	sbi(TFT_CS_PORT, TFT_CS_PIN);	/* reset Chip Select */

	return;
}

void TFTInit()
{

	TFTIOInit();
	TFTSPIInit();

	TFTWriteCmd(ST7735_SWRESET); // software reset
	Tick(50);
	TFTWriteCmd(ST7735_SLPOUT);  // out of sleep mode
	Tick(500);

	TFTWriteCmd(ST7735_COLMOD);  // set color mode
	TFTWriteData(0x05);          // 16-bit color
	Tick(10);

	TFTWriteCmd(ST7735_FRMCTR1); // frame rate control
	TFTWriteData(0x00);          // fastest refresh
	TFTWriteData(0x06);          // 6 lines front porch
	TFTWriteData(0x03);          // 3 lines backporch
	Tick(10);

	TFTWriteCmd(ST7735_MADCTL);  // memory access control (directions)
	TFTWriteData(0xC8);          // row address/col address, bottom to top refresh

	TFTWriteCmd(ST7735_DISSET5); // display settings #5
	TFTWriteData(0x15);          // 1 clock cycle nonoverlap, 2 cycle gate rise, 3 cycle oscil. equalize
	TFTWriteData(0x02);          // fix on VTL

	TFTWriteCmd(ST7735_INVCTR);  // display inversion control
	TFTWriteData(0x0);           // line inversion
/*
	TFTWriteCmd(ST7735_PWCTR1);  // power control
	TFTWriteData(0x02);          // GVDD = 4.7V
	TFTWriteData(0x70);          // 1.0uA
	Tick(10);
	TFTWriteCmd(ST7735_PWCTR2);  // power control
	TFTWriteData(0x05);          // VGH = 14.7V, VGL = -7.35V
	TFTWriteCmd(ST7735_PWCTR3);  // power control
	TFTWriteData(0x01);          // Opamp current small
	TFTWriteData(0x02);          // Boost frequency


	TFTWriteCmd(ST7735_VMCTR1);  // power control
	TFTWriteData(0x3C);          // VCOMH = 4V
	TFTWriteData(0x38);          // VCOML = -1.1V
	Tick(10);

	TFTWriteCmd(ST7735_PWCTR6);  // power control
	TFTWriteData(0x11);
	TFTWriteData(0x15);
*/
	TFTWriteCmd(ST7735_GMCTRP1);
	TFTWriteData(0x09);
	TFTWriteData(0x16);
	TFTWriteData(0x09);
	TFTWriteData(0x20);
	TFTWriteData(0x21);
	TFTWriteData(0x1B);
	TFTWriteData(0x13);
	TFTWriteData(0x19);
	TFTWriteData(0x17);
	TFTWriteData(0x15);
	TFTWriteData(0x1E);
	TFTWriteData(0x2B);
	TFTWriteData(0x04);
	TFTWriteData(0x05);
	TFTWriteData(0x02);
	TFTWriteData(0x0E);
	TFTWriteCmd(ST7735_GMCTRN1);
	TFTWriteData(0x0B);
	TFTWriteData(0x14);
	TFTWriteData(0x08);
	TFTWriteData(0x1E);
	TFTWriteData(0x22);
	TFTWriteData(0x1D);
	TFTWriteData(0x18);
	TFTWriteData(0x1E);
	TFTWriteData(0x1B);
	TFTWriteData(0x1A);
	TFTWriteData(0x24);
	TFTWriteData(0x2B);
	TFTWriteData(0x06);
	TFTWriteData(0x06);
	TFTWriteData(0x02);
	TFTWriteData(0x0F);
	Tick(10);
/*
	TFTWriteCmd(ST7735_CASET);	/* Set window area X
	TFTWriteData(0x00);
	TFTWriteData(0x02);
	TFTWriteData(0x00);
	TFTWriteData(0x81);

	TFTWriteCmd(ST7735_RASET);	/* Set window area Y
	TFTWriteData(0x00);
	TFTWriteData(0x02);
	TFTWriteData(0x00);
	TFTWriteData(0x81);
*/
	TFTWriteCmd(ST7735_NORON);   // normal display on
	Tick(10);

	TFTWriteCmd(ST7735_DISPON);
	Tick(500);

	TFTBackLight(1);

}

void TFTSetWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
{
	TFTWriteCmd(ST7735_CASET);   /* col address command */
	TFTWriteData(0x00);
	TFTWriteData(x0);          /* X Start */
	TFTWriteData(0x00);
	TFTWriteData(x1);          /* X end */

	TFTWriteCmd(ST7735_RASET);   /* row address command */
	TFTWriteData(0x00);
	TFTWriteData(y0);          /* Y Start */
	TFTWriteData(0x00);
	TFTWriteData(y1);          /* Y end */
}

void TFTPixel(uint16_t x, uint16_t y, uint16_t color)
{
//	TFTSetWindow(x, y, x , y);
//	TFTWriteCmd(ST7735_RAMWR);		/* RAM Access */
	TFTWriteData(color >> 8);
	TFTWriteData(color);
}

test (main):

#include 
#include 
#include "ST7735.h"
#include 


int main()
{

	int x, y, z;


	TFTInit();

	TFTSetWindow(0, 0, 127, 159);
	   TFTWriteCmd(ST7735_RAMWR);      /* RAM Access */


for(z = 0; z < 65535; z=z+100) {

	for(y = 0; y < 159; y++) {
		for(x = 0; x < 127; x++) {
			TFTPixel(x, y, z);
		}
	}

}

	while(1) {
		//TFTBackLight(0);
		//_delay_ms(3000);
		//TFTBackLight(1);
		//_delay_ms(3000);
	}



}

Any help is highly appreciated.

Regards,
Darren

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Alex,

Well, the F_CPU is set to 16000000 and the _delay_xs() functions are spot on, in terms of timing so I assume the system is running at 16. I have not modified the fuses from whatever they are set at on the Arduino by default.

Yes, I can see the signals on a scope but I don't have a desktop scope with me at the moment so it's hard to see the exact timing. However, it appears to be okay.

I'm not using any SPI libraries, just straight to the registers as there's only one I really need to set as well as wring to the SPI data reg.

Hope you can help...

Darren.

Pages