1111
1212# PCF8574
1313
14- Arduino library for PCF8574 - 8 channel I2C IO expander
14+ Arduino library for PCF8574 - 8 channel I2C IO expander.
1515
1616
1717## Description
@@ -36,17 +36,52 @@ The library allows to read and write both single pins or 8 pins at once.
3636Furthermore some additional functions are implemented that are playful and useful.
3737
3838
39- #### Interrupts
39+ #### Interrupts intro
4040
4141The PCF8574 has an interrupt output line (INT) to notify an MCU that one of the input lines has changed.
4242This can be used to prevent active polling of the PCF8574, which can be more efficient.
4343
44+ From the datasheet:
45+
46+ _ An interrupt is generated by any rising or falling edge of the port inputs in the input mode.
47+ After time, (Tiv), INT is valid. Resetting and reactivating the interrupt circuit is achieved
48+ when data on the port is ** changed to the original setting** or data is ** read from** , or
49+ ** written to** , the port that generated the interrupt.
50+ Resetting occurs in the read mode at the acknowledge bit after the rising edge of the SCL signal,
51+ or in the write mode at the acknowledge bit after the high-to-low transition of the SCL signal._
52+
53+ So there are three scenarios how the INT is reset.
54+
55+ 1 . pins revert to original state (lesser known).
56+ 2 . read from the device (well known)
57+ 3 . write to the device (well known)
58+
59+ This implies that polling the PCF8574 can miss an INT in scenario 1. (see #48 )
60+ In practice if you have faster polling than your signals changes this would not
61+ be a problem. E.g. tactile switches and a polling frequency > 100 Hz will work.
62+
63+
64+ #### Interrupts library
65+
4466The library cannot handle the PCF8574 interrupts as it has no code for it.
45- The user should catch the interrupt in his own code and can use the library to see which line has changed.
67+ The user should catch the interrupt in his own code to set a flag and can use
68+ the library to see which line has changed.
4669
47- There are two examples to show how interrupts can be used:
48- - PCF8574_interrupt.ino
49- - PCF8574_rotaryEncoder.ino
70+ There are two examples to show how interrupts can be handled:
71+
72+ - ** PCF8574_interrupt.ino**
73+ - ** PCF8574_rotaryEncoder.ino**
74+
75+ A more advanced interrupt handler would not set a boolean flag in the interrupt
76+ routine but increase a counter (uint8_t or larger).
77+ Then it would be possible to see that:
78+
79+ 1 . an interrupt occurred. (counter > 0)
80+ 2 . if one or more interrupts are not handled (counter > 1)
81+
82+ A minimal example that shows catching missed interrupts:
83+
84+ - ** PCF8574_interrupt_advanced.ino**
5085
5186
5287#### 0.4.0 Breaking change
@@ -194,7 +229,8 @@ It is advised to use pull-up or pull-down resistors so the lines have a defined
194229
195230#### Must
196231
197- - keep in sync with PCF8575
232+ - update documentation.
233+ - keep in sync with PCF8575 (as far as meaningful)
198234
199235#### Should
200236
@@ -214,3 +250,4 @@ donate through PayPal or GitHub sponsors.
214250
215251Thank you,
216252
253+
0 commit comments