Author Topic: PCF8575  (Read 894 times)

0 Members and 2 Guests are viewing this topic.

Offline Sai ShobyTopic starter

  • Newbie
  • Posts: 9
  • Country: sg
PCF8575
« on: October 13, 2020, 01:57:49 am »
Hi all,
I am trying to control switches in PCF8575 through I2C, when I press the switch which is connected in port0 in PCF8575, I want to glow the led which i connect in port1 of pcf8575. i attached schematics. Please help me to solve this
 

Offline greenpossum

  • Frequent Contributor
  • **
  • Posts: 408
  • Country: au
Re: PCF8575
« Reply #1 on: October 13, 2020, 02:21:52 am »
It's just an I2C to GPIO adaptor, not a FPGA or CPLD, you need a MCU to implement the action.
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: PCF8575
« Reply #2 on: October 13, 2020, 12:47:17 pm »
would be useful to know, how you control the I2C bus?
I have some C code for the PCF8575 on AVR, but no idea if it is for any help for you
 

Offline Sai ShobyTopic starter

  • Newbie
  • Posts: 9
  • Country: sg
Re: PCF8575
« Reply #3 on: October 14, 2020, 03:55:21 am »
Thank You for your reply. I am using pic 18f25k80 to connect scl and sda
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: PCF8575
« Reply #4 on: October 14, 2020, 11:22:52 am »
ok, as you maybe know the PCF8575 is widely used in I2C-backpacks for HD44780-compatible LCD displays, so I normally use the following code to control them, here a write sample

Code: [Select]
void lcd_write(uint8_t data, uint8_t type) {
    uint8_t temp=0x0;
    uint8_t i=2;

    do {                                                              // verify is LCD is ready to receive commands)
        i2c_start();
        i2c_write(LCD_ADDR + I2C_WRITE);    // address PCF8575 in write mode
        i2c_write(0x8a);                                       // write command
        i2c_write(0x8e);                                       // latch command (toggling Enable pin)
        i2c_start();                                               // I2C restart
        i2c_write(LCD_ADDR + I2C_READ);      // address PCF8575 in read mode
        temp=i2c_read_nack();                            // read PCF8575 pin status with non-ACK
        i2c_start();                                                // I2C restart
        i2c_write(LCD_ADDR + I2C_WRITE);     // address PCF8575 in write mode
        i2c_write(0x8a);                                        // write command
        i2c_write(0x8e);                                        // latch command (set Enable pin)
        i2c_write(0x8a);                                        // reset Enable pin
        }
    while(temp & 0x80);                                     // do loop all over till LCD is ready

    while(i) {
        if(i==2) {
            temp=data & 0xf0;
            }
        else {
            temp=data & 0xf;
            temp*=0x10;
            }
        if(type==1) {
            temp+=1;
            }
        i2c_write(temp+0x8);
        i2c_write(temp+0xc);
        i2c_write(temp+0x8);
        i--;
    }

    i2c_stop();
}

the I2C commands are AVR compatible, so I thing they are not fully portable to PICs, but the manual should give you a clue about it
 

Offline Sai ShobyTopic starter

  • Newbie
  • Posts: 9
  • Country: sg
Re: PCF8575
« Reply #5 on: October 15, 2020, 01:02:13 am »
Yes. got it. Thank you
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf