This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PCF8574: How to configure some port output and some port input?

Part Number: PCF8574

My understanding is that P0-P7 are all input when I2C in read mode, and all are output at write mode, we can't configure such as P0-P3 input, P4-P7 output, right?

But in datasheet 9.2 typical application, 

B. P0, P2, and P3 are configured as outputs.

C. P1, P4, and P5 are configured as inputs.

How can we achieve that?

  • Hi Howard,

    The IO pins on this device are all Quasi-bidirectional without explicit directional control. Driving the pin either weakly pulls the line up to Vdd or sinks the pin to GND. Reading the pin returns the actual status of the pin. In order to use a pin exclusively as an input, the pin should be driven HIGH (default at startup) so the pin remains weakly pulled to Vdd. The other device driving this pin should pull low for the device to read when called by the master.

    Does this help answer your question?

    Regards,
    Eric
  • Eric,
    I don't understand.
    The pin should be driven HIGH (default at startup) in order to use it as an input, then how can it be output? Since by default it's input and there is no command to set a specific pin as output.
    What's the point if driving the port high to use it as an input? Even if I set all port high with external pull up resistor, by writing to the device 00000000, all eight ports are set 0, right? If there is no external pull up resistor, these ports are also set 0 with the writing command.
  • Hi Howard,

    Since the device doesn't have directional control, it's always "driving" using a CMOS push/pull architecture. The receiver is tied to the same line and will read the actual state of the line, independent of what the device is set to drive. This can be seen in figure 8.2.2 on the datasheet. Here's a simplified version with an example slave device connected to the pin:

    See above that only one of the PCF8574 FETs will be on at a time, either pulling directly to GND or pulling up to Vcc through a 100uA current source. When the output is set to HIGH (default), the line will be weakly pulled up by this source and an exampled slave device can safely pull the line LOW without drawing too much current through either device. When the slave pulls LOW, there's a voltage drop across the current source and the PCF8574 receiver (Rx) will see the lower voltage. 

    Now imagine a slave device with a different push/pull architecture. 

    In this case, if the PCF8574 is set to drive LOW and the slave tries to pull the line up, there's nothing limiting the current through the devices and the short could damage either or both devices. If the PCF8574 is set to drive HIGH, the slave device will be able to safely drive LOW with the current being limited by the current source. A pull-down FET will be able to drive the entire line LOW so the PCF8574 receiver (Rx) reads a LOW. It can also safely drive HIGH because the line is already being pulled to Vcc.

    For this configuration, not external pull-up resisters are needed because the line will be weakly pulled up by the internal CMOS architecture. 

    Let me know if this makes sense. More information can also be found at this similar E2E post.

    Regards,

    Eric

  • Eric,
    thank you.
    So the P port should not connect to push/pull architecture device because it's possible to cause damage as you referred, right?
  • Hi Howard,

    "So the P port should not connect to push/pull architecture device"
    This is only true if the device is driving a LOW.

    When the device drives a HIGH, the current will be limited to a slave device even if it has a push/pull architecture. Therefore, to "configure" a PCF8574 pin as an output, it should be driven HIGH and connected to the output of a slave. The slave (with pull-down architecture, standard for I2C communication) will be able to transmit data through the line that can be read by the PCF8574 receiver.

    For example, to make P0 - P3 inputs, when initializing the device, drive these pins HIGH (or leave them HIGH as is the default) and you'll be able to read any information from the slave device from these pins. Pins P4 - P7 can be driven normally as outputs.

    Let me know if this helps answer your question.

    Regards,
    Eric
  • Hey Howard,

    Just chiming in, you can connect a device with push pull architecture to the I/O pins if you place a series resistor between the I/O pin and the push pull architecture of another device to limit the current draw.

    -Bobby