Example for the ILI9341 display usage

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
codebreaker7
Date:
Sun Nov 05 14:51:21 2017 +0000
Parent:
1:cdeae0693b01
Commit message:
Updated to work with display correctly

Changed in this revision

ILI9341_Init.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r cdeae0693b01 -r 82f5f57eac91 ILI9341_Init.h
--- a/ILI9341_Init.h	Sun Oct 29 09:34:33 2017 +0000
+++ b/ILI9341_Init.h	Sun Nov 05 14:51:21 2017 +0000
@@ -6,114 +6,90 @@
 // See ST7735_Setup.h file for an alternative format
 
 {
-  writecommand(0xEF);
-  writedata(0x03);
-  writedata(0x80);
-  writedata(0x02);
-
-  writecommand(0xCF);
+  writecommand(0x01);
+  wait(0.01);
+  writecommand(0x11);
+  wait(0.01);
+  
+  writecommand(0x3a);
+  writedata(0x05);
+  
+  writecommand(0x26);
+  writedata(0x04);
+  
+  writecommand(0xf2);
+  writedata(0x01);
+  
+  writecommand(0xE0);
+  writedata(0x3f);
+  writedata(0x25);
+  writedata(0x1c);
+  writedata(0x1e);
+  writedata(0x20);
+  writedata(0x12);
+  writedata(0x2a);
+  writedata(0x90);
+  writedata(0x24);
+  writedata(0x11);
   writedata(0x00);
-  writedata(0XC1);
-  writedata(0X30);
-
-  writecommand(0xED);
-  writedata(0x64);
-  writedata(0x03);
-  writedata(0X12);
-  writedata(0X81);
-
-  writecommand(0xE8);
-  writedata(0x85);
   writedata(0x00);
-  writedata(0x78);
-
-  writecommand(0xCB);
-  writedata(0x39);
-  writedata(0x2C);
   writedata(0x00);
-  writedata(0x34);
-  writedata(0x02);
-
-  writecommand(0xF7);
-  writedata(0x20);
-
-  writecommand(0xEA);
   writedata(0x00);
   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]
-
-  writecommand(ILI9341_VMCTR1);    //VCM control
-  writedata(0x3e);
-  writedata(0x28);
-
-  writecommand(ILI9341_VMCTR2);    //VCM control2
-  writedata(0x86);  //--
-
-  writecommand(ILI9341_MADCTL);    // Memory Access Control
-  writedata(0x48);
-
-  writecommand(ILI9341_PIXFMT);
-  writedata(0x55);
-
-  writecommand(ILI9341_FRMCTR1);
-  writedata(0x00);
-  writedata(0x13); // 0x18 79Hz, 0x1B default 70Hz, 0x13 100Hz
-
-  writecommand(ILI9341_DFUNCTR);    // Display Function Control
-  writedata(0x08);
-  writedata(0x82);
-  writedata(0x27);
-
-  writecommand(0xF2);    // 3Gamma Function Disable
+  
+  writecommand(0xE1);
+  writedata(0x20);
+  writedata(0x20);
+  writedata(0x20);
+  writedata(0x20);
+  writedata(0x05);
   writedata(0x00);
-
-  writecommand(ILI9341_GAMMASET);    //Gamma curve selected
-  writedata(0x01);
-
-  writecommand(ILI9341_GMCTRP1);    //Set Gamma
-  writedata(0x0F);
-  writedata(0x31);
-  writedata(0x2B);
-  writedata(0x0C);
-  writedata(0x0E);
+  writedata(0x15);
+  writedata(0xa7);
+  writedata(0x3d);
+  writedata(0x18);
+  writedata(0x25);
+  writedata(0x2a);
+  writedata(0x2b);
+  writedata(0x2b);
+  writedata(0x3a);
+  
+  writecommand(0xb1);
+  writedata(0x08);
   writedata(0x08);
-  writedata(0x4E);
-  writedata(0xF1);
-  writedata(0x37);
+  
+  writecommand(0xb4);
   writedata(0x07);
-  writedata(0x10);
-  writedata(0x03);
-  writedata(0x0E);
-  writedata(0x09);
-  writedata(0x00);
-
-  writecommand(ILI9341_GMCTRN1);    //Set Gamma
+  
+  writecommand(0xc0);
+  writedata(0x0a);
+  writedata(0x02);
+  
+  writecommand(0xc1);
+  writedata(0x02);
+  
+  writecommand(0xc5);
+  writedata(0x50);
+  writedata(0x5b);
+  
+  writecommand(0xc7);
+  writedata(0x40);
+  
+  writecommand(0x2a);
   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);
-
-  writecommand(ILI9341_SLPOUT);    //Exit Sleep
- 
-  //spi_end();
-  wait_ms(120);
-  //spi_begin();
+  writedata(0x00);
+  writedata(0x00);
+  writedata(0x7f);
   
-  writecommand(ILI9341_DISPON);    //Display on
+  writecommand(0x2a);
+  writedata(0x00);
+  writedata(0x00);
+  writedata(0x00);
+  writedata(0x9f);
+  writedata(250);
+  
+  writecommand(0x36);
+  writedata(0xc8);
+  
+  writecommand(0x29);
 }
diff -r cdeae0693b01 -r 82f5f57eac91 main.cpp
--- a/main.cpp	Sun Oct 29 09:34:33 2017 +0000
+++ b/main.cpp	Sun Nov 05 14:51:21 2017 +0000
@@ -4,6 +4,8 @@
 SPI spi_dev(PB_15, PB_14, PB_13);
 DigitalOut cs(PC_4);
 DigitalOut ao(PB_3);
+uint8_t tarr[1024];
+uint8_t rarr[1024];
 
 void writecommand(uint8_t command) {
     cs = 0;
@@ -19,12 +21,37 @@
     cs = 1;
 }
 
+void setAddress(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
+    writecommand(0x2a);
+    writedata(0x00);
+    writedata(x1);
+    writedata(0x00);
+    writedata(x2);
+    writecommand(0x2b);
+    writedata(0x00);
+    writedata(y1);
+    writedata(0x00);
+    writedata(y2);
+    writecommand(0x2c);
+}
+
+void writeColorData(uint8_t * arr, int length) {
+    cs = 0;
+    ao = 1;
+    spi_dev.write((char*)arr, length, NULL, length);
+    cs = 1;
+}
+
 int main() {
     HAL_Init();
     #include "ILI9341_Init.h"
-    //cs = 0;
-    //cs = 1;
-    //cs = 0;
+    setAddress(0, 0, 127, 127);
+    for (int i = 0; i < 1024; i++) {
+        tarr[i] = 0;
+    }
+    for (int i = 0; i < 32; i++) {
+        writeColorData(tarr, 1024);
+    }
     while(1) {
     }
 }