![VersaLogic Iguana VL-EPIC-25 Reference Manual Download Page 50](http://html.mh-extra.com/html/versalogic/iguana-vl-epic-25/iguana-vl-epic-25_reference-manual_1006776050.webp)
Interfaces and Connectors
VL-EPIC-25 Reference Manual
44
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
MOV
AL, 00h
;SPIDATA1: 00h for outputs
OUT
DX, AL
MOV
DX, CACh
MOV
AL, 00h
;SPIDATA2: MCP23S17 register address 00h
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
;Write 55h to MCP23S17 register GPIOA
MOV
DX, CABh
MOV
AL, 55h
;SPIDATA1: data to write
OUT
DX, AL
MOV
DX, CACh
MOV
AL, 14h
;SPIDATA2: MCP23S17 register address 14h
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
BUSY: MOV DX, CA9h
IN
AL, DX
;Get SPISTATUS
AND
AL, 01h
;Isolate the BUSY flag
JNZ
BUSY
;Loop if SPI transaction not complete
Reading a Digital I/O Port Using the SPI Interface
The following code example reads the DIO15-DIO8 input lines.
'REGISTER ASSIGNMENT
'---------------------
CONST SPICONTROL1 = &HCA8
CONST SPICONTROL2 = &HCA9
CONST SPISTATUS = &HCA9
CONST SPIDATA1 = &HCAB
CONST SPIDATA2 = &HCAC
CONST SPIDATA3 = &HCAD
'INITIALIZE SPI CONTROLLER