ADDING GPIO
This design uses two NXP PCA9554Ds (datasheet) and has an onboard regulator capable of supplying 150 mA for the module.
The design has 2x8 bits of GPIO that can user configured over the I2C bus. Up to four GPIO of these modules may be added to your Scamp, giving you up to an additional 64-bits of GPIO. |
Schematic
|
The address selection switch maps the two PCA9554D in pairs to addresses in the range $24 to $27. The table on the PCB indicates switch settings and the corresponding addresses of the PCA9554Ds. Once the GPIO module is attached to your Scamp, use the modules word to scan for its presence. Each module will appear as two addresses in the address table.
Configuring
The PCA9554D has four registers.
Register 0 is the Input Port Register and is a read-only port. It reflects the incoming logic levels of the pins, regardless of whether the pin is defined as an input or an output by Register 3. Writes to this register have no effect.
Register 1 is the Output Port Register and reflects the outgoing logic levels of the pins defined as outputs by Register 3. Bit values in this register have no effect on pins defined as inputs. Reads from this register return the value that is in the flip-flop controlling the output selection, not the actual pin value.
Register 2 is the Polarity Inversion Register allows the user to invert the polarity of the Input Port register data. If a bit in this register is set (written with ‘1’), the corresponding Input Port data is inverted. If a bit in this register is cleared (written with a ‘0’), the Input Port data polarity is retained.
Register 3 is the Configuration Register and controls the direction of the I/O pins individually. If a bit in this register is set, the corresponding port pin is enabled as an input with high-impedance output driver. If a bit in this register is cleared, the corresponding port pin is enabled as an output. At reset, the I/Os are configured as inputs with a weak pull-up.
Registers may be accessed from within your words, or directly from the command line.
The following words configure the PCA9554D at address $24 to have all 8 bits as inputs:
Register 0 is the Input Port Register and is a read-only port. It reflects the incoming logic levels of the pins, regardless of whether the pin is defined as an input or an output by Register 3. Writes to this register have no effect.
Register 1 is the Output Port Register and reflects the outgoing logic levels of the pins defined as outputs by Register 3. Bit values in this register have no effect on pins defined as inputs. Reads from this register return the value that is in the flip-flop controlling the output selection, not the actual pin value.
Register 2 is the Polarity Inversion Register allows the user to invert the polarity of the Input Port register data. If a bit in this register is set (written with ‘1’), the corresponding Input Port data is inverted. If a bit in this register is cleared (written with a ‘0’), the Input Port data polarity is retained.
Register 3 is the Configuration Register and controls the direction of the I/O pins individually. If a bit in this register is set, the corresponding port pin is enabled as an input with high-impedance output driver. If a bit in this register is cleared, the corresponding port pin is enabled as an output. At reset, the I/Os are configured as inputs with a weak pull-up.
Registers may be accessed from within your words, or directly from the command line.
The following words configure the PCA9554D at address $24 to have all 8 bits as inputs:
start
$24 write . \ begin a write to the PCA9554D and
\ display boolean indicating success/fail
$3 send . \ select the config register
$ff send . \ configure 8 bits as input
stop
To read from this device:
start
$24 write . \ begin a write to select the register and
\ display boolean indicating success/fail
$0 send . \ select the input register
repstart \ restart a new I2C sequence
$24 read . \ read back the input
stop
The following words configure the PCA9554D at address $25 to have all 8 bits as outputs:
start
$25 write . \ begin a write to the PCA9554D and
\ display boolean indicating success/fail
$3 send . \ select the config register
$00 send . \ configure 8 bits as output
stop
To output the value $aa to the second PCA9554D:
start
$25 write . \ begin a write to select the register and
\ display boolean indicating success/fail
$1 send . \ select the output register
$aa write . \ write $aa to the output
stop