Interfaces and Connectors
EBX-22 Reference Manual
59
'MCP23S17 SPI Control Byte (Write)
'---------------------------------
'D7 SLAVEFA3 = 0 Slave Address (Fixed Portion)
'D6 SLAVEFA2 = 1 " " " "
'D5 SLAVEFA1 = 0 " " " "
'D4 SLAVEFA0 = 0 " " " "
'D3 SLAVEHA2 = 0 Slave Address Bits (Hardware Address Bits)
'D2 SLAVEHA1 = 0 " " " "
'D1 SLAVEHA0 = 0 " " " "
'D0 READWRITE = 0 Read/Write Bit = Write
OUT SPIDATA3, &H40
WHILE (INP(SPISTATUS) AND &H1) = &H1: WEND
'INITIALIZE DIRECTION OF DIO LINES D15-D8 AS INPUTS
'==================================================
'Direction = All Inputs
OUT SPIDATA1, &HFF
'MCP23S17 IODIRA Register Address
OUT SPIDATA2, &H0
'MCP23S17 SPI Control Byte (Write)
OUT SPIDATA3, &H40
WHILE (INP(SPISTATUS) AND &H1) = &H1: WEND
'Repeat until ESC key is pressed
WHILE INKEY$ <> CHR$(27)
'READ DIO INPUT DATA FROM MCP23S17
'---------------------------------
'MCP23S17 GPIOA Register Address
OUT SPIDATA2, &H12
'MCP23S17 SPI Control Byte (Read)
OUT SPIDATA3, &H41
WHILE (INP(SPISTATUS) AND &H1) = &H1: WEND
'DIO Input Data
PRINT HEX$(INP(SPIDATA1))
WEND
SYSTEM
D
IGITAL
I/O
“B
IT
B
ANG
”
R
EGISTER
A special register is available at 1D6h, which enables the direct control (“bit banging”) of digital
I/O. To use this register, the DIO field (bits D4-D3) of the MODCON register (1DFh) must be set
to 0h (see Table 44 for mode control settings).
DIOBB (Read/Write) 1D6h
D7 D6 D5 D4 D3 D2 D1 D0
DIOIN DIOINT
Reserved
Reserved
DIOCLK
DIOOUT
DIOCS1
DIOCS0
Table 29: DIOBB Register Bit Assignments
StockCheck.com