VersaLogic VL-EBX-37 Reference Manual page 44

Intel core 2 duo sbc with video, ethernet, usb, serial, sata, audio, analog + digital i / o, pcie mini card, eusb, and spx
Table of Contents

Advertisement

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
'================================
'SPICONTROL1 Register
'---------------------------
'D7 CPOL
'D6 CPHA
'D5 SPILEN1
'D4 SPILEN0
'D3 MAN_SS
'D2 SS2
'D1 SS1
'D0 SS0
OUT SPICONTROL1, &H26
'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
'MCP23S17 SPI Control Byte (Write)
'---------------------------------
'D7 SLAVEFA3
EBX-37 Reference Manual
= 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
= 0 Slave Address (Fixed Portion)
"
"
"
"
"
"
Interfaces and Connectors
38

Advertisement

Table of Contents
loading

Table of Contents