– 80C51 core wit h 6 clocks per instructi on
– 8 MHz On-Chip Oscil lator
– PLL for generating clock to supply CPU core, USB and Smart Card Interfaces
– Programmable CPU clock from 500 KHz / X1 to 48 MHz / X1
• Reset Controller
– Power On Reset (POR) featur e avoiding an external reset capacitor
– Power Fail Detector (PFD)
– Watch-Dog Timer
• Power Management
– Two power saving modes : Idle and Power Down
– Four Power Down Wake-u p Sources : Smart Card Detection, Keyboard Interrupt, USB
Resume, External Interrupt
– Input Voltage Range : 3.0V - 5.5V
– Core’s Power Consu mp ti on (Without Smart Card and USB) :
•30 mA Maximum Operating Current @ 48 MHz / X1
•200 μA Maximum Power- down Current @ 5.5V
• Interrupt Controller
– up to 9 interrupt sources
– up to 4 Leve l P rio r ity
• Memory Controller
– Internal Progra m memory :
•up to 32KB of Flash or CRAM or ROM for AT8xC5122
•up to 30KB of ROM for AT83C5123
– Internal Data Me mory : 768 bytes including 256 bytes of data and 512 bytes of XRAM
– Optional : inter nal data E2PROM 512 bytes
• T w o 16-bit Timer/Counters
• USB 2.0 Full Speed Interface
–48 MHz DPLL
– On-Chip 3.3V USB voltage regulator and transcei vers
– Software detach feature
– 7 endpoints programmable with In or out directions and ISO, Bulk or Int errupt Transf ers :
•Endpoint 0: 32 Bytes Bidirectionnal FIFO for Control transfers
•Endpoint s 1,2,3: 8 bytes FIFO
•Endpoint s 4,5: 64 Bytes FIFO
•Endpoint 6: 2*64 byt es FIFO with Pin-Pong feature
• ISO 7816 UART Interface Fully Compliant with EMV, GIE-CB and WHQL Standards
– Programmable ISO clock from 1 MHz to 4.8 MHz
– Card insertion/removal detection wit h automatic deactiva tion sequence
– Programmable Baud Rate Generator from 372 to 11.625 clock pulses
– Synchronous/Asynchronous Protocols T=0 and T=1 with Direct or Inverse Convention
– Automatic character repetition on parity errors
– 32 B it Wa iting Time Count e r
– 16 Bit Guard Time Counter
– Internal Step Up/Down Converter with Programmable Voltage Output:
•VCC = 4.0V to 5.5V, 1.8V -30 mA, 3V- 60 mA and 5V-60 mA
•VCC = 3.0V, 1.8V-30 mA, 3V-30 m A and 5V-30 mA
– Current overload protection
– 6 kV ESD (MIL/STD 833 Class 3) protection on whole Smart Card Interface
• Alternate Smart Card Interface with CLK, IO and RST
• UART Interface with Integrat ed Baud Rate Gener ator (BRG)
• Keyboard interface with up to 20x8 matrix management capability
• Master/Slave SPI Interface
• Four 8 bit Ports, one 6 bit port, one 3-bit port
– Up to Seven LED outputs with 3 lev el programmable current source : 2, 4 and 10 mA
– Two Gene ral Purpose I/O programmable as ext ernal interrupts
– Up to 8 input lines programmable as interrupts
– Up to 30 outp ut lines
C51
Microcontroller
with USB and
Smart Card
Reader
Interfaces
Reference DocumentsThe user must get the following additionnal documents which are not included but which
complete this product datasheet
•Product Errata Sheet
•Bootloader Datasheet
2
4202E–SCR–06/06
AT8xC5122/23
Product DescriptionAT8xC5122/23 products are high-performance CMOS derivatives of the 80C51 8-bit
microcontrollers designed for USB smart card reader applications.
The AT8xC5122 is proposed in four versions :
- ROM vers ion w ith or wi thout interna l data E 2PR OM. T he RO M dev ice is on ly fa ctory
programmable.
- CRAM version withou t interna l data E2PR OM. The CRAM devi ce impl ements a vol atile program memory whic h is programmed by means of a n embedded ROMed
bootloader which transfers the code from a remote software programming tool called
FLIP through UART or USB interfaces.
- Flash version without internal data E2PROM. At power-up, the program located in the
flash memory is transferred into the CRAM then executed.
The AT83C5123 is a low pi n count of the AT 8xC5122 and is propos ed in ROM version
with or without internal data E2PROM. The ROM device is only factory programmable.
The AT8xC5122DS is a secure version of the AT8xC5122 on which the external program memory access mode is disabled.
The Port pins are driven to their reset conditions when a voltage
is applied, whether or not the oscillator is running.
IL
when the chip is in Idle mode or Power-Down mode
Ω
VREF < 3.6 V
can be connected to D+ through a 1.5 KΩ resistor. The V
RST
V
341645193416VCCI/0
D+6029526029DVCCI/O
D-5928415928DVCCI/O
6130636130AVCCO
REF
lower than V
This pin has an internal 10K pull-up resistor which allows the device
to be reset by connecting a capacit or between this pi n and VSS.
Asserting RST
returns the chip to normal operation.
The output is active for at least 12 oscillator periods when an internal
reset occurs.
USB Positive Data Upstream Port
This pin requires an external serial resistor of 27Ω (AT8xC122) or
33Ω (AT83C5123) and a 1.5 K
configuration.
USB Negative Data Upstream Port
This pin requires an external serial resistor of 27Ω (AT8xC122) or
33Ω (AT83C5123)
USB Voltage Reference: 3.0 <
V
REF
voltage is controlled by software.
Input
WPD
Input
WPD
Input
WPD
pull-up to VREF for full speed
Input
WPU
Input
WPU
Input
WPU
REF
XTAL
XTAL
VCC
ALE21-32-21- VCCO
311442173114VCCI
1
321543183215VCCO
2
EA
/
63-8-63-VCCI
Input to the on-chip inverting oscillator amplifier
To use the internal oscillator, a crystal or an external oscillator must
be conn ected to this pin.
Output of the on-chip inverting oscillator amplifier
To use the internal oscillator, a crystal circuit must be connected to
this pin. If an external oscillator is used, leave XTAL2 unconnected.
Exter nal Access Enable (Only AT8xC5122)
must be strapped to ground in order to enable the device to fetch
EA
code from external memory locations 0000h to FFFFh.
If security level 1 is programmed, EA
Warning : EA pin cannot be left floating. If the External Access
Enable mod e i s not u se d, EA pi n mus t b e st rapp ed to V CC . I f this l ast
condition is not met,the MCU may have an unpredictable behaviour.
VCC (Only AT89C5122DS)
Address Latch Enable/Program Pulse: Ou tp ut puls e f or latc hing
the low byte of the address during an access to external memory. In
normal operation, ALE is emitted at a constant rate of 1/6 (1/3 in X2
mode) t he os cil lat or f r equ enc y, and can be use d fo r ex ter nal t i mi ng or
clocki ng. Note that one ALE pulse is skipped during each access to
external data memory. ALE can be disabled by setting SFR’s
AUXR.0 bit. With this bit set, ALE will be inactive during internal
fetches
will be latched on reset.
4202E–SCR–06/06
15
AT8xC5122/23
Table 2. Pin Description (Continued)
Internal
Power
QFN64
Port
PSEN15-24-15-VCCO
VQFP64
VQFP32
PLCC68
PLCC28
QFN32
Supply ESDI/O
Reset
LevelAlt
Program Strobe Enable: The read strobe to external program
memory. When executing code from the external program memory,
PSEN
activations are skipped during each access to external data memory.
PSEN
Reset
ConfigConf 1Conf 2Conf 3Led
is activated twice each machine cycle, except that two PSEN
is not activated during fetches from internal program memory.
PLLF542667275426AVCCO
AVCC552768285527PWR
VCC201231152012PWR
LI181029131810PWR
CVCC1792812179PWR
DVCC1110511PWR
PLL Low Pass Filter input
Receives the RC network of the PLL low pass filter.
Analog Supply Voltage
AVCC is used to supply the internal 3.3V analog regulator which
supplies the i nternal USB driver
Supply Voltage
VCC is used to supply the internal 3.3V digital regulator which
supplies the PLL, CPU core and internal I/O ’s
DC/DC Input
LI supplies the current for the charge pump of the DC/DC converter.
- LI tied directly to VCC : the DC/DC converter must be configured in
regulator mode.
- LI tied to VC C through an ext ernal 10 µH coil : the DC/DC convert er
can be configured either in regulator or in pump mode.
Card Supply Voltage
CVCC is t he ouput of internal DC/DC co nverter w hich supplies the
Smart Card Interface. It must be connected to an external decoupling
capacitor of 10 µF with the lowest ESR as this parameter influences
on the CVCC noise
Digital Supply V olta ge
DVCC is t he output of the internal analog 3.3V regulator whi c h
supplies the USB driver. This pin must be connected to an external
680nF decoupling capacitor if the USB interface is used.
This ou tpu t ca n be use d by th e ap pl ic ati on w ith a max im um of 10 mA.
CVSS191130141911GND
VSS1682511168GND
AVSS532566265325GND
16
DC/DC Ground
CVSS is used to sink high shunt currents from the external coil
Digital Ground
VSS is used to supply the PLL, buffer ring and the digital core
Analog Ground
AVSS is used to supply the USB driver.
4202E–SCR–06/06
Typical Applications
Recommended External components
All the external components described in the figure and table below must be implemented as close as possible from the microcontroller package.
Table 3. External Components Bill Of Materials
Reference DescriptionValueComments
R1USB Full Speed Pull-up1.5 KΩ +/-10%All product versions
C10Reset capa citor10 µF +/-10%Option al capacitor for all produ c t versio ns
L1DC/DC converter input inductance
Q1Crystal
10 µH +/- 1 0%
Min rated current : 200 mA
Min rated freq. : 4 MHz
8.0000 Mhz +/- 2500 ppm
max
ESR max : 100 Ω
All product versions.
Qualified component : Murata LQH32CN100K21L
If DC/DC converter is not used at 5V, this inductance is optional.
All product versions
4202E–SCR–06/06
17
AT8xC5122/23
USB Keyboard with Smart Card Reader Using the AT8xC5122 and AT89C5122DS Versions
VCC
C9
GND
VCC
EA/VCC (1)
10mA Max
GND
R1
R2
R3
R19
R18
R17
R16
R15
D+
D-
VCC
GND
R14
R13
R12
R11
R10
R09
R08
USB
VBUS
GND
R07
R06
R05
R04
R03
R02
R01
R00
C4
C0
C1
C2
C3
C4
C5
C6
C7
DVCC
VREF
D+
D-
KB0
KB1
KB2
KB3
KB4
KB5
KB6
KB7
P3[0-1,3-4]
P2[0-7]
P0[0-7]
GND
VCCAVCC
C8
VCC
CPRES
CRST1
CCLK1
GND
LEDx
CVCC
CVSS
CRST
CCLK
CC4
CIO
CC8
CIO1
C1
VCC
C7
R5
VCC
VCC
Smart Card
C1
VCC
C5
GND
C2
RST
C3
CLK
C4
C4
C7
I/O
C8
C8
S1
S1
S2
GND
L1
LI
C6
GND
Alternate Card
C1
VCC
C2
RST
C3
CLK
C7
I/O
C5
GND
GND
Keyboard Matrix
Notes :
1 - Pin configuration depends on product versions
18
R4
C3
GND
C2
PLLF
AVSS
VSS
GND
XTAL2XTAL1
Q1
RST
C10
Optional
Capacitor
GND
4202E–SCR–06/06
USB Smart Card Reader Using the AT83C5123 Version
AT8xC5122/23
USB
VBUS
D+
GND
D-
VCC
GND
VCC
10mA Max
GND
R1
R2
R3
C4
C9
VCC
GND
EA
DVCC
VREF
D+
D-
GND
VCCAVCC
C8
VCC
CVCC
CPRES
GND
LEDx
CVSS
CRST
CCLK
CC4
CIO
CC8
C1
VCC
VCC
L1
LI
C6
GND
C7
R5
Smart Card
C1
VCC
C5
GND
C2
RST
C3
CLK
C4
C4
C7
I/O
C8
C8
S1
S1
S2
GND
R4
C3
GND
C2
PLLF
AVSS
VSS
GND
CRST1
CCLK1
CIO1
RST
XTAL2XTAL1
Q1
C10
GND
VCC
GND
Optional
Capacitor
Alternate Card
C1
VCC
C2
RST
C3
CLK
C7
I/O
C5
GND
4202E–SCR–06/06
19
AT8xC5122/23
Memory Or ga nizationThe AT8xC5122/23 devices have separated address spaces for Program and Data
Memory, as shown in Figure 13 on page 29, Figure 14 on page 31 and Figure 15 on
page 32. The logical separation of Program and Data memory allows the Data Memory
to be accessed by 8-bi t addresses , which can be more quic kly stored and m anipulate d
by an-bit CPU. Nevertheless, 16-bit Data Memory addresses can also be generated
through the DPTR register.
Program Memory
Managament
Depending on the state of EA pin, the MCU fetches the code from internal or external
progr am memory (R OMless mod e )
Warning : the EA pin c an not be lef t flo ating , oth er wise M CU m ay have an unpr ed ictable behaviour.
If EA is strapped to VCC, the MCU fetches the code from the internal program memo ry.
The wa y th e MC U works in this mod e depe nds o n the d evic e ve rsi on. S ee next pa ragraphs for further details.
If the EA is strapped to GND, the MCU fetches the code from external program memory.
This mode is common for all device versions wich supports it. After reset, the CPU
begins the execution from location 0000h. There can be up to 64 KBytes of program
memory. In this mode, the internal program memories are disabled.
The hardware configuration for external program execution is shown in Figure 9.
Figure 9. Executing from External Program Memory
AT8xC5122
ALE
P2
P0
AD7:0
A15:8
Latch
EXTERNAL PROGRAM
MEMORY
A15:8
A7:0
A7:0
20
D7:0
OEPSEN#
Note that the 16 I/O line s (Ports 0 and 2) are dedicated to bus func tions during ex ternal
Program Mem ory fetches. P ort 0 serves a s a m ultiplexed a ddre ss/dat bus. It em its the
low byte of the Program Counter (PC L) as an add ress, and then go es into a floa t state
awaiting the arrival of the code byte from the Program Mem ory . During the time that the
low byte of the Program Counter is valid on P0, the signal ALE (Address Latch Enable)
clocks the byte into an address latch. Meanwhile, Port 2 emits the high byte of the Program Counter (PCH). Then PSEN strobes the External Program M emory and the code
byte is read into the MCU.
PSEN is not activated and Ports P0 and P2 are not affected during internal program
fetches.
4202E–SCR–06/06
AT8xC5122/23
Data Memory
Managament
RAM AchitectureThe internal RAM is mapped into three separate segments :
All device versions implements :
- 256 Bytes of RAM to increase data parameter handling and high level language usage
- 512 bytes of XRAM (Extended RAM) to store program data.
•The Lower 128 bytes (addresses 00h to 7Fh) are directly and indirectly
addressable.
•The Upper 128 bytes (addresses 80h to FFh) are indirectly addressable only.
•The Special Function Registers (SFRs) (addresses 80h to FFh) are directly
addressable only.
The U pper 12 8 bytes and SF R’s ha ve the same address spac e but ar e phys ically
separated.
When an instruction ac cesses an i nternal location ab ove addres s 7Fh, the CPU knows
whether the ac cess is in the upper 128 b ytes of data RA M or to SFR space by the
addressing mode used in the instruction.
•Instructions that use direct addressing access SFR space. For example: MOV
0A0H, # data, accesses the SFR at location 0A0h (which is P2).
•Instructions that use indirect addressing access the Upper 128 bytes of data RAM.
For example: MOV @R0, # data where R0 contains 0A0h, accesses the data byte
at address 0A0h, rather than P2 (whose address is 0A0h).
The stack pointer (SP) may be locat ed anywhere in the 256 bytes RAM (lowe r and
upper RAM) internal data memory. The stack may not be located in the XRAM.
The M0 bit al lows to st retc h the X RA M ti mings . If M 0 is s et, t he re ad an d w rite pu ls es
are extended from 6 to 30 clock periods. This is useful to access externa l slow
peripherals.
XRAM AchitectureDepending on the state of EXTRAM bit in AUXR register (See Table 5 on p age 24), t he
MCU fetches data from internal or external XRAM.
If EXTRAM=0 (reset condition), the MCU fetches the data from internal XRAM. The size
of internal XRAM is configured by the bit XRS0 in AUXR register (See Table 5 on page
24).
Table 4. XRAM Size Configuration
Address
XRS0XRAM size
0
1512 bytes000h1FFh
The XRAM logically occupie s the first bytes of external data memory. The bit XRS0 can
be used to hide a part of the available XRAM . This can be use ful if external peripherals
are mapped at addresses already used by the internal XRAM.
The XRAM is indirectly addressed, using the MOVX instruction in combination with any
of the registers R0, R1 of the selected bank or DPTR.
256 Bytes
(Reset condition)
StartEnd
000h0FFh
4202E–SCR–06/06
For example, MOVX @R0, # data where R0 contains 0A0H, accesses the XRAM at
address 0A0H rather than external memory.
21
AT8xC5122/23
An access to e xternal XRAM m emory locations hig her than the accessi ble size o f the
memory (roll-over feature) will be performed with the M OVX DPTR i nstructions, with P 0
and P2 as data/address busses, WR
and RD as respectively write and read signals.
Accesses above XRAM size can only be done by the use of DPTR.
If EXTRAM=1 the MCU fetches the data from external XRAM Memory. There can be up
to 64 KBytes of external XRAM Memory.
The hardware configuration for external Data Memory Access is shown in Figure 10
Figure 10. Accessing to External XRAM Memory
AT8xC5122/23
EXTERNAL XRAM
MEMORY
AD7:0
A15:8
Latch
A7:0
A15:8
A7:0
D7:0
OERD#WR
P2
ALE
P0
WR#
MOVX @Ri an d M OVX @DPT R wil l be similar to the standard 80C51. MOVX @ Ri will
provide an eight-bit address multiplexed with data on Port 0 and any output port pins
can be use d to ou tput hi gher ord er addre ss bi ts. Thi s is to p rovide t he ext ernal pagin g
capability. MO VX @DP TR will generate a sixteen -bit addre ss. Po rt 2 outputs the highorder eight address bits (DPH) while Port0 m ultiplexes the low -order eight address bits
(DPL) with data. MOVX @ Ri a nd M OVX @DPTR will generate either read or write signals on W
R and RD.
Ports P0, P2 are not affected and RD, WR signals are not activated during access to
internal XR AM.
Note that external XRAM Memory access is only available on High Pin Count Packages.
External Program Memory and ext ernal XRAM Memory may be combined if desired by
applying the RD and PSEN sig nals t o the in puts o f a n AND gat e and using the ouput of
the gate as the read strobe to the external program/data memory.
Dual Data Pointer
Register (DDPTR)
22
RD
STROBE
PSEN
The addi tion al da ta poin ter ca n be u sed t o spe ed up code exe cuti on and reduc e cod e
size.
The dual DPTR structure is a way by which the chip will specify the address of an external data memory location. There are two 16-bit DPTR registers that address the external
memory, and a single bit called DPS = AUXR1.0 (see Table 7) that allow the program
code to switch between them (Figure 11).
4202E–SCR–06/06
Figure 11. Use of Dual Pointer
AUXR1(A2H)
Assembly Language
AT8xC5122/23
External Data Memory
07
DPS
DPH(83H) DPL(82H)
a. Bit 2 stuck at 0; this allows to use INC AUXR1 to toggle DPS without changing GF3.
; Block move using dual data pointers
; Modifies DPTR0, DPTR1, A and PSW
; note: DPS exits opposite of entry state
; unless an extra INC AUXR1 is added
;
00A2 AUXR1 QU 0A2H
;
0000 909000MOV DPTR,#SOURCE ; address of SOURCE
0003 05A2 INC AUXR1 ; switch data pointers
0005 90A000 MOV DPTR,#DEST ; address of DEST
0008 LOOP:
0008 05A2 INC AUXR1 ; switch data pointers
000A E0 MOVX A,@DPTR ; get a byte from SOURCE
000B A3 INC DPTR ;increment SOURCE address
000C 05A2 INC AUXR1 ; switch data pointers
000E F0 MOVX @DPTR,A ; write the byte to DEST
000F A3 INC DPTR ; increment DEST address
0010 70F6JNZ LOOP ; check for 0 terminator
0012 05A2 INC AUXR1 ; (optional) restore DPS
DPTR1
DPTR0
4202E–SCR–06/06
INC is a short (2 bytes) and fast (12 clocks) way to manipulate the DPS bit in the AUXR1
SFR. However, note that the INC instruction does not directly force the DPS bit to a particular state, but simply toggl es it. In simple rou tines, such as the block move example,
only the fact that DPS is toggled in the proper sequence matters, not its actual value.
For example, the block move routine works the sam e whether DPS is '0' or '1 ' on ent ry.
Observe that witho ut the last ins truction (INC AUXR1), th e routine will exit with DP S in
the opposite state.
23
AT8xC5122/23
Registers
Table 5. Auxiliary Register - AUXR (8Eh)
76543210
DPU---XRS0EXTRAMAO
Bit
Number
7DPU
6-3-
2XRS0
1EXTRAM
0AO
Bit
Mnemonic Description
Disable weak Pull-up
0weak pull-up is enabled
1 weak pull-up is disabl ed
Reserved
The value read from this bit is indeterminate. Do not change these bits.
XRAM Size
0256 bytes (default)
1512 bytes
EXTRAM bit
Cleared to access internal XRAM using MOVX @ Ri/ @ DPTR.
Set to access external memory.
Programmed by hardware after Power-up regarding Hardware Security Byte
(HSB), default setting , XRAM selected.
ALE Output bit
Cleared , ALE is emitted at a constant rate of 1/6 the o s cillator frequency (or 1/3 if
X2 mode is used)( default).
Set , ALE is active only when a MOVX or MOVC instruction is used.
Reset Value = 0XXX X000b
24
4202E–SCR–06/06
AT8xC5122/23
Table 6. Auxiliary Register 1 AUXR1- (0A2h) for AT8xC5122
76543210
--ENBOOT-GF30-DPS
Bit
Number
7 - 6-
5ENBOOT
4-
3GF3This bit is a general-purpose user flag.
20Always cleared .
1-
0DPS
Bit
Mnemonic Description
Reserved
The valu e re a d from this bit is ind et er m in at e. Do not chang e th es e bits .
Enable Boot ROM (CRAM / E2PROM version only)
Set this bit to map the Boot ROM from 8000h to FFFFh. If the PC increments
beyond 7FFFh address, the code is fetch from int ernal ROM
Clear this bit to disable Bo ot ROM. If the PC increments beyond 7FFF h address,
the code is fetch from external code memory (C51 standard roll over function)
This bit is forced to 1 at reset
Reserved
The value rea d fro m thi s bit is ind et erm in at e. Do no t chang e th is bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. Do no t chang e th is bit.
Data Pointer Selection
Cleared to select DPTR0. Set to select DPTR1.
Reset Value = XX1X XX0X0b (Not bit addressable)
Table 7. Auxiliary Register 1 AUXR1- (0A2h) for AT83C5123
76543210
----GF30-DPS
Bit
Number
7 - 6-
5
4-
3GF3This bit is a general-purpose user flag.
20Always cleared .
1-
0DPS
Bit
Mnemonic Description
Reserved
The valu e re a d from this bit is ind et er m in at e. Do not chang e th es e bits .
Reserved
The valu e re a d from this bit is ind et er m in at e. Do not chang e th es e bits .
Reserved
The value rea d fro m thi s bit is ind et erm in at e. Do no t chang e th is bit.
Reserved
The value rea d fro m thi s bit is ind et erm in at e. Do no t chang e th is bit.
Data Pointer Selection
Cleared to select DPTR0.
Set to select DPTR1.
Reset Value = XXXX XX0X0b (Not bit addressable)
4202E–SCR–06/06
25
AT8xC5122/23
Table 8. CRAM Configuration Register - RCON (D1h)
76543210
----RPS---
Bit
Number
7 - 4-
3RPS
2-0-
Bit
MnemonicDescription
Reset Value = XXXX 0XXXb
AT8xC5122’s CRAM and E2PROM Versions
The AT8xC5122’s CRAM and E2PROM versions implements :
- 32 KB of ROM mapped from 8000 to FFFF in which is embed ded a bootlo ader for In-
System Programming feature
- 32 KB of CRAM (Code RAM) , a volatile program memory mapped from 0000 to 7FFF
In CRAM versions only :
- 512 bytes of E2PROM can be optionally implemented to store permane nt data
Reserved
The value read from this bit is indeterminate. Do not change these bits.
CRAM Memory Mapping Bit
Set to map the CRAM memory during MOVX instructions
Clear to map the XRAM memory during MOVX .
This bit has priority over th e EXTRAM bit.
Reserved
The value read from this bit is indeterminate. Do not change these bits.
In E2PR OM ver sion :
- 32KB of E2PROM are implemented to store permanent code
Warnings :
–so me bytes of user program memory space are reserved for bootloader
configuration. Depending on the configuration, up to 256 bytes of code may
be not available for the user code from 7F00h location. Refer to bootloader
datasheet for further details.
–Port P3.7 may be used by the bootloader as a hardware condition at reset to
select the In-System Programming mode. Once the bootloader has started,
the P3.7 Port is no more used.
26
4202E–SCR–06/06
AT8xC5122 Microcontroller
FFFFh
Bootloader
AT8xC5122/23
P3.7
7FFFh
7F00h
7EFFh
0000h
When pin EA =1 and after the reset, the MCU begins the execution of the embedded
bootloade r from loca tion F8 00h of the ROM. T he b ootload er implem ent s an In-Sys tem
Programming (ISP) mode which manages the transfer of the code in the volatile Program Memory (CR A M) .
For CRAM ve rsion, th e code is sup plied b y the ATME L’s FL exible In-system Pro gramming software (FLIP) through USB or UART interface
For E2PROM vers ion, t he code is supplied from the internal cod e E2P ROM or by F LI P.
The s tate of pi n P 3.7 at re set de term ines the code so urc e. I f P3 .7=1 (re set cond ition )
the source is the internal E2PROM and the transfer takes about 1.5 seconds. If P3.7=0
the source is FLIP and the transfer time depends mainly on external conditions not
related to bootloader.
Reserved
User code
4202E–SCR–06/06
Once the code is running in CRAM, the roll-over condition (code fetched beyond
address 7FFFh) depends on the state of ENBOOT bit of AUXR1 register (Table 6 on
page 25).
If ENBOOT=1 (reset condition) the MCU fetche s the code from bootloader ROM. If
ENBOOT=0, the MCU fetches the code from the external Program Memory. In this last
case, PSEN is activated and Ports P0 and P2 are used to emit data and address
signals.
Warning : external Program Memory access is not allowed on Low Pin Count
Packages.
27
AT8xC5122/23
Using CRAM MemoryThe CRAM is a read / write volatile memory that is mapped in the program memory
space. Then wh en the p ower is sw itched off t he code is l ost and ne eds to be reload at
each power up. In return, the CRAM enabl es a lot of f lexibility in the code dev elopment
as it can be programm ed indefinite ly. The user code runnin g in the CRAM c an perform
read operations in CRAM itself by means of MOVC instructions like any C51 m icrocontroller does. Although the writing operations in CRAM are usually handled by the
bootloader, it is possible for the user code to handle its own writing operations in CRAM
as well. The user co de must c all API functi ons prov ide d by th e bootlo ade r in the R OM
memory. Refer to bootloader datasheet for further details about the use of these API
functions. These API functions use a mechanism provided by the AT8xC5122 microcontroller. When the bit RPS is set in RCON register (Tabl e 8 on page 26), the MOVX
intructions are configured to write in CRAM instead of XRAM m em ory. Ho wever, due t o
C51 architecture, it is not possible for the user c ode to write directly in CRAM when it is
itself running in CRAM. This is why the API functions must be called in order to have the
code executing in ROM while the CRAM is written.
Figure 12. Read / Write Mechanisms in CRAM Memory
API Call
API functions
BOOTLOADER
CRAM
User code
MOVC
RPS=1
MOVX
Writing operation
Read operation
28
4202E–SCR–06/06
Figure 13. AT8xC5122’s CRAM and E2PROM Versions
AT8xC5122/23
(E2PROM version)
FFFF
32K
INTERNAL
E2PROM
(Read/Write)
8000
PROGRAM
MEMORY
Reset@
FFFF
<F800>
8000
Roll-Over
7FFF
0000
EA = 1
ENBOOT=1
32K
INTERNAL
ROM
(Read Only)
32K
INTERNAL
CRAM
(Read/Write)
FFFF
8000
ENBOOT=0
32K
EXTERNAL
PROGRAM
MEMORY
PSEN
Reset@
EA = 0
EXTERNAL
PROGRAM
MEMORY
<0000>
PSEN
DATA MEMORY
(Read / Write)
01FF
0000
EXTRAM=0
Roll-Over
On-chip
512 bytes
XRAM
FFFF
0200
01FF
0000
EXTRAM=1
EXTERNAL
XRAM
EXTERNAL
XRAM
RDWR
Optional
(applicable only to CRAM version)
01FF
512 Bytes
INTERNAL
E2PROM
0000
On-Chip 256 bytes RAM
Indirect
Addressing
FF
128 Bytes
80
7F
00
Upper
RAM
128 Bytes
Direct
Addressing
FF
SFR
Space
80
Lower
RAM
4202E–SCR–06/06
29
AT8xC5122/23
AT8xC5122’s ROM
Version
Security LevelThere are two security levels (applicable to High Pin Count packages only) :
The AT8xC5122’s ROM version implements :
- 32 K of ROM mappe d fro m 0 000h to 7FFFh in which is em bedded the user code. The
ROM device is only factory programmable.
- 512 byte s of E 2P ROM can be op tiona lly imp lem ente d to s tore pe rman en t data. Wi th
this option, the size of ROM is reduced to 30K.
After the rese t, th e MCU b egins t he exe cutio n of the user code fr om lo cation 00 00 h of
the ROM.
Access to external Program Memory is not allowed.
Table 9. Security Level s Des cri ption
Securi ty LevelProte ction description
1No protection lock enabl ed
MOVC instruction executed from external Program Memory is disabled when fe tching
2
code bytes from internal Program Memory
EA
is sampled and latched on r eset.
External code execution is enabled.
The security level 2 can be used to protect the user code from piracy. This option is configured at factory and must be requested by the customer at order time.
30
4202E–SCR–06/06
Figure 14. AT8xC5122’s ROM Version
AT8xC5122/23
PROGRAM MEMORY
(Read only)
7FFF
0000
EA=1
Roll-Over
INTERNAL
32K ROM
EXTRAM=0
FFFF
8000
RESET@
<0000>
EA=0
EXTERNAL
EXTERNAL
PSEN
EXTRAM=1
Optional
DATA MEMORY
(Read / Write)
01FF
0000
On-chip
512 bytes
XRAM
FFFF
0200
Roll-Over
01FF
0000
EXTERNAL
XRAM
EXTERNAL
XRAM
RDWR
01FF
512 Bytes
INTERNAL
E2PROM
0000
On-Chip 256 bytes RAM
Indirect
Addressing
FF
80
7F
00
Upper
128 Bytes
RAM
FF
80
Lower
128 Bytes
RAM
Direct
Addressing
SFR
Space
4202E–SCR–06/06
31
AT8xC5122/23
AT83C5123 VersionThe AT83C5123 device is a low pin count version of the AT8xC5122.
The ROM version implements :
- 30 KB of ROM mapp ed from 0000 t o 77 FF in w hich is em bedded the user co de. Th e
ROM device is only factory programmable.
- 512 bytes of E2PROM can be optionally implemented to store permane nt data
Figure 15. AT83C5123’s Device
7FFF
PROGRAM MEMORY
(Read only)
DATA MEMORY
(Read / Write)
RESET@
<0000>
OPTIONAL
01FF
0000
01FF
0000
INTERNAL
30K ROM
512 Bytes
INTERNAL
E2PROM
On-chip
512 bytes
XRAM
On-Chip 256 bytes RAM
Indirect
Addressing
FF
80
7F
00
Upper
128 Bytes
RAM
FF
80
Lower
128 Bytes
RAM
Direct
Addressing
SFR
Space
32
4202E–SCR–06/06
AT8xC5122/23
Special Function
Register s (S FR ’s)
IntroductionThe Special Function Registers (SFRs) of the AT8xC5122/23 can be ranked into the fol-
Can store a new byte to be transmitted on the I/O pin when SCTBE is set. Bit ordering on the I/O pin
depend s on the convention
Provides the byte receive d from th e I/O pin when SCRI is s et. Bit ordering on the I/O pin depends on
the conv en tion.
CARDC8CARDC4CARDIOCARDCLK CARDRST CARDVCC
ICARDOVF VCARDOKSCWTOSCTCSCRCSCPE
ICARDERR VCARDERR
ICARDER EVCARDERESCWTIESCTIESCRIESCPI
WT31-24
ETU10-8
SCWTISCTISCRISCPI
38
4202E–SCR–06/06
AT8xC5122/23
Table 18. SCIB SFRs
MnemonicAddName76543210
SCICLKC1h
Smart Card Frequency
Prescaler Register
XTSCS
(1)
SCICLK5-0
Note:1. Only for AT8xC5122
Table 19. DC/DC SFRs
MnemonicAddName76543210
DCCKPSBFh
DC/DC Converter Reload
Register
MODEOVFADJBOOST[1-0]DCCKPS3-0
Table 20. Keyboard SFRs
MnemonicAddName76543210
(1)
KBF
KBE
KBLS
(1)
(1)
9Eh Keyboard Flag RegisterKBE7 - 0
Keyboard Input Enable
9Dh
Register
Keyboard Level Selector
9Ch
Register
KBF7 - 0
KBLS7 - 0
Note:1. Only for AT8xC5122
Table 21. SPI SFRs
MnemonicAddName76543210
(1)
SPCON
C3h Serial Peripheral ControlSPR2SPENSSDISMSTRCPOLCPHASPR1SPR0
SPSTA
SPDAT
(1)
(1)
Serial Peripheral Status-
C4h
Control
C5h Serial Peripheral DataR7 - 0
SPIFWCOL
MODF
Notes: 1. Only for AT8xC5122
Table 22. USB SFRs
MnemonicAddName76543210
USBCONBCh USB Global ControlUSBESUSPCLK
USBADDRC6h USB AddressFENUADD6-0
USBINTBDh USB Global Interrupt
USBIENBEh
UEPNUMC7 h USB Endpo int Number
UEPCONXD4 h USB Endpo int X ControlEPENNA KIENNA KO UTNAK INDTGLEPDIRE PTYPE1EPTYPE0
UEPSTAXC Eh USB Endpoint X StatusDIRRXOUTB1 STALLRQTXRDYST L/CR CRXSETUP RXOUTB0T XCM P
UEPRSTD5h USB Endpoint Reset
UEPINTF8h USB Endpoint Interrup t
USB Global Interrupt
Enable
EP6RSTEP5RSTEP4RSTEP3RSTEP2RSTEP1RSTEP0RST
EP6INTEP5INTEP4INTEP3INTEP2INTEP1INTEP0INT
SDRMWUP
WUPCPUEORINTS OFINTSPINT
EWUPCPU EEORINTESOFINTESPINT
DETACHUPRSMRMWUPECONFGFADDEN
EPNUM3-0
4202E–SCR–06/06
39
AT8xC5122/23
Table 22. USB SFRs
MnemonicAddName76543210
UEPIENC2h
UEPDATXCFh USB Endpoint X Fifo DataFDAT7 - 0
UBYCTXE2h
UFNUMLBAh USB Frame Number LowFNUM7 - 0
UFNUMHBBh USB Frame Number High
USB Endpoint Interrupt
Enable
USB Byte Counter Low
(EPX)
EP6INTEEP5INTEEP4INTEEP3INTEEP2INTEEP1INTEEP0INTE
BYCT6-0
CRCOKCRCERRFNUM10-8
Table 23. LED SFRs
MnemonicAddName76543210
LEDCON0F1h LED Control 0LED3LED2LED1L ED0
LEDCON1
(1)
E1h LED Control 1LED6LED5LED4
Note:1. Only for AT8xC5122
40
4202E–SCR–06/06
AT8xC5122/23
Clock ControllerThe clock controller is based on an on-chip oscillator feeding an on-chip Phase Lock
Loop (PLL). All the internal clocks to the CPU core and peripherals are generated by this
controller.
On-Chip OscillatorThe on-chip oscillator is composed of a single-stage inverter and a parallel feedback
resistor. The XTAL1 and XTAL2 pins are respectively the input and the output of the
inverter, which can be configured with off-chip components as a Pierce oscillator (see
Figure 16).
The on-chip oscillator has been designed and optimized to work with an external 8 MHz
crystal and very few load capacitance. Then external load capacitors are not needed
given that :
–the internal capacitance of the microcontroller and the stray capacitance of
circuit board are enough to ensure a stable oscillation
–a very high accuracy on the oscillation frequency is not needed
The circuit works on its fundamental frequency at 8 MHz.
Figure 16. Oscillator Schematic
Microcontroller
To internal
Feedback
Resistor
clock ci rcuitry
XTAL1
C1C2
C1 and C2 represents the internal capacitance o f the microcontroller and the stray
capacitance of the circuit board. It is recommended to implement the crystal as close as
possible from the microcontroller package.
Quartz SpecificationThe equivalent circuit of a crystal is represented on the figure below :
The Equivalent Serial Resistance R1 must be lower than 100 Ohm.
8 MHz
GNDGND
L1C1R1
XTAL2
C0
4202E–SCR–06/06
41
AT8xC5122/23
Phase Lock Loop (P LL)
PLL Descrip t io nThe AT8xC5122/23’s PLL is used to generate internal high frequency clock synchro-
nized with an external low-frequency. Figure 17 shows the internal structure of the PLL.
The PFLD block is the Phase Frequency Comparator and Lock Detector. This block
makes the com parison betwe en the ref erence clock coming f rom the N divi der and th e
reverse clock coming from the R divider and generates some pulses on the Up or Down
signal depending o n the edge po sition of the reverse clock . The PLLE N bit in PLLCON
register is used to enable the clock generation. When the PLL is locked, the bit PLOCK
in PLLCON register is set.
The CHP block is the Charge Pump that generates the voltage reference for the VCO by
injecting or e xtracting charges from the extern al filter conne cted on P LLF pin (se e
Figur e 18). Va lue of the filter co mponents are deta iled in th e Section “DC
Characteristics”.
CK_XTAL1
The VCO block is the Voltage Controlled Oscillator controlled by the voltage V
REF
produced by th e charge pump . It generates a squ are wave signal: t he PLL clock. Th e
CK_PLL frequency is defined by the follwing formula:
F
CK_PLL
= F
CK_XTAL1
* (R+1) / (N+1)
Figure 17. PLL Block Diagram and Symbol
PLLF
CHP
R divider
R3:0
V
REF
VCOCK_PLL
N Divider
N3:0
PLLCON.1
PLLEN
Up
PFLD
Down
PLOCK
PLLCON.0
Figure 18. PLL Filter V alu e
PLLF
1,8
K
Ω
150 pF
VSS
33 pF
VSS
PLL Program m i ngThe PLL must be programmed t o wo rk a t 96 MHz frequency by means of PL LCON a nd
PLLDIV registers. As soon as the PLL is enabled, the firmware must wait for the lock bit
status to ensure that the PLL is ready.
42
4202E–SCR–06/06
Figure 19. PLL Programming Flow
PLL
Programming
Configure Divi ders
N3:0=
xxxxb
R3:0= xxxxb
Enable PLL
PLLEN= 1
PLL Locked?
PLOCK= 1?
AT8xC5122/23
Clock Tree ArchitectureThe clock controller outputs several different clocks as shown in Figure 20:
•a clock for the CPU core
•a clock for the peripherals which is used to generate the timers, watchdog, SPI,
UART, and ports sampling clocks. This divided clock will be used to generate the
alternate card clock.
•a clock for the USB
•a clock for the SCIB controller
•a clock for the DC/DC converter
These clocks are enabled or not depending on th e power redu ction mode as detailed in
Section “Power Management”, page 180.
These clocks are generated using four presacalers defined in the table below:
CPU and Peripheral ClocksTwo clocks sources are available for CPU and peripherals:
–on -c h ip o s c illator
–a derivative of the PLL clock.
These clock sources are configured by the PR1 prescaler to generate the CPU core
CK_CPU and the peripheral clocks:
–CK_IDLE fo r alternate card and peripherals registers access
–CK_T0 for Timer 0
–CK_T1 for Timer 1
–C K_SI for th e UART
–CK_WD for the Watchdog Timer
–CK_SPI for SPI
44
4202E–SCR–06/06
AT8xC5122/23
The CPU and peripherals clocks frequencies are defined in the table below.
CKSX2F
00F
01F
10F
11Not allowed
X1 and X2 ModesUse of on - chip osc illator
When the C PU a nd P eri phe rals cl ock s are fe d by the on -chi p os ci lla tor, the C PU an d
Peripherals can be configured independently in X1 or X2 mode depending on the frequencies wanted by the user. There is however one exception : the periperals can be
configured in X2 mode while the CPU remains in X1 mode. This exception is handled by
the hardware and the user does not need to take care of.
Table 1. X1 and X2 Mode Selection
CPUPeripheralsStatusFrequenci
X1 modeX1 mode
X1 modeX2 modeNot Allowed by the hardware
X2 modeX1 mode
CK_IDLE
CK_XTAL1
CK_XTAL1
CK_PLL
(default configurat ion at reset)
Once the CPU is swi tche d t o X2
mode, the user is free to switch
any of the peripherals to X1
/(2*(16-CKRL))
/(2*(16-CKRL))
Allowed
Allowed
mode
F
CK_IDLE
F
CK_IDLE
= F
= 2*F
CK_PERIPH
CK_PERIPH
Allowed
X2 modeX2 mode
Defaul t conf ig ura ti on wh en CPU
is switched to X2 mode
F
CK_IDLE
= F
CK_PERIPH
The X1 or X2 modes can be individually selected for the CPU and each peripheral by
means of CKC ON0 and CKCO N1 register s. At rese t, the C PU and P eriphe rals are set
all by default to X1 mode. In this mode, changing any peripheral to X2 mode has no
effec t. Wh en X2 bit is se t in C KCO N 0 reg iste r, C PU an d Al l pe riph eral s are au toma tically switched to X2 mode. It is then possible for the user to individually switch any
peripheral back to X1 mode.
In X1 mode (X2 bit cleare d in CKCON0 reg siter), the PR1 pres caler is active while it is
bypassed in X2 mode (X2 bit set in CKCON0 register).
The X1 mode is true only when the prescaler PR1 is set to 1/2 (default condition at
reset).
4202E–SCR–06/06
45
AT8xC5122/23
)
)
Figure 21. X1 mode
Crystal
8 MHz
PR1 prescaler
1/2
CPU frequency
4 MHz
Peripheral frequency
4 MHz
When the X1 mode is selected, the CPU and Peripherals work at 8Mhz / X1
Figure 22. X2 mode
Crystal
8 MHz
Internal Prescaler
1/2
CPU frequency (X2 Mode)
8 MHz
Peripheral frequency (X2 mode
8 MHz
Peripheral frequency (X1 mode
4 MHz
When the X2 mode is selected, the CPU works at 8 MHz / X2. The Peripherals can work
at 8 MHz / X2 or 8 MHz / X1.
When the PR1 prescaler is different from 1/2 , the usual X1 mode can not be defined. I n
this case, it is necessary to define a X1 or X2 equivalent mode from equivalent clock
circuits.
Example : PR1=1/8, X2=0.
In this configuration, the CPU works at 1 MHz. This frequency could also be obtained by
an equivalent cloc k circuit where t he on-chip o scillator woul d run at 2 MHz in X1 mod e
or at 1 MHz in X2 mode. So we can say that the CPU works at 2 MHz / X1 or 1MHz / X2.
As the X2 bit is cleared in CKCON0 register, we have F
CK_IDLE
= F
CK_PERIPH
.
46
4202E–SCR–06/06
AT8xC5122/23
Crystal
8 MHz
External Clock
2 MHz
External Clock
1 MHz
PR1 Prescaler
1/8
(Equivalent to)
X1 mode selected
1/2
(Equivalent to)
X2 mode selected
CPU frequency
1 MHz
PERIPH frequency
1 MHz
CPU frequency
1 MHz
PERIPH frequency
1 MHz
CPU frequency
1 MHz
PERIPH frequency
1 MHz
Use of PLL ClockWhen the CPU clock is fed by the P LL, the X2 mode is forbi dden. The bit X2 m ust
always remain cleared in CKCON0 register. As the PR1 prescaler is always different
from 1/2, the usual X1 mode can not be defined. So it is neces sary to defi ne an eq uivalent X1 or X2 mode from equivalent clock circuits, as in previous section.
Examp le: P R1= 1/4 , PL L feed s th e C PU. T he C PU works in this ca se at 2 4 MH z. Thi s
frequency could also be ob tai ned by an equivalent clock circuit where th e on-c hip osc illator would run at 48 MHz in X1 mode o r at 24 Mhz in X2 mode. So we c an say that in
this configuration, the CPU works at 48 MHz / X1 or 24 MHz / X2 (See figures below).
As the X2 bit is cleared in CKCON0 register, we have always F
SCIB clock frequency must be lower than CPU clock frequency.
During SCIB Reset, the CK_ISO input m ust be in the range 1 - 5 M H z ac cording to ISO
7816. The SCIB clocks frequency is defined in Figure 42 on page 74 and Tab le 42 on
page 74.
Two conditions must be met for a correct use of the SCIB:
•CK_CPU > 4/3 * CK_ISO and
•CK_CPU < 6 * CK_ISO.
48
4202E–SCR–06/06
AT8xC5122/23
If the CK_CPU <= 4/3 * CK_ISO, the SCIB doesn’t work.
If the CK_CPU >= 6* CK_ISO, the programmer must take care in three cases:
•Read (or write) operation on a SCIB register followed immediatly with an other Read
(or write) operation on the same register.
•Read (or write) operation on a SCIB register followed immediatly with an other Read
(or write) operation on a linked register. The list of linked registers is in the table
below.
Linked registers
Write in SCICR and after read of SCETU0-1
Write in SCIBUF and after read of SCISR
•Write operation on a register of the list below followed immediatly with a read
operation on a SCIB register.
Wait after Write operation on thi s registers
SCICR, SCIER, SCETU0-1,SCGT0-1,
SCWT0-3,SCCON
To avoid any trouble, a delay must be added between the two accesses on the SCIB
register. The SCIB must complete the first read (or write) operation before to receive the
second. A solution is to add NOP (no operation) instructions. The number of NOP to add
depends of the rate between CK_CPU and CK_ISO (see table below).
The value read from this bit is indeterminate. Do not set this bit.
Watchdog clock
This control bit is validated when the CPU clock X2 is set; when X2 is low,
this bit has no effec t.
Cleare d to bypass the PR1 prescaler.
Set to select the PR 1 output for this periphe ral.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Enhanced UART clock (Mode 0 and 2)
This control bit is validated when the CPU clock X2 is set; when X2 is low,
this bit has no effec t.
Cleare d to bypass the PR1 prescaler.
Set to select the PR 1 output for this periphe ral.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Timer 1 clock
This control bit is validated when the CPU clock X2 is set; when X2 is low,
this bit has no effec t.
Cleare d to bypass the PR1 prescaler.
Set to select the PR 1 output for this periphe ral.
Timer 0 clock
This control bit is validated when the CPU clock X2 is set; when X2 is low,
this bit has no effec t.
Cleare d to bypass the PR1 prescaler.
Set to select the PR 1 output for this periphe ral.
System clock Control bit
Cleared to select the PR1 output for CPU and all the peripherals .
Set to byp a ss the PR1 p r esc aler an d to en ab le th e indi vi du al pe rip hera ls ‘X 2’
bits.
4202E–SCR–06/06
51
AT8xC5122/23
Table 27. Clock Configuration Register 1 - CKCON1 (S:AFh) only for AT8xC5122
76543210
-------SPIX2
Bit Number Bit Mnemonic Description
7 - 4-
3-
0SPIX2
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
SPI clock
This control bit is validated when the CPU clock X2 is set. When X2 is low,
this bit has no effec t.
Cleare d to bypass the PR1 prescaler.
Set to select the PR 1 output for this periphe ral.
Reset Value = XXXX XXX0b
Table 28. PLL Control Register - PLLCON (S:A3h)
76543210
-----EXT48PLLEN PLOCK
Bit Number Bit Mnemonic Description
7 - 3-
2EXT48
Reserved
The value read from these bits is always 0. Do not set this bits.
External 48 MHz Enable Bit
Set this bit to select XTAL1 as USB clock.
Clear this bit to select PLL as USB clock.
SCIB clock is controlled by EXT48 bit and XTSCS bit.
52
PLL Enable bit
1PLLEN
0PLOCK
Set to enable the PLL.
Clear to disable the PLL.
PLL Lock Indicator
Set by hardware when PLL is locked
Clear by hardware when PLL is unlocked
Reset Value = 0000 0000b
Table 29. PLL Divider Register - PLLDIV (S:A4h)
76543210
R3R2R1R0N3N2N1 N0
Bit Number Bit Mnemonic Description
7 - 4R3:0PLL R Divider Bits
3 - 0N3:0PLL N Divider Bits
Reset Value = 0000 0000b
4202E–SCR–06/06
I/O Port Definition
Ports vs PackagesTable 30. I/O Number vs Packages
P0P1P2P3P4P5Tot al
AT8xC5122/23
VQFP64
QFN64
VQFP32
QFN32
PLCC28-6-6-113
88886846
-8-8-117
Port 0Port 0 has the following functions:
–Default function: Port 0 is an 8-bit I/O port.
–Alternate function: Port 0 is also the multiplexed low-order address and data
bus during accesses to external Program and Data Memory. In this
application, it uses strong internal pull-ups when emitting 1’s and it can drive
CMOS inputs without external pull-ups.
Port 0 has the following configurations:
–Default configuration: open drain bi-directional I/O port. Port 0 pins that have
1’s written to them float, and in this state they can be used as high-
–Default function: Port 3 is an 8-bit I/O port.
–Alternate functions : see table below
Port 3 has the following configurations:
–Default configuration: Pseudo bi-directional “Port51” digital input/output with
internal pull-ups.
–Alternate configurations: See Table 32.
Table 32. Port 3 Description
Alternate FunctionsConfigurations
AT8xC5122/23
Port
P3.0RxD
P3.1TxD
P3.2INT0External interrupt 0 input/timer 0 gate control inputLED0
P3.3INT1External interrupt 1input/timer 1 gate control inputPush-pullKB_OUTInput WPU
P3.4T0Timer 0 coun ter inpu tPush-pullKB_OUTInput WPULED1
P3.5T1Timer 1 coun ter input
P3.6WR
P3.7RD
SignalDescripti onMode 1Mode 2Mod e 3Mode 4
Receiver data input (asynchronous) or data input/output
(synchronous) of the serial interface
Transmitter data output (asynchronous) or clock output
(synchronous) of the serial interface
External Data Memory write strobe; latches the data byte
from port 0 into the external data memory
External Data Memory read strobe; Enables the external
data memor y. Port 3 can drive C MOS in pu t s wit ho ut ext e rna l
pull-ups
Push-p ullKB_OUTInput WP U
Push-p ullKB_OUTInput WP U
LED2
LED3
4202E–SCR–06/06
55
AT8xC5122/23
Port 4Port 4 has the following functions:
–Default function: Port 4 is an 6-bit I/O port.
–Alternate functions : see table below
Port 4 has the following configurations:
–Default configuration: Pseudo bi-directional “Port51” digital input/output with
internal pull-ups.
–Alternate configurations: See Table 33.
Table 33. Port 4 Description
Alternate FunctionsConfigurations
Port
P4.0MISOSPI Master In Slave Out I/O
P4.1MOSISPI Master Out Slave In I/O
P4.2SCKSPI clock
P4.3Push-pullKB_OUTInput MPU
P4.4Push-pullKB_OUTInput MPU
P4.5Push-pullKB_OUTInput MPU
SignalDescriptionMode 1Mode 2Mode 3
Port 5Port 5 has the following functions:
–Default function: Port 5 is an 8-bit I/O port.
–Alternate function 1: Port 5 is an 8-bit keyboard port KB0 to KB7.
Port 5 has the following configurations:
–Default configuration: Pseudo bi-directional “Port51” digital input/output with
internal pull-ups.
–Alternate configuration: see T able 34.
Standard I/O P0The P0 port is described in Figure 23.
Figure 23. Standard Input/Output Port
AT8xC5122/23
PMOS
NMOS
Vcc
Pin
ADDR/DATA
CONTROL
1
Port latch
Data
0
MUX
Vss
Input
Data
Quasi Bi-directional PortThe default port output configuration for standard I/O ports is the quasi-bi-directional
output that is common on the 80C51 and most of its derivatives. The “Port51” output
type can be used as bot h an inpu t and ou tput witho ut the nee d to recon figure th e port.
This is possible because when the port outputs a logic high, it is weakly driven, allowing
an external device to pull the pin low.
When the port outputs a logic low state, it is driven strongly and is able to sink a fairly
large current.
These features are somewhat similar to an open-drain output except that there are three
pull-up transistors in the quasi-bi-directional output that serve different purposes.
One of these pull-ups, called the wea k pull-up, is turne d on whenever t he port latch for
the pin contains a logic 1. The weak pull-up sources a very small current that will pull the
pin high if it is left floatin g. The weak pull-up ca n be turned of f by the DPU b it in AUXR
register.
A second pull-up, called the medium pull-up, is turned on when t he port latch for the pin
contains a logic 1 and the pin itself is also at a logic 1 level. This pull-up provides the primary source current for a quasi-bi-directional pin that is outputting a 1. If a pin that has a
logic 1 on it is pulled low by an external device, the medium pull-up turns off, and only
the weak pull-up remains on. In order to pull the pin low under these conditions, the
external dev ice h as to sink e no ugh cu rre nt to o ver power the medi um pull-up an d ta ke
the voltage on the port pin below its input threshold.
Note:for CIO, CC4, CC8 ports of SCIB interface , in input mode when the ICC (smart card) is
driving the port pin :
–if 0 < Vin < CVCC/2 : weak pull-up is active (~100KOhm)
–if CVCC/2 < Vin < CVCC : weak (~100KOhm) and medium (~12KOhm) pull-
up’s are active
4202E–SCR–06/06
57
AT8xC5122/23
n
The “Port51” is described in Figure 24.
Figure 24. Quasi Bi-directional Port
2 CPU
CLOCK DELAY
DPU (AUXR.7)
vccvccvcc
P
StrongWeakMedium
P
P
Push-pull Out p ut
Configuration
Port Latch
Data
Input
Data
N
Vss
Pi
The push-pull output configuration has the same pull-down structure as both the open
drain and the quas i-bi- direct ional out put mod es, bu t provid es a co ntinuou s stro ng pul lup when the port latc h cont ains a logic 1. The push-pull mode m ay be used when more
source current is needed from a port output.
The Push-pull port configuration is shown in Figure 25.
Figure 25. Push-pull Output
P
PMOS
Port latch
Data
Strong
Pin
N
NMOS
Input with Medium or Weak
Pull-up Configuration
58
The input with pull-up (Input MPU and Input WPU) configuration is shown in Figure 26.
4202E–SCR–06/06
Figure 26. Input with Pull-up
AT8xC5122/23
Input with Weak Pull-down
Configuration
Low Speed Output
Configuration
Stuck to 0 if Medium
Stuck to 0 if Weak
Input
Data
P
P
Medium
Weak
Pin
The input with pull-down (input WPD) configuration is shown in Figure 27
Figure 27. Input with Pull-down
Input
Data
Pin
Weak
The low speed output with low speed t
FALL
and t
1
can drive keyboard.
RISE
N
The current limitation of the LED2CTRL block requires a polarisation current of about
250 µA. This block is automatically disabled in power-down mode.
The low speed output configuration (KB_OUT) is shown in Figure 28.
Figure 28. Low-speed Output
Port latch
Data
PCON.1
LED Sourc e Cu rrent The LED configuration is shown in Figure 29.
PWEAKCTRL
NMOS
LED2CTRL
P
Weak
Pin
N
N
4202E–SCR–06/06
59
AT8xC5122/23
Figure 29. LED Source Current
Pin
NMOS
LEDx.0
Port Latch
Data
LEDx.1
Notes: 1. When switching a low level, LEDCTRL device has a permanent current of about
N mA/15 (N is 2, 4 or 8).
2. The port must be configured as standard C51 port by means of PMOD0 and PMOD1
registers and the level of current must be programmed by means of LEDCON0 and
LEDCON1 registers before switching the led on.
LEDCTRL
N
N
Table 35. LED Source Current
LEDx.1LEDx.0Port Latch DataNMOSPINComments
00 010
00 101
01 000
01 101
LED co ntrol disabl ed
LED mode 2 mA
10 000
10 101
11 000
11 101
LED mode 4 mA
LED mode 10 mA
60
4202E–SCR–06/06
Registers
AT8xC5122/23
Table 36. Port Mode Register 0 - PMOD0 (91h) for AT8xC5122
7654 3 210
P3C1P3C0P2C1P2 C0CPRESRES-P0C1P0C0
Bit Number Bit Mnemonic Description
Port 3 Configuration bits (Applicable to P3.0, P3.1, P3.3, P3.4 only)
00 Quasi bi-directional
7 - 6P3C1-P 3C 0
5-4P2C1-P2C0
3CPRESRES
01 Push-pull
10 Output Low Spe ed
11 Input with weak pull-up
Port 2 Configuration bits
00 Quasi bi-directional
01 Push-pull
10 Output Low Spe ed
11 Input with weak pull-down
Card Presence Pull-up resistor
Cleared to connect the internal 100K pull-up
Set to disconnect the internal pull-up
2-
1-0P0C1-P0C0
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Port 0 Configuration bits
00 C51 Standard P0
01 Reserved
10 Output Low Spe ed
11 Push-pull
Reset Value = 0000 0x00b
Table 37. Port Mode Register 0 - PMOD0 (91h) for AT83C5123
7654 3 210
P3C1P3C0--CPRESRES---
Bit Number Bit Mnemonic Description
Port 3 Configuration bits (Applicable to P3.0, P3.1, P3.3, P3.4 only)
00 Quasi bi-directional
7 - 6P3C1-P 3C 0
5-4
3CPRESRES
01 Push-pull
10 Output Low Spe ed
11 Input with weak pull-up
Reserved
The value read from these bits are indeterminate. Do not set these bit.
Card Presence Pull-up resistor
Cleared to connect the internal 100K pull-up
Set to disconnect the internal pull-up
4202E–SCR–06/06
2-0-
Reset Value = 00xx 0xxxb
Reserved
The value read from these bits are indeterminate. Do not set these bit.
61
AT8xC5122/23
Table 38. Port Mode Register 1 - PMOD1 (84h) for AT8xC5122
76543210
P5HC1P5HC0P5MC1P5MC0P5LC1P5LC0P4C1P4C0
Bit NumberBit Mnemonic Description
Port 5 High Configuration bits (Applicable from P5.6 to P5.7 only)
00 Quasi bi- directi onal
7 - 6P5HC1-P5HC0
5 - 4P5MC1-P5MC0
3 - 2P5LC1-P5 LC0
01 Push-pull
10 Input with weak pull-down
11 Input with weak pull-up
Port 5 Medium Configuration bits (Applicable from P5.3 to P5.5 only)
00 Quasi bi- directi onal
01 Push-pull
10 Input with weak pull-down
11 Input with weak pull-up
Port 5 Low Configuration bits (Applicable from P5.0 to P5.2 only)
00 Quasi bi- directi onal
01 Push-pull
10 Input with medium pull-up
11 Input with weak pull-up
Port 4 Configuration bits (Applicable from P4.3 to P4.5 only)
00 Quasi bi- directi onal
1 - 0P4C1-P 4 C 0
01 Push-pull
10 Output Low Spe ed
11 Input with medium pull-up
Reset Value = 0000 0000b
Table 39. Port Mode Register 1 - PMOD1 (84h) for AT83C5123
76543210
----P5LC1P5LC0--
Bit NumberBit Mnemonic Description
7 - 4
3 - 2P5LC1-P5 LC0
1 - 0
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Port 5 Low Configuration bits (Applicable from P5.0 to P5.2 only)
00 Quasi bi- directi onal
01 Push-pull
10 Input with medium pull-up
11 Input with weak pull-up
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Reset Value = xxxx 00xxb
62
4202E–SCR–06/06
AT8xC5122/23
Table 40. LED Port Control Register 0 - LEDCON0 (F1h)
00 LED control disabled
01 2 mA current source when P3.7 is configured as Quasi-bi-directional mode
10 4 mA current source when P3.7 is configured as Quasi-bi-directional mode
11 10 mA current source when P3.7 is configured as Quasi-bidir ect. mode
Port LED2 Config urat ion bit s
00 LED control disabled
01 2 mA current source when P3.6 is configured as Quasi-bi-directional mode
10 4 mA current source when P3.6 is configured as Quasi-bi-directional mode
11 10 mA current source when P3.6 is configured as Quasi-bidir ect. mode
Port LED1 Config urat ion bit s
00 LED control disabled
01 2 mA current source when P3.4 is configured as Quasi-bi-directional mode
10 4 mA current source when P3.4 is configured as Quasi-bi-directional mode
11 10 mA current source when P3.4 is configured as Quasi-bidir ect. mode
Port LED0 Config urat ion bit s
1 - 0LED 0
00 LED control disabled
01 2 mA current source when P3.2 is configured as Quasi-bi-directional mode
10 4 mA current source when P3.2 is configured as Quasi-bi-directional mode
11 10 mA current source when P3.2 is configured as Quasi-bidir ect. mode
Reset Value = 0000 0000b
Table 41. LED Port Control Register 1- LEDCON1 (F1h) only for AT8xC5122
76543210
--LED6.1LED6.0LED5.1LED5.0LED4.1LED4.0
Bit Number Bit Mnemonic Description
7 - 6
5 - 4LED 6
3 - 2LED 5
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Port LED6 Config urat ion bit s
00 LED control disabled
01 2 mA current source when P4.5 is configured as Quasi-bi-directional mode
10 4 mA current source when P4.5 is configured as Quasi-bi-directional mode
11 10 mA current source when P4.5 is configured as Quasi-bidir ect. mode
Port LED5 Config urat ion bit s
00 LED control disabled
01 2 mA current source when P4.4 is configured as Quasi-bi-directional mode
10 4 mA current source when P4.4 is configured as Quasi-bi-directional mode
11 10 mA current source when P4.4 is configured as Quasi-bidir ect. mode
4202E–SCR–06/06
Port LED0 Config urat ion bit s
1 - 0LED 4
00 LED control disabled
01 2 mA current source when P4.3 is configured as Quasi-bi-directional mode
10 4 mA current source when P4.3 is configured as Quasi-bi-directional mode
11 10 mA current source when P4.3 is configured as Quasi-bidir ect. mode
Reset Value = 0000 0000b
63
AT8xC5122/23
Smart Card Interface
Block (SCIB)
The SCIB provides all signals to interface directly with a smart card. The compliance
with the ISO7816, EMV’2000, GSM and WHQL standards has been ce rtified.
Both synchronous (e.g. memory card) and asynchronous smart cards (e.g. microprocessor card) are supported. The component supplies the different voltages requested by
the smart card. The power off sequence is directly managed by the SCIB.
The card presence switch of the smart card connector is used to detect card insertion or
card removal. In case of card removal, the SCIB de-activates the smart card using the
de-activation sequence. An interrupt can be generated when a card is inserted or
removed.
Any malfunction is reported to the microcontroller (interrupt + control register).
The different operating modes are configured by internal registers.
•Support of ISO/IEC 7816
•character mode
•one transmit/receive buffer
•1 1 bits ETU counter
•9 bits guard time counter
•32 bits waiting time counter
•Auto character repetition on error signal detection in transmit mode
•Auto error signal generation on parity error detection in receive mode
•Power on and power off sequence generation
•Manual mode to drive directly the card I/O
64
4202E–SCR–06/06
Block Diagram
The Smart Card Interface Block diagram is shown Figure 30:
Figure 30. SCIB Block Diagram
Ba rr el sh ifte r
AT8xC5122/23
IO (in)
Clk_iso
Clk_cpu
INT
Etu counter
Guard time counter
Waiting time counter
SCI Registers
Interrupt generator
Scart
fsm
I/O
mux
Power on
Power off
fsm
IO (out)
CLK
RST
C4 (o ut)
C8 (out)
C4 (in)
C8 (in)
VCARD
DefinitionsThis paragraph introdu ces some of the terms used in ISO 7816-3 and E MV recom m en-
dations. Please refer to the full recommendations for a complete list of terms.
Terminal and ICCTerminal is the reader, ICC is the Integrated Circuit Card
ETUElementary Timing Unit (Bit time)
T=0Character oriented half duplex protocol T=0
T=1Block oriented half duplex protocol T=1
Activation: Cold ResetRe set initiated by the Term inal with Vcc power-up. Th e card will answer with ATR (see
below)
Activation: Warm ResetReset initiated by the Terminal with Vcc already powered-up, and after a prior ATR or
Warm Reset
De-ActivationDeactivation by the Terminal as a result of : unresponsive ICC, or ICC removal.
4202E–SCR–06/06
65
AT8xC5122/23
ATRAnswer To Reset. Response from the ICC to a Reset initiated by the Terminal
F and D F = Clock Rate Conv ersi on F acto r, D = B it rate ad justm ent fa ctor . ETU is de fined as :
ETU = F/(D*f) with f = Card Clock frequency . If f is in Hertz, ETU is in second. F and D
are available in the ATR (byte TA1). The default values are F=372, D=1.
Guard TimeThe ti me betwee n 2 lea din g edg es of th e sta rt b it o f 2 c onsec uti ve chara ct ers is com-
prised of the character duration (10) plus the guard time. Be aware that the Guard Time
counter and the Guard Time registers in the AT8xC5122/23 consider the time between 2
consecutive charac ters. So the equation is Guard Time C ounter = Guard Time + 10. In
other w or ds, the G ua rd Ti me is the n umb er of S t op Bi ts b etw een 2 ch ar acte rs s ent i n
the same direction.
Extra Guard TimeISO IEC 7816-3 and EMV introduc e th e Extra Gua rd time t o be adde d to the m inimum
Guard Time . Extra Gu ard Time onl y apply to con secutive ch aracters sent by the t erminal to the ICC. The T C1 byte in the A TR def ine the num ber N. For N=0 the character to
character duration is 12 ETUs. For N=254 the character to character duration is 266. For
N=255 (special case) The minimum character to character duration is to be used : 12 for
T=0 protocol and 11 for T=1 protocol.
Block Guard TimeThe time betwee n the le ading ed ges of 2 co nsecutive charact ers se nt in opposi t direc-
tion. ISO IEC 7816-3 and EMV recommend a fixed Block Guard Time of 22 ETUs.
Work Waiting Time (WWT)In T=0 protocol WWT is the interval between the leading edge of any character sent by
the ICC, and the leading edge of the previous character sent either by the ICC or the
Terminal. If no char acter is received b y the t erminal after W WTm ax time, t he Te rminal
initiates a De-Activation Sequence.
Character Waiting Time (CWT)In T=1 protocol CWT is the interval between the leading edge of 2 consecut ive charac-
ters sent by the ICC. If the next character is not received by the Terminal after CWTmax
time, the Terminal initiates a De-Activation Sequence.
Block Waiting Time (BWT)In T=1 pro tocol BWT is the interval between the l eading ed ge of the start bi t of the last
character sent by the Terminal that gives the right to sent to the ICC, and the leading
edge of the start bit of the first character sent by the ICC. If the first character from the
ICC is not received by the Terminal after BWTmax time, the Terminal initiates a De-Activation Sequence.
Waiting Time Extention (WTX)I n T= 1 prot ocol the ICC can reques t a Wa iting T im e Exten sio n with a S(W TX re quest )
request. The Terminal should acknowlege it. The Waiting time between the leading
edge of the start bit of the last character sent by the Terminal that gives the right to sent
to the ICC, and the leading edge of the start bit of the first character sent by the ICC will
be BWT*WTX ETUs.
Parity error in T=0 protocolIn T=0 protocol, a Terminal (respectively an ICC) detecting a parity error while receiving
a character shall force the Card IO line at 0 starting at 10.5 ETUs, thus reducing the first
Guard bi t by ha lf the t ime. Th e Ter minal (res pect ivel y an IC C) sh all mai ntain a 0 f or 1
ETU min and 2 ETUs max (according to ISO IEC) or to 2 ETUs (according to EMV). The
ICC (respectively a Terminal) shall monitor the Card IO to detect this error signal then
attempt to repeat the character. According to EMV, following a parity error the character
can be repeated one time, if parity error is detected again this procedure can be
repeated 3 more times. The same character can be transmitted 5 times in total. ISO
66
4202E–SCR–06/06
AT8xC5122/23
IEC7816-3 says this procedure is mandatory in ATR for card supporting T=0 while EMV
says this procedure is mandatory for T=0 but does not apply for ATR.
Functional DescriptionT he arch itecture of the Smart Card Interface Block can be detailed as follows:
Barrel ShifterThe Barrel Shifter pe rforms t he tr anslati on bet ween 1 bit se rial dat a and 8 b its pa rallel
data
The barrel function is useful for character repetition since the character is still present in
the shifter at the end of the character transmission.
This shifter is able to shift the data in both directions and to invert the input or output
value in order to manage both direct and inverse ISO7816-3 convention.
Coupled with the barrel shifter is a parity checker and generator.
There are 2 regist ers conn ected to this barre l shifter, one for the trans mission and on e
for the reception. They act as buffers to relieve the CPU of timing constraints.
SCART FSM(Smart Card Asynchronous Receiver Transmitter Finite State Machine)
This is the core of the block. Its purpose is to control the barrel shifter. To sequence correctly the barrel shifter for a reception or a transmission, it uses the signals issued by the
different counters. One of the most important counters is the guard time counter that
gives time slots corresponding to the character frame.
The SCART FSM is enabled only in UART mode.
The transition from the receipt mode to the transmit mode is done automatically. Priority
is given to the transm ission. Transmissi on refers to Te rminal tran smission to th e ICC.
Reception refers to reception by the Terminal from the ICC.
ETU CounterThe ETU (Elementary Timing Unit) counter controls the working frequency of the barrel
shifter, in fact it generates the enable signal of the barrel shifter. It receives the Card
Clock, and generat es t he ETU c l ock. T he Card Clock frequency is called “f ” below. The
ETU counter is 11 bit wide.
A special compensation mode can be activated. It accomodates situations where the
ETU is not an integer number of Card Clock (CK_ISO). The compensation mode is controlled by the COMP bit in SCETU1 register bit position 7. With COMP=1 the ETU of
every c hara cter even b its i s redu ce d by 1 C ar d C lock pe riod . As a resu lt, th e av erag e
ETU is : ETU_average = (ETU - 0.5). One should bear in mind that the ETU counter
should be programmed to deliver a faster ETU which will be reduced by the COMP
mechanism, not the other way around. This allows to reach the required precision of the
character duration specified by the ISO7816-3 standard.
Example1 : F=372, D=32 => ETU= F/D = 11.625 clock cycles.
We select ETU[10-0] = 12 , COMP=1. ETUaverage= 12 - (0.5*COMP) = 11.5
The result will be a full charac ter duration (10 bit) = (10 - 0. 107)* ETU. The EMV spec ifi-
cation is (10 +/- 0.2)*ETU
Guard Time C ounter The minimum time between the leading edge of the start bit of 2 consecutive characters
transmitted by the Terminal is controlled by the Guard Time counter, as described in
Figure 33.
4202E–SCR–06/06
67
AT8xC5122/23
The Guard Time counter is an 9 bit counter It is initialized at 001h at the start of a transmission by the Terminal. It then increments itself at each ETU until it reach the 9 bit
value loaded into the SCGT1[0] concatenated with SCGT 0[7:0]. At this time a new Terminal transmission i s ena bled and the Guard Time Counter stop incrementing. As so on
as a new transmission start, the Guard Time Counter is re-initialized at 1 decimal value.
It should be noted that the value of the Guard Time Counter cannot be red. Reading
SCGT1,0 only gives the minimum time between 2 characters that the Guard Time
Counter will allow.
Care mus t be ta ken w i th th e G uard Tim e C o unter wh ich co unts the du rat ion betw ee n
the lead ing ed ges of 2 consec utive char acters. This correspo nd to the ch arac ter duration (10 ETU) pl us the Gu ard Time as d efine d by the IS O and EM V recom menda tions.
To program Guard Time = 2 : 2 stop bits between 2 characters which is equivalent to the
minimum delay of 12 ETUs between the leading edges of 2 consecutive characters,
SCGT1[0],SCGT0[7:0] should be loaded with the value 12 decimal. See Figure 31
Figure 31. Guard Time.
TRANSMISSION to ICC
CHAR n+1CHAR n+2CHAR n+3
>= SCGT
Block Guard Tim e C o unt erThe Block Guard Time counter provides a way to program a minimum time between the
leading edge of the start bit of a character received from the ICC and the leading edge of
the start bit of a character sent by the terminal. ISO IEC 7816-3 and EMV recommend a
fixed Blo ck Gu ard Ti me of 22 ETUs . The AT 8xC512 2/23 offer th e po ssibility to ex tend
this delay up to 512 ETUs.
The Block Guard Time is a 9 bit counter. When the Block Guard Time mode is enabled
(BGTEN=1 in SCSR registe r) The Block G uard Time count er is initialized at 000h at the
start of each character transmissions from the ICC. It then increments at each ETU until
it reach the 9 bit value loaded into shado w SCGT 1,0 registers, or until it is re-initialized
by the start of an new transmiss ion from the ICC. If the Blo ck Guard Tim e counter
reaches the 9 bit value loaded into shadow SCGT1,0 registers, a transmission by the
TERMINAL is enabled, and the Block Guard Time counter stop incrementing. The Block
Guard Time counter is re-initialized at the start of each TERMINAL transmission.
The SCGT1 S CGT 0 s hado w regi sters are loaded with the cont ent of GT[8-0] contained
in the registers SCGT1[0),SCGT0(7: 0] with the rising edge of the bit BGTEN in the
SCSR register. See Figure 33.
68
4202E–SCR–06/06
Figure 32. Block Guard Time.
it
AT8xC5122/23
ETU Counter
Enable
transmit
RECEPTION from ICC
Write SCGT1,0 with
a value for Guard Time
CHAR 1
CHAR 2
CHAR n
>= Block Guard Time
Write “Block Guard Time” in SCGT1,0
and set BGTEN to transfer the value to the
shadow SCGT1,0 registers
CHAR n+1CHAR n+2CHAR n+3
Figure 33. Guard Time and Block Guard Time counters
Guard Time Counter
Block Guard Time Counter
9 bits
Comparator
9 bits
9 bits
Shadow SCGT1 ,Shadow SCGT0
>= SCGT
TRANSMISSI ON to IC C
9 bits
Comparator
Enable
transm
GT[8:0]
SCGT1
SCGT0
To illustrat e the use of Gu ard Time an d Block Guard Time, let us cons ider the
ISO/IEC7816-3 recommendation : Guard Time = 2 (minimum delay between 2 consecutive characters sent by the Terminal = 12 ETUs), and Block Guard Time = 22 ETUs.
After A smart Card Reset
–Write 00decimal in SCGT1, Write 21decimal in SCGT 0
–Set BGTEN in SCSR (BGTEN was 0 before as a result of the smart card
reset)
–Write 12decimal in SCGT0
Now the Guard Time and Block Guard Time are properly initialized. The TERMINAL will
insure a minimun 12 ETUs between 2 leading edges of 2 consecutive characters transmitted. The TERMINAL will also insure a minimum of 22 ETUs between the leading
edge of a character sent by the ICC, and the leading edge of a character sent by the
TERMINAL. There is no need to write SCGT1,0 again and again.
Waiting Time (W T) CounterThe WT counter is a 32 bits down counter which can be loaded with the value contained
in the SCWT3, SCWT2, SCWT1, SCWT0 registers. Its main purpose is timeout signal
generation. It is 32 bits wide and is decremented at the ETU rate. see Figure 34.
4202E–SCR–06/06
69
AT8xC5122/23
Figure 34. Waiting Time Counter
When the WT counter times out, an interrupt is generated and the SCIB function is
locked: reception and emission are disabled. It can be enabled by resetting the macro or
reloading the counter.
The Waiting Time Counter can be used in T=0 protocol for the Work Waiting Time. It can
be used in T=1 protocol for the Ch arac ter W aiting Tim e and for t he Block Wai ting Time.
See the detailed explanation below.
ETU Counter
WTEN
Write_SCWT2
UART
Start Bit
WT Counter
Load
Timeout
WT[31:0]
SCWT3
SCWT2
SCWT1
SCWT0
In the s o c all ed m anu el mo de, t he co unter is loa ded, if W TE N = 0, duri ng t he w ri te of
SCWT2 register. The counter is loaded with a 32 bit word built with SCWT3 SCWT2
SCWT1 SCWT0 registers (SCWT0 contain WT[7-0] byte. WTEN is located in the
SCICR register.
When WTEN=1 and in UART mode, the counter is re-loaded at the occurenc e of a start
bit. This mode will be detailed below in T=0 protocol and T=1 protocol.
In manual mode, the WTEN signal controls the start of the counter (rising edge) and the
stop of the counter (falling edge). After a timeout of the counter, a falling edge on
WTEN, a reload of SCWT 2 and a risin g edge of WT EN are neces sary to start aga in the
counter and to release the SCIB macro. The reload of SCWT2 transfers all SCWT0,
SCWT1, SCWT2 and SCWT3 registers to the WT counter.
In UART mode there is an aut oma tic load on the start bit detection. This automatic load
is very usef ul for cha nging o n-the -fly the timeou t valu e since the re i s a register t o hol d
the load value. This is the case for T=1 protocol.
70
In T=0 protocol the maximun interval between the start leading edge of any character
sent by the ICC and the start of the previous character sent by either the ICC or the Terminal is the maximum Work Waiting Time. The Work Waiting Time shall not exceed
960*D*WI E TUs with D and WI p arameters a re return ed by the field TA1 and TC2
respectively in the A nswer To R eset (A TR). This is the val ue the us er shall write in th e
SCWT0,1,2,3 register. This value will be reloaded in the Waiting Time counter every
start bit.
4202E–SCR–06/06
AT8xC5122/23
Figure 35. T=0 mode
> GT
CHAR 1
< WT
In T=1 protocol : The maximum interval between the leading edge of the start bit of 2
consecutive characters sent by the ICC is called maximum Character Waiting Time. The
Character Waiting Time shall not exceed (2**CWI + 11) ETUs with 0 =< BWI =< 5. Consequently 12 ETUs =< CWT =< 43 ETUs.
T=1 protocol also specify the maximum Block Waiting Time. This is the time between
the leading edge of the last character sent by the Terminal giving the right to send to the
ICC, and the leading edge of the start bit of the first character sent by the IC C. The
Block Waiting Time shall not exceed (2**BWI*960 + 11) ETUs with 0 =< BWI =< 4. Consequently 971 ETUs =< BWT =< 15371 ETUs.
CHAR 2
In T=1 protocol it is possible to extend the Block Waiting Time with the Waiting Time
Extension (WTX). When selected the waiting time becomes BW T*WTX ETUs. Th e
Waiting Time counter is 32 bit wide to accomodate this feature.
It is possible to take advantage of the automatic reload of the Waiting Time counter with
a start bit in UART mode (T=1 protocol use UART mode) . If the Terminal sends a block
of N characters, and the ICC i s supposed t o respond immediately after, then the following sequence can be used.
While sending the (N-1)th character of the block, the Terminal can write the
SCWT0,1,2,3 with BWImax.
At the start bit of the Nth character, the BWImax is loaded in the Waiting Time counter
During the trans mis sion of the Nth character, the T erm inal c a n write SCWT0,1,2,3 with
the CWImax.
At the start bit of the first character sent by the ICC, the CWIm ax will be loaded in the
Waiting Time counter.
Figure 36. T=1 Mode
RECEPTION
BLOC 2
CHAR 1
TRANSMISSION
BLOC 1
CHAR 2
CHAR n
CHAR n+1CHAR n+2CHAR n+3
4202E–SCR–06/06
< BWT
< CWT
71
AT8xC5122/23
Power-on and Power-off FSMTh e Pow er- on P owe r-off Finite Sta te M ach ine (FS M) a pplie s th e sig nals on the sm art
card in accordance with ISO7816-3 standard. It conducts the Activation (Cold Reset and
Warm Reset as well as De-Activation) it also manages the exception conditions such as
overcurrent (see DC/DC Converter)
To be able to power on the SCIB, the card presence is mandatory. Upon detectection of
a card presence, the Terminal initiate a Cold Reset Activation.
The Cold Reset Activation Terminal procedure is as follow and the Figure 37. Timing
indications are given according to ISO IEC 7816
–RESET= Low , I/O in the receive state
–Power Vcc (see DC/DC Converter)
–Once Vcc is established, apply Clock at time Ta
–Maintain Reset Low until time T a+tb (tb< 400 clocks)
–Monitor The I/O line for the Answer To Reset (ATR) between 400 and 40000
Figure 37. SCIB Activation Cold Reset Sequence after a Card Insertion
CVCC
CRST
CCLK
CIO
TaTa+tb
DataUndefined
Tb+tc
The Warm Reset Activation Terminal procedure is as follow and the Figure 38
–Vcc active, Reset = High, CLK active
–Terminal drive Re set low at time T to init ia t e the w ar m Reset. Reset=0
maintained for at least 400 clocks until time Td = T+te (400 clocks < te)
–Terminal keep the IO line in receive state
–Terminal drive Reset high after at least 400 clocks at time Td
–ICC shall respond with an ATR within 40000 clocks (tf<40000 clocks)
Figure 38. SCIB Activation Warm Reset Sequence
CVCC
72
CRST
CCLK
CIO
Undefined
TTd=T + te
Data
Td + tf
4202E–SCR–06/06
AT8xC5122/23
Removal of the smart card will automatically start the power off sequence as described
in Figure 39.
The SCIB deactivation sequence after a reset of the CPU or after a lost of power supply
is ISO7816-3 co mpliant. The s witching ord er of the signal s is the sam e as in Figu re 39
but the delay between signals is analog and not clock dependant.
Figure 39. SCIB Deactivation Sequence after a Card Extraction
CVCC
CRST
CCLK
8 Clock Cycles
CIO
Interrupt Gen e ratorThere are several sourc es of interrup tion but the SCIB m ac ro-cell issues onl y o ne inter-
This signal is high level active. Each of the sources is able to activate the SCIB interruption which is cleared when the Smart Card Interrupt register is read by the
microcontroller.
If during the read of the Smart Card Interrupt register another interrupt occurs, the activation of th e corr es pond ing b it in t he Sm art Ca rd I nterru p t regi ste r and t he new S CI B
interruption is delayed until the interrupt register is read by the microcontroller.
Warning : Each bit of the SCIIR register is irre levant whi le the corresp ond ing interr uption is disabled in SCIER register. When the interruption mode is not used, the bits of
the SCISR register must be used instead of the bits of the SCIIR register.
73
AT8xC5122/23
Additional Features
ClockThe CK_ISO input must be in the range 1 - 5 MHz according to ISO 7816.
The CK_ISO can b e program m ed up t o 1 2 M H z. In this c ase, the timin g spec ification of
the output buffer will not comply to ISO 7816.
Figure 41. Clock Diagram of the SCIB Block
CK_IDLE
CK_PLL or
CK_XTAL1
PR2
Ck_cpu
Ck_ISO
SCIB
Figure 42. Prescaler 2 Description
PR2
<48
CK_ISO
=48
SCICLK[5:0]
XTSCS
SCICLK.7
EXT48
PLLCON.2
CK_PLL
CK_XTAL1
0
1
1/(2*(48 - SCICLK[5-0]))
The divi sion f act or SC ICLK m ust be sm all er than 4 9. If it is g reat er or eq ua l to 49, t he
PR2 prescaler is locked.
See Figure 17 clock tree diagram in the clock controller chapter.
Table 42. Examples of Clock settings
XTAL1 (MHz)EXT48SCICLKCK_ ISO
80364
804412
80428
80406
80242
8001
Card Presence InputThe internal pull-up (weak pull-up) on Card Presence input can be disconnected in order
to reduce the consumption (CPRESRES , bit 3 in PMOD0).
Ω
In this case, an external resistor (typically 1 M
) must be externally tied to Vcc.
CPRES input can generate an interrupt (see Interrupt system section).
The detection level can be selected.
74
4202E–SCR–06/06
AT8xC5122/23
Transmit / Receive BufferThe contents of the SCIBUF Transmit / Receive Buffer is transferred or received into /
from the Shift Register. The Shift Register is not accessible by microcontroller. Its role is
to prepare the byte to be copied on the I/O pin for a transmission or in the SCIBUF
buffer after a reception.
During a character transmission proc ess, as s oon a s the contents of the SCIBUF buffer
is transferred to the shift register, the SCTBE bit is set in SCISR register to indicate that
the SCIBUF buffer i s em pty a nd ready to acce pt a new byte. This mechanism a voids t o
wait for the complete transmission of the previous byt e before writing a new byte in the
buffer and enables to speed up the transmission.
–If the Character repetition mode is not selected (bit CREP=0 in SCICR), as
soon as the contents of the Shift Register is transferred to I/O pin, the SCTC
bit is set in SCISR register to indicate that the byte has been transmitted.
–If the Character repetition mode is selected (bit CREP=1 in SCICR) The
TERMINAL will be able to repeat characters as requested by the ICC (See
the Parity Error in T=0 protocol description in the definition paragraph
above). The SCTC bit in SCISR register will be set after a successful
transmission (no retry or no further retry requested by the ICC). If the
number of retries is exhausted (up to 4 retries depending on CREPSEL bit i n
SCSR) and the last retry is still unsuccessful, the SCTC bit in SCISR will not
be set and the SCPE bit in SCISR register will be set instead.
During a character reception process, the conten ts of the Shift Registe r is transferred in
the SCIBUF buffer.
–If the Character repetition mode is not selected (bit CREP=0 in SCICR), as
soon as the contents of the Shift Register is transferred to the SCIBUF the
SCRC bit is set in SCISR register to indicate that the byte has been
received, and the SCIBUF contains a valid character ready to be red by the
microcontroller.
–If the Character repetition mode is selected (bit CREP=1 in SCICR) The
TERMINAL will be able to request repetition if the received character exhibit
a parity error. Up to 4 retries can be requested depending on CREPSEL bit
in SCSR. The SCRC bit will be set in SCISR register after a successful
reception, first reception or after retry(ies). If the number of retries is
exhausted (up to 4 retries depending on CREPSEL bit in SCSR) and the last
retry is still unsuccessful, the SCRC bit and the SCPE bit in SCISR register
will be set. It will be possible to read the erroneous character.
Warning : the SCTBI, SCTI SCRI and SCPI bits have the same function as SCTBE,
SCTC, SCRC and SCPE bits. The first ones are able to generate interruptions if the
interruptions are enabled in SCIER register while the second ones are only status bits to
be used in pulling mode. If the interruption mode is not used, the status bits must be
used. The SCTBI, SCTI and SCRI bits do not contain valid information while their
respective interrupt enable bits ESCTBI, EXCTI, ESCRI are cleared.
4202E–SCR–06/06
75
AT8xC5122/23
Figure 43. CharacterT rans m ission Diagra m
SCISR register
SCTBE
SCTC
SCPE
Transmitted
Character
SCIBUF
SCTBI
SCIIR register
Shift Register
ESCTBI
ESCTI
SCIER Register
I/O pin
SCTI
Parity error
Parity error
SCPI
76
4202E–SCR–06/06
Figure 44. Character Reception Diagram
r
SCISR register
SCTBE
AT8xC5122/23
SCTC
SCRC
SCPE
Parity error
Received
I/O pin
Shift Register
SCIBUF
Characte
ESCTBI
SCTBI
SCIER Register
ESCTI
ESCRI
SCTI
SCRI
Parity error
SCPI
SCIIR register
SCIB ResetThe SCICR register contains a reset bit. If set, this bit generates a reset of the SCIB and
its registers. Table 43 defines the SCIB registers that are reset and their reset values.
Alternate CardA second card named ‘Alternate Card’ can be controlled.
The Clock signal CCLK1 can be adapted to the XTAL frequency. Thanks to the clock
prescaler which can divide the frequency by 1, 2, 4 or 8. The bits ALTKPS0 and
ALTKPS1 in SCSR Register are used to set this factor.
Figure 45. Alternate Card
CVCC
CRST
CIO
CCLK
CPRES
SMART
CARD
Main
card
Registers
CK_IDLE
PR3
ALTKPS0,1
SCSR Reg.
1, 1/2, 1/4 or 1/8
P1.7
1
0
SCCLK1
SCSR R eg.
CCLK1
SIM, SAM
CARD
Alternate
card
There are fifteen registers to control the SCIB macro-cell. They are described from
Table 58 to Table 45.
Some of the register widths are greater than a byte. Despite the 8 bits access provided
by the BIU, the address mapping of this kind of register respects the following rule :
The Low significant byte register is implemented at the higher address.
This implementation makes access to these registers easier when using high level pro-
Set this bit to reset and deactivate the Smart Card Interface.
Clear this bit to activate the Smart Card Interface.
This bit acts as an active high software reset.
Card Pr esence D etector Sense
Clear this bit to indicate the card presence detector is open when no card is inserted (CPRES is high).
Set this bit to indicate the card presence detector is closed when no card is inserted (CPRES is low).
Card Voltage Selection:
VCARD[1]
VCARD[0] CVCC
00 0 V
01 1.8 V
10 3.0 V
1 15.0 V
3UART
2WTEN
1CREP
0CONV
Reset Value = 0000 0000b
Card UART Selection
Clear this bit to use the CARDIO bit (P1.0) bit to drive the Card I/O (P1.0) pin.
Set this bit to use the Smart Card UART to drive the Card I/O pin (P1.0 pin).
Contr ols also the Waiting T ime Counter as described in S ection “Waiting Time (WT) C ounter”, page 69
Waiting Time Counter Enable
Clear this bit to stop the counter and enable the load of the Waiting Time co unter hold regist ers.
The hold regist ers are l oaded with SCWT0, SCWT1, SCWT 2 and SCWT3 values when SCWT2 is written.
Set this bit to start the Waiting Time Counter. The counters stop when it reaches the timeout value.
If the UART bit is set, the Waiting Time Counter automatically reloads with the hold registers whenever a start bit is
sent or received.
Character Repetition
Clear this bit to disabl e parit y error detection and indication on the Card I/O pin in receive mode and to disable
charac ter repetitio n in transmit mode.
Set this bit to enable parity error indication on the Card I/O pin in receive mode and to set automatic character
repetition when a parity error is indicated in transmit mode.
Depending upon CREPSET bit is SCSR register, the receiver can indicate parity error up to 4times (3 repetitions) or
up to 5times (4 repetitions) after which it will raise the parity error bit SCPE bit in the SCISR register. If parity interrupt
is enabled, the SCPI bit in SCIIR register will be set too.
Alternately, the transmitter will detect ICC character repetition request. After 3 or 4 unsuccessful repetitions
(depending on CREPSEL bit in SCSR register), the transmitter will raise the parity error bit SCPE bit in the SCISR
register. If parity interrupt is enabled, the SCPI bit in SCIIR regist er will be set too.
Note : Character repetition mode is specified for T=0 protocol onl y and should not be used in T=1 protocol (block
oriented protocol)
ISO Convention
Clear this bit to use the direct convention: b0 bit (LSB) is sent first, the parity bit is added after b7 bit and a low level
on the Card I/O pin represents a’0’.
Set this bit to use the inverse convention: b7 bit (LSB) is sent first, the parity bit is added after b0 bit and a low level on
the Car d I/O pin r epresents a’1’.
Clear this bit to use the Card CLK bit (CARDCLK bit below) to drive Card CLK (P1.4) pin.
Set this bit to use CK_XTAL1 or CK_PLL signals for CK_ISO to drive the Card CLK pin (CCLK = P1.4 pin)
Note: internal synchro nization avoids g litches on the CLK pi n when switching this bit.
6-
5CARDC8
4CARDC4
3CARDIO
2CARDCLK
1CARDRST
Reserved
This bit can be changed by software but the read value is indeterminate.
Card C8
Clear this bit to drive a low level on the Card C8 pin (CC8 = P1.1 pin).
Set this bit to s et a high level on the Card C8 pin (CC8 = P1 .1 pin)..
The CC8 pin can be used as a pseudo bi- directi onal I/O w hen this bit is set.
Warning : VCARDOK=1 (SCISR.4 bit) condition must be true to change the state of CC8 pin
Card C4
Clear this bit to drive a low level on the Card C4 pin (CC4 = P1.3 pin).
Set this bit to s et a high level on the Card C4 pin (CC4 = P1.3 pin).
The CC4 pin can be used as a pseudo bi- directi onal I/O w hen this bit is set.
Warning : VCARDOK=1 (SCISR.4 bit) condition must be true to change the state of CC4 pin
Card I/O
If UART bit is cleared in SCICR register, this bit enables the use of the Card IO pin (CIO = P1.0) as a C51
pseudo bi-directional port :
To read from CIO (P1.0) port pin : set CARDIO (P1.0) bit then read CARDIO (P1.0) bit to have the CIO port
value
To writ e in CIO (P1.0) po rt pi n : se t CARDI O (P1 .0 ) bit to writ e a 1 in CI O ( P1. 0 ) port pin , clea r CARDI O (P 1.0)
bit to write a 0 in CIO (P1.0) port pin.
Warning : VCARDOK=1 (SCISR.4 bit) condition must be true to change the state of CIO pin
Card CLK
When the CLK bit is cleared in SCCON Register, the value of this bit is driven to the Card CLK pin.
Warning : VCARDOK=1 (SCISR.4 bit) condition must be true to change the state of Card CLK pin
Card RST
Clear this bit to drive a low level on the Card RST pin.
Set this bit to s et a high level on the Card RST pin.
Warning : VCARDOK=1 (SCISR.4 bit) condition must be true to change the state of Card RST pin
0CARDVCC
Reset Value = 0X00 0000b
80
Card VCC Control
Clear this bit to desactivate the Card interface and set its power-off. The other bits of SCCON register have no
effect while thi s bit is cl ea red .
Set this bit to pow er-on the C ard interface. The activa tion sequence shou ld be handled by software.
4202E–SCR–06/06
AT8xC5122/23
Table 46. Smart Card UART Interface Status Register -
SCISR (S:ADh, SCRS=0)
76 5 4 32 10
SCTBECARDINICARDOVFVCARDOKSCWTOSCTCSCRCSCPE
Bit NumberBit MnemonicDescription
UART Transmit Buffer Empty Status
7SCTBE
6CARDIN
5ICARDOVF
4VCARDOK
This bit is set by hardware when the Transmit Buffer is copied to the transmit shift register of the Smart Card
UART.
It is cleared by hardware when SCIBUF register is written.
Card Presence Status
This bit is set by hardware if there is a card presence (debouncing filter has to be done by software).
This bit is cleared by hardware if there is no card presence.
Card Current Overflow Status
This bit is set when the current on card is above the limit specified by bit OVFADJ in DCCKPS register (Table 61
on page 94)
It is cleared by hardware.
Card Voltage Correct Status
This bit is set when the output voltage is within the voltage range specified by VCARD[1:0] in SCICR register.
It is cleared otherwise.
3SCWTO
2SCTC
1SCRC
0SCPE
Reset Value = 1000 0000b
Waiting Time Counter Timeout Status
This bit is set by hardware when the Waiting Time Counter has expired.
It is cleared by the reload of the counter or by the reset of the SCIB.
UART Transmitted Character Status
This bit is s et by hard war e when the S ma rt C ar d UA RT ha s tr an smit te d a char act er. If c ha ract e r re pe tit io n mo de is
selected, this bit will be set only after a successful transmission. If the last allowed repetition in not successful, this
bit will not be set.
It is cleared by so ftware when this register is read.
UART Received Character Status
This bit is set by hardware when the Smart Card UART has received a character
It is cleared by hardware when SCIBUF register is read. If character repetition mode is selected, this bit will be set
only after a successful reception. If the last allowed repetition is still unsuccessful, this bit will be set to let the user
read the er ro neous value if ne ce s sa r y.
Character Reception Parity Error Status
This bit is set whe n a parity error is de tec ted on the recei ve d ch ar ac t er.
It is cleared by software when this register is read. If character repetition mode is selected, this bit will be set only
if the ICC report an error on the last allowed repetition of a TERMINAL transmission, or if a reception parity error
is foun d on the last allowe d IC C character repetition.
This bit is set by hardware when the Transmit Buffer is copied into the transmit shift register of the Smart
Card UART. It generates an inte rrupt if ESCTBI bit is set in SCIER register otherwise th is bit is irre levant.
It is cleared by hardware when this register is read.
6-
5ICARDERR
4VCARDERR
3SCWTI
2SCTI
1SCRI
0SCPI
Reset Value = 0X00 0000b
Reserved
The value read from this bit is indeterminate. Do not change this bit.
Card Current Overflow Interrupt
This bit is set when the current on card is above the limit specified by bit OVFADJ in DCCKPS register (Table
61 on page 94). It generates an interrupt if ICARDER bit is set in SCIER register otherwise this bit is
irrelevant.
It is cleared by hardware when this register is read.
Card Voltage Error Interrupt
This bit is set when the output volta ge goes out of the voltage range specified by VCARD field. It gener ates
an interrupt if EVCARDER bit is set in SCIER register otherwise this bit is irrelevant.
It is cleared by hardware when this register is read.
Waiting Time Counter Timeout Interrupt
This bit is set by hardware when the Waiting Time Counter has expired. It generates an interrupt if ESCWTI
bit is set in SCIER register otherwise this bit is irrelevant.
It is cleared by hardware when this register is read.
UART Transmitted Character Interrupt
This bit is set by hardware when the Smart Card UART has completed the character transmission. It
generates an interrupt if ESCTI bit is set in SCIER register otherwise this bit is irrelevant.
It is cleared by hardware when this register is read.
UART Received Character Interrupt
This bit is set by hardware when the S mart Card UART has completed the c haracter reception. It generates
an interrupt if ESCRI bit is set in SCIER register otherwise this bit is irrelevant.
It is cleared by hardware when this register is read.
Character Reception Parity Error Interrupt
This bit is set at the same time as SCTI or SCRI if a parity error is detected on the received character. It
generates an interrupt if ESCPI bit is set in SCIER register otherwise this bit is irrelevant.
It is cleared by hardware when this register is read.
Note:1) In case of multiple interrupts occuring at the same t ime (sampled by the same edge of
the internal clock), the interrupts will be serviced in the following order from the highest t o
the lowest priority :
-
UART Transmit Buffer Empty
- Card Current Overflow
- Card Vo ltage Error
- Waiting Time Counter Timeout
- UART Transmi tt e d C ha racter
- UART Received Character
- Character Reception Parity Error
82
2) It is recommended that the application saves the SCIIR register after reading it in
order to avoid the loss of pending interru ptions as the SCIIR register is cleared when it is
read by the MC U .
Clear this bit to disable the Smart Card UART Transmit Buffer Empty interrupt.
Set this bit to enable the Smart Card UART Transmit Buffer Empty interrupt.
6-
5ICARDER
4EVCARDER
3ESCWTI
2ESCTI
1ESCRI
0ESCPI
Reset Value = 0X00 0000b
Reserved
The value read from this bit is indeterminate. Do not change this bit.
Card Current Overflow Interrupt Enabled
Clear this bit to disable the Card Current Overflow interrupt.
Set this bit to enable the Card Current Overflow interrupt.
Card Voltage Error Interrupt Enabled
Clear t his bit to disabl e the Card Voltage Error interrupt.
Set this bit to enable the Card Voltage Error interrupt.
WaitingTime Counter Timeout Interrupt Enabled
Clear this bit to disable the Waiting Time Counter timeout interrupt.
Set this bit to enable the Waiting Time Counter timeout interrupt.
UART Transmitted Character Interrupt Enabled
Clear this bit to disable the Smart Card UART Transmitted Character interrupt.
Set this bit to enable the Smart Card UART Transmitted Character interrupt.
UART Received Character Interrupt Enabled
Clear this bit to disable the Smart Card UART Received Character interrupt.
Set this bit to enable the Smart Card UART Received Character interrupt.
Character Reception Parity Error Interrupt Enabled
Clear this bit to disable the Smart Card Character Reception Parity Error interrupt.
Set this bit to enable the Smart Card Character Reception Parity Error interrupt.
The val ue read from this bit is inde terminate. Do no t change this bit.
Block Guard Time Enabl e
Set this bit to s elect the minimum i nterval between t he leading edge of the start bits of the last chara c ter
received from the ICC and the first character sent by the Terminal. The transfer of GT[8-0] value to the BGT
counter is done on the rising edge of the BGTEN.
Clear this bit to suppress the minimum time between reception and transmission.
Reserved
The val ue read from this bit is inde terminate. Do no t change this bit.
Character repetition selection
Clear this bit to select 5 times transmission (1 original + 4 repetitions) before parity error indication (conform to
EMV)
Set this bit to select 4 times transmission (1 original + 3 repetitions) before parity error indication
Clear this bit when no time compensation is needed (i.e. when the ETU to Card CLK period ratio is close to an
integer with an error less than 1/4 of Card CLK period).
Set this bit otherwise and reduce the ETU period by 1 Card CLK cycle for even bits.
6-3-
2-0ETU[10:8]
Reserved
The val ue read from these bits is indeterminate. Do not change these bits.
ETU MSB
Used together with the ETU LSB in SCETU0 (Table 52)
Warning : the ETU counter is reloaded at each register’s write operation.
Do not change this register during character reception or transmission or while Guard Time or Waiting Time
The Elementary Time Unit is (ETU[10:0] - 0.5*COMP)/f, where f is the Card CLK frequency.
According to ISO 7816, ETU[10:0] can be set between 1 1 and 2048 (2047 ?)
The default reset value of ETU[10:0] is 372 (F=372, D=1).
Guard Time +10 (see Guard Time Counter description.
According to ISO IEC 7816,the time between 2 consecut ive leading edge st art bits can be set between 11 and
266 (11 to 254+12 ET Us) .
7 - 1-
0GT8
Reserved
The val ue read from these bits is indeterminate. Do not change these bits.
T ransmit Guard Time MSB
Used together with the Transmit Guard Time LSB in SCG T0 register (Table 53).
WT[31:0] is the reload va lue of the Waiting Time Counter ( WTC).
7 - 0WT[7: 0]
The WTC is a general-purpose timer. It is using the ETU clock and is controlled by the WTEN bit (see Table 44 on
page 79 and Section “Waiting Time (WT) Counter”, page 69).
When UART bit of Registers is set, the WTC is automatically reload ed at each start bit of the UART. It is used to
check the maximum time between to consecutive start bits.
If XTSCS bit is set OR EXT48 bit is set (in PLLCON register) , CK_PLL is used to generate CK_ISO.
Otherwise, CK_XTAL1 is used to generate CK_ISO.
See the C lock Tree diagram figure 17.
6-
5 - 0SCICLK[5: 0]
Reserved
The value read from this bit is indeterminate. Do not change these bits.
SCIB clock reload register
Prescaler 2 reload value is used to defines the card clo ck frequency.
If SCICLK[5:0] is smaller than 48 :
Fck_is o = Fck_pll or Fck_XTAL1/ (2 * (48 - SCI CLK[5:0 ]))
If SCICLK[5:0] is equal to 48 :
Fck_iso = Fck_XTAL1
SCICLK[5:0] must be smaller than 49.
Reset Value = 0X10 1111b (default value for a divider by two)
DC/DC ConverterThe Smart Card voltage (CVCC) is supplied by the integrated DC/DC converter which is
controlled by several registers:
•The SCICR register (Table 44 on page 79) controls the CVCC level by means of bits
VCARD[1:0].
•The SCCON register (Table 45 on page 80) enables to switch the DC/DC converter
on or off by means of bit CARDVCC.
•The DCCKPS register (Table 61 on page 94) controls the DC/DC clock and current.
The DC/DC co nverter ca nnot be sw itched o n while th e CPRES pi n rema ins inacti ve. If
CPRES pin becomes inactive while the DC/DC converter is operating an automatic shut
down sequence of the DC/DC converter is initiated by the electronics.
It is mandatory to switch off the DC/DC Converter before entering in Power-down mode.
ConfigurationThe DC/DC Conv erter can work in two different modes which are selected by bit MODE
in DCCKPS register:
•Pump Mode: an external inductance of 10 µH must be connected between pins LI
and VCC. VCC can be higher or lower than CVCC.
•Regulator mode : no external inductance is required but VCC must be always higher
than CVCC+0.3V. The Regulation mode will work even if an external inductance of
10 µH is connected between pins LI and VCC
The DC/DC clock prescaler which is controlled by bits DCCKPS[3:0], in DCCKPS register must be confi gured to set the DC/DC cloc k to a w orking frequenc y of 4 MHz w hich
depends upon the value of the crystal. There is no need to change the default configuration set by the reset sequence if an 8 MHz crystal is used by the application.
The DC/DC Converter implements a current overflow controller which avoids permanent
damage of the DC/DC converter in case of short circuit between CVCC and CVSS. The
maximum limit is around 100 mA. It is possible to increase this limit in normal operating
88
4202E–SCR–06/06
AT8xC5122/23
mode by 20% by means of bit OVFADJ in DCCKPS register. When the current overflow
controller is operating, the ICARDOVF is set by the hardware in SCISR register.
The curren t dra wn fr om po wer s upply by th e DC/ DC con verte r is c ontroll ed du ring th e
startup phase in order to avoid hig h tran sient cu rrent mainly in P um p Mo de which could
cause the power sup ply vo ltage to drop dram atic ally. Th is cont rol is don e by mea ns of
bits BOOST[1:0], which increases progressively the startup current level.
Initializat i on P rocedureThe initialization procedure is different depending upon the required Card Vcc. One pro-
cedure apply for Card Vcc =< 3 volts and one procedure for Card Vcc = 5 volts.
The initialization procedure involves :
•Select the CVCC level by means of bits VCARD[1:0] in SCICR register,
•Set bits BOOST[1:0] in DCCKPS register following the current level control wanted.
•Switch the DC/DC on by means of bit CARDVCC in SCCON register,
•Monitor bit VCARDOK in SCISR register in order to know when the DC/DC
Converter is ready (CVCC voltage has reached the expected level)
Procedure for CVcc =< 3 voltsThe DC/DC regulation mode must be selected for Card Vcc = 1.8 volts and Card Vcc =
3 volts (MO DE = 1 in DCC KPS regi ster) The detailed procedur es is des cribed in flo w
chart of Figure 46. for Card Vcc = 1.8 v olts and i n the flow chart o f Figure 47. for Card
Vcc = 3 volts
Procedure for CVcc = 5voltsThe DC/DC pump mode must be selected (MODE = 0 in DCCKPS register). The
detailed procedure is described in flow chart of Figure 48.
Figure 48. Card Vcc = 5V Initialization Procedure
SCICR.7=Reset=1
SCICR.7=Reset=0
VCARD[1:0] = 11
Mode Pump
DCCKPS[7]=0
BOOST[1:0]=[0:0]
SCCON CardVcc=1
Set Timeout to 3 ms
VCARDOK=1
BOOST[1:0]
Timeout
Expired
BOOST[1:0]
= max = 3?
Increment
BOOST [1:0]
DC/DC Initialization
Failure
= [0:0]
Decrement
BOOST[1:0]
to adjust the
current overflow
DC/DC Initialization
Successful
While VCC remains higher than 4.0V and startup current lower than 30 mA (depending
on the load type), the DC/DC converter should be ready without having to increment
BOOST[1:0] bits beyond [0:0] level. If VCC > 4.0V and startup current > 30 mA, it will be
necessary to increment the BOOST[1:0] bits until the DC/DC converter is ready.
92
Incrementation of BOOST[1:0] bits increases at the same time the current overflow level
in the same proportion as the startup current. So once the DC/DC converter is ready it is
4202E–SCR–06/06
AT8xC5122/23
advised to decrem ent the BOO ST[1:0] bits to restore the overflo w current t o its norma l
or desired value.
Monitoring ProcedureOnce the DC/DC has b een s ucces sfuly in itialized, it is neces sary t o m oni tor the DC/ DC
converter by means of bits VCARDOK and ICARDOVF in the SCISR register.
Table 60. DC/DC converter status
VCARDOKICARDOVFDC/DC Status
- Not Started or switched off by application.
The curr ent overflow sensor is disab led during the DC/DC converter startu p. Then if a current
overflow condition is applied during the DC/DC converter startup, the DC/DC converter is unable
00
01Started and automatically switched off by a current overflow condition
10Operating properly accor ding to ISO/IEC 7816-3 and EMV recomm endations
to start and both bits VCARDOK and ICARDOVF remains at 0.
DC/DC converter correctly started then the output voltage is out of ISO/IEC 7816-3
specifications. In this case the firmware must take appropriate actions like deactivating the
DC/DC converter in compliance with ISO/IEC 7816.
00 : Normal = OVFADJ
01 : Normal + 30%
10 : Normal + 50%
11 : Normal + 80%
94
4202E–SCR–06/06
AT8xC5122/23
USB ControllerThe A T8xC5122D implement s a USB device c ontroller supportin g Full Speed da ta
transfer. In addition to the default control endpoint 0, it provides 6 other endpoints, which
can be configured in Control, Bulk, Interrupt or Isochronous modes:
• Endpoint 0: 32-byte FIFO, default control endpoint
• Endpoint 1,2,3: 8-byte FIFO
• Endpoint 4,5: 64-byte FIFO
• Endpoint 6: 2 x 64-byte Ping-pong FIFO
This allows the firmware to be developed conforming to most USB device classes, for
example:
•USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport, Revision 1.0 December 14, 1998.
•USB Mass Storage Class Bulk-Only Transport, Revision 1.0 - September 31, 1999.
•USB Human Interface Device Class, Version 1.1 - April 7, 1999.
Within the CBI framework, the Control endpoint is used to transport command blocks as
well as to transport standard US B reque sts. One Bulk-Out endpoint is used to transport
data from the host to the device. One Bulk-In endpoint is used to transport data from the
device to the host. And one interrupt endpoint may also be used to signal command
completion (protocol 0); it is optional and may not be used (protocol 1).
The following configuration adheres to these requirements:
•Endpoint 0: 8 bytes, Control In-Out
•Endpoint 4: 64 bytes, Bulk-Out
•Endpoint 5: 64 bytes, Bulk-In
•Endpoint 1: 8 bytes, Interrupt In
Within the Bulk-Only framework, the Control endpoint is only used to transport classspecific and s tandard US B reques ts for devi ce set- up and con figura tion. One B ulk-Out
endpoint is used to transport commands and data from the host to the device. One BulkIn endpoint is used to transport status and data from the device to the host. No interrupt
endpoint is needed.
The following configuration adheres to these requirements:
•Endpoint 0: 8 bytes, Control In-Out
•Endpoint 4: 64 bytes, Bulk-Out
•Endpoint 5: 64 bytes, Bulk-In
The USB Device Firmwa re Upda te (DFU) protocol c an be used to upgrad e the on-chi p
program memory of the AT8xC5122D. This allows the implementation of product
enhancements and patches to devices that are already in the field. Two different configurations and description sets are used to support DFU functions. The Run-Time
configuration co-exists with the usual functions of the devic e, which may be USB Mas s
Storage for the AT8xC5122D. It is used to initiate DFU from the normal operating mode.
The DFU configuration is used to perform the firmware update after device re-configuration and USB reset. It excludes any other function. Only the default control pipe
(endpoint 0) is used to support DFU services in both configurations.
4202E–SCR–06/06
95
AT8xC5122/23
r
The only p ossi ble va lue for the wMa xPac ketSiz e in th e DFU co nfi gurat ion is 32 b ytes ,
which is the size of the FIFO implemented for endpoint 0.
DescriptionThe USB device controller provides the hardware that the AT8xC5122D and the
AT83C5123 need to interface a USB link to a data flow stored in a double port memory
(DPRAM).
The US B co ntroll er requ ires a 48 M Hz r eferen ce cl ock, w hich i s the outpu t of th e
AT8xC5122D/23 PLL (see Section "Phase Lock Loop (PLL)", page 42) divided by a
clock prescaler. This clock is used to generate a 12 MHz full speed bit clock from the
received USB d ifferential data and to transmit data according t o full speed USB devic e
tolerance. Clock recovery is done by a Digital Phase Loc ked Loop (DP LL) block, which
is compliant with the jitter specification of the USB bus.
The Interface Engine (SIE) block performs NRZI encoding and decoding, bit stuffing,
CRC generation and checking, and the serial-parallel data conversion. The Universal
Function Interface (UFI) performs the interface between the data f low and the Dual Port
Ram
Figure 49. USB Device Controller Block Diagram
48 MHz +/- 0.25%
D+
DPLL
USB
12MHz
D+/D-
D-
Buffer
SIE
Serial Interface Engine (SIE)The SIE performs the following functions:
•NRZI data encoding and decoding.
•Bit stuffing and unstuffing.
•CRC generation and checking.
•Handshakes.
•TOKEN type identifying.
•Address checking.
•Clock generation (via DPLL).
C51
Microcontrolle
Interface
UFI
Up to 48 MHz
UC_SYSCLK
96
4202E–SCR–06/06
Figure 50. SIE Block Diagram
r
End of Pack et
Detection
AT8xC5122/23
SYNC detection
PID decoder
Address Decoder
Serial to Parallel
Conversion
CRC5 & CRC16
Generation/Check
8
Dat aIn [7 :0]
DataOut
8
D+
D-
Start of Packet
Detection
Clock
Recovery
Clk48
(48 MHz)
NRZI ‘ NRZ
Bit Unstuffing
Packet bit counter
SysClk
(12 MHz)
USB Pattern Ge nerator
Parallel to Serial Converter
Bit Stuffing
NRZI Converter
CRC16 Generator
Function Interface Unit (UFI)The Function Interface Unit provides the interface between the AT8xC5122D (or
AT83C5123) and the SIE. It manages transactions at the packet level with minimal intervention from the device firmware, which reads and writes the endpoint FIFOs.
Figure 51. UFI Block Diagram
UFI
DPLL
Transfer
Control
FSM
SIE
DPR Control
USB side
Asynchronous Information
Transfer
Endpoint 6
Endpoint 5
Endpoint 4
Endpoint 3
Endpoint 2
Endpoint 1
Endpoint 0
User DPRAM
CSREG 0 to 7
Registers
Bank
DPR Control
mP side
C51
Microcontrolle
Interface
Up to 48 MHz
UC_SYSCLK
4202E–SCR–06/06
97
AT8xC5122/23
Figure 52. Minimum Intervention from the USB Device Firmware
OUT Transactions:
HOST
UFI
C51
IN Transactions:
HOST
UFI
C51
OUT DATA0 (n Bytes)
IN
NACK
Endpoi nt F IF O wr it e
ACK
interrupt C51
Endpoint FIFO read (n bytes)
IN
DATA1
OUTDATA1
OUTDATA1
NACK
IN
DATA1
ACK
interrupt C51
Endpoint FIFO write
ACK
98
4202E–SCR–06/06
Configuration
General Configuration•USB controller enable
Before any USB transaction, the 48 MHz required by the USB controller must be correctly generated (Section "Clock Controller", page 41).
The USB controller should be then enabled by setting the USBE bit in the USBCON
register.
•Set address
After a Reset or a USB reset, the software has to set the FEN (Function Enable) bit in
the USBADDR register. This action will allow the USB controller to answer to the
requests sent at the address 0.
When a SET _ADDRE SS request has be en receive d, the USB con troller must on ly
answer to the address defined by the request. The new addres s should be st ored in the
USBADDR register. The FEN bit and the FADDEN bit in the USBCON register should
be set to allow the USB controller to answer only to requests sent at the new address.
•Set configuration
The CONFG bit in the USBCON regist er should be set after a SET_CO NFIGUR ATION
request with a non-zero value. Otherwise, this bit should be cleared.
AT8xC5122/23
Endpoint Configuration•Selection of an Endpoint
The endpoint register access is performed using the UEPNUM register. The following
registers
correspond to the endpoint whose numbe r is stored in the UEPNUM register. To select
an Endpoint, the firmware has to write the endpoint number in the UEPNUM register.
–UEPSTAX,
–UEPCONX,
–UEPDATX,
–UBYCTX,
Figure 53. Endpoint Selection
Endpoint 0
Endpoint 6
UEPSTA0UEPCON0UEPDAT0
UBYCT0
UEPSTA6UEPCON6UEPDAT6
UBYCT6
0
SFR Registers
1
2
X
3
4
UEPSTAXUEPCONXUEPDATX
UBYCTX
5
6
4202E–SCR–06/06
UEPNUM
99
AT8xC5122/23
•Endpoint enable
Before using an endpoint, this one should be enabled by setting the EPEN bit in the
UEPCONX register.
An endpoint which is not enabled won’t answer to any USB request. The Default Control
Endpoint (Endpoint 0) should always be enabled in order to answer to USB standard
requests.
•Endpoint type configuration
All Standard Endpoints can be configured in Control, Bulk, Interrupt or Isochronous
mode. The Ping-pong Endpoints can be configured in Bulk, Interrupt or Isochronous
mode. The configuration of an endpoint is performed by setting the field EPTYPE with
the following values:
The Endpoint 0 is the Default Control Endpoint and should always be configured in Control type.
•Endpoint direction configuration
For Bulk, Int errup t and Isochro nous en dpo ints, th e direct ion is define d with t he EP DIR
bit of the UEPCONX register with the following values:
–IN:EPDIR = 1b
–OUT:EPDIR = 0b
For Control endpoints, the EPDIR bit has no effect.
•Summary of Endpoint Configuration:
Make sure to select the correct endpoint number in the UEPNUM register before
accessing to endpoint specific registers.