VersaLogic EBX-22 Reference Manual page 64

Table of Contents

Advertisement

OUT
CALL
BUSY: MOV
IN
AND
JNZ
Reading a Digital I/O Port Using the SPI Interface
The following code example reads the DIO15-DIO8 input lines.
'REGISTER ASSIGNMENT
'---------------------
CONST SPICONTROL1 = &H1D8
CONST SPICONTROL2 = &H1D9
CONST SPISTATUS = &H1D9
CONST SPIDATA1 = &H1DB
CONST SPIDATA2 = &H1DC
CONST SPIDATA3 = &H1DD
'INITIALIZE EPM-22 SPI CONTROLLER
'================================
'EPM-22 SPICONTROL1 Register
'---------------------------
'D7 CPOL
'D6 CPHA
'D5 SPILEN1
'D4 SPILEN0
'D3 MAN_SS
'D2 SS2
'D1 SS1
'D0 SS0
OUT SPICONTROL1, &H26
'EPM-22 SPICONTROL2 Register
'---------------------------
'D7 IRQSEL1
'D6 IRQSEL0
'D5 SPICLK1
'D4 SPICLK0
'D3 HW_IRQ_EN = 0 Hardware IRQ Enable (Disabled)
'D2 LSBIT_1ST = 0 SPI Shift Direction (Left Shifted)
'D1 0
'D0 0
OUT SPICONTROL2, &H30
'INITIALIZE MCP23S17
'===================
'MCP23S17 IOCON Register
'-----------------------
'D7 BANK
'D6 MIRROR
'D5 SEQOP
'D4 DISSLW
'D3 HAEN
'D2 ODR
'D1 INTPOL
'D0 0
OUT SPIDATA1, &H44
'MCP23S17 IOCON Register Address
'-------------------------------
OUT SPIDATA2, &HA
EBX-22 Reference Manual
DX, AL
BUSY
;Poll busy flag to wait for SPI transaction
DX, 1D9h
AL, DX
;Get SPISTATUS
AL, 01h
;Isolate the BUSY flag
BUSY
;Loop if SPI transaction not complete
= 0 SPI Clock Polarity (SCLK idles low)
= 0 SPI Clock Phase (Data read on rising edge)
= 1 SPI Frame Length (24-Bit)
= 0
"
"
"
= 0 SPI Slave Select Mode (Automatic)
= 1 SPI Slave Select (On-Board DIO 0-15)
= 1
"
"
"
= 0
"
"
"
= 0 IRQ Select (IRQ3)
= 0
"
"
"
= 1 SPI SCLK Frequency (8.333 MHz)
= 1
"
"
"
= 0 This bit has no function
= 0 This bit has no function
= 0 Registers in same bank (addresses are sequential)
= 1 The INT pins are internally connected
= 0 Sequential op disabled. Addr ptr does not increment.
= 0 Slew rate control for SDA output (enabled)
= 0 Hardware address enable (addr pins disabled)
= 1 INT pin is open-drain
= 0 Polarity of INT output pin (ignored when ODR=1)
= 0 This bit has no function
Interfaces and Connectors
"
"
"
"
"
"
58

Advertisement

Table of Contents
loading

Table of Contents