Analog Input Using The Spi Interface - VersaLogic EBX-22 Reference Manual

Table of Contents

Advertisement

A
I
U
NALOG
NPUT
See SPI Interface for a description of the EBX-22 SPI interface and registers.
Initiating an Analog Conversion Using the SPI Interface
The following procedure can be used to initiate an analog conversion using the SPI interface.
1. Write 15h to the SPICONTROL register (I/O address 1D8h) – This value configures the
SPI port to select the on-board A/D converter, 16-bit frame length, low SCLK idle state,
rising edge SCLK edge, and automatic slave select.
2. Write 30h to the SPISTATUS register (I/O address 1D9h) – This value selects 8 MHz
SCLK speed, hardware IRQ disable, and left-shift data.
3. Write any value to SPIDATA2 (I/O address 1DCh) – This data will be ignored by the
A/D converter.
Write the analog input channel number to bits 5-3 of SPIDATA3 (1DDh) – Any write
4.
operation to this register triggers an SPI transaction.
Poll the BUSY bit until the conversion is completed.
5.
Read the conversion data from SPIDATA2 (lower 8 bits) and SPIDATA3 (upper 4 bits).
6.
Each analog conversion returns the conversion data from the previous conversion. The first
analog conversion after power-up or reset returns the data from ADCH0. The second conversion
returns the conversion data from the channel addressed in the first conversion. Each successive
conversion returns conversion data from the previous conversion.
This means that multiple conversions on the same A/D channel return valid data after every
conversion, starting with the second conversion. However, if a different channel is selected
between analog reads, two conversions will be necessary to return valid data from the new
channel. The analog input code example on page 50 shows how to use a 32bit SPI frame for an
automatic second conversion when only one sample is desired.
SPI Analog Input Code Example
The following code example illustrates the procedure for reading an analog voltage from the
onboard ADC channel 3. A 32bit SPI frame is used to provide a valid single sample.
MOV
MOV
OUT
MOV
MOV
OUT
MOV
MOV
OUT
BUSY: MOV
IN
AND
JNZ
MOV
EBX-22 Reference Manual
SPI I
SING THE
NTERFACE
DX, 1D8h
AL, 35h
;SPICONTROL: SPI Mode 00, 32bit, auto ADC_SS#
DX, AL
DX, 1D9h
AL, 30h
;SPISTATUS: 8MHz, no IRQ, left-shift
DX, AL
;SPIDATA2, SPIDATA1, SPIDATA0: don't care
DX, 1DDh
AL, 18h
;SPIDATA3: ADC78H90 AIN4 = EBX-11 ADCH3
DX, AL
DX, 1D9h
;Get SPISTATUS
AL, DX
AL, 01h
;Isolate the BUSY bit
BUSY
;Loop back if SPI transaction not complete
DX, 1DAh
;Point to SPIDATA0 register
Interfaces and Connectors
54

Advertisement

Table of Contents
loading

Table of Contents