• AVR Freaks

Hot!Problem with I2C start

New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2019/07/24 03:10:42
  • Location: 0
  • Status: offline
2020/02/22 04:52:51 (permalink)

Problem with I2C start

I have 50 and more of the same devices. The main materials found in the device:
  • 1 x Display: 2x16 LCD
  • 1 x I/O expander for I2C Bus: PCF8574T
  • 1 x Regulator: L78M05CDT-TR
  • 1 x PIC: PIC16F1765-I/SL
  • 1 x Rotary encoder
  • 1 x Switch for ON/OFF
The problem is one out of every 10or15 faulty. The LCD doesnt launch correctly. when i close the switch 12 volts applied to the circuit. The most of the devices launching and working perfectly. But a few of them unable to initialize the LCD but rest of the code works fine(Encoder readings, Pwm outputs etc.)
The pic runs PCF8574T. The PCF8574T runs LCD.
All of these devices were manufactured in machine string. They were programmed with the same code at the same time.
Some determinations:
  1. I think, faulty devices cant start I2C with PCF8574T. when i close the switch meaningless characters appear on single line of screen and sliding when i change the values via encoder. Second line is always empty. Normally there should be values that are updated occasionally on both lines of the LCD.
  2. The interesting one: when i touch the MCLR pin of the pic with tweezers the pic is being reset and that time lcd starts fine. When you on and off the switch the same problem appears. MCLR pin has external pull_ups. On the flawless devices when i touch the MCLR pin the pic does not being reset as expected.
  3. On faulty devices only when I change the pic and replace with new one and reprogram it the problem goes away. When i change the rest of the components with new ones the problem stands still.
  4. On faulty devices when i close the switch while MCLR pin of PIC is grounded, lcd backlight turns on as expected and everything waits. when i set high the MCLR same problem occurs, same meaningless slideable chars.. when I reset the PIC same way again but without opening switch this time, problem goes away as I said previously.
  5. Tried to ramp-up the supply voltage several times while switch is closed ofc. ramp-up from 4V to 12V. some times while ramp-up the pic is reset several times then problem goes away.
Do you think that in such a case do we need to suspect the code or should we look for the solution elsewhere?
Image 1: The regulation
Image 2: The main part of circuit i think its the faulty part
Image 3: yes this is what happens,, this chars can shift right whenever i change a value
Image 4: These are the decoupling and bypass caps located at nearest location to ICs
Image 5: I2C Configuration from MCC
#pragma config FOSC = INTOSC 
#pragma config WDTE = OFF 
#pragma config PWRTE = OFF 
#pragma config MCLRE = ON 
#pragma config CP = ON 
#pragma config BOREN = ON 
#pragma config CLKOUTEN = OFF 
#pragma config IESO = ON 
#pragma config FCMEN = ON 

#pragma config WRT = OFF 
#pragma config PPS1WAY = ON
#pragma config ZCD = OFF 
#pragma config PLLEN = ON 
#pragma config STVREN = ON 
#pragma config BORV = LO 
#pragma config LPBOR = OFF 
#pragma config LVP = OFF

post edited by LenHar - 2020/02/22 05:07:40

Attached Image(s)


3 Replies Related Threads

    Super Member
    • Total Posts : 3671
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Problem with I2C start 2020/02/22 09:00:52 (permalink)
    When Character LCD Display is used in 4 bit mode,
    High nibble of Data, and Low nibble of data must be transferred correctly in sequence.
    During Initialization of LCD Display controller,
    there is procedure specified in Datasheet for Hitachi  HD44780  display controller.
    Suggest checking that procedure is performed correctly in software.
    If Delays are not sufficient, or if timing is marginal, or if noise or disturbances in communication occur,
    then Display Controller may get out of synch with Data transfer.
    Then display will show garbage characters. 
    In software for one of the boards that have problems,
    1 second after program have started, Do the Display controller initialization procedure again.
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2019/07/24 03:10:42
    • Location: 0
    • Status: offline
    Re: Problem with I2C start 2020/02/27 04:04:16 (permalink)
    The delays didn't worked, but the solution is putting these codes berofe "lcd_init()" ;
    void I2C_Test() {

    uint8_t writeBuffer[10] = {0,0,0,0,0,0,0,0,0,0};
    I2C_MESSAGE_STATUS status;
    uint8_t timeOut=0;

    while (status != I2C_MESSAGE_FAIL) {

    while (status == I2C_MESSAGE_PENDING);

    if (status == I2C_MESSAGE_COMPLETE) break;
    if (timeOut == 10)break; else timeOut++;

    Klaatu Barada Nikto
    • Total Posts : 3956
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with I2C start 2020/02/28 06:08:19 (permalink)
    I2C needs time to become stable.
    A few stops appear on the i2c bus when the cpu powers up for the first time.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    + ST:Continues, "What Ships are Made for", Q's back.
    Jump to:
    © 2020 APG vNext Commercial Version 4.5