PCF8567 LCD Driver is not working properly with i2c protocol.

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone ! 
 

I'm working on a customize circuit which has atmega2560 microcontroller and a PCF8576 lcd driver which is interfaced with i2c protocol and a 40 segment monochromatic LCD.
I have uploaded a simple program which is working very well on arduino uno but works only once with atmega2560 customized board. 
more over some points to remember that the customized board of atmega2560 has a 8mhz crystal and operationg voltages are 3.3v.
Once i programs the atmega2560 board the LCD shows the digits but when i cut off the power and again powers the system, the display goes forever, then if i again program the atmega2560 the lcd don't shows the digits (But controller is powered on and working well as it shows serial data on serial monitor) and i have to wait a long time e.g 10 to 15 mins to program it again to make it work (only if the power is cut off of the microcontroller ).
further more if i program the arduino uno with the same code and uses it's SDA and SCL pins and jumper them with atmega2560's SCL SDA pins it starts work and keep working if i also remove the SCL and SDA connections from Arduino uno and also i could program it as many as time i want from atmega2560 the code works until power is cut off again.
 

 

I have attached the code below for the reference,
In debugging i found that either there is some capacitor on the atmega2560 board which is not allowing the PCF8576 driver to initialize after power cut off or reset or either their is a issue of frequency because i'm using 8mhz crystal and arduino uno is working fine because it has 16 mhz crystal.

Attachment(s): 

This topic has a solution.
Last Edited: Mon. Nov 25, 2019 - 06:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the benefit of others his "pfcode.txt" contains:

#define ADDRESS            B0111000      //  I2C Address of PCF8576
#define MODE_SET           B11001001   //  MODE SET      [C]   [10]   [LowPower]   [Enable]   [Bias]   [Mux]
#define DEVICE_SELECT      B11100000   //  Device select   [Command]    [1100]    [A2 A1 A0]
#define BANK_SELECT        B11111010      //  no effect in 1:4 multiplex mode

#define eight             B11111110 

#define pointer_digit1     B00000000 

#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  delay(3000);
  Clear_Screen();
  delay(3000);
}

void loop() {
  Digit_1(eight);
  Serial.println("Hello World");
  delay(1000);
}


void Clear_Screen() {
  Wire.beginTransmission (ADDRESS);
  Wire.write (MODE_SET) ;
  Wire.write (DEVICE_SELECT);
  Wire.write (BANK_SELECT) ;
  Wire.write (pointer_digit1) ;
  for (int i = 0; i <  20; i++) {
    Wire.write(0x00);
  }
  Wire.endTransmission () ;
}

void Digit_1 (int digit)
{
  Wire.beginTransmission (ADDRESS) ;
  Wire.write (MODE_SET) ;
  Wire.write (DEVICE_SELECT) ;
  Wire.write (BANK_SELECT) ;
  Wire.write (pointer_digit1) ;
  Wire.write (digit) ;
  Wire.endTransmission () ;
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define ADDRESS            B0111000      //  I2C Address of PCF8576
#define MODE_SET           B11001001   //  MODE SET      [C]   [10]   [LowPower]   [Enable]   [Bias]   [Mux]
#define DEVICE_SELECT      B11100000   //  Device select   [Command]    [1100]    [A2 A1 A0]
#define BANK_SELECT        B11111010      //  no effect in 1:4 multiplex mode

#define eight             B11111110 

#define pointer_digit1     B00000000

@obad - if you're thinking they will just give you binary numbers, they won't!

 

Maybe you are relying on some other definitions  to make it so ... ?

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Nov 18, 2019 - 11:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Awneil !

The above mention code is working perfectly on an Arduino uno . i also initialized the variable defining the datatype as byte. 
I also tried different versions of codes and all are working on arduino uno but the problem persist on atmega2560.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They are standard macros defined by Arduino.

 

If the code works on a Uno,  it will work on a Mega (and every other Arduino).

Note that I2C requires external pullup resistors typical 4k7 for 5V systems.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using arduino uno without any external pull up register, arduino have 13k ohm pull up resister on both SCL and SDA pins. The above code along with two more codes are working fine with the same circuitry. It does not seems a hardware issue, most probably i'm lacking in setting registers of i2c for 8mhz and 3.3v on atmega2560.

 

Regards;
Obad Zafar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
Maybe you are relying on some other definitions  to make it so ... ?
I guess it must be because Arduino works on other hardware besides avr-gcc/avr-g++ but those compilers have had 0bNNNN constants for a long time.

 

But anyway, Arduino does have a rather tortuous header that defines:

D:\arduino-1.8.8\hardware\arduino\avr\cores\arduino>head -n 40 binary.h
/*
  binary.h - Definitions for binary constants
  Copyright (c) 2006 David A. Mellis.  All right reserved.

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

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef Binary_h
#define Binary_h

#define B0 0
#define B00 0
#define B000 0
#define B0000 0
#define B00000 0
#define B000000 0
#define B0000000 0
#define B00000000 0
#define B1 1
#define B01 1
#define B001 1
#define B0001 1
#define B00001 1
#define B000001 1
#define B0000001 1
#define B00000001 1
#define B10 2
#define B010 2
etc.
etc.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

obad wrote:

I'm using arduino uno without any external pull up register, arduino have 13k ohm pull up resister on both SCL and SDA pins. The above code along with two more codes are working fine with the same circuitry. It does not seems a hardware issue, most probably i'm lacking in setting registers of i2c for 8mhz and 3.3v on atmega2560.

 

Regards;
Obad Zafar

The Uno has no external pullup resistors.

The Mega2560 has no external pullup resistors

 

If you can not afford $0.02 the I2C will not work properly.

The MEGA2560 is 5V

If you want to run at 3.3V use the ATmega2560V chip.

2k2 is a typical value for pullup to 3.3V

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As i said earlier i'm working on a customized board which has a atmega2560 microcontroller, i'm not using arduino mega2560 board. The customize board has an external resistor of 2k2 ohms, 8mhz clock, and 3.3v operating voltages. I can't use another board except this one, also The customize board was a working board but i had to reprogram it. i don't have the previous version of code with me. 

Obad.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In which case it should work 100% on the custom board.
I would still check that the custom board has no pcb shorts, opens or trace mis-routes. Or incorrect value components.
And runs regular Arduino programs e.g. Wire.h examples.
David.

Last Edited: Tue. Nov 19, 2019 - 07:31 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

obad wrote:
As i said earlier i'm working on a customized board

So how about posting the schematic of that board? And the PCB layout.

 

And some good, clear, in-focus photographs so that we can see what you're talking about.

 

Is it a commercial board, or one that you've made yourself?

 

As David says, what checking & testing have you done to verify that the board is working correctly?

 

Have you checked voltages?

 

Have you done basic LED blink tests to verify that it is operating at the speed you think - see my Tip #3 and clawson's FAQ #3

 

Have you used an oscilloscope to look at the I2C waveforms?

 

Do you have a debugger to see what the code is doing?

 

Do you have a UART available & working to give debug output?

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Awneil !

I have conducted many tests, i'm going to describe my scenario in deep, along with that i'm going to answer your each question in steps.

1) Yes it's a commercial board and i don't have any schematic or board diagram with me.
2) Board is working perfectly fine as we have many of them and i have a task to reprogram one of them.
3) I'm sharing some pictures of board and schematic of 4 digit lcd with PCF8576 driver which i made by myself after tracing the tracks.
4) Yes, voltages are fine, e.g 3.3v in my case.
5) I have seen i2c waveform from oscilloscope in both cases i.e working state and not working state in which i was simply printing (8), and i'm sharing it's videos here.
6) I'm programming the board via spi pins using USB ASP programmer.
7) I can debug the board via FTDI from hardware serial3 of ATmega2560.

* Furthermore i want to add here that I ran the i2c scanner code and found 3 i2c ic's i.e  0x34, 0x38, 0x49 in both cases (with power cut off and without power cutt off), it's returning me the address of i2c IC's which means there is no issue in i2c communication. (Picture is attached below).

*There are two LCD's on board, 4 digit and 6 digit i found only one difference in both the circuit, that there is no 1k ohm resistor on SA0 pin and A0 pin is short to ground for sub addressing, nothing else.

*There is a 5 pin i2c IC and one of it's pin is connected to OSC pin of both the PCF8576 driver. (I don't know it's package name or model).  Pin 1 = SCL, Pin 2 = SDA, Pin 3 = GND, Pin 4 = OSC, Pin 5 = VCC, also i'm not handling this is neither i know the purpose of it.

*I'm also sharing the picture of Arduino 328p SDA and SCL frequency from oscilloscope. 
 
*I also found that Wire.endTransmission() is returning 0 means success in both cases i.e (Power cut off and without power cut off).

Now after debugging my doubt is clear that there is no i2c communication issue but i'm curious to know why LCD starts working when i connect external Arduino 328p SDA and SCL (with same code as in atmega2560) with atmega2560 SDA and SCL after power cutt off. 

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I would expect Slave addresses 0x38 and 0x39 from the PCF8576 datasheet.   Max Bus speed is 100kHz.   The chip is very input voltage tolerant.

The schematic shows internal oscillator

I am horrified by your waveform in "External Arduino 328p"

 

The thread title says PCF8567.   This part does not exist.

 

I would like to see some external pullup resistors.   e.g. a photo of your 3k3 resistors.

 

With 3k3 pullup the voltage waveforms should look much better.

 

David.

Last Edited: Wed. Nov 20, 2019 - 02:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

david.prentice wrote:
I am horrified by your waveform in "External Arduino 328p"

Indeed:

 

Definitely looks like your pullups are way too high!

 

surprise

 

Surely, that oscilloscope can give you a screenshot?

 

EDIT: Like this: https://www.youtube.com/watch?v=a9ewbSkNFFU

Or:  https://www.tek.com/support/faqs/can-i-download-waveform-data-and-screenshots-my-computer-using-hyperterminal

 

 

See Tip #1 for how to post the pictures so that we can see them - as above.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Nov 20, 2019 - 02:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have uploaded a video of atmega2560 waveform in LCD NOT WORKING.rar. Arduino 328p is just for reference and i know that due to less resistance rise time of waves are different with the pull up one's.
a 2k2 ohm resistor is there on board and i also found somewhere that according to number of i2c devices on bus line resistance may vary and for three i2c devices 2k2 is recommended as in my case i have 3 i2c. 

 

Yes you are right that salve address must be 0x38 or 0x39 but the other two are current measurement ic and may be a switching ic for oscillator pin.

 

Obad.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well finally i resolved my problem ! In the process of debugging i found that PCF8576 is storing the previous values in it's RAM (In setting of BANK SELECT). So when after power cut off i initialize the PCF8576 i had the previous values in it's ram and after initializing it's get out of sync, so i had to reinitialize the wire.begintransmission after every print statement so that it can print the previous value in it's RAM. 
Now it's working perfectly fine.

Thank You for your time and good suggestions :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

obad wrote:
Now it's working perfectly fine.

Excellent - thanks for feeding back with the solution.

 

Now please see Tip #5 and mark the solution.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...