Interfaces and Connectors
EBX-41 Reference Manual
42
MOV
DX, CA9h
MOV
AL, 30h
;SPISTATUS: 8MHz, no IRQ, left-shift
OUT
DX, AL
MOV
DX, CABh
MOV
AL, 44h
;SPIDATA1: Mirror & Open-Drain interrupts
OUT
DX, AL
MOV
DX, CACh
MOV
AL, 0Ah
;SPIDATA2: MCP23S17 address 0x0A
OUT
DX, AL
MOV
DX, CADh
MOV
AL, 40h
;SPIDATA3: MCP23S17 write command
OUT
DX, AL
BUSY: MOV DX, CA9h
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, CA8h
MOV
AL, 27h
;SPICONTROL: SPI Mode 00, 24bit, auto SPI 6
OUT
DX, AL
MOV
DX, CA9h
MOV
AL, 30h
;SPISTATUS: 8MHz, no IRQ, left-shift
OUT
DX, AL
MOV
DX, CABh
MOV
AL, 44h
;SPIDATA1: Mirror & Open-Drain interrupts
OUT
DX, AL
MOV
DX, CACh
MOV
AL, 0Ah
;SPIDATA2: MCP23S17 address 0x0A
OUT
DX, AL
MOV
DX, CADh
MOV
AL, 40h
;SPIDATA3: MCP23S17 write command
OUT
DX, AL
Writing to a Digital I/O Port Using the SPI Interface
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, CA8h
MOV
AL, 26h
;SPICONTROL: SPI Mode 00, 24bit,
SPI 6
OUT
DX, AL
MOV
DX, CA9h
MOV
AL, 30h
;SPISTATUS: 8MHz, no IRQ, left-shift
OUT
DX, AL
MOV
DX, CABh
MOV
AL, 44h
;SPIDATA1: mirror and open-drain interrupts
OUT
DX, AL
MOV
DX, CACh
MOV
AL, 0Ah
;SPIDATA2: MCP23S17 IOCON register address 0Ah
OUT
DX, AL
MOV
DX, CADh
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, CABh