As an example of the operation if the I2C function of the CGMMSTICK, this example interfaces to a PCF8574A I/O expansion device.
PCF8574A I2C port expander circuit.
I/O Pins 12 and 13 are used for I2C, as described in the documentation.
The code used in this example assumes that the address pins (A0-A2) are all grounded, giving this chip an address (offset) of 0.
The example code runs a ‘cylon’ pattern on the LEDs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
' Enable I2C ' speed = 100 kHz ' timeout = 100 milliseconds I2CEN 100, 100 DO FOR loop1 = 0 TO 7 cylon = 2^loop1 cylon = (cylon XOR &hFF) ' Send I2C command to PCF8574A ' 8574A address = &h38 ' send 1 byte I2CSEND &h38, 0, 1, cylon PAUSE 100 NEXT loop1 FOR loop2 = 6 TO 1 STEP -1 cylon = 2^loop2 cylon = (cylon XOR &hFF) ' Send I2C command to PCF8574A ' 8574A address = &h38 ' send 1 byte I2CSEND &h38, 0, 1, cylon PAUSE 100 NEXT loop2 LOOP ' Disable I2C I2CDIS |
Simplified schematic for general CGMMSTICK to PCG8574 interface. This example also includes the resistors and LEDs on the output lines as well as pull up resistors for the I2C lines.
Schematic including I2C pull up resistors and the resistor/LED combination for one of the eight I/O lines.
Leave a Reply