Getting started with NHD-2.4-240320SF-CTXI#-FT1

Comments

26 comments

  • Michael_L

    I'm not sure how fast your micro is running, but you may need to add more delay after the hard reset.  I have posted some Arduino code below that illustrates this, along with the rest of the initialization, and how to write to the display.  Please try to match this code as close as you can, as it is 100% working code:

    //---------------------------------------------------------
    /*
    NHD_2_4_240320SF_CTXI_mega.ino
    Program for writing to Newhaven Display 2.4” TFT with ILI9341 controller

    (c)2014 Mike LaVine - Newhaven Display International, LLC.

            This program is free software; you can redistribute it and/or modify
            it under the terms of the GNU General Public License as published by
            the Free Software Foundation; either version 2 of the License, or
            (at your option) any later version.

            This program is distributed in the hope that it will be useful,
            but WITHOUT ANY WARRANTY; without even the implied warranty of
            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
            GNU General Public License for more details.
    */
    //---------------------------------------------------------

    // The 8 bit data bus is connected to PORTA of the Arduino Mega2560
    // 5V voltage regulator on Arduino Mega has been replaced with a 3.3V regulator to

    provide 3.3V logic

    int RS = 30;      // RS signal connected to Arduino digital pin 30
    int WR = 31;      // /WR signal connected to Arduino digital pin 31
    int RD = 32;      // /RD signal connected to Arduino digital pin 32
    int RES = 33;     // /RES signal connected to Arduino digital pin 33

    // /CS signal tied to GND
    // IM0 signal tied to VDD

    void comm_out(unsigned char c)
    {
      digitalWrite(RS, LOW);
      PORTA = c;
      digitalWrite(WR, LOW);
      digitalWrite(WR, HIGH);
    }

    void data_out(unsigned char d)
    {
      digitalWrite(RS, HIGH);
      PORTA = d;
      digitalWrite(WR, LOW);
      digitalWrite(WR, HIGH);
    }
    void disp()
    {
    unsigned int i;
    comm_out(0x2C);              //command to begin writing to frame memory
    for(i=0;i<38400;i++)         //fill screen with blue pixels
    {
        data_out(0x00);
                data_out(0x1F);
                data_out(0x00);
                data_out(0x1F);
    }
            for(i=0;i<38400;i++)         //fill screen with green pixels
    {
        data_out(0x07);
                data_out(0xE0);
                data_out(0x07);
                data_out(0xE0);
            }
    }

    void setup()
    {
      DDRC = 0xFF;   
      PORTC = 0x00;
      DDRA = 0xFF;
      PORTA = 0x00;
      digitalWrite(RD, HIGH);
      digitalWrite(WR, LOW);
      digitalWrite(RES, LOW);
      delay(250);
      digitalWrite(RES, HIGH);
      delay(250);
     
      comm_out(0x28);                                  //display off
      comm_out(0x11);  //exit SLEEP mode
     
      comm_out(0xCB);  //power control A
      data_out(0x39);
      data_out(0x2C);
      data_out(0x00);
      data_out(0x34);
      data_out(0x02);
     
      comm_out(0xCF);  //power control B
      data_out(0x00);
      data_out(0x81);
      data_out(0x30);
     
      comm_out(0xC0);
      data_out(0x26);  //power control 1
      data_out(0x04);  //second parameter for ILI9340 (ignored by ILI9341)
     
      comm_out(0xC1);
      data_out(0x11);                  //power control 2
     
      comm_out(0xC5);
      data_out(0x35);
      data_out(0x3E);  //VCOM control 1
     
      comm_out(0x36);
      data_out(0x88);                  //memory access control = BGR
     
      comm_out(0xB1);
      data_out(0x00);
      data_out(0x18);  //frame rate control
     
      comm_out(0xB6);
      data_out(0x0A);
      data_out(0xA2);  //display function control
     
      comm_out(0xC7);
      data_out(0xBE);                  //VCOM control 2
     
      comm_out(0x3A);
      data_out(0x55);                  //pixel format = 16 bit per pixel
     
      /*comm_out(0xE0);
      data_out(0x1F);                  //positive gamma correction
      data_out(0x1B);
      data_out(0x18);
      data_out(0x0B);
      data_out(0x0F);
      data_out(0x09);
      data_out(0x46);
      data_out(0xB5);
      data_out(0x37);
      data_out(0x0A);
      data_out(0x0C);
      data_out(0x07);
      data_out(0x07);
      data_out(0x05);
      data_out(0x00);
     
      comm_out(0xE1);
      data_out(0x00);                  //negative gamma correction
      data_out(0x24);
      data_out(0x27);
      data_out(0x04);
      data_out(0x10);
      data_out(0x06);
      data_out(0x39);
      data_out(0x74);
      data_out(0x48);
      data_out(0x05);
      data_out(0x13);
      data_out(0x38);
      data_out(0x38);
      data_out(0x3A);
      data_out(0x1F);*/
     
      comm_out(0xF2);                  //3g damma control
      data_out(0x02);                  //off
     
      comm_out(0x26);                  //gamma curve 3
      data_out(0x01);
     
      comm_out(0x2A);
      data_out(0x00);                  //column address set
      data_out(0x00);                  //start 0x0000
      data_out(0x00);
      data_out(0xEF);                  //end 0x00EF
     
      comm_out(0x2B);
      data_out(0x00);                  //page address set
      data_out(0x00);                  //start 0x0000
      data_out(0x01);
      data_out(0x3F);                  //end 0x003F
     
      comm_out(0x29);                  //display ON

      delay(10);
    }

    void loop()
    {
      disp();
      delay(1000);
    }

     

    0
  • sean

    Thanks Michael_L.  A quick question as I start to go through the code.  It uses RS.  This version of the display does not use an RS but a D/C (data or command).  It is a major change since the last version and all the commands are different.  It is using a ILI9341.  Am I correct that I can just change D/C when the code references RS?

    0
  • Michael_L

    Yes that is correct. The D/C and RS signals are interchangeable, and they represent the same pin.  Some of our displays call that pin RS, whereas others call it D/C, sorry for the confusion!

    0
  • sean

    I changed the code to match, very closely, to the code you posted.  I also matched the timer/delay (I am assuming that the number represents milliseconds).  I still do not get any response (any change visually) from the display.    I thought maybe I had wired it wrong.  So I checked the pinout on the data sheet against my schematic and it is the same.  Then I verified that I can change each of the following signals (to make sure there was not a break in the pcb): CS, DC, WR, RD, RST, D0:D8.  They all responded.  I checked this on the connector going to the display.

    I have attached a shot of the schematic.  Is it hooked up as you would expect?  I don't really know where to go from here.  I have two identical boards and they both are acting the same way, with the same version of code loaded.

    0
  • sean

    Michael_L: Is the schematic wired the way you would expect in order to make the code you provided work?

    0
  • Michael_L

    Yes the schematic looks good.  Do you see the backlight turn on when you apply power?

    0
  • sean

    Yes,  I can adjust the brightness of the backlight using the two transistors.  Yesterday I ohmed out all the grounds at the connector and then measured all the power lines. Every connection looks like it is good.  Do you have any suggestions on what I could try?

    0
  • Michael_L

    Not anything I can think of.  The code I sent you is confirmed to work, and your schematic looks fine.  How fast is your micro running?  Do you have another display you can try?  What do you see on the display when it is powered on?

    0
  • sean

    The micro is running at 30 Mhz.  I am transferring at about 150 Khz on the data line (6.72 uS per bit).  When I power on the backlight comes on but I never see anything on the display.

    0
  • Michael_L

    Thank you, I just wanted to make sure you micro wasn't running too fast for the code I sent to work.  What exactly do you see on the display?  All white screen? Any lines or colors?
    Please double check that you have matched the code I sent in terms of initialization (the order and the values), my write functions, and how I am writing to the display.

    0
  • sean

    The display is basically white. There are no colors.  Nothing is ever displayed on the screen.  I have gone through the code I am using again and very carefully compared it to the code you said works.  I think it is the same but I am going to put down my code here so I am being clear as to what I am doing.


    Setting up the ports is done in MCU initialization and is not shown.

    In main.c  the backlight is turned on and the LCD initialized
    // Set up LCD
      LCD_BACKLIGHT_ON;
      init_lcd();

    Then the program loops forever waiting for a command from the user. In this case the letter ‘L’.
    //=======================================================
    //LCD
    //=======================================================

    else if (c == 'L'|| c == 'l')
    {
       putstring1("Write blue and green to screen then loop\n");
       putstring1("Power cycle to exit\n");
       loopL:
       display();
       waitsome(1000);
       goto loopL;
    }



    This is the wait routine.  Millisecond counter, but even ms only:
    void waitsome (uint16_t lev)
    {
       // Each count is 2 ms; e.g. lev=50 is 100ms.
       // Write lev as the ms you want let the code divide by 2
       extern uint16_t P;
       P=0;
       while (P< (lev/2));// 2 ms/count
     
    }

    Write a command:
    // Write a command to the LCD Controller
    void LCD_CMD (uint8_t cmd)
    {
      LCD_DC0;            // This is a Command
      LCD_DATA_SET(cmd);   // Command index
      LCD_WR0;
      LCD_WR1;            // Data latched on rising edge
         // (8080 parallel interface). Minimum data setup and hold time is
            // 10ns and 15ns respectively. Shouldn't need NOP through 100 MHz
          // unless capacitance is high (>30pF) on data bus/control lines
      LCD_DC1;            // Default to argument/data      
    }

    Write data:
    // Write byte argument (arg) to LCD controller
    void LCD_ARG(uint8_t arg)
    {
      LCD_DC1;            // This is an Argument/data
      LCD_DATA_SET(arg);   //  Argument put on data lines
      LCD_WR0;
      LCD_WR1;            // Data latched on rising edge
    }

    This writes the blue and green to memory:
    void display(void)
    {
       uint16_t i;
       LCD_CMD(0x2C);   // Begin writing to frame memory
       for (i=0; i<38400; i++)   // fill screen with blue pixels
       {
          LCD_ARG(0x00);
          LCD_ARG(0x1F);
          LCD_ARG(0x00);
          LCD_ARG(0x1F);
       }
       for (i=0; i<38400; i++)   // fill screen with green pixels
       {
          LCD_ARG(0x07);
          LCD_ARG(0xE0);
          LCD_ARG(0x07);
          LCD_ARG(0xE0);
       }
    }


    Here is the initialization code:
    void init_lcd(void)
    {
      putstring1("\nInitializing LCD\n");
      GPIO[(GPIO_PORTA + GPIO_OVRC) >> 2] = NH_CS; // Clear chip select (make active)
      LCD_RD1;      // Not doing a read so make sure it's high
      LCD_WR0;
      LCD_RESET0;
      waitsome(250);
      LCD_RESET1;
      waitsome(250); 
     
      // New routine
      LCD_CMD (0x28);   // Display OFF
      LCD_CMD(0x11);   // exit sleep mode
     
      LCD_CMD(0xCB);   // Power Control A
      LCD_ARG(0x39);   //
      LCD_ARG(0x2C);   //
      LCD_ARG(0x00);   //
      LCD_ARG(0x34);   // Vcore=1.6V
      LCD_ARG(0x02);   // DDVDH=5.6V
     
      LCD_CMD(0xCF);   // Power Control B
      LCD_ARG(0x00);   //
      LCD_ARG(0x81);   // PCEQ off
      LCD_ARG(0x30);   // ESD protection
     
      LCD_CMD(0xC0);
      LCD_ARG(0x26);   // Power Control 1
      LCD_ARG(0X04);   // second parameter for ILI9340 (ignored by ILI9341)
     
      LCD_CMD(0xC1);   // Power control 2
      LCD_ARG(0x11);   //
     
      LCD_CMD(0xC5);   // VCOM control 1
      LCD_ARG(0x35);   //
      LCD_ARG(0x3E);   //

      LCD_CMD(0x36);   // memory access control=BGR
      LCD_ARG(0x88);   //

      LCD_CMD(0xB1);   // Frame rate control
      LCD_ARG(0x00);   //
      LCD_ARG(0x18);   //

      LCD_CMD(0xB6);   // display function control
      LCD_ARG(0x0A);   //
      LCD_ARG(0xA2);   //

      LCD_CMD(0xC7);   // VCOM control 2
      LCD_ARG(0xBE);   //
     
      LCD_CMD(0x3A);   // pixel format = 16 bit per pixel
      LCD_ARG(0x55);   //

      /*LCD_CMD(0xE0);   // Positive gamma correction
      LCD_ARG(0x1F);
      LCD_ARG(0x1B);
      LCD_ARG(0x18);
      LCD_ARG(0x0B);
      LCD_ARG(0x0F);
      LCD_ARG(0x09);
      LCD_ARG(0x46);
      LCD_ARG(0xB5);
      LCD_ARG(0x37);
      LCD_ARG(0x0A);
      LCD_ARG(0x0C);
      LCD_ARG(0x07);
      LCD_ARG(0x07);
      LCD_ARG(0x05);
      LCD_ARG(0x00);

      LCD_CMD(0xE1);   // Negative gamma correction
      LCD_ARG(0x00);
      LCD_ARG(0x24);
      LCD_ARG(0x27);
      LCD_ARG(0x04);
      LCD_ARG(0x10);
      LCD_ARG(0x06);
      LCD_ARG(0x39);
      LCD_ARG(0x74);
      LCD_ARG(0x48);
      LCD_ARG(0x05);
      LCD_ARG(0x13);
      LCD_ARG(0x38);
      LCD_ARG(0x38);
      LCD_ARG(0x3A);
      LCD_ARG(0x1F);*/

      LCD_CMD(0xF2);   // 3G Gamma control
      LCD_ARG(0x02);   // off

      LCD_CMD(0x26);   // Gamma curve 3
      LCD_ARG(0x01);   //
     
      LCD_CMD(0x2A);   // column address set
      LCD_ARG(0x00);   //
      LCD_ARG(0x00);   // start 0x0000
      LCD_ARG(0x00);   //
      LCD_ARG(0xEF);   // end 0x00EF (240)

      LCD_CMD(0x2B);   // page address set
      LCD_ARG(0x00);   //
      LCD_ARG(0x00);   // start 0x0000
      LCD_ARG(0x01);   //
      LCD_ARG(0x3F);   // end 0x013F (320)
     
      LCD_CMD(0x29);   // Turn on Display

      waitsome(10); 
    }

    That is all of it.

    0
  • sean

    FYI Here is the board I am working with.  The connector on the left of the screen is where I am measuring the voltages.  For some reason the picture shows stripes on the screen but it is really just a white screen.

    0
  • sean

    Here is a link to the connector that I am using to attach the LCD to the board: http://www.digikey.com/product-detail/en/FH28-40S-0.5SH(05)/HFV140CT-ND/2119015.  It is a 40 Pin Bottom contact 0.020" pitch.

    0
  • Michael_L

    The code I sent you is confirmed to work, are your connections look good.  It seems there is some issue with the board you are using.  Do you have another display you can try?

    0
  • sean

    Yes.  I have two identical boards.  They both behave the same, that is I only get a white screen that does not change when I run the code.  I have tried a few things.  I swapped the display between the two boards with no change.  I was talking to a friend who thought it might be a timing issue during the init routine.  So I have placed a 250ms delay after each command  ( command, arguments, delay, next command).  That did not change anything except make the initialization take much longer.

    I think I am so close to making this work. I feel like a am missing some small detail and have no idea how to get past this roadblock.

    0
  • Michael_L

    You said you code loops forever until it gets a user input of an "L"; are you providing this input?  Can you just try writing pixels of any color to the display without the loop?

    0
  • sean

    I verified that the value I write to the data port shows up on the pins to the LCD.

    Then I wrote the following code but did not get any green (or any changed) pixels.

       // Define an area of 100 Pixels
       LCD_CMD(0x2A);               // Column Address
       LCD_ARG(0x00);LCD_ARG(0x0A);   // Set Start column at pixel 10
       LCD_ARG(0x00);LCD_ARG(0x13);   // Set End column at pixel 19
       LCD_CMD(0x2B);               // Page Address
       LCD_ARG(0x00);LCD_ARG(0x0A);   // Set Start row at 10
       LCD_ARG(0x00);LCD_ARG(0x13);   // Set End row at 19

       // Turn the area defined from white to green
       LCD_CMD(0x2C);
       for (i=0; i<100; i++)   // write out 100 values
          {
             LCD_ARG(0x07);   // Set color to green
             LCD_ARG(0xE0);   
          }   

    0
  • Michael_L

    Can you try grounding the /CS line?

    0
  • sean

    I hard wired the CS line to ground.  Same result.  I also rechecked my code against the know good code and did not find any inconsistencies.

    0
  • sean

    In the datasheet is days that for 8-bit parallel communication we should use DB8-DB15.  Is that correct (as shown in my schematic)?  The LCD is behaving as though it is not getting anything at all.  I disabled the init routine briefly just to see what it would do and I got the same display, all white.

    0
  • sean

    I measured the current draw of the board with the backlight off and with the LCD disconnected and I do not see a change.  It seams the current change should be 7-9mA.

    0
  • Michael_L

    That is odd, it sounds like something is wrong with your board.  I'm not sure what, possibly you are exceeding the output current rating and therefore your code isn't really running on your processor? (Since you said the current is not changing at all with the backlight on or off).  I'm assuming you are powering the display with 3.3V, and using 3.3V logic?
    Is there a way you can try using the display with a different board/MCU?  The code I sent you works, and your connections are correct, and the speed of your micro is not too fast.  This is the only thing I can suggest you try at this point.

    I highly doubt the displays are defective, but you may email nhtech@newhavendisplay.com to set up an RMA if you would like to return the displays to us for analysis.

    0
  • sean

    Sorry I was not clear.  I have  a 1 ohm resistor on main 3.3V regulator for the whole board.  I can set the back light to draw 25mA, 100mA or I can turn the backlight off.  With the backlight off, but the LCD connected and initialized, I am measuring 97mA draw for the entire board.  Then I remove the LCD and measure the current again and I get roughly the same 97mA (the difference is in the noise).  It seams like the LCD is not drawing any current or it is drawing less then 1mA.  I have two board I have test the LCD on each board and have swaped the LCD between boards and they act the same.

    I also opened the LCD connector and measured from the pin that contacts the LCD flex cable to the pad on my PCB and found them all making a good connection.

    0
  • brybot

    EDIT: Fixed. Please ignore.

    Was this ever resolved? I'm experiencing the same issue. I'm sending commands to the display, but nothing happens. The backlight is on, and the screen is blank. I'm using the example code on the website. Reading through this thread, I seem to be experiencing the same issues (although I haven't checked the current draw). I've tried two LCDs and two hardware platforms. Any help would be appreciated!

    0
  • sean

    brybot,

    We have not fixed it yet.  We have turned it over to someone to review the design and debut the project.  As of yet they have not discovered the problem either.  You said you have fixed your problem.  Would you mind explaining what was happening and how you solved the problem. Perhaps it will help us solve our problem.  Thanks.

    Sean

    0
  • brybot

    Hi Sean,

    My problem was that when I copied the example code, I had misinterpreted one of the signals, RS, as RESET. As soon I corrected that signal my problem was resolved.

    0

Please sign in to leave a comment.