Author Topic: NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started  (Read 3304 times)

RichardR

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Hello,
I'm trying to get an OLED display type NHD‐0420CW‐AG3 working with a 16F1789 PIC controller, via I2C.
Unfortunately, even after several days of digging through the datasheets, checking out code examples, and just trying to get things working, I still can't get anything to show. No doubt, this has to do with the facts that
1. This is the first time that I try to use I2C with a PIC controller,
2. I'm working in assembler, not C or another higher language, and
3. There are some things in the display datasheet unclear to me.
As far as I can tell, the electrical signals should be OK, and from what I can see, and at least the I2C Start condition is initiated. But after that, nothing much happens. So my problems may very well be due to programming error.

If I may address the last point first: I understand most things in the display datasheet, except the table with the display commands.
There, three yellow columns labeled IS, RE, and SD are shown. What are these bits, and how are they addressed? Even the far more elaborate US2066 datasheet doesn't explain this -- or are these bits implicit in the command sent? If so, what is their function? Or did I overlook something here? I really tried reading the datasheets thoroughly, but still haven't a clue what these three bits are supposed to be. Also, I'm afraid that I don't completely understand Figure 5-7 in the US2066 datasheet (the I2C bus data format), even though I understand the basics of I2C communication itself.

Then there's the actual I2C addressing. I try sending simple byte sequences to the display, but it doesn't appear to respond at all, so I must be doing something wrong.
In the US2066 datasheet, I see that the display's slave address is supposed to be 0x78, OR'ed with SA0 (=0 in my case), and R/W (=0 so far). The following byte is supposed to be the control byte, to indicate the nature of the next byte (command or data), with 0x80 (Co=1, D/C#=0) for commands, and 0x40 (Co=0, D/C#=1) for data.

So I tried sending the following to the display from the PIC16F1789, translated from the example program code in the display datasheet:

[Initiate Start condition]
0x78 (address)
0x80 (command code)
0x01 (clear display)
0x80 (command code)
0x02 (return home)
0x04 (data code)
0x1F (write one solid block in first position)
[Initiate Stop condition]

Unfortunately, this doesn't do anything. I tried breaking this up in single commands, each one preceded by the address and terminated by a Stop condition, but that also doesn work properly.
It is very well possible that my PIC ASM code is to blame -- when I try sending these bytes without using the I2C block interrupt mechanism, the I2C bus immediately hangs after initiating the Start condition. When trying to send subsequent bytes through the proper interrupt routine, the I2C bus appears to function properly, but still nothing shows. In the US2066, there's also a description of a Power ON sequence, by sending fundamental command 0x0C, with RE=0, and SD=0(?). Should I use this first?

So actually I hope that my question is simple: is at least the above sequence of bytes sent out correct? If not, then what should be the correct sequence to turn on the display, and to get at least one character to show?
As long as I know that I should be sending out the right byte sequences, I can more easily figure out what I'm doing wrong in my assembly code. I tried locating I2C code examples, but there's very little to be found in PIC assembly code (at least I couldn't find anything).

Thanks in advance for any hints,

Best regards,

Richard
« Last Edit: December 15, 2015, 02:19:05 PM by RichardR »

Saurabh_B

  • Administrator
  • Hero Member
  • *****
  • Posts: 363
  • Karma: 10
    • View Profile
Re: NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started
« Reply #1 on: December 15, 2015, 09:01:14 AM »
Richard,

Have you initialized the display?

This display does have a lengthy initialization sequence that needs to occur to setup the registers on the display controller.

RichardR

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started
« Reply #2 on: December 15, 2015, 01:19:15 PM »
Hello Saurabh,

Quote
This display does have a lengthy initialization sequence that needs to occur to setup the registers on the display controller.

No, I did not initialize the display -- I assumed that it would default to a simple 4x20 character mode, like most other displays I worked with. Also, I thoroughly read both the NHD-0420CW-AG3 and the US2066 datasheets, and the only reference to initialization I can find has to do with the RES# pin: "When the pin is pulled LOW, initialization of the chip is executed."
The code examples don't mention any initialization either.
Am I using the wrong datasheets? Because that would explain a lot...

Where can I find information about this initialization sequence? On pages 15-16 of the US2066 datasheet, a Power ON and OFF sequence is mentioned, but that deals with several different voltages for the US2066 controller (VDDIO, VDD, VCC etcetera) -- while the actual display unit only has one VDD connection. So I assume this is dealt with internally. The only commands here are 0Ch for On and 08h for Off -- neither of which do anything visible here. Is there perhaps some sort of simple test mode?

And what initialization sequence should I use to get a 4 x 20 display? And is there some document that explains about the IS, RE and SD command bits?

Sorry if I ask a lot of questions, but I really can't find any answers in the datasheets that I have here.

Thank you for your reply,

Best regards,

Richard
« Last Edit: December 15, 2015, 04:43:56 PM by RichardR »

Saurabh_B

  • Administrator
  • Hero Member
  • *****
  • Posts: 363
  • Karma: 10
    • View Profile
Re: NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started
« Reply #3 on: December 16, 2015, 03:00:08 PM »
Richard,

On pages 21 and 22 of the datasheet for the display you can find an example program that will drive this display. In the program you have the recommended initialization sequence. This will set the necessary registers required for the display to work.
Code: [Select]
void init()
{
RES = 1; //reset HIGH inactive
delayms(1); //delay
command(0x2A); //function set (extended command set)
command(0x71); //function selection A
data(0x00); // disable internal VDD regulator (2.8V I/O). data(0x5C) = enable regulator (5V I/O)
command(0x28); //function set (fundamental command set)
command(0x08); //display off, cursor off, blink off
command(0x2A); //function set (extended command set)
command(0x79); //OLED command set enabled
command(0xD5); //set display clock divide ratio/oscillator frequency
command(0x70); //set display clock divide ratio/oscillator frequency
command(0x78); //OLED command set disabled
command(0x09); //extended function set (4-lines)
command(0x06); //COM SEG direction
command(0x72); //function selection B
data(0x00); //ROM CGRAM selection
command(0x2A); //function set (extended command set)
command(0x79); //OLED command set enabled
command(0xDA); //set SEG pins hardware configuration
command(0x10); //set SEG pins hardware configuration
command(0xDC); //function selection C
command(0x00); //function selection C
command(0x81); //set contrast control
command(0x7F); //set contrast control
command(0xD9); //set phase length
command(0xF1); //set phase length
command(0xDB); //set VCOMH deselect level
command(0x40); //set VCOMH deselect level
command(0x78); //OLED command set disabled
command(0x28); //function set (fundamental command set)
command(0x01); //clear display
command(0x80); //set DDRAM address to 0x00
command(0x0C); //display ON
delayms(100); //delay
}


You can also reference the program in the following link to help you get the display up and running.
https://github.com/NewhavenDisplay/NHD_US2066

RichardR

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started
« Reply #4 on: December 17, 2015, 03:12:49 AM »
Ah, OK, I surmised that this was a demo program to show how different functions are addressed -- I never realized that this initialization sequence was actually necessary for proper functioning of the display.

Thank you for clarifying this! (Although it might be handy if the datasheet mentioned that this initialization is actually more than just an example -- it is vitally important.)

OK, at least I know what to transmit -- so now I can get on with debugging my I2C code.

Thanks again for the heads-up!

Best regards,

Richard

 

MOVED: NHD-0420CW-AY3 display, text is mirror image

Started by Saurabh_BBoard Character LCDs

Replies: 0
Views: 2150
Last post March 11, 2016, 07:51:03 AM
by Saurabh_B
0420CW-AB3 I2C Talking, Display is off and low current drawn

Started by AreswayBoard OLEDs

Replies: 3
Views: 2887
Last post February 10, 2015, 07:39:49 AM
by Paul_B
NHD-0420CW-AG3 MPU Interface Pin Selection and Power Supply

Started by blaubaerBoard OLEDs

Replies: 14
Views: 6423
Last post April 20, 2015, 03:51:06 PM
by oldmaker
NHD-0420DZW-AY5 vs 763-NHD-0420CW-AY3 for brightness and power consumption

Started by timmwalkBoard OLEDs

Replies: 1
Views: 1837
Last post December 07, 2015, 08:37:17 AM
by Saurabh_B
NHD-0420CW-AY3 display, text is mirror image

Started by zleozBoard OLEDs

Replies: 1
Views: 2011
Last post March 11, 2016, 07:59:53 AM
by Paul_B