Interfaces and Connectors
EBX-11 Reference manual
53
MOV
AL, 44h
;SPIDATA1: Mirror & Open-Drain interrupts
OUT
DX, AL
MOV
DX, 1DCh
MOV
AL, 0Ah
;SPIDATA2: MCP23S17 address 0x0A
OUT
DX, AL
MOV
DX, 1DDh
MOV
AL, 40h
;SPIDATA3: MCP23S17 write command
OUT
DX, AL
BUSY: MOV DX, 1D9h
IN
AL, DX
;Get SPI status
AND
AL, 01h
;Isolate the BUSY bit
JNZ
BUSY
;Loop back if SPI transaction is not complete
MOV
DX, 1D8h
MOV
AL, 27h
;SPICONTROL: SPI Mode 00, 24bit, auto DIO_1_SS#
OUT
DX, AL
MOV
DX, 1D9h
MOV
AL, 30h
;SPISTATUS: 8MHz, no IRQ, left-shift
OUT
DX, AL
MOV
DX, 1DBh
MOV
AL, 44h
;SPIDATA1: Mirror & Open-Drain interrupts
OUT
DX, AL
MOV
DX, 1DCh
MOV
AL, 0Ah
;SPIDATA2: MCP23S17 address 0x0A
OUT
DX, AL
MOV
DX, 1DDh
MOV
AL, 40h
;SPIDATA3: MCP23S17 write command
OUT
DX, AL
W
RITING TO A
D
IGITAL
I/O
P
ORT
The following code example initiates a write of 55h to Digital I/O port bits DIO15-DIO8.
;Write 44h to configure MCP23S17 register IOCON
MOV
DX, 1D8h
MOV
AL, 26h
;SPICONTROL: SPI Mode 00, 24bit, DIO_0_SS#
OUT
DX, AL
MOV
DX, 1D9h
MOV
AL, 30h
;SPISTATUS: 8MHz, no IRQ, left-shift
OUT
DX, AL
MOV
DX, 1DBh
MOV
AL, 44h
;SPIDATA1: mirror and open-drain interrupts
OUT
DX, AL
MOV
DX, 1DCh
MOV
AL, 0Ah
;SPIDATA2: MCP23S17 IOCON register address 0Ah
OUT
DX, AL
MOV
DX, 1DDh
MOV
AL, 40h
;SPIDATA3: MCP23S17 write command
OUT
DX, AL
CALL BUSY
;Poll busy flag to wait for SPI transaction
;Configure MCP23S17 register IODIRA for outputs
MOV
DX, 1DBh
MOV
AL, 00h
;SPIDATA1: 00h for outputs
OUT
DX, AL
MOV
DX, 1DCh
MOV
AL, 00h
;SPIDATA2: MCP23S17 register address 00h
OUT
DX, AL
StockCheck.com