Newhaven Display Forum

Newhaven Products => Character LCDs => Topic started by: carlosflr on August 07, 2015, 11:21:25 AM

Title: NHD-C0216CiZ-FSW-FBW-3V3
Post by: carlosflr on August 07, 2015, 11:21:25 AM
I am trying to use the NHD-C0216CiZ-FSW-FBW-3V3 display with a Kinetis microcontroller (Cortex M4). I think I'm following the datasheet for the initialization routine and to send data. However, the display doesn't show the proper data. The first five characters of the first row are missing. The rest of the characters on the same line are shifted to the right. The second line looks OK. I'm attaching an image of how it looks. I tried this with two boards and it looks the same so I assume I am doing something wrong in my code.

I would appreciate any help you can provide.

Thanks,
Carlos

This is my code:

Code: [Select]
void vfnLCDInit(void)
{
    // send LCD reset pulse
    GPIOD_PCOR |= (1 << LCD_RST);
    GPIOD_PDDR |= (1 << LCD_RST);
    SysTickWait(0.0005);
    GPIOD_PSOR |= (1 << LCD_RST);
    SysTickWait(0.001);

    // disable backlight by default
    GPIOD_PCOR |= (1 << LCD_BK);
    GPIOD_PDDR |= (1 << LCD_BK);

    //Function Set
    ST7032iCommandWrite(0x38);
    SysTickWait(0.000030);

    //Function Set
    ST7032iCommandWrite(0x39);
    SysTickWait(0.000030);

    //Bias and OSC frequency
    ST7032iCommandWrite(0x14);
    SysTickWait(0.000030);

    //Contrast set
    ST7032iCommandWrite(0x72);
    SysTickWait(0.000030);

    //Power
    ST7032iCommandWrite(0x5E);
    SysTickWait(0.000030);

    //Follower control
    ST7032iCommandWrite(0x6D);
    SysTickWait(0.000030);

    //Display control : on
    ST7032iCommandWrite(0x0C);
    SysTickWait(0.000030);

    //Clear
    ST7032iCommandWrite(0x01);
    SysTickWait(0.002);

    //Entry mode
    ST7032iCommandWrite(0x06);

    // wait 100 ms
    SysTickWait(0.1);
}

void vfnLCDPutString(int8_t x, int8_t y, int8_t String[])
{
  uint8_t i = 0;
  uint8_t addr;

  if (y == 1)
    addr = 0x00;
  else if (y == 2)
    addr = 0x40;
  else
    return;

  addr += (x - 1);

  ST7032iCommandWrite(0x80 | addr);
  SysTickWait(0.000030);

  while(String[i] != '\0')
  {
    ST7032iPutchar(String[i]);
    i++;
  }
}

void ST7032iPutchar(int8_t chardata)
{
  uint32_t i;

  ST7032iDataWrite((uint8_t)chardata);
  SysTickWait(0.000030);
}

void ST7032iCommandWrite(uint8_t Data)
{
  uint8_t buf[2];
  buf[0] = 0x00;
  buf[1] = Data;
  ST7032ii2cWrite(buf, 2);
}

void ST7032iDataWrite(uint8_t Data)
{
  uint8_t buf[2];
  buf[0]= 0x40;
  buf[1] = Data;
  ST7032ii2cWrite(buf, 2);
}

on main...

vfnLCDInit();
vfnLCDPutString(1,1,"0123456789abcdef");
vfnLCDPutString(1,2,"0123456789ABCDEF");

Title: Re: NHD-C0216CiZ-FSW-FBW-3V3
Post by: Michael_L on August 07, 2015, 11:35:39 AM
From my experience, this happens when the timing is not correct.  Can you please try to increase the delay after you set the RAM address for the first line?  I know it looks as if the delay you have is 30us, however I still think it will be beneficial to try what I have suggested to see if anything changes.
Perhaps also try increasing the delay after the controller is initialized.
Title: Re: NHD-C0216CiZ-FSW-FBW-3V3
Post by: carlosflr on August 07, 2015, 11:48:40 AM
I just increased all my delays to 500 ms, including the delays in the initialization routine. I can see how each character is displayed. However, the display looks the same. Anything else that could be wrong?

Thanks,
Carlos
Title: Re: NHD-C0216CiZ-FSW-FBW-3V3
Post by: carlosflr on August 08, 2015, 07:35:57 AM
I checked my I2C timing and it was too fast. I fixed this and now I see the correct strings on the display. Thanks for your help Michael.
Title: Re: NHD-C0216CiZ-FSW-FBW-3V3
Post by: Michael_L on August 10, 2015, 08:09:56 AM
You're very welcome, thank you for sharing you solution!  :)