PARTS: 8BIT IO EXPANDER (PCF8574)
in some cases a job has much more sensors, buttons, or LEDs than your microcontroller has pins. The PCF8574 is an simple method to add 8 low-speed input or output pins to a microcontroller. A configurable address lets several PCF8574s exist on the exact same bus, so two microcontroller pins can manage lots of IO pins. We’ll show you exactly how to utilize this chip below.
TI PCF8574 I2C 8bit IO expander (Mouser #595-PCF8574N, $1.86)
We discovered PCB footprints for this chip in i2c.lbr as well as micro-phillips.lbr on the Cadsoft Eagle library download page. The PCF8574 is managed with the 2 cable I2C protocol, so we utilized our Bus Pirate universal serial interface to demonstrate this chip. The exact same fundamental operations will apply to any type of microcontroller.
The schematic shows our easy test circuit for the PCF8574, here’s the datasheet (PDF). We powered the chip with 5volts, as well as utilized a 0.1uF decoupling capacitor (C1) between the power as well as ground pins. R1 as well as R2 hold the I2C clock as well as data bus at 5volts. We’ll utilize an LED to test the chip’s output features; P0 is linked to LED1 with present limiting resistor R3 (330+ ohms). P6 as well as P7 are connected to understood specifies so we can quickly test the chip’s input capabilities.
The PCF8574’s I2C address is 0100xxxy, with three bits (x) identified by the specify of the address pins A2-0, as well as a final bit (y) that sets the checked out (1) or compose (0) mode. numerous PFC8574s can share an I2C bus by utilizing different address pin settings. because we connected the address pins to ground, the compose address is 01000000 (0x40).
Výstup
The LED on P0 is managed by composing a 1 (on) or 0 (off) to bit 0 of the byte complying with the compose address.
I2C>{0x40 0b00000001} <–command 210 I2C begin CONDITION 220 I2C WRITE: 0x40 got ACK: YES<–write address 220 I2C WRITE: 0x01 got ACK: YES<–output value 240 I2C stop CONDITION I2C>
{ problems an I2C begin condition, complied with by the compose address, 0x40. The output value, 0b00000001, sets P0 high as well as the staying bits low. } sends the I2C bus stop condition, ending the transaction. When the corresponding bit is set high, the LED turns on.
To turn the LED off, repeat the sequence with the corresponding output bit set to 0.
I2C>{0x40 0b00000000}<–command 210 I2C begin CONDITION 220 I2C WRITE: 0x40 got ACK: YES<–write address 220 I2C WRITE: 0x00 got ACK: YES<–output value 240 I2C stop CONDITION I2C>
With P0 now set to ground, the LED turns off.
Vstup
Pins set to output high can likewise be utilized as inputs (datasheet page 1). In the example, P6 is held high (+5 volts) as well as P7 is held low (ground), however these might likewise be buttons, sensors, or other digital logic. The other pins are left floating as well as don’t represent valid data.
I2C>{0x40 0b11000000}<–command 210 I2C begin CONDITION 220 I2C WRITE: 0x40 got ACK: YES<–write address 220 I2C WRITE: 0xC0 got ACK: YES<–output value 240 I2C stop CONDITION I2C>
First, we set the preferred input pins to output high by composing 1 to the corresponding bits in the output value. bits 6 as well as 7 set P6 as well as P7 to output high.
Now, we can checked out the pin. We did this operation with the Bus Pirate’s output set to binary mode to ensure that the pin values are promptly obvious.
I2C>{0x41 r}<–command 210 I2C begin CONDITION 220 I2C WRITE: 0b01000001 got ACK: YES<–address 230 I2C READ: 0b01000000<–pin state 240 I2C stop CONDITION I2C>
{ problems an I2C begin condition, 0x41 is the checked out address, as well as r reads one byte from the device. } sends the I2C bus stop condition, ending the transaction.
The reply, 01000000, represents the specify of the input pins. the most considerable bit is 0 since P7 is connected to ground. The next bit is 1 since P6 is held high The other bits (0) are garbage data.
This is far from the only IO expander IC. have you utilized one more chip?
Don’t fail to remember to catch up on any type of parts messages you may have missed.