Download AN-812 APPLICATION NOTE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Resistive opto-isolator wikipedia , lookup

History of electric power transmission wikipedia , lookup

Electrical substation wikipedia , lookup

Power over Ethernet wikipedia , lookup

Rectifier wikipedia , lookup

Stray voltage wikipedia , lookup

Fault tolerance wikipedia , lookup

Alternating current wikipedia , lookup

Computer program wikipedia , lookup

Earthing system wikipedia , lookup

Buck converter wikipedia , lookup

Power MOSFET wikipedia , lookup

Voltage optimisation wikipedia , lookup

Surge protector wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Opto-isolator wikipedia , lookup

Mains electricity wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Transcript
AN-812
APPLICATION NOTE
One Technology Way • P.O. Box 9106 • Norwood, MA 02062-9106, U.S.A. • Tel: 781.329.4700 • Fax: 781.461.3113 • www.analog.com
Microcontroller-Based Serial Port Interface (SPI®) Boot Circuit
by Alfredo Barriga
INTRODUCTION
SPI DEFINITIONS
This application note describes the operation of a generalpurpose, microcontroller-based Serial Port Interface (SPI) boot
circuit. This is a low cost solution for users who need to modify
some of their device’s parameters at power up. This circuit
addresses a 3-wire SPI application for programming converters,
or any device that has a SPI option, and sends commands to
user-defined SPI registers.
The SPI port consists of three pins. These are the serial clock
pin (SCLK), the serial data IO pin (SDIO) and the chip select
bar pin (CSB). SCLK is the serial shift clock in and is used to
synchronize serial interface reads and writes. SDIO is a dualpurpose pin, which is used as an input and output depending
on the instruction being sent and the relative position in the
timing frame. CSB is an active low control that gates the read
and write cycles. Figure 1 shows the SPI timing details. Table 1
provides specifications.
tDS
tS
tHI
tDH
CSB
DON’T CARE
SDIO
DON’T CARE
tLO
DON’T CARE
R/W
W1
W0
A12
A11
A10
A9
A8
A7
D5
D4
D3
D2
Figure 1. SPI Timing Details
Table 1.
Specification Name
tDS
tDH
tCLK
tS
tH
tHI
tLO
Meaning
Setup time between data and rising edge of SCLK
Hold time between data and rising edge of SCLK
Period of the clock
Setup time between CSB and SCLK
Hold time between CSB and SCLK
Minimum period that SCLK should be in a logic high state
Minimum period that SCLK should be in a logic low state
www.BDTIC.com/ADI
Rev. 0 | Page 1 of 8
D1
D0
DON’T CARE
05686-001
SCLK
tH
tCLK
AN-812
TABLE OF CONTENTS
Introduction ...................................................................................... 1
SPI Definitions .................................................................................. 1
Revision History ........................................................................... 2
Circuit Description........................................................................... 3
Configuration File ........................................................................ 3
Circuit Operation ......................................................................... 4
Programming the Device................................................................. 5
Off-PCB Programming................................................................ 5
Voltage Level Translation ............................................................ 6
Obtaining Code and Programming Tools................................. 6
Component Details and BOM ........................................................ 7
References .......................................................................................... 8
REVISION HISTORY
12/05—Revision 0: Initial Version
www.BDTIC.com/ADI
Rev. 0 | Page 2 of 8
AN-812
CIRCUIT DESCRIPTION
The core of this particular SPI boot circuit is the PIC12F629
microcontroller. This Flash™-based device is capable of writing
to the SPI port using the SCLK, SDIO, and CSB control signals.
It can be programmed many times to fit different application
needs, and because of its small size, can be easily incorporated
on any design.
CONFIGURATION FILE
05686-002
The configuration file to be programmed into the chip is
automatically generated by a standalone LabVIEW™ application
which allows the user to specify the number of registers to be
accessed and the 8-bit data-word to be written on each location.
LabView generates the assembly code which is then compiled
and linked to produce the hex file to be programmed into the
microcontroller.
There are two applications used for this purpose, which are
called by the main LabVIEW standalone configuration program
(SPI Code Builder.exe). MPASM® by Microchip® is used to
compile and link the assembly program, and PicFLASH® by
MikroElektronika® serves as a programmer to load the
generated hex file into the microcontroller. These two
Windows®-based applications have been included in the SPI
Code Builder application setup file. The user may also employ
any other compiler and programming application to assemble
the source code provided by the standalone program. Figure 2
shows an example of the SPI Code Builder and PicFLASH®
Programmer windows.
Figure 2. SPI Code Builder and PicFLASH® Windows
www.BDTIC.com/ADI
Rev. 0 | Page 3 of 8
AN-812
CIRCUIT OPERATION
The PIC12F629 is a low cost 8-pin, 8-bit microcontroller. It
features an internal oscillator which can be enabled to eliminate
the need of using an external clock source. The device operates
at an internal frequency of 4 MHz, and the clock output
frequency from the SCLK pin is based on its operating speed
and number of instruction cycles.
down mode in which minimal power is dissipated (13 μW
max). The device can be restarted at any time by pressing the
RESET button or simply by cycling the power supply. An
optional LED may be connected to Pin 3 (GP4) to indicate that
the device is busy during the data transfer process. Figure 3
shows the SPI boot circuit schematic diagram. This circuit can
be used for any 3.3 V tolerant SPI interface and can be
implemented very inexpensively. A voltage level translator may
also be incorporated for devices requiring lower input voltages.
The microcontroller operates immediately after power up by
sending write commands to the target device. After the
microcontroller has finished sending the data, it enters a power-
3.3V
SW1
1 B
2
OFF
3 A
U1
1
C2
0.1µF
R1
4.7kΩ
2
3
SW2
4
2
4
3
VSS
GP5
GP0
GP4
GP1 6
MCLA
GP2 5
7
GND
R2
4.7kΩ
SPI PORT
R3
4.7kΩ
R4
4.7kΩ
SCLK
SDI
CSB
PIC12F629_SN
OPTIONAL
RESET
R5
200Ω
CR1
U2
5.0V
3.3V P1
GND P2
1
2
L1
120nF
2
3
4
5
6
7
8
9
10
ISP
(PIC PROGRAMMER)
3.3V
C3
10µF
1
C4
0.1µF
05686-003
1
8
VDD
OPTIONAL
Figure 3. SPI Boot Circuit
www.BDTIC.com/ADI
Rev. 0 | Page 4 of 8
AN-812
PROGRAMMING THE DEVICE
OFF-PCB PROGRAMMING
The microcontroller used in this implementation can be serially
programmed while in the end application circuit. This is done
with two lines for clock and data, and three lines for power,
ground, and programming voltage/RESET. There are a number
of low cost serial and USB programmers available in the market,
such as the PicFLASH®USB programmer by MikroElektronika®.
This programmer can be purchased online at a low cost.
The user may choose to program the microcontroller before
soldering it to the board. This can be done by using the
appropriate socket for the package selected (8-lead PDIP, SOIC,
or DFN-S). The control lines used by the programmer can be
directly connected into the socket for off-PCB programming.
Figure 3 shows a simplified schematic using a preprogrammed
microcontroller. In this circuit, VDD is directly connected to
the 3.3 V supply and the RESET button is permanently removed
from MCLR (Pin 4). The user can choose to enable or disable
the microcontroller by adding a jumper between the supply and
the VDD pin.
Programming specifications require that the unit be powered at
5 V during programming. If the microcontroller is operated at a
voltage smaller than 5 V, a switch or a two-position jumper
must be added to select from system supply and programming
supply (SW1). A three-position switch allows the circuit to be
in three different modes—programming mode, normal SPI
mode, and power off. The off position can be incorporated if
the user does not want to write to the SPI port when the system
is powered up. To eliminate the need of switching between
programming supply and system supply, the microcontroller
can be permanently powered at 5 V. This adds simplicity to the
design and at the same time complies with the programming
voltage requirement.
Another advantage of programming the microcontroller offPCB is that there is no worry about setting the microcontroller
to a voltage that matches the required programming supply
voltage. The device can be powered at any voltage between 2 V
and 5.5 V, providing the flexibility of using an existing power
supply.
3.3V
U1
2
R1
4.7kΩ
3
4
VDD
GP5
GP4
MCLA
VSS
GP0
GP1
GP2
8
7
6
5
PIC12F629_SN
GND
SCLK
SDI
CSB
SPI PORT
R2
0.1µF
05686-004
1
Figure 4. SPI Boot Circuit (Simplified)
www.BDTIC.com/ADI
Rev. 0 | Page 5 of 8
AN-812
VOLTAGE LEVEL TRANSLATION
Logic thresholds are dictated by the process and design
implemented on each product. On some products, SPI inputs
are 5 V or 3.3 V tolerant. However, other products may only
accept smaller voltages (for example, 1.8 V). In this case, it
might be necessary to incorporate a voltage level translator to
adapt the levels from the microcontroller to levels acceptable to
the inputs of the DUT. It is recommended that the customer
uses the ADG3304 which is a four-channel bidirectional level
translator. The translator can be customized to perform
bidirectional logic level translation without an additional signal
to set the direction in which the translation takes place. For
instance, if the microcontroller is operating at 5 V supply and
the SPI port is 1.8 V tolerant, the ADG3304 can be set so that it
translates the SCLK, SDI, and CSB signals from 5 V to 1.8 V.
The ADG3304 is an easy-to-use solution that requires very few
external components. Moreover, the user can disable the
outputs from the translator at any time by pulling Pin 8 (EN)
low. Figure 5 shows the implementation of the SPI boot circuit
with the voltage level translator.
OBTAINING CODE AND PROGRAMMING TOOLS
Source code and installer with programming tools can be found
at no cost at www.analog.com. For information about the
PicFLASH USB programmer, go to www.mikroelektronika.co.yu.
5V
C428
0.1µF
U402
1
R418
4.7kΩ
S401
1
2
3
3
VDD
VSS
GP5
GP0
GP4
GP1
8
7
6
4 MCLA/GP3 GP2 5
4
RESET/REPROGRAM
C427
0.1µF
PIC12F629_SN
OPTIONAL
2
R419
261Ω
CR401
LED_SS
14
R421
4.7kΩ
R422
4.7kΩ
R423
4.7kΩ
13
12
11
10
5V
9
R425
10kΩ
E401
J401
PICVCC 1
2
GP1 3
4
GP0 5
6
NCLA/GP3 7
8
9
PICVCC
GP1
8
2
VCCY
VCCA
Y1
A1
Y2
A2
Y3
A3
Y4
A4
9
EN
NC
GND
1
2
3
4
5
SCLK_DUT
SDIO_DUT
CSB_DUT
6
7
ADC3304BRUZ
JP401
1
GP0
CLOSED—HI-Z
OPEN—NORMAL OP
NCLA/GP3
10
CLOSE WHEN PROGRAMMING PIC (U402)
ISP
(PIC PROGRAMMING HEADER)
Figure 5. SPI Boot Circuit with Translator
www.BDTIC.com/ADI
Rev. 0 | Page 6 of 8
C429
0.1µF
U403
05686-005
5V
SPI_VDD
AN-812
COMPONENT DETAILS AND BOM
Table 2. Recurring Components
QTY
4
1
1
1
1
DEVICE
RES_402
SWITCH01 1
PIC12F629_SOIC
HEADER10
Any three-position switch. May also use a jumper block.
Table 3. One Time Purchases
QTY
1
1
DEVICE
PIC Flash USB Programmer 1
Or any PIC compatible serial programmer.
Table 4. Optional Components
QTY
1
1
1
1
1
DEVICE
8-Lead SOIC Socket
LED_GAAS
RES_402
ADG3304
PUSHBUTTON
www.BDTIC.com/ADI
Rev. 0 | Page 7 of 8
AN-812
REFERENCES
•
Interfacing to High Speed ADCs via SPI® User Manual is available at www.analog.com.
•
The ADG3304 data sheet is available at www.analog.com.
•
The PIC12F629 data sheet and MPLAB® PM3 ICSP Design Guide can be obtained from Microchip® at www.microchip.com.
•
Information on the PicFLASH® USB Programmer and open source software can be obtained at www.mikroelektronika.co.yu
© 2005 Analog Devices, Inc. All rights reserved. Trademarks and
registered trademarks are the property of their respective owners.
AN05686-0-12/05(0)
T
T
www.BDTIC.com/ADI
Rev. 0 | Page 8 of 8