6
« on: December 14, 2015, 10:17:20 AM »
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