Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SPI_TFT_ILI9341 by
Revision 1:6d6125e88de7, committed 2013-06-13
- Comitter:
- dreschpe
- Date:
- Thu Jun 13 19:54:24 2013 +0000
- Parent:
- 0:da1bf437cbc1
- Child:
- 2:0a16083193a4
- Commit message:
- Init sequence changed based on MI0283QT datasheet
Changed in this revision
| SPI_TFT_ILI9341.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SPI_TFT_ILI9341.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SPI_TFT_ILI9341.cpp Wed Jun 12 22:54:38 2013 +0000
+++ b/SPI_TFT_ILI9341.cpp Thu Jun 13 19:54:24 2013 +0000
@@ -98,66 +98,165 @@
+// Init code based on MI0283QT datasheet
+
void SPI_TFT_ILI9341::tft_reset()
{
- //static unsigned short driverCode;
_spi.format(8,3); // 8 bit spi mode 3
- _spi.frequency(12000000); // 12 Mhz SPI clock
+ _spi.frequency(10000000); // 10 Mhz SPI clock
_cs = 1; // cs high
_dc = 1; // dc high
_reset = 0; // display reset
wait_us(50);
- _reset = 1; // end reset
+ _reset = 1; // end hardware reset
wait_ms(5);
+
+ wr_cmd(0x01); // SW reset
+ wait_ms(5);
+ wr_cmd(0x28); // display off
/* Start Initial Sequence ----------------------------------------------------*/
- wr_cmd(0xCD); // Power Control A
+ wr_cmd(0xCF);
+ _spi.write(0x00);
+ _spi.write(0x83);
+ _spi.write(0x30);
+ _cs = 1;
+
+ wr_cmd(0xED);
+ _spi.write(0x64);
+ _spi.write(0x03);
+ _spi.write(0x12);
+ _spi.write(0x81);
+ _cs = 1;
+
+ wr_cmd(0xE8);
+ _spi.write(0x85);
+ _spi.write(0x01);
+ _spi.write(0x79);
+ _cs = 1;
+
+ wr_cmd(0xCB);
_spi.write(0x39);
_spi.write(0x2C);
_spi.write(0x00);
_spi.write(0x34);
_spi.write(0x02);
_cs = 1;
-
- wr_cmd(0xCF); // Power Control B
- _spi.write(0x00);
- _spi.write(0xAA);
- _spi.write(0xB0);
+
+ wr_cmd(0xF7);
+ _spi.write(0x20);
_cs = 1;
- wr_cmd(0xF7); // CMD_PUMP_RATIO_CONTROL
- _spi.write(0x30);
+
+ wr_cmd(0xEA);
+ _spi.write(0x00);
+ _spi.write(0x00);
_cs = 1;
+
wr_cmd(0xC0); // POWER_CONTROL_1
- _spi.write(0x25);
+ _spi.write(0x26);
_cs = 1;
+
wr_cmd(0xC1); // POWER_CONTROL_2
_spi.write(0x11);
_cs = 1;
+
wr_cmd(0xC5); // VCOM_CONTROL_1
- _spi.write(0x5C);
- _spi.write(0x4C);
+ _spi.write(0x35);
+ _spi.write(0x3E);
_cs = 1;
+
wr_cmd(0xC7); // VCOM_CONTROL_2
- _spi.write(0x94);
- _cs = 1;
- wr_cmd(0xE8); // DRIVER_TIMING_CONTROL_A
- _spi.write(0x85);
- _spi.write(0x01);
- _spi.write(0x78);
+ _spi.write(0xBE);
_cs = 1;
- wr_cmd(0xEA); // DRIVER_TIMING_CONTROL_B
- _spi.write(0x00);
- _spi.write(0x00);
- _cs = 1;
- wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET
- _spi.write(0x05);
- _cs = 1;
+
wr_cmd(0x36); // MEMORY_ACCESS_CONTROL
_spi.write(0x48);
_cs = 1;
- WindowMax ();
-}
+
+ wr_cmd(0x3A); // COLMOD_PIXEL_FORMAT_SET
+ _spi.write(0x55); // 16 bit pixel
+ _cs = 1;
+
+ wr_cmd(0xB1); // Frame Rate
+ _spi.write(0x00);
+ _spi.write(0x1B);
+ _cs = 1;
+
+ wr_cmd(0xF2); // Gamma Function Disable
+ _spi.write(0x08);
+ _cs = 1;
+
+ wr_cmd(0x26);
+ _spi.write(0x01); // gamma set for curve 01/2/04/08
+ _cs = 1;
+
+ wr_cmd(0xE0); // positive gamma correction
+ _spi.write(0x1F);
+ _spi.write(0x1A);
+ _spi.write(0x18);
+ _spi.write(0x0A);
+ _spi.write(0x0F);
+ _spi.write(0x06);
+ _spi.write(0x45);
+ _spi.write(0x87);
+ _spi.write(0x32);
+ _spi.write(0x0A);
+ _spi.write(0x07);
+ _spi.write(0x02);
+ _spi.write(0x07);
+ _spi.write(0x05);
+ _spi.write(0x00);
+ _cs = 1;
+
+ wr_cmd(0xE1); // negativ gamma correction
+ _spi.write(0x00);
+ _spi.write(0x25);
+ _spi.write(0x27);
+ _spi.write(0x05);
+ _spi.write(0x10);
+ _spi.write(0x09);
+ _spi.write(0x3A);
+ _spi.write(0x78);
+ _spi.write(0x4D);
+ _spi.write(0x05);
+ _spi.write(0x18);
+ _spi.write(0x0D);
+ _spi.write(0x38);
+ _spi.write(0x3A);
+ _spi.write(0x1F);
+ _cs = 1;
+
+ WindowMax ();
+
+ //wr_cmd(0x34); // tearing effect off
+ //_cs = 1;
+
+ //wr_cmd(0x35); // tearing effect on
+ //_cs = 1;
+
+ wr_cmd(0xB7); // entry mode
+ _spi.write(0x07);
+ _cs = 1;
+
+ wr_cmd(0xB6); // display function control
+ _spi.write(0x0A);
+ _spi.write(0x82);
+ _spi.write(0x27);
+ _spi.write(0x00);
+ _cs = 1;
+
+ wr_cmd(0x11); // sleep out
+ _cs = 1;
+
+ wait_ms(100);
+
+ wr_cmd(0x29); // display on
+ _cs = 1;
+
+ wait_ms(100);
+
+ }
void SPI_TFT_ILI9341::pixel(int x, int y, int color)
--- a/SPI_TFT_ILI9341.h Wed Jun 12 22:54:38 2013 +0000
+++ b/SPI_TFT_ILI9341.h Thu Jun 13 19:54:24 2013 +0000
@@ -58,7 +58,7 @@
*
*
* // the TFT is connected to SPI pin 5-7
- * SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p15,"TFT"); // mosi, miso, sclk, cs, reset
+ * SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
*
* int main() {
* TFT.claim(stdout); // send stdout to the TFT display
@@ -70,7 +70,6 @@
* TFT.set_font((unsigned char*) Arial12x12); // select the font
*
* TFT.set_orientation(0);
- * TFT.locate(0,0);
* printf(" Hello Mbed 0");
* TFT.set_font((unsigned char*) Arial24x23); // select font 2
* TFT.locate(48,115);
@@ -81,12 +80,15 @@
class SPI_TFT_ILI9341 : public GraphicsDisplay {
public:
- /** Create a SPI_TFT object connected to SPI and two pins
+ /** Create a SPI_TFT object connected to SPI and three pins
*
- * @param mosi,miso,sclk SPI
+ * @param mosi pin connected to SDO of display
+ * @param miso pin connected to SDI of display
+ * @param sclk pin connected to RS of display
* @param cs pin connected to CS of display
* @param reset pin connected to RESET of display
- *
+ * @param dc pin connected to WR of display
+ * the IM pins have to be set to 1110 (3-0)
*/
SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
