Menu

i2c LCD with PCF8574AT

2018-02-08
2018-02-17
1 2 > >> (Page 1 of 2)
  • renzo zorzi

    renzo zorzi - 2018-02-08

    Good morning. I'm trying an 'i2c display with PCF8574AT interface (Address 0x3F) using the following code but I can not get any results.

    #chip 16f886, 16
    
      ; ----- Define Hardware settings
      ' Define I2C settings - CHANGE PORTS
    
       #define I2C_MODE Master
       #define I2C_DATA PORTC.5
       #define I2C_CLOCK PORTC.7
       #define I2C_DISABLE_INTERRUPTS ON
       #define LCD_IO 10
       '    #define LCD_I2C_Address 0x3F
    
       #define LCD_Backlight_On_State  1
       #define LCD_Backlight_Off_State 0
    
        Do Forever
    
            CLS
            locate 0,0
            PRINT "START TEST"
            locate 1,0
            PRINT "DISPLAY ON"
            wait 3 s
    
        loop
    
    end
    

    image date and clk at the start

    Using a display with PCF8574A interface (Address 0x27) everything correctly works . Can you help me understand the problem?
    Ps. all displays work on Arduino programmed with Arduino IDE:
    Greetings.

     
  • renzo zorzi

    renzo zorzi - 2018-02-08

    https://postimg.org/image/sfn61ga1v/
    image date and clk at the start

     
  • Anobium

    Anobium - 2018-02-08

    Looks relatively simple to resolve.

    #define LCD_I2C_Address 0x4E
    

    Why? The address of your device is 0x27 as a 7-bit address. And, an 8-bit address for the device is 0x4e. Do try.

    If this fails. Ensure the I2C is working - use I2c discovery

     
  • renzo zorzi

    renzo zorzi - 2018-02-08

    I had already tried with "#define LCD_I2C_Address 0x4E" "#define LCD_I2C_Address 0x27" "#define LCD_I2C_Address 0x37" but it does not work, furthermore the address of the PCF8574AT is 0x3F should be in binary 0100111 as I also see on oscilloscope.
      Excuse my ignorance but what is I2c discovery?

     
  • stan cartwright

    stan cartwright - 2018-02-08

    It's in C:\GCB@Syn98.01\GreatCowBasic\Demos\I2C Solutions on my pc.

     
  • renzo zorzi

    renzo zorzi - 2018-02-08

    Ok found, I changed PIC with #chip 18f45k22,4 because I do not have a 16F1829. The serial monitor gives me:
    omit the "Unknown_Device"

    ID: 0x30 DS2482_1Channel_1Wire Master
    ID: 0x31 DS2482_1Channel_1Wire Master

    ID: 0x40 Serial_Expander_Device
    ID: 0x41 Serial_Expander_Device

    ID: 0x48 IC2/Serial_Expander_Device
    ID: 0x49 IC2/Serial_Expander_Device
    ID: 0x4A IC2/Serial_Expander_Device
    ID: 0x4B IC2/Serial_Expander_Device
    ID: 0x4C IC2/Serial_Expander_Device
    ID: 0x4D IC2/Serial_Expander_Device
    ID: 0x4E IC2/Serial_Expander_Device
    ID: 0x4F IC2/Serial_Expander_Device

    ID: 0x60 GCB Slave Device
    ID: 0x61 GCB Slave Device

    ID: 0x70 PCF8574T IC2/Serial_Expander_Device
    ID: 0x71 PCF8574T IC2/Serial_Expander_Device
    ID: 0x72 PCF8574T IC2/Serial_Expander_Device
    ID: 0x73 PCF8574T IC2/Serial_Expander_Device

    ID: 0x78 IC2 OLED Display
    ID: 0x79 IC2 OLED Display

    ID: 0x7E PCF8574T IC2/Serial_Expander_Device
    ID: 0x7F PCF8574T IC2/Serial_Expander_Device

    ID: 0xA0 EEProm_Device_Device
    ID: 0xA1 EEProm_Device_Device
    ID: 0xA2 EEProm_Device_Device
    ID: 0xA3 EEProm_Device_Device
    ID: 0xA4 EEProm_Device_Device
    ID: 0xA5 EEProm_Device_Device
    ID: 0xA6 EEProm_Device_Device
    ID: 0xA7 EEProm_Device_Device
    ID: 0xA8 EEProm_Device_Device
    ID: 0xA9 EEProm_Device_Device
    ID: 0xAA EEProm_Device_Device
    ID: 0xAB EEProm_Device_Device
    ID: 0xAC EEProm_Device_Device
    ID: 0xAD EEProm_Device_Device
    ID: 0xAE EEProm_Device_Device
    ID: 0xAF EEProm_Device_Device

    ID: 0xC0 TEA5767 FM Radio
    ID: 0xC1 TEA5767 FM Radio

    ID: 0xC6 AXE033 I2C LCD Device
    ID: 0xC7 AXE033 I2C LCD Device

    ID: 0xD0 DS1307_RTC_Device
    ID: 0xD1 DS1307_RTC_Device

    ID: 0xF8 FRAM_Device
    ID: 0xF9 FRAM_Device

    but I can not find a PCF8574AT in the list

     
  • renzo zorzi

    renzo zorzi - 2018-02-08

    I noticed that #define LCD_I2C_Address "...." has no effect in the program, even if you set incorrect Address values, if I use PCF8574T it always works.
    With PCF8574AT I tried all the values in the table but it does not work

     
  • Anobium

    Anobium - 2018-02-08

    It is very late here. Check back Friday please.

     
  • Anobium

    Anobium - 2018-02-09

    Morning.

    I know you said Arduino code worked but I want to start at first principles as the Arduino library may or may not comply with the protocol.

    Questions.
    1. Do you have pull-up resistors? I cannot tell from the scope JPG as this picture does not show a sustained HIGH state. You should have a pull-up resistor for SDA and SCL lines.
    2. You are using software I2C. Why?
    3. The Discovery is failing. You should not all those devices - just the ones attached. So, we need to figure out what is happening with this first. Please ignore the LCD until we have discovery working. I am assuming you took a demo and adapted for 18f45k22. Correct?
    4. Post a foto of your LCD device please. Is this an LCD_IO 10 or LCD_IO 12 device? You have assummed a #10 . Why? But., let us get I2C Discover working first.
    5. Attached your ASM from the 866 LCD code please. I want to review.

    I will pull at 886 and hook up an LCD now. I can think of no reason why this is not working.

     
  • renzo zorzi

    renzo zorzi - 2018-02-09

    I have not inserted pullup resistors. When I have some time I will do what you suggest, then I will post the results.
    Thank you.

     
  • renzo zorzi

    renzo zorzi - 2018-02-09

    I am using the example HWI2C2_Discovery_for_16F1829 @ 32
    My conf. for 18F45K22:

      #chip 18F45K22,4
      #option explicit
      #config Osc = INT
      #include <chipino.h>
      #include <lowlevel\hwi2c2.h>
      #define SendAHigh Set PORTC.7 ON
      #define SendALow Set PORTC.7 OFF
        Dir PORTc.7 Out
        InitSer 1, r9600, 1+WaitForStart, 8, 1, none, normal
    
            ' Define I2C settings - CHANGE PORTS if required for your specific device.
      #define HI2C2_BAUD_RATE 100
      #define HI2C2_DATA PORTB.5
      #define HI2C2_CLOCK PORTB.7
            'Initialise I2C Master
            'I2C pins need to be input for SSP2 module
      Dir HI2C2_DATA in
      Dir HI2C2_CLOCK in
            'MASTER Second Port
      HI2C2Mode Master
      #chip 18F45K22,4
      #option explicit
      #config Osc = INT
    
      #include <chipino.h>
      #include <lowlevel\hwi2c2.h>
      #define SendAHigh Set PORTC.7 ON
      #define SendALow Set PORTC.7 OFF
        Dir PORTc.7 Out
        InitSer 1, r9600, 1+WaitForStart, 8, 1, none, normal
    
            ' Define I2C settings - CHANGE PORTS if required for your specific device.
      #define HI2C2_BAUD_RATE 100
      #define HI2C2_DATA PORTB.5
      #define HI2C2_CLOCK PORTB.7
            'Initialise I2C Master
    
      Dir HI2C2_DATA in
      Dir HI2C2_CLOCK in
            'MASTER Second Port
      HI2C2Mode Master
      #chip 18F45K22,4
      #option explicit
      #config Osc = INT
    
      #include <chipino.h>
      #include <lowlevel\hwi2c2.h>
      #define SendAHigh Set PORTC.7 ON
      #define SendALow Set PORTC.7 OFF
        Dir PORTc.7 Out
        InitSer 1, r9600, 1+WaitForStart, 8, 1, none, normal
    
    ; ----- Define Hardware settings for HWI2C2
            ' Define I2C settings - CHANGE PORTS if required for your specific device.
      #define HI2C2_BAUD_RATE 100
      #define HI2C2_DATA PORTB.5
      #define HI2C2_CLOCK PORTB.7
            'Initialise I2C Master
            'I2C pins need to be input for SSP2 module
      Dir HI2C2_DATA in
      Dir HI2C2_CLOCK in
            'MASTER Second Port
      HI2C2Mode Master
    

    I tried with 2,7k pullups and then with 10K pullups
    the result is always the following:

    I2C2 Hardware Device Search for Microchip
    ID: 0x00 Unknown_Device

    My LCD
    https://postimg.org/image/9474rrryr/

     
    • Anobium

      Anobium - 2018-02-09

      You have a complete mixed up piece of code.
      1. There are two headers sections.
      2. code for sections for the arduino
      3. Hardware I2C2 - second channel

      Let us start with the basic question. Tell me what hardware and the chip you have and any ports constraints please (ie what ports can you not move with respect to I2C).

       
  • stan cartwright

    stan cartwright - 2018-02-09

    The lcd has a ucontroller to convert it to i2c from the photo. Is it set to 8 or 4 bit for lcd and any set up stuff relevant to the "i2c to parallel converter"

     
  • Anobium

    Anobium - 2018-02-09

    Here is an operational and tested solution. This is for the same family of chips.

    This is for the 18F26K22 which is same chip architecture. This works. I have compiled and programmed and then tested.

    If your pulls are correct - just change the chip.

    Hardware I2C 18F26K22
    
       00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
    00 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70 -- -- -- -- -- -- -- -- 78 79 -- -- -- -- -- --
    80 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    90 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    A0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    B0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    C0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    D0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    E0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    F0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    
    End of Search
    

    We need to make sure this works first, or, you are shooting in the dark.

     

    Last edit: Anobium 2018-02-09
  • renzo zorzi

    renzo zorzi - 2018-02-09

    I'm sorry, the setting code has been pasted twice, now I'm attaching the real part.
    HWI2C2_Discovery_for_16F1829 @ 32 modified for 18F45K22

      'Chip Settings.
      #chip 18F45K22,4
      #option explicit
      #config Osc = INT
      #include <chipino.h>
      #include <lowlevel\hwi2c2.h>
    
      #define SendAHigh Set PORTC.7 ON
      #define SendALow Set PORTC.7 OFF
      Dir PORTc.7 Out
      InitSer 1, r9600, 1+WaitForStart, 8, 1, none, normal
    
    ; ----- Define Hardware settings for HWI2C2
      ' Define I2C settings - CHANGE PORTS if required for your specific device.
      #define HI2C2_BAUD_RATE 100
      #define HI2C2_DATA PORTB.5
      #define HI2C2_CLOCK PORTB.7
      'Initialise I2C Master
      'I2C pins need to be input for SSP2 module
      Dir HI2C2_DATA in
      Dir HI2C2_CLOCK in
     'MASTER Second Port
      HI2C2Mode Master
    
     
  • renzo zorzi

    renzo zorzi - 2018-02-09

    This is the ASM file working with PCF8574T (address 0x27) loaded on 16F886.
    With PCF8574AT (address 0x3f) it does not work
    https://ufile.io/i80dj

     
  • stan cartwright

    stan cartwright - 2018-02-09

    It's an expander. I used a mcp one,works. The 3 pins that control address, I tied all high so I knew address. Is this relevent?

     
  • renzo zorzi

    renzo zorzi - 2018-02-09

    it is used to set a different address when you are controlling more than one display.

     
  • stan cartwright

    stan cartwright - 2018-02-09

    I used a MCP23017 for stepper motors, I didn't leave the pins floating. I'm following this as I have some parallel displays and thinking how to convert to i2c or serial. with some expanders or shift registers.

     
  • Anobium

    Anobium - 2018-02-10

    Back to the issue of basic I2C.

    @Renzo. I have number the questions so you can answer the specific questions.


    1) What is the state of play? You have posted a confusing message. You got I2C discovery to work ? This is a YES or NO answer.


    2) Then, you post the following asking a question:

    The result is:
    7E 01111110 = 0x3F

    4E 01001110 = 0x27
    it's correct?

    You post pictures of 0x4e and 0x7e without any explanation. Did you change something? or, did you get this result when rerunning the program? Very confusing.


    3 ) Then, you post some code in the post that commences with

    I'm sorry, the setting code has been pasted twice, now I'm attaching the real part.
    HWI2C2_Discovery_for_16F1829 @ 32 modified for 18F45K22

    Is this the code that works? I think not. Please confirm.


    4) Let me assume that the operation code I posted is the code you got working. A few points. i) This uses I2C, the first I2C channel within the microcontroller, you tried using I2C2. Why? ii) I used hardware serial. You used software serial why? What am I missing in your choices?


    5) Thank you for the ASM. This told me the version of the compiler. The first line of the ASM file shows the version number.

    ;Program compiled by Great Cow BASIC (0.98.01 2017-10-27)
    

    6) Can we sort out these questions before we jump to the LCD? I have no idea what the I2C is and how to explain what is going on as I am confused.


    Anobium

    @Stan - please let me complete the root cause analysis before we start trying to sort the LCD. We need to get the basics correct first.

     

    Last edit: Anobium 2018-02-10
  • renzo zorzi

    renzo zorzi - 2018-02-10

    1)Yes, I used it "i2cHardwareDiscovery to Terminal_18F26K22" to work

    2)I said that badly.

    This is the result of the I2C discovery with MCP8574AT connected:

    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    00 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7E 7F
    80 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    90 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    A0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    B0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    C0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    D0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    E0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    F0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    This is the result of the I2C discovery with MCP8574T connected:
    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    00 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4E 4F
    50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    80 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    90 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    A0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    B0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    C0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    D0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    E0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    F0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    3)The correct code to detect the addresses is:
    "i2cHardwareDiscovery to Terminal_18F26K22"
    I only changed the initial configuration with "#chip 18F45K22,4".

    4)Now I'm using HI2CMode and it works.

    I'm sorry I messed up but I'm new with PIC programming
    plus my English is very poor.
    Thanks for the infinite patience

     
    • Anobium

      Anobium - 2018-02-10

      OK. Sounds like you have I2C abd Serial working. The LCD address is whatever is displayed on the Discovery program. These are 8-bit addreses. If you change the address of the slave device via pullups/pulldown/float then the address may change.

      You should find the LCD works now.

      And, please do not every apologise forhaving to use English. I am at fault with my poor language skills (being 50% English and 50% Welsh).

      ood luck with the rest of the project.

       
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.