The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers.    


Datasheet Search Engine   
 
Part # or Description: • 5V RS232 Driver • 2SC5066* • "Real Time Clock" • "USB connector" • "blue led" 5mm • 10 watt zener diode • 2N3055* motorola
 
Search Tip: Try entering the part number only. Include a wildcard (eg. lm317* or 1n4148*)

 

 

64/44-PIN, 8-BIT WITH FLASH/ROM, FIVE TIMERS, SPI, SCI, INTERFACE


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet



ST72321B
64/44-PIN, 8-BIT WITH FLASH/ROM, FIVE TIMERS, SPI, SCI, INTERFACE
Memories dual voltage High Density Flash (HDFlash) with read-out protection capability. In-Application Programming In-Circuit Programming HDFlash devices HDFlash endurance: cycles, data retention: years 55°C Clock, Reset Supply Management Enhanced voltage supervisor (LVD) main supply auxiliary voltage detector (AVD) with interrupt capability Clock sources: crystal/ceramic resonator oscillators, internal oscillator, clock security system bypass external clock frequency multiplication Four Power Saving Modes: Halt, Active-Halt, Wait Slow Interrupt Management Nested interrupt controller interrupt vectors plus TRAP RESET Level Interrupt (TLI) 64-pin devices external interrupt lines vectors) Ports 48/32 multifunctional bidirectional lines 34/22 alternate function lines 16/12 high sink outputs Timers Main Clock Controller with: Real time base, Beep Clock-out capabilities Configurable watchdog timer 16-bit timers with: input captures, output compares, external clock input timer, pulse generator modes 8-bit Auto-reload timer with: input captures, outputs, output compare time base interrupt, external clock with event
Features ST72321B(R/AR/J)9
2048 (256)
TQFP64
TQFP64
TQFP44
detector Communications Interfaces synchronous serial interface asynchronous serial interface (LIN compatible) multimaster interface Analog peripheral (low current coupling) 10-bit with robust input ports Instruction 8-bit Data Manipulation Basic Instructions main Addressing Modes Unsigned Multiply Instruction Development Tools Full hardware/software development package In-Circuit Testing capability
Device Summary
ST72321B(R/AR/J)7 ST72321B(R/AR/J)6
Program memory bytes (stack) bytes Operating Voltage Temp. Range Package 1536 (256) 1024 (256) 3.8V 5.5V -40°C +125°C TQFP64 14x14 (R), TQFP64 10x10 (AR), TQFP44 10x10 (JxT)
Rev. October 2003 1/183
This preliminary information product development undergoing evaluation. Details subject change without notice.
Table Content1 INTRODUCTION DESCRIPTION REGISTER MEMORY FLASH PROGRAM MEMORY INTRODUCTION MAIN FEATURES STRUCTURE 4.3.1 Read-out Protection INTERFACE (IN-CIRCUIT PROGRAMMING) (IN-APPLICATION PROGRAMMING) RELATED DOCUMENTATION
4.7.1 Register Description CENTRAL PROCESSING UNIT INTRODUCTION MAIN FEATURES REGISTERS
SUPPLY, RESET CLOCK MANAGEMENT PHASE LOCKED LOOP MULTI-OSCILLATOR (MO) RESET SEQUENCE MANAGER (RSM)
6.3.1 Introduction 6.3.2 Asynchronous External RESET 6.3.3 External Power-On RESET 6.3.4 Internal Voltage Detector (LVD) RESET 6.3.5 Internal Watchdog RESET SYSTEM INTEGRITY MANAGEMENT (SI) 6.4.1 Voltage Detector (LVD) 6.4.2 Auxiliary Voltage Detector (AVD) 6.4.3 Clock Security System (CSS) 6.4.4 Power Modes 6.4.5 Register Description INTERRUPTS INTRODUCTION
MASKING PROCESSING FLOW INTERRUPTS POWER MODES CONCURRENT NESTED MANAGEMENT INTERRUPT REGISTER DESCRIPTION EXTERNAL INTERRUPTS 7.6.1 Port Interrupt Sensitivity EXTERNAL INTERRUPT CONTROL REGISTER (EICR)
POWER SAVING MODES INTRODUCTION SLOW MODE
2/183
Table Content8.3 WAIT MODE ACTIVE-HALT HALT MODES
8.4.1 ACTIVE-HALT MODE 8.4.2 HALT MODE PORTS INTRODUCTION 9.2.1 Input Modes 9.2.2 Output Modes 9.2.3 Alternate Functions PORT IMPLEMENTATION
FUNCTIONAL DESCRIPTION
POWER MODES INTERRUPTS
9.5.1 Port Implementation ON-CHIP PERIPHERALS 10.1 WATCHDOG TIMER (WDG) 10.1.1 Introduction 10.1.2 Main Features 10.1.3 Functional Description 10.1.4 Program Watchdog Timeout 10.1.5 Power Modes 10.1.6 Hardware Watchdog Option 10.1.7 Using Halt Mode with (WDGHALT option) 10.1.8 Interrupts 10.1.9 Register Description 10.2 MAIN CLOCK CONTROLLER WITH REAL TIME CLOCK BEEPER (MCC/RTC) 10.2.1 Programmable Clock Prescaler 10.2.2 Clock-out Capability 10.2.3 Real Time Clock Timer (RTC) 10.2.4 Beeper 10.2.5 Power Modes 10.2.6 Interrupts 10.2.7 Register Description 10.3 AUTO-RELOAD TIMER (ART) 10.3.1 Introduction 10.3.2 Functional Description 10.3.3 Register Description 10.4 16-BIT TIMER 10.4.1 Introduction 10.4.2 Main Features 10.4.3 Functional Description 10.4.4 Power Modes 10.4.5 Interrupts 10.4.6 Summary Timer modes 10.4.7 Register Description 10.5 SERIAL PERIPHERAL INTERFACE (SPI)
3/183
Table Content10.5.1 Introduction 10.5.2 Main Features 10.5.3 General Description 10.5.4 Clock Phase Clock Polarity 10.5.5 Error Flags 10.5.6 Power Modes 10.5.7 Interrupts 10.5.8 Register Description 10.6 SERIAL COMMUNICATIONS INTERFACE (SCI)
10.6.1 Introduction 10.6.2 Main Features 10.6.3 General Description 10.6.4 Functional Description 10.6.5 Power Modes 10.6.6 Interrupts 10.6.7 Register Description 10.7 INTERFACE (I2C) 10.7.1 Introduction 10.7.2 Main Features 10.7.3 General Description 10.7.4 Functional Description 10.7.5 Power Modes 10.7.6 Interrupts 10.7.7 Register Description 10.8 10-BIT CONVERTER (ADC) 10.8.1 Introduction 10.8.2 Main Features 10.8.3 Functional Description 10.8.4 Power Modes 10.8.5 Interrupts 10.8.6 Register Description INSTRUCTION 11.1 ADDRESSING MODES 11.1.1 Inherent 11.1.2 Immediate 11.1.3 Direct 11.1.4 Indexed Offset, Short, Long) 11.1.5 Indirect (Short, Long) 11.1.6 Indirect Indexed (Short, Long) 11.1.7 Relative mode (Direct, Indirect) 11.2 INSTRUCTION GROUPS
ELECTRICAL CHARACTERISTICS 12.1 PARAMETER CONDITIONS 12.1.1 12.1.2 12.1.3 12.1.4 12.1.5 Minimum Maximum values Typical values Typical curves Loading capacitor input voltage
4/183
Table Content12.2 ABSOLUTE MAXIMUM RATINGS 12.2.1 Voltage Characteristics 12.2.2 Current Characteristics 12.2.3 Thermal Characteristics 12.3 OPERATING CONDITIONS
12.3.1 Operating Conditions 12.4 LVD/AVD CHARACTERISTICS 12.4.1 Voltage Detector (LVD) thresholds 12.4.2 Auxiliary Voltage Detector (AVD) Thresholds 12.4.3 External Voltage Detector (EVD) Thresholds 12.5 SUPPLY CURRENT CHARACTERISTICS 12.5.1 CURRENTCONSUMPTION 12.5.2 Supply Clock Managers 12.5.3 On-Chip Peripherals 12.6 CLOCK TIMING CHARACTERISTICS 12.6.1 General Timings 12.6.2 External Clock Source 12.6.3 Crystal Ceramic Resonator Oscillators 12.6.4 Oscillators 12.6.5 Clock Security System (CSS) 12.6.6 Characteristics 12.7 MEMORY CHARACTERISTICS
12.7.1 Hardware Registers 12.7.2 FLASH Memory 12.8 CHARACTERISTICS 12.8.1 Functional 12.8.2 Electro Magnetic Interference (EMI) 12.8.3 Absolute Electrical Sensitivity 12.8.4 Protection Strategy 12.9 PORT CHARACTERISTICS
12.9.1 General Characteristics 12.9.2 Output Driving Current 12.10 CONTROL CHARACTERISTICS 12.10.1Asynchronous RESET 12.10.2ICCSEL/VPP 12.11 TIMER PERIPHERAL CHARACTERISTICS 12.11.18-Bit PWM-ART Auto-Reload Timer 12.11.216-Bit Timer 12.12 COMMUNICATION INTERFACE CHARACTERISTICS 12.12.1SPI Serial Peripheral Interface 12.12.2I2C Inter Control Interface 12.13 10-BIT CHARACTERISTICS 12.13.1Analog Power Supply Reference Pins 12.13.2General Design Guidelines 12.13.3ADC Accuracy PACKAGE CHARACTERISTICS 13.1 PACKAGE MECHANICAL DATA
5/183
Table Content13.2 THERMAL CHARACTERISTICS 13.3 SOLDERING GLUEABILITY INFORMATION ST72321B CONFIGURATION ORDERING INFORMATION 14.1 FLASH OPTION BYTES 14.2 DEVICE ORDERING INFORMATION TRANSFER CUSTOMER CODE 14.2.1 Version-Specific Sales Conditions 14.3 DEVELOPMENT TOOLS 14.3.1 Socket Emulator Adapter Information 14.4 APPLICATION NOTES KNOWN LIMITATIONS 15.1 EXTERNAL OPTION 15.2 FUNCTION 15.3 SAFE CONNECTION OSC1/OSC2 PINS 15.4 UNEXPECTED RESET FETCH 15.5 16-BIT TIMER MODE 15.6 LIMITATIONS DEVICES ONLY SUMMARY CHANGES
obtain most recent version this datasheet, please check www.st.com>products>technical literature>datasheet. Please also special attention Section "KNOWN LIMITATIONS" page 181.
6/183
ST72321B
INTRODUCTION
ST72321B devices enhanced versions ST72321 microcontroller family designed mid-range applications devices based common industrystandard 8-bit core, featuring enhanced instruction available with FLASH program memory. Under software control, devices placed WAIT, SLOW, ACTIVE-HALT HALT mode, Figure Device Block Diagram
8-BIT CORE RESET OSC1 OSC2 CONTROL
reducing power consumption when application idle stand-by state. enhanced instruction addressing modes offer both power flexibility software developers, enabling design highly efficient compact application code. addition standard 8-bit data management, microcontrollers feature true manipulation, unsigned multiplication indirect addressing modes.
PROGRAM MEMORY (16K Bytes) (512 2048 Bytes)
WATCHDOG PORT PORT PB7:0 (8-bits) PORT TIMER PORT PC7:0 (8-bits) ADDRESS DATA MCC/RTC/BEEP PA7:0 (8-bits)
PORT PF7:0 (8-bits) TIMER BEEP PORT PE7:0 (8-bits)
PD7:0 (8-bits) 10-BIT VAREF VSSA
7/183
ST72321B
DESCRIPTION
Figure 64-Pin TQFP 14x14 10x10 Package Pinout
(HS) (HS) (HS) (HS) PWM3 PWM2 PWM1 PWM0 /PB3 ARTCLK /(HS) ARTIC1 ARTIC2 AIN0 AIN1 AIN2 AIN3
VDD_2 OSC1 OSC2 VSS_2 RESET ICCSEL (HS) SCLI (HS) SDAI (HS) (HS)
VSS_1 VDD_1 (HS) AIN15 ICCCLK MOSI AIN14 MISO ICCDATA (HS) ICAP1_B (HS) ICAP2_B OCMP1_B AIN13 OCMP2_B AIN12 VSS_0 VDD_0
8/183
AIN4 AIN5 AIN6 AIN7 VAREF VSSA VDD_3 VSS_3 AIN8 BEEP (HS) (HS) OCMP2_A AIN9 OCMP1_A AIN10 ICAP2_A AIN11 ICAP1_A (HS) EXTCLK_A (HS) (HS) 20mA high sink capability associated external interrupt vector
ST72321B
Figure 44-pin Device Pinout
PWM3 /PB0 PWM2 PWM1 PWM0 ARTCLK (HS) AIN0 AIN1 AIN2 AIN3 AIN4
AIN5 VAREF VSSA AIN8 BEEP (HS) (HS) OCMP1_A AIN10 ICAP1_A (HS) EXTCLK_A (HS) VDD_0 VSS_0
VDD_2 OSC1 OSC2 VSS_2 RESET ICCSEL (HS) SCLI (HS) SDAI (HS) (HS)
VSS_1 VDD_1 (HS) AIN15 ICCCLK MOSI AIN14 MISO ICCDATA (HS) ICAP1_B (HS) ICAP2_B OCMP1_B AIN13 OCMP2_B AIN12
(HS) 20mA high sink capability associated external interrupt vector
9/183
ST72321B
DESCRIPTION (Cont'd) external connection guidelines, refer "ELECTRICAL CHARACTERISTICS" page 137. Legend Abbreviations Table Type: input, output, supply Input level: Dedicated analog input In/Output level: CMOS 0.3VDD/0.7VDD CMOS 0.3VDD/0.7VDD with input trigger 0.8V with Schmitt trigger Output level: 20mA high sink N-buffer only) Port control configuration: Input: float floating, weak pull-up, interrupt robust analog ports Output: open drain push-pull Refer "I/O PORTS" page more details software configuration ports. RESET configuration each shown bold. This configuration valid long device reset state. Table Device Description
TQFP64 TQFP44 Type Name Level Output Input Input float Port Output Main functio (after reset) Port Port Port Port Port Output Port Output Port Output Port Output Port PWM-ART External Clock Port PWM-ART Input Capture Port PWM-ART Input Capture Port Port Analog Input Port Analog Input Port Analog Input Port Analog Input Port Analog Input Port Analog Input Port Analog Input Port Analog Input Analog Reference Voltage Analog Ground Voltage Digital Main Supply Voltage
Alternate function
(HS) (HS) (HS) (HS) PB0/PWM3 PB1/PWM2 PB2/PWM1 PB3/PWM0 (HS)/ARTCLK ARTIC1 ARTIC2 PD0/AIN0 PD1/AIN1 PD2/AIN2 PD3/AIN3 PD4/AIN4 PD5/AIN5 PD6/AIN6 PD7/AIN7 VAREF VSSA VDD_3
10/183
ST72321B
TQFP64 TQFP44 Type Name
Level Output Input Input float
Port Output
Main functio (after reset)
Alternate function
VSS_3 PF0/MCO/AIN8 (HS)/BEEP (HS) PF3/OCMP2_A/AIN9
Digital Ground Voltage Port Main clock (fOSC/2) Analog Input
Port Beep signal output Port Timer OutPort Compare Timer OutPort Compare Port Analog Input Analog Input
PF4/OCMP1_A/AIN10 PF5/ICAP2_A/AIN11 (HS)/ICAP1_A (HS)/EXTCLK_A VDD_0 VSS_0 PC0/OCMP2_B/AIN12
Timer Input Analog Capture Input Timer External Clock Source
Port Timer Input Capture Port
Digital Main Supply Voltage Digital Ground Voltage Timer OutPort Compare Timer OutPort Compare Analog Input Analog Input
PC1/OCMP1_B/AIN13 (HS)/ICAP2_B (HS)/ICAP1_B PC4/MISO/ICCDATA
Port Timer Input Capture Port Timer Input Capture Master Data InPort Slave Data Master Analog Port Slave Input Data Port Serial Clock Clock Output
PC5/MOSI/AIN14 PC6/SCK/ICCCLK PC7/SS/AIN15 (HS) VDD_1 VSS_1 (HS)
Slave SeADC Analog Port lect (active Input low) Port Port Port Port Digital Main Supply Voltage Digital Ground Voltage
Port
11/183
ST72321B
TQFP64 TQFP44 Type Name
Level Output Input Input float
Port Output
Main functio (after reset) Port Port Port
Alternate function
(HS) (HS)/SDAI (HS)/SCLI
Data Clock
VPP/ ICCSEL
Must tied low. flash programming mode, this acts programming voltage input VPP. Section 12.10.2 more details. High voltage must applied devices priority maskable interrupt. External voltage detector level interrupt input Digital Ground Voltage Resonator oscillator inverter output External clock input Resonator oscillator inverter input Digital Main Supply Voltage Port Transmit Data Port Receive Data Port Port
RESET VSS_2 OSC2
OSC13) VDD_2 PE0/TDO PE1/RDI
Notes: interrupt input column, "eiX" defines associated external interrupt vector. weak pull-up column (wpu) merged with interrupt column (int), then configuration pull-up interrupt input, else configuration floating interrupt input. open drain output column, defines true open drain (P-Buffer protection diode implemented). "I/O PORTS" page Section 12.9 PORT CHARACTERISTICS more details. OSC1 OSC2 pins connect crystal/ceramic resonator, external source on-chip oscillator; Section INTRODUCTION Section 12.6 CLOCK TIMING CHARACTERISTICS more details. chip, each port pads. Pads that bonded external pins input pull-up configuration after reset. configuration these pads must kept reset state avoid added current consumption.
12/183
ST72321B
REGISTER MEMORY
shown Figure capable addressing bytes memories registers. available memory locations consist bytes register locations, 2Kbytes 60Kbytes user program memory. space includes bytes stack from 0100h 01FFh. Figure Memory
0000h 007Fh 0080h
highest address bytes contain user reset interrupt vectors. IMPORTANT: Memory locations marked "Reserved" must never accessed. Accessing reseved area have unpredictable effects device.
Registers (see Table
0080h
Short Addressing (zero page)
00FFh 0100h
(2048, 1536 1024 Bytes)
087Fh 0880h
Bytes Stack
01FFh 0200h 1000h
Reserved
0FFFh 1000h
16-bit Addressing
047Fh 067Fh 087Fh
KBytes KBytes KByte
4000h 8000h
Program Memory (60K, 32K)
FFDFh FFE0h FFFFh
Interrupt Reset Vectors (see Table
FFFFh
13/183
ST72321B
Table Hardware Register
Address 0000h 0001h 0002h 0003h 0004h 0005h 0006h 0007h 0008h 0009h 000Ah 000Bh 000Ch 000Dh 000Eh 000Fh 0010h 0011h 0012h 0017h 0018h 0019h 001Ah 001Bh 001Ch 001Dh 001Eh 001Fh 0020h 0021h 0022h 0023h 0024h 0025h 0026h 0027h 0028h 0029h FLASH SPIDR SPICR SPICSR ISPR0 ISPR1 ISPR2 ISPR3 EICR FCSR I2CCR I2CSR1 I2CSR2 I2CCCR I2COAR1 I2COAR2 I2CDR Block Register Label PADR PADDR PAOR PBDR PBDDR PBOR PCDR PCDDR PCOR PDADR PDDDR PDOR PEDR PEDDR PEOR PFDR PFDDR PFOR Register Name Port Data Register Port Data Direction Register Port Option Register Port Data Register Port Data Direction Register Port Option Register Port Data Register Port Data Direction Register Port Option Register Port Data Register Port Data Direction Register Port Option Register Port Data Register Port Data Direction Register Port Option Register Port Data Register Port Data Direction Register Port Option Register Reset Status 00h1) 00h1) 00h1) 00h1) 00h1) 00h1) Remarks R/W2) R/W2)
Port
Port
Port
Port
Port
Port
Reserved Area Bytes)
Control Register Status Register Status Register Clock Control Register Address Register Address Register2 Data Register Reserved Area Bytes)
Read Only Read Only
Data Register Control Register Control/Status Register Interrupt Interrupt Interrupt Interrupt Software Priority Software Priority Software Priority Software Priority Register Register Register Register
External Interrupt Control Register Flash Control/Status Register
14/183
ST72321B
Address 002Ah 002Bh 002Ch 002Dh 002Eh 0030h 0031h 0032h 0033h 0034h 0035h 0036h 0037h 0038h 0039h 003Ah 003Bh 003Ch 003Dh 003Eh 003Fh 0040h 0041h 0042h 0043h 0044h 0045h 0046h 0047h 0048h 0049h 004Ah 004Bh 004Ch 004Dh 004Eh 004Fh 0050h 0051h 0052h 0053h 0054h 0055h 0056h 0057h
Block WATCHDOG
Register Label WDGCR SICSR
Register Name Watchdog Control Register System Integrity Control/Status Register Main Clock Control Status Register Main Clock Controller: Beep Control Register
Reset Status
Remarks
000x 000x
MCCSR MCCBCR
Reserved Area Bytes)
TIMER
TACR2 TACR1 TACSR TAIC1HR TAIC1LR TAOC1HR TAOC1LR TACHR TACLR TAACHR TAACLR TAIC2HR TAIC2LR TAOC2HR TAOC2LR
Timer Control Register Timer Control Register Timer Control/Status Register Timer Input Capture High Register Timer Input Capture Register Timer Output Compare High Register Timer Output Compare Register Timer Counter High Register Timer Counter Register Timer Alternate Counter High Register Timer Alternate Counter Register Timer Input Capture High Register Timer Input Capture Register Timer Output Compare High Register Timer Output Compare Register Reserved Area Byte)
xxxx x0xxb
Read Only Read Only Read Only Read Only Read Only Read Only Read Only Read Only
TIMER
TBCR2 TBCR1 TBCSR TBIC1HR TBIC1LR TBOC1HR TBOC1LR TBCHR TBCLR TBACHR TBACLR TBIC2HR TBIC2LR TBOC2HR TBOC2LR SCISR SCIDR SCIBRR SCICR1 SCICR2 SCIERPR SCIETPR
Timer Control Register Timer Control Register Timer Control/Status Register Timer Input Capture High Register Timer Input Capture Register Timer Output Compare High Register Timer Output Compare Register Timer Counter High Register Timer Counter Register Timer Alternate Counter High Register Timer Alternate Counter Register Timer Input Capture High Register Timer Input Capture Register Timer Output Compare High Register Timer Output Compare Register Status Register Data Register Baud Rate Register Control Register Control Register Extended Receive Prescaler Register Reserved area Extended Transmit Prescaler Register
xxxx x0xxb x000 0000h -00h
Read Only Read Only Read Only Read Only Read Only Read Only Read Only Read Only Read Only
15/183
ST72321B
Address 0058h 006Fh 0070h 0071h 0072h 0073h 0074h 0075h 0076h 0077h 0078h 0079h 007Ah 007Bh 007Ch 007Dh 007Eh 007Fh
Block
Register Label
Register Name
Reset Statu
Remark
Reserved Area Bytes)
ADCCSR ADCDRH ADCDRL PWMDCR3 PWMDCR2 PWMDCR1 PWMDCR0 PWMCR ARTCSR ARTCAR ARTARR ARTICCSR ARTICR1 ARTICR2
Control/Status Register Data High Register Data Register Timer Duty Cycle Register Timer Duty Cycle Register Timer Duty Cycle Register Timer Duty Cycle Register Timer Control Register Auto-Reload Timer Control/Status Register Auto-Reload Timer Counter Access Register Auto-Reload Timer Auto-Reload Register Timer Input Capture Control/Status Reg. Timer Input Capture Register Timer Input Capture Register Reserved Area Bytes)
Read Only Read Only Read Only Read Only
Legend: x=undefined, R/W=read/write Notes: contents port registers readable only output configuration. input configuration, values pins returned instead register contents. bits associated with unavailable pins must always keep their reset value.
16/183
ST72321B
FLASH PROGRAM MEMORY
Introduction dual voltage High Density Flash (HDFlash) non-volatile memory that electrically erased single block individual sectors programmed Byte-by-Byte basis using external supply. HDFlash devices programmed erased off-board (plugged programming tool) on-board using (In-Circuit Programming) (In-Application Programming). array matrix organisation allows each sector erased reprogrammed without affecting other sectors. Main Feature
Depending overall Flash memory size microcontroller device, there three user sectors (see Table Each these sectors erased independently avoid unnecessary erasing whole Flash memory when only partial erasing required. first sectors have fixed size Kbytes (see Figure They mapped upper part addressing space reset interrupt vectors located Sector (F000hFFFFh). Table Sectors available Flash deviceFlash Size (bytes) Available Sectors Sector Sectors Sectors 0,1,
Three Flash programming modes: Insertion programming tool. this mode, sectors including option bytes programmed erased. (In-Circuit Programming). this mode, sectors including option bytes programmed erased without removing device from application board. (In-Application Programming) this mode, sectors except Sector programmed erased without removing device from application board while application running. (In-Circuit Testing) downloading executing user application test patterns Read-out protection against piracy Register Access Security System (RASS) prevent accidental programming erasing
4.3.1 Read-out Protection Read-out protection, when selected, makes impossible extract memory content from microcontroller, thus preventing piracy. Even cannot access user code. flash devices, this protection removed reprogramming option. this case, entire program memory first automatically erased. Read-out protection selection depends device type: Flash devices enabled removed through FMP_R option byte. devices enabled mask option specified Option List.
Structure Flash memory organised sectors used both code data storage. Figure Memory Sector Addres4K
1000h 3FFFh 7FFFh 9FFFh BFFFh D7FFh DFFFh EFFFh FFFFh
FLASH MEMORY SIZE
SECTOR Kbytes Kbytes Kbytes Kbytes Kbytes Kbytes Kbytes Kbytes SECTOR SECTOR
17/183
ST72321B
FLASH PROGRAM MEMORY (Cont'd) Interface needs minimum pins connected programming tool (see Figure These pins are: RESET: device reset VSS: device power supply ground Figure Typical Interface
PROGRAMMING TOOL CONNECTOR Cable APPLICATION BOARD OPTIONAL (See Note OPTIONAL (See Note CONNECTOR HE10 CONNECTOR TYPE APPLICATION RESET SOURCE Note APPLICATION POWER SUPPLY Note APPLICATION
ICCCLK: output serial clock ICCDATA: input/output serial data ICCSEL/VPP: programming voltage OSC1(or OSCIN): main clock input external source (optional) VDD: application board power supply (optional, Figure Note
RESET
Notes: ICCCLK ICCDATA pins only used outputs application, signal isolation necessary. soon Programming Tool plugged board, even session progress, ICCCLK ICCDATA pins available application. they used inputs application, isolation such serial resistor implemented case another device forces signal. Refer Programming Tool documentation recommended resistor values. During session, programming tool must control RESET pin. This lead conflicts between programming tool application reset circuit drives more than high level (push pull output pull-up resistor<1K). schottky diode used isolate application RESET circuit this case. When using classical network with R>1K reset management with open drain output pull-up
sistor>1K, additional components needed. cases user must ensure that external reset generated application during session. connector depends Programming Tool architecture. This must connected when using most Programming Tools used monitor application power supply). Please refer Programming Tool manual. connected OSC1 OSCIN when clock available application selected clock option programmed option byte. devices with multi-oscillator capability need have OSC2 grounded this case.
18/183
ICCSEL/VPP
ICCDATA
ICCCLK
OSC2
OSC1
ST72321B
FLASH PROGRAM MEMORY (Cont'd) (In-Circuit Programming) perform microcontroller must switched (In-Circuit Communication) mode external controller programming tool. Depending code downloaded RAM, Flash memory programming fully customized (number bytes program, program locations, selection serial communication interface downloading). When using STMicroelectronics third-party programming tool that supports specific microcontroller device, user needs only implement hardware interface application board (see Figure more details locations, refer device pinout description. (In-Application Programming) This mode uses BootLoader program previously stored Sector user mode plugging device programming tool). This mode fully controlled user software. This allows adapted user application, (user-defined strategy entering programming mode, choice communications protocol used fetch data stored, etc.). example, possible download code from SPI, SCI, interface program Flash. mode used program Flash sectors except Sector which write/erase protected allow recovery case errors occur during programming operation. Related Documentation details Flash programming protocol, refer Flash Programming Reference Manual Protocol Reference Manual. 4.7.1 Register Description FLASH CONTROL/STATUS REGISTER (FCSR) Read /Write Reset Value: 0000 0000 (00h)
This register reserved Programming Tool software. controls Flash programming erasing operations.
Table Flash Control/Status Register Address Reset Value
Address (Hex.) 0029h Register Label FCSR Reset Value
19/183
ST72321B
CENTRAL PROCESSING UNIT
INTRODUCTION This full 8-bit architecture contains internal registers allowing efficient 8-bit data manipulation. MAIN FEATURES
REGISTERS registers shown Figure present memory mapping accessed specific instructions. Accumulator Accumulator 8-bit general purpose register used hold operands results arithmetic logic calculations manipulate data. Index Registers These 8-bit registers used create effective addresses temporary storage areas data manipulation. (The Cross-Assembler generates precede instruction (PRE) indicate that following instruction refers register.) register affected interrupt automatic procedures. Program Counter (PC) program counter 16-bit register containing address next instruction executed CPU. made 8-bit registers (Program Counter which LSB) (Program Counter High which MSB).
Enable executing basic instructions Fast 8-bit 8-bit multiply main addressing modes (with indirect addressing mode) 8-bit index registers 16-bit stack pointer power HALT WAIT modes Priority maskable hardware interrupts Non-maskable software/hardware interrupt
Figure Register7 RESET VALUE RESET VALUE RESET VALUE PROGRAM COUNTER RESET VALUE RESET VECTOR FFFEh-FFFFh CONDITION CODE REGISTER RESET VALUE STACK POINTER RESET VALUE STACK HIGHER ADDRESS Undefined Value INDEX REGISTER INDEX REGISTER ACCUMULATOR
20/183
ST72321B
CENTRAL PROCESSING UNIT (Cont'd) Condition Code Register (CC) Read/Write Reset Value: 111x1xxx
Zero. This cleared hardware. This indicates that result last arithmetic, logical data manipulation zero. result last operation different from zero. result last operation zero. This accessed JREQ JRNE test instructions. Carry/borrow. This cleared hardware software. indicates overflow underflow occurred during last arithmetic operation. overflow underflow occurred. overflow underflow occurred. This driven instructions tested JRNC instructions. also affected "bit test branch", shift rotate instructions. Interrupt Management Bits Interrupt combination bits gives current interrupt software priority.
Interrupt Software Priority Level (main) Level Level Level interrupt disable)
8-bit Condition Code register contains interrupt masks four flags representative result instruction just executed. This register also handled PUSH instructions. These bits individually tested and/or controlled specific instructions. Arithmetic Management Bits Half carry. This hardware when carry occurs between bits during instructions. reset hardware during same instructions. half carry occurred. half carry occurred. This tested using JRNH instruction. useful arithmetic subroutines. Negative This cleared hardware. representative result sign last arithmetic, logical data manipulation. It's copy result bit. result last operation positive null. result last operation negative (i.e. most significant logic This accessed JRMI JRPL instructions.
These bits set/cleared hardware when entering interrupt. loaded value given corresponding bits interrupt software priority registers (IxSPR). They also set/ cleared software with RIM, SIM, IRET, HALT, PUSH/POP instructions. interrupt management chapter more details.
21/183
ST72321B
CENTRAL PROCESSING UNIT (Cont'd) Stack Pointer (SP) Read/Write Reset Value:
Stack Pointer 16-bit register which always pointing next free location stack. then decremented after data been pushed onto stack incremented before data popped from stack (see Figure Since stack bytes deep, most significant bits forced hardware. Following Reset, after Reset Stack Pointer instruction (RSP), Stack Pointer contains reset value (the bits set) which stack higher address. Figure Stack Manipulation Example
CALL Subroutine 0100h Interrupt Event PUSH
least significant byte Stack Pointer (called directly accessed instruction. Note: When lower limit exceeded, Stack Pointer wraps around stack upper limit, without indicating stack overflow. previously stored information then overwritten therefore lost. stack also wraps case underflow. stack used save return address during subroutine call context during interrupt. user also directly manipulate stack means PUSH instructions. case interrupt, stored first location pointed Then other registers stored next locations shown Figure When interrupt received, decremented context pushed stack. return from interrupt, incremented context popped from stack. subroutine call occupies locations interrupt five locations stack area.
IRET
01FFh
Stack Higher Address 01FFh Stack Lower Address 0100h
22/183
ST72321B
SUPPLY, RESET CLOCK MANAGEMENT
device includes range utility features securing application critical situations (for example case power brown-out), reducing number external components. overview shown Figure more details, refer dedicated parametric section. PHASE LOCKED LOOP clock frequency input range MHz, used multiply frequency obtain fOSC2 MHz. enabled option byte. disabled, then fOSC2 fOSC/2. Caution: recommended applications where timing accuracy required. Caution: must used with internal oscillator.
Main features Optional multiplying frequency (not used with internal oscillator order respect max. operating frequency) Reset Sequence Manager (RSM) Figure Block Diagram Multi-Oscillator Clock Management (MO) Crystal/Ceramic resonator oscillators Internal oscillator fOSC System Integrity Management (SI) fOSC2 Main supply voltage detection (LVD) Auxiliary Voltage detector (AVD) with interrupt OPTION capability monitoring main supply Clock Security System (CSS) with Clock Filter Backup Safe Oscillator (enabled option byte) Figure Clock, Reset Supply Block Diagram
SYSTEM INTEGRITY MANAGEMENT CLOCK SECURITY SYSTEM (CSS) OSC2 OSC1 MULTIOSCILLATOR (MO) fOSC (option) fOSC2 CLOCK FILTER SAFE fOSC2
MAIN CLOCK fCPU CONTROLLER WITH REALTIME CLOCK (MCC/RTC)
RESET SEQUENCE RESET MANAGER (RSM)
Interrupt Request SICSR
WATCHDOG TIMER (WDG)
Interrupt Request VOLTAGE DETECTOR (LVD)
AUXILIARY VOLTAGE DETECTOR (AVD)
23/183
ST72321B
MULTI-OSCILLATOR (MO) main clock generated three different source types coming from multioscillator block: external source crystal ceramic resonator oscillators internal high frequency oscillator Each oscillator optimized given frequency range terms consumption selectable through option byte. associated hardware configurations shown Table Refer electrical characteristics section more details. Caution: OSC1 and/or OSC2 pins must left unconnected. purposes Failure Mode Effect Analysis, should noted that OSC1 and/or OSC2 pins left unconnected, main oscillator start and, this configuration, could generate fOSC clock frequency excess allowed maximum (>16MHz.), putting unsafe/undefined state. product behaviour must therefore considered undefined when pins left unconnected. External Clock Source this external clock mode, clock signal (square, sinus triangle) with ~50% duty cycle drive OSC1 while OSC2 tied ground. Crystal/Ceramic Oscillators This family oscillators advantage producing very accurate rate main clock ST7. selection within list oscillators with different frequency ranges done option byte order reduce consumption (refer Section 14.1 page more details frequency ranges). this mode multioscillator, resonator load capacitors have placed close possible oscillator pins order minimize output distortion start-up stabilization time. loading capacitance values must adjusted according selected oscillator. These oscillators stopped during RESET phase avoid losing time oscillator start-up phase. Internal Oscillator This oscillator allows cost solution main clock using only internal resistor capacitor. Internal oscillator mode drawback lower frequency accuracy should used applications that require accurate timing. this mode, oscillator pins have tied ground. order exceed max. operating frequency, internal oscillator must used with PLL. Table Clock SourceHardware Configuration
External Clock
OSC1 OSC2
EXTERNAL SOURCE
Crystal/Ceramic Resonator
OSC1 OSC2
LOAD CAPACITORS
Internal Oscillator
OSC1 OSC2
24/183
ST72321B
RESET SEQUENCE MANAGER (RSM) 6.3.1 Introduction reset sequence manager includes three RESET sources shown Figure External RESET source pulse Internal RESET (Low Voltage Detection) Internal WATCHDOG RESET These sources RESET always kept during delay phase. RESET service routine vector fixed addresses FFFEh-FFFFh memory map. basic RESET sequence consists phases shown Figure Active Phase depending RESET source 4096 clock cycle delay (selected option byte) RESET vector fetch 4096 clock cycle delay allows oscillator stabilise ensures that recovery taken place from Reset state. shorter longer clock cycle delay should selected option byte correspond stabilization time external oscillator used application. Figure Reset Block Diagram RESET vector fetch phase duration clock cycles. Figure RESET Sequence Phase
RESET
Active Phase INTERNAL RESET 4096 CLOCK CYCLES FETCH VECTOR
6.3.2 Asynchronous External RESET RESET both input open-drain output with integrated weak pull-up resistor. This pull-up fixed value varies accordance with input voltage. pulled external circuitry reset device. Electrical Characteristic section more details. RESET signal originating from external source must have duration least th(RSTL)in order recognized (see Figure 13). This detection asynchronous therefore enter reset state even HALT mode.
RESET
Filter INTERNAL RESET
PULSE GENERATOR
WATCHDOG RESET RESET
25/183
ST72321B
RESET SEQUENCE MANAGER (Cont'd) RESET asynchronous signal which plays major role performance. noisy environment, recommended follow guidelines mentioned electrical characteristics section. 6.3.3 External Power-On RESET disabled option byte, start microcontroller correctly, user must ensure means external reset circuit that reset signal held until over minimum level specified selected fOSC frequency. proper reset signal slow rising supply generally provided external network connected RESET pin. 6.3.4 Internal Voltage Detector (LVD) RESET different RESET sequences caused internal circuitry distinguished: Power-On RESET Voltage Drop RESET device RESET acts output that pulled when VDD<VIT+ (rising edge) VDD<VIT- (falling edge) shown Figure filters spikes larger than tg(VDD) avoid parasitic resets. 6.3.5 Internal Watchdog RESET RESET sequence generated internal Watchdog counter overflow shown Figure Starting from Watchdog counter underflow, device RESET acts output that pulled during least tw(RSTL)out.
Figure RESET Sequences
VIT+(LVD) VIT-(LVD)
RESET
EXTERNAL RESET
WATCHDOG RESET
ACTIVE PHASE
ACTIVE PHASE
ACTIVE PHASE
th(RSTL)in
EXTERNAL RESET SOURCE
tw(RSTL)out
RESET
WATCHDOG RESET WATCHDOG UNDERFLOW INTERNAL RESET (256 4096 TCPU) VECTOR FETCH
26/183
ST72321B
SYSTEM INTEGRITY MANAGEMENT (SI) System Integrity Management block contains Voltage Detector (LVD), Auxiliary Voltage Detector (AVD) functions Clock Security System (CSS). managed SICSR register. 6.4.1 Voltage Detector (LVD) Voltage Detector function (LVD) generates static reset when supply voltage below VIT- reference value. This means that secures power-up well power-down keeping reset. VIT- reference value voltage drop lower than VIT+ reference value power-on order avoid parasitic reset when starts running sinks current supply (hysteresis). Reset circuitry generates reset when below: VIT+ when rising VIT- when falling function illustrated Figure voltage threshold configured option byte low, medium high. Provided minimum value (guaranteed oscillator frequency) above VIT-, only modes: under full software control static safe reset these conditions, secure operation always ensured application without need external reset hardware. During Voltage Detector Reset, RESET held low, thus permitting reset other devices. Notes: allows device used without external RESET circuitry. medium thresholds selected, detection occur outside specified operating voltage range. Below 3.8V, device operation guaranteed. optional function which selected option byte.
Figure Voltage Detector Reset
Vhys VIT+ VIT-
RESET
27/183
ST72321B
SYSTEM INTEGRITY MANAGEMENT (Cont'd) 6.4.2 Auxiliary Voltage Detector (AVD) Voltage Detector function (AVD) based analog comparison between VIT-(AVD) VIT+(AVD) reference value main supply external voltage level (VEVD). VIT- reference value falling voltage lower than VIT+ reference value rising voltage order avoid parasitic detection (hysteresis). output comparator directly readable application software through real time status (AVDF) SICSR register. This read only. Caution: function active only enabled through option byte (see Section 14.1 page 172). 6.4.2.1 Monitoring Main Supply This mode selected clearing AVDS SICSR register. voltage threshold value relative selected threshold configured option byte (see interrupt enabled, interrupt generated when voltage crosses VIT+(AVD) VIT-(AVD) threshold (AVDF toggles). case drop voltage, interrupt acts early warning, allowing software shut down safely before resets microcontroller. Figure interrupt rising edge used inform application that warning state over. voltage rise time less than 4096 cycles (depending reset delay selected option byte), interrupt will generated when VIT+(AVD) reached. greater than 4096 cycles then: interrupt enabled before VIT+(AVD) threshold reached, then interrupts will received: first when AVDIE set, second when threshold reached. interrupt enabled after VIT+(AVD) threshold reached then only interrupt will occur.
Figure Using Monitor (AVDS bit=0) Early Warning Interrupt (Power dropped, reset)
Vhyst
VIT+(AVD) VIT-(AVD) VIT+(LVD) VIT-(LVD)
VOLTAGE RISE TIME
AVDF INTERRUPT REQUEST AVDIE
RESET VALUE
INTERRUPT PROCESS
INTERRUPT PROCESS
RESET
28/183
ST72321B
SYSTEM INTEGRITY MANAGEMENT (Cont'd) 6.4.2.2 Monitoring Voltage This mode selected setting AVDS SICSR register. circuitry generate interrupt when AVDIE SICSR register set. This interrupt generated rising falling edges comparator output. This means generated when either these events occur: VEVD rises VIT+(EVD) VEVD falls down VIT-(EVD) function illustrated Figure more details, refer Electrical Characteristics section.
Figure Using Voltage Detector Monitor (AVDS bit=1) VEVD
VIT+(EVD) VIT-(EVD)
Vhyst
AVDF INTERRUPT REQUEST AVDIE
INTERRUPT PROCESS
INTERRUPT PROCESS
29/183
ST72321B
SYSTEM INTEGRITY MANAGEMENT (Cont'd) 6.4.3 Clock Security System (CSS) Clock Security System (CSS) protects against breakdowns, spikes overfrequencies occurring main clock source (fOSC). based clock filter clock detection control with internal safe oscillator (fSFOSC). Caution: function guaranteed current silicon revision. "KNOWN LIMITATIONS" page 181. 6.4.3.1 Clock Filter Control integrated glitch filtering capability making possible protect internal clock from overfrequencies created individual spikes. This feature available only when enabled. glitches occur fOSC (for example, loose connection noise), filters these automatically, internal frequency (fCPU) continues deliver glitch-free signal (see Figure 17). 6.4.3.2 Clock detection Control clock signal disappears (due broken disconnected resonator.), safe oscillator delivers frequency clock signal (fSFOSC) which allows perform some rescue operations. Automatically, clock source switches back from safe oscillator (fSFOSC) main clock source (fOSC) recovers. When internal clock (fCPU) driven safe oscillator (fSFOSC), application software notified hardware setting CSSD SICFigure Clock Filter Function
Clock Filter Function
fOSC2 fCPU
register. interrupt generated CSSIE been previously set. These bits described SICSR register description. 6.4.4 Power ModeMode WAIT Description effect interrupts cause device exit from Wait mode. CRSR register frozen. (including safe oscillator) disabled until HALT mode exited. previous configuration resumes when woken interrupt with "exit from HALT mode" capability from counter reset value when woken RESET.
HALT
6.4.4.1 Interrupts interrupt events generate interrupt corresponding Enable Control (CSSIE AVDIE) interrupt mask register reset (RIM instruction).
Interrupt Event Enable Event Control Flag CSSIE AVDIE Exit from Wait Exit from Halt
event detection (safe oscillator acti- CSSD vated main clock) event AVDF
Clock Detection Function
fOSC2 fSFOSC fCPU
30/183
ST72321B
SYSTEM INTEGRITY MANAGEMENT (Cont'd) 6.4.5 Register Description SYSTEM INTEGRITY (SI) CONTROL/STATUS REGISTER (SICSR) Read /Write detected Clock Security System (CSSD set). cleared software. Reset Value: 000x 000x (00h) Clock security system interrupt disabled Clock security system interrupt enabled When disabled OPTION BYTE, CSSIE effect.
AVDS Voltage Detection selection This cleared software. Voltage Detection available only enabled option byte. Voltage detection supply Voltage detection AVDIE Voltage Detector interrupt enable This cleared software. enables interrupt generated when AVDF flag changes (toggles). pending interrupt information automatically cleared when software enters interrupt routine. interrupt disabled interrupt enabled AVDF Voltage Detector flag This read-only cleared hardware. AVDIE set, interrupt request generated when AVDF changes value. Refer Figure Section 6.4.2.1 additional details. VEVD over VIT+(AVD) threshold VEVD under VIT-(AVD) threshold LVDRF reset flag This indicates that last Reset generated block. hardware (LVD reset) cleared software (writing zero). WDGRF flag description more details. When disabled OPTION BYTE, LVDRF value undefined. Bits Reserved, must kept cleared. CSSIE Clock security syst interrupt enable This enables interrupt when disturbance
CSSD Clock security system detection This indicates that safe oscillator Clock Security System block been selected hardware disturbance main clock signal (fOSC). hardware cleared reading SICSR register when original oscillator recovers. Safe oscillator active Safe oscillator been activated When disabled OPTION BYTE, CSSD value forced WDGRF Watchdog reset flag This indicates that last Reset generated Watchdog peripheral. hardware (watchdog reset) cleared software (writing zero) Reset ensure stable cleared state WDGRF flag when starts). Combined with LVDRF flag information, flag description given following table.
RESET Sources External RESET Watchdog LVDRF WDGRF
Application notes LVDRF flag cleared when another RESET type occurs (external watchdog), LVDRF flag remains keep trace original failure. this case, watchdog reset detected software while external reset not. CAUTION: When activated with associated option byte, WDGRF flag used application.
31/183
ST72321B
INTERRUPTS
INTRODUCTION enhanced interrupt management provides following features: Hardware interrupts Software interrupt (TRAP) Nested concurrent interrupt management with flexible interrupt priority level management: software programmable nesting levels interrupt vectors fixed hardware maskable events: RESET, TRAP maskable Level event: This interrupt management based register (I1:0), Interrupt software priority registers (ISPRx), Fixed interrupt vector addresses located high addresses memory (FFE0h FFFFh) sorted hardware priority order. This enhanced interrupt controller guarantees full upward compatibility with standard (not nested) interrupt controller. MASKING PROCESSING FLOW interrupt masking managed bits register ISPRx registers which give interrupt software priority level Figure Interrupt Processing Flowchart
RESET PENDING INTERRUPT TRAP Interrupt same lower software priority than current I1:0 Interrupt higher software priority than current
each interrupt vector (see Table processing flow shown Figure When interrupt request serviced: Normal processing suspended current instruction execution. registers saved onto stack. bits register according corresponding values ISPRx registers serviced interrupt vector. then loaded with interrupt vector interrupt service first instruction interrupt service routine fetched (refer "Interrupt Mapping" table vector addresses). interrupt service routine should with IRET instruction which causes contents saved registers recovered from stack. Note: consequence IRET instruction, bits will restored from stack program previous level will resume. Table Interrupt Software Priority LevelInterrupt software priority Level (main) Level Level Level interrupt disable) Level
High
FETCH NEXT INSTRUCTION
INTERRUPT STAYS PENDING
"IRET"
RESTORE FROM STACK
EXECUTE INSTRUCTION
STACK LOAD I1:0 FROM INTERRUPT REG. LOAD FROM INTERRUPT VECTOR
32/183
ST72321B
INTERRUPTS (Cont'd) Servicing Pending Interrupts several interrupts pending same time, interrupt taken into account determined following two-step process: highest software priority interrupt serviced, several interrupts have same software priority then interrupt with highest hardware priority serviced first. Figure describes this decision process. Figure Priority Decision ProcesPENDING INTERRUPTS
TRAP (Non Maskable Software Interrupt) This software interrupt serviced when TRAP instruction executed. will serviced according flowchart Figure Caution: TRAP interrupted TLI. RESET RESET source highest priority ST7. This means that first current routine highest software priority (level highest hardware priority. RESET chapter more details.
Same
SOFTWARE PRIORITY
Different
HIGHEST SOFTWARE PRIORITY SERVICED HIGHEST HARDWARE PRIORITY SERVICED
When interrupt request serviced immediately, latched then processed when software priority combined with hardware priority becomes highest one. Note hardware priority exclusive while software not. This allows previous process succeed with only interrupt. Note TLI, RESET TRAP considered having highest software priority decision process. Different Interrupt Vector Sources interrupt source types managed interrupt controller: non-maskable type (RESET, TRAP) maskable type (external from internal peripherals). Non-Maskable Sources These sources processed regardless state bits register (see Figure 18). After stacking registers (except RESET), corresponding vector loaded register bits disable interrupts (level These sources allow processor exit HALT mode.
Maskable Sources Maskable interrupt vector sources serviced corresponding interrupt enabled interrupt software priority ISPRx registers) higher than currently being serviced register). these conditions false, interrupt latched thus remains pending. (Top Level Hardware Interrupt) This hardware interrupt occurs when specific edge detected dedicated pin. will serviced according flowchart Figure trap. Caution: TRAP instruction must used service routine. External Interrupts External interrupts allow processor exit from HALT power mode. External interrupt sensitivity software selectable through External Interrupt Control register (EICR). External interrupt triggered edge will latched interrupt request automatically cleared upon entering interrupt service routine. several input pins group connected same interrupt line selected simultaneously, these will logically ORed. Peripheral Interrupts Usually peripheral interrupts cause exit from HALT mode except those mentioned "Interrupt Mapping" table. peripheral interrupt occurs when specific flag peripheral status registers corresponding enable peripheral control register. general sequence clearing interrupt based access status register followed read write associated register. Note: clearing sequence resets internal latch. pending interrupt (i.e. waiting being serviced) will therefore lost clear sequence executed.
33/183
ST72321B
INTERRUPTS (Cont'd) INTERRUPTS POWER MODES interrupts allow processor exit WAIT power mode. contrary, only external other specified interrupts allow processor exit from HALT modes (see column "Exit from HALT" "Interrupt Mapping" table). When several pending interrupts present while exiting HALT mode, first serviced only interrupt with exit from HALT mode capability selected through same decision process shown Figure Note: interrupt, that able Exit from HALT mode, pending with highest priority when exiting HALT mode, this interrupt serviced after first serviced. Figure Concurrent Interrupt Management
TRAP SOFTWARE PRIORITY LEVEL
CONCURRENT NESTED MANAGEMENT following Figure Figure show different interrupt management modes. first called concurrent mode does allow interrupt interrupted, unlike nested mode Figure interrupt hardware priority given this order from lowest highest: MAIN, IT4, IT3, IT2, IT1, IT0, TLI. software priority given each interrupt. Warning: stack overflow occur without notifying software failure.
HARDWARE PRIORITY
TRAP MAIN MAIN
Figure Nested Interrupt Management
TRAP
SOFTWARE PRIORITY LEVEL
HARDWARE PRIORITY
TRAP MAIN MAIN
34/183
USED STACK BYTES
USED STACK BYTES
ST72321B
INTERRUPTS (Cont'd) INTERRUPT REGISTER DESCRIPTION REGISTER INTERRUPT BITS Read /Write Reset Value: 111x 1010 (xAh)
ISPR1 I1_7 I0_7 I1_6 I0_6 I1_5 I0_5 I0_9 I1_4 I1_8 I0_4 I0_8
INTERRUPT SOFTWARE PRIORITY REGISTERS (ISPRX) Read/Write (bit ISPR3 read only) Reset Value: 1111 1111 (FFh)
ISPR0 I1_3 I0_3 I1_2 I0_2 I1_1 I0_1 I1_0 I0_0
Software Interrupt Priority These bits indicate current interrupt software priority.
Interrupt Software Priority Level (main) Level Level Level interrupt disable*) Level
ISPR2 ISPR3
I1_11 I0_11 I1_10 I0_10 I1_9
I1_13 I0_13 I1_12 I0_12
High
These bits set/cleared hardware when entering interrupt. loaded value given corresponding bits interrupt software priority registers (ISPRx). They also set/cleared software with RIM, SIM, HALT, WFI, IRET PUSH/POP instructions (see "Interrupt Dedicated Instruction Set" table). *Note: TLI, TRAP RESET events interrupt level program.
These four registers contain interrupt software priority each interrupt vector. Each interrupt vector (except RESET TRAP) corresponding bits these registers where software priority stored. This correspondance shown following table.
Vector address FFFBh-FFFAh FFF9h-FFF8h FFE1h-FFE0h ISPRx bits I1_0 I0_0 bits* I1_1 I0_1 bits I1_13 I0_13
Each I1_x I0_x value ISPRx registers same meaning bits register. Level written (I1_x=1, I0_x=0). this case, previously stored value kept. (example: previous=CFh, write=64h, result=44h) TLI, RESET, TRAP vectors have software priorities. When serviced, bits register both set. *Note: Bits ISPRx registers which correspond read written they significant interrupt process management. Caution: I1_x I0_x bits modified while interrupt executed following behaviour considered: interrupt still pending (new interrupt flag cleared) software priority higher than previous one, interrupt re-entered. Otherwise, software priority stays unchanged next interrupt request (after IRET interrupt
35/183
ST72321B
INTERRUPTS (Cont'd)
Table Dedicated Interrupt Instruction
Instruction HALT IRET JRNM TRAP Description Entering Halt mode Interrupt routine return Jump I1:0=11 (level Jump I1:0<>11 from Stack Enable interrupt (level set) Disable interrupt (level set) Software trap Wait interrupt I1:0=11 I1:0<>11 Load I1:0 Load I1:0 Software Function/Example
Note: During execution interrupt routine, HALT, POPCC, RIM, instructions change current software priority next IRET instruction previously mentioned instructions.
36/183
ST72321B
INTERRUPTS (Cont'd) Table Interrupt Mapping
Source Block RESET TRAP TIMER TIMER MCC/RTC Reset Software interrupt External level interrupt Main clock controller time base interrupt Safe oscillator activation interrupt External interrupt port A3.0 External interrupt port F2.0 External interrupt port B3.0 External interrupt port B7.4 used peripheral interrupts TIMER peripheral interrupts TIMER peripheral interrupts Peripheral interrupts Auxiliary Voltage detector interrupt Peripheral interrupts overflow interrupt SPICSR TASR TBSR SCISR SICSR (see periph) ARTCSR Lower Priority Description Register Label EICR MCCSR SICSR Higher Priority Priority Order Exit from HALT1) Address Vector FFFEh-FFFFh FFFCh-FFFDh FFFAh-FFFBh FFF8h-FFF9h FFF6h-FFF7h FFF4h-FFF5h FFF2h-FFF3h FFF0h-FFF1h FFEEh-FFEFh FFECh-FFEDh FFEAh-FFEBh FFE8h-FFE9h FFE6h-FFE7h FFE4h-FFE5h FFE2h-FFE3h FFE0h-FFE1h
Notes: Valid HALT ACTIVE-HALT modes except MCC/RTC interrupt source which exits from ACTIVE-HALT mode only. EXTERNAL INTERRUPTS 7.6.1 Port Interrupt Sensitivity external interrupt sensitivity controlled IPA, ISxx bits EICR register (Figure 22). This control allows have fully independent external interrupt source sensitivities. Each external interrupt source generated four five) different events pin: Falling edge Rising edge Falling rising edge Falling edge level Rising edge high level (only ei2) guarantee correct functionality, sensitivity bits EICR register modified only when bits register both (level This means that interrupts must disabled before changing sensitivity. pending interrupts cleared writing different value ISx[1:0], bits EICR.
37/183
ST72321B
Figure External Interrupt Control bitPORT [3:0] INTERRUPTS PAOR.3 PADDR.3 CONTROL EICR IS20 IS21
SENSITIVITY
INTERRUPT SOURCE
PORT [2:0] INTERRUPTS PFOR.2 PFDDR.2
EICR IS20 IS21
SENSITIVITY CONTROL
INTERRUPT SOURCE
PORT [3:0] INTERRUPTS PBOR.3 PBDDR.3
EICR IS10 IS11
SENSITIVITY CONTROL
INTERRUPT SOURCE
PORT [7:4] INTERRUPTS PBOR.7 PBDDR.7
EICR IS10 IS11
SENSITIVITY CONTROL
INTERRUPT SOURCE
38/183
ST72321B
INTERRUPTS (Cont'd) EXTERNAL INTERRUPT CONTROL REGISTER (EICR) Read /Write Reset Value: 0000 0000 (00h)
IS11 IS10 IS21 IS20 TLIS TLIE
(port A3.0)
External Interrupt Sensitivity IS21 IS20 Falling edge level Rising edge only Falling edge only Rising edge high level Falling edge only Rising edge only
IS1[1:0] sensitivity interrupt sensitivity, defined using IS1[1:0] bits, applied following external interrupts: (port B3.0)
External Interrupt Sensitivity IS11 IS10 Falling edge level Rising edge only Falling edge only Rising edge high level Falling edge only Rising edge only
Rising falling edge
(port F2.0)
IS21 IS20 External Interrupt Sensitivity Falling edge level Rising edge only Falling edge only Rising falling edge
Rising falling edge
(port B7.4)
IS11 IS10 External Interrupt Sensitivity Falling edge level Rising edge only Falling edge only Rising falling edge
These bits written only when register both (level Interrupt polarity port This used invert sensitivity port [3:0] external interrupts. cleared software only when register both (level sensitivity inversion Sensitivity inversion TLIS sensitivity This allows toggle edge sensitivity. cleared software only when TLIE cleared. Falling edge Rising edge TLIE enable This allows enable disable capability dedicated pin. cleared software. disabled enabled Note: parasitic interrupt generated when
These bits written only when register both (level Interrupt polarity port This used invert sensitivity port [3:0] external interrupts. cleared software only when register both (level sensitivity inversion Sensitivity inversion IS2[1:0] sensitivity interrupt sensitivity, defined using IS2[1:0] bits, applied following external interrupts:
39/183
ST72321B
INTERRUPTS (Cont'd) Table Nested Interrupts Register Reset ValueAddress (Hex.) 0024h Register Label ISPR0 Reset Value ISPR1 Reset Value ISPR2 Reset Value ISPR3 Reset Value EICR Reset Value I1_3 0025h I1_7 0026h I1_11 I0_11 I1_10 I0_7 I1_6 I0_10 I0_6 I1_5 I0_3 I1_2 I0_2 I1_1 I0_5 I1_4 I0_1 I0_4
TIMER I1_9 I0_9 PWMART I1_13 IS20 I0_13
TIMER I1_8 I0_8 I1_12 TLIS I0_12 TLIE
0027h 0028h
IS11
IS10
IS21
40/183
ST72321B
POWER SAVING MODES
INTRODUCTION give large measure flexibility application terms power consumption, four main power saving modes implemented (see Figure 23): SLOW, WAIT (SLOW WAIT), ACTIVE HALT HALT. After RESET normal operating mode selected default (RUN mode). This mode drives device (CPU embedded peripherals) means master clock which based main oscillator frequency divided multiplied (fOSC2). From mode, different power saving modes selected setting relevant register bits calling specific software instruction whose action depends oscillator status. Figure Power Saving Mode Transitions Figure SLOW Mode Clock TransitionHigh
fOSC2/2 fOSC2/4 fOSC2
SLOW MODE This mode targets: reduce power consumption decreasing internal clock device, adapt internal clock frequency (fCPU) available supply voltage. SLOW mode controlled three bits MCCSR register: which enables disables Slow mode bits which select internal slow frequency (fCPU). this mode, master clock frequency (fOSC2) divided peripherals clocked this lower frequency (fCPU). Note: SLOW-WAIT mode activated when entering WAIT mode while device already SLOW mode.
SLOW MCCSR WAIT SLOW WAIT ACTIVE HALT HALT POWER CONSUMPTION
fCPU
fOSC2 CP1:0
SLOW FREQUENCY REQUEST
NORMAL MODE REQUEST
41/183
ST72321B
POWER SAVING MODES (Cont'd) WAIT MODE WAIT mode places power consumption mode stopping CPU. This power saving mode selected calling `WFI' instruction. peripherals remain active. During WAIT mode, I[1:0] bits register forced `10', enable interrupts. other registers memory remain unchanged. remains WAIT mode until interrupt RESET occurs, whereupon Program Counter branches starting address interrupt Reset service routine. will remain WAIT mode until Reset Interrupt occurs, causing wake Refer Figure Figure WAIT Mode Flow-chart
OSCILLATOR PERIPHERALS I[1:0] BITS
INSTRUCTION
RESET INTERRUPT OSCILLATOR PERIPHERALS I[1:0] BITS
4096 CLOCK CYCLE DELAY
OSCILLATOR PERIPHERALS I[1:0] BITS
FETCH RESET VECTOR SERVICE INTERRUPT
Note: Before servicing interrupt, register pushed stack. I[1:0] bits register current software priority level interrupt routine recovered when register popped.
42/183
ST72321B
POWER SAVING MODES (Cont'd) ACTIVE-HALT HALT MODES ACTIVE-HALT HALT modes lowest power consumption modes MCU. They both entered executing `HALT' instruction. decision enter either ACTIVE-HALT HALT mode given MCC/RTC interrupt enable flag (OIE MCCSR register).
MCCSR Power Saving Mode entered when HALT instruction executed HALT mode ACTIVE-HALT mode
pending option byte). Otherwise, enters HALT mode remaining tDELAY period. Figure ACTIVE-HALT Timing Overview
ACTIVE 4096 HALT CYCLE DELAY RESET INTERRUPT
HALT INSTRUCTION [MCCSR.OIE=1]
FETCH VECTOR
Figure ACTIVE-HALT Mode Flow-chart 8.4.1 ACTIVE-HALT MODE ACTIVE-HALT mode lowest power consumption mode with real time clock available. entered executing `HALT' instruction when Main Clock Controller Status register (MCCSR) (see Section 10.2 page more details MCCSR register). exit ACTIVE-HALT mode reception either MCC/RTC interrupt, specific interrupt (see Table "Interrupt Mapping," page RESET. When exiting ACTIVEHALT mode means interrupt, 4096 cycle delay occurs. resumes operation servicing interrupt fetching reset vector which woke (see Figure 27). When entering ACTIVE-HALT mode, I[1:0] bits register forced `10b' enable interrupts. Therefore, interrupt pending, wakes immediately. ACTIVE-HALT mode, only main oscillator associated counter (MCC/RTC) running keep wake-up time base. other peripherals clocked except those which their clock supply from another clock generator (such external auxiliary oscillator). safeguard against staying locked ACTIVEHALT mode provided oscillator interrupt. Note: soon interrupt capability oscillators selected (MCCSR.OIE set), entering ACTIVE-HALT mode while Watchdog active does generate RESET. This means that device cannot spend more than defined delay this power saving mode. CAUTION: When exiting ACTIVE-HALT mode following interrupt, MCCSR register must cleared before tDELAY after interrupt occurs (tDELAY 4096 tCPU delay deHALT INSTRUCTION (MCCSR.OIE=1) OSCILLATOR PERIPHERALS I[1:0] BITS
RESET
INTERRUPT
OSCILLATOR PERIPHERALS I[1:0] BITS
4096 CLOCK CYCLE DELAY OSCILLATOR PERIPHERALS I[1:0] BITS
FETCH RESET VECTOR SERVICE INTERRUPT
Notes: This delay occurs only exits ACTIVEHALT mode means RESET. Peripheral clocked with external clock source still active. Only MCC/RTC interrupt some specific interrupts exit from ACTIVE-HALT mode (such external interrupt). Refer Table "Interrupt Mapping," page more details. Before servicing interrupt, register pushed stack. I[1:0] bits register current software priority level interrupt routine restored when register popped.
43/183
ST72321B
POWER SAVING MODES (Cont'd) 8.4.2 HALT MODE HALT mode lowest power consumption mode MCU. entered executing `HALT' instruction when Main Clock Controller Status register (MCCSR) cleared (see Section 10.2 page more details MCCSR register). exit HALT mode reception either specific interrupt (see Table "Interrupt Mapping," page RESET. When exiting HALT mode means RESET interrupt, oscillator immediately turned 4096 cycle delay used stabilize oscillator. After start delay, resumes operation servicing interrupt fetching reset vector which woke (see Figure 29). When entering HALT mode, I[1:0] bits register forced `10b'to enable interrupts. Therefore, interrupt pending, wakes immediately. HALT mode, main oscillator turned causing internal processing stopped, including operation on-chip peripherals. peripherals clocked except ones which their clock supply from another clock generator (such external auxiliary oscillator). compatibility Watchdog operation with HALT mode configured "WDGHALT" option option byte. HALT instruction when executed while Watchdog system enabled, generate Watchdog RESET (see Section 14.1 page 172) more details. Figure HALT Timing Overview
HALT 4096 CYCLE DELAY RESET INTERRUPT FETCH VECTOR FETCH RESET VECTOR SERVICE INTERRUPT
Figure HALT Mode Flow-chart
HALT INSTRUCTION (MCCSR.OIE=0) ENABLE WDGHALT WATCHDOG RESET OSCILLATOR PERIPHERALS I[1:0] BITS WATCHDOG DISABLE
RESET INTERRUPT OSCILLATOR PERIPHERALS I[1:0] BITS
4096 CLOCK CYCLE DELAY OSCILLATOR PERIPHERALS I[1:0] BITS
HALT INSTRUCTION [MCCSR.OIE=0]
Notes: WDGHALT option bit. option byte section more details. Peripheral clocked with external clock source still active. Only some specific interrupts exit from HALT mode (such external interrupt). Refer Table "Interrupt Mapping," page more details. Before servicing interrupt, register pushed stack. I[1:0] bits register current software priority level interrupt routine recovered when register popped.
44/183
ST72321B
POWER SAVING MODES (Cont'd) 8.4.2.1 Halt Mode Recommendations Make sure that external event available wake microcontroller from Halt mode. When using external interrupt wake microcontroller, reinitialize corresponding "Input Pull-up with Interrupt" before executing HALT instruction. main reason this that wrongly configured external interference unforeseen logical condition. same reason, reinitialize level sensitiveness each external interrupt precautionary measure. opcode HALT instruction 0x8E. avoid unexpected HALT instruction program counter failure, advised clear occurrences data value 0x8E from memory. example, avoid defining constant with value 0x8E. HALT instruction clears interrupt mask register allow interrupts, user choose clear pending interrupt bits before executing HALT instruction. This avoids entering other peripheral interrupt routines after executing external interrupt routine corresponding wake-up event (reset external interrupt).
45/183
ST72321B
PORTS
INTRODUCTION ports offer different functional modes: transfer data through digital inputs outputs specific pins: external interrupt generation alternate signal input/output on-chip peripherals. port contains pins. Each programmed independently digital input (with without interrupt generation) digital output. FUNCTIONAL DESCRIPTION Each port main registers: Data Register (DR) Data Direction Register (DDR) optional register: Option Register (OR) Each programmed using corresponding register bits registers: corresponding port. same correspondence used register. following description takes into account register, (for specific ports which provide this register refer Port Implementation section). generic block diagram shown Figure 9.2.1 Input Modes input configuration selected clearing corresponding register bit. this case, reading register returns digital value applied external pin. Different input modes selected software through register. Notes: Writing register modifies latch value does affect status. When switching from input output mode, register written first drive correct level soon port configured output. read/modify/write instructions (BSET BRES) modify register External interrupt function When configured Input with Interrupt, event this generate external interrupt request CPU. Each independently generate interrupt request. interrupt sensitivity independently programmable using sensitivity bits EICR register. Each external interrupt vector linked dedicated group port pins (see pinout description interrupt section). several input pins selected simultaneously interrupt sources, these first detected according sensitivity bits EICR register then logically ORed. external interrupts hardware interrupts, which means that request latch (not accessible directly application) automatically cleared when corresponding interrupt vector fetched. clear unwanted pending interrupt software, sensitivity bits EICR register must modified. 9.2.2 Output Modes output configuration selected setting corresponding register bit. this case, writing register applies this digital value through latch. Then reading register returns previously stored value. different output modes selected software through register: Output push-pull open-drain. register value output status:
Push-pull Open-drain Floating
9.2.3 Alternate Functions When on-chip peripheral configured pin, alternate function automatically selected. This alternate function takes priority over standard programming. When signal coming from on-chip peripheral, automatically configured output mode (push-pull open drain according peripheral). When signal going on-chip peripheral, must configured input mode. this case, state also digitally readable addressing register. Note: Input pull-up configuration cause unexpected value input alternate peripheral input. When on-chip peripheral input output, this configured input floating mode.
46/183
ST72321B
PORTS (Cont'd) Figure Port General Block Diagram
REGISTER ACCESS ALTERNATE OUTPUT ALTERNATE ENABLE
P-BUFFER (see table below) PULL-UP (see table below)
PULL-UP CONDITION implemented N-BUFFER CMOS SCHMITT TRIGGER ANALOG INPUT DIODES (see table below)
EXTERNAL INTERRUPT SOURCE (eix)
Table Port Mode OptionConfiguration Mode Input Floating with/without Interrupt Pull-up with/without Interrupt Push-pull Open Drain (logic level) True Open Drain Pull-Up P-Buffer Diodes
Output
Legend: implemented implemented activated implemented activated
DATA
ALTERNATE INPUT
(see note)
Note: diode implemented true open drain pads. local protection between implemented protect device against positive stress.
47/183
ST72321B
PORTS (Cont'd) Table Port ConfigurationHardware Configuration
IMPLEMENTED TRUE OPEN DRAIN PORTS PULL-UP CONDITION REGISTER ACCESS
REGISTER
DATA
INPUT
ALTERNATE INPUT EXTERNAL INTERRUPT SOURCE INTERRUPT CONDITION ANALOG INPUT IMPLEMENTED TRUE OPEN DRAIN PORTS
OPEN-DRAIN OUTPUT
REGISTER ACCESS
REGISTER
DATA
ALTERNATE ENABLE
ALTERNATE OUTPUT
PUSH-PULL OUTPUT
IMPLEMENTED TRUE OPEN DRAIN PORTS
REGISTER ACCESS
REGISTER
DATA
ALTERNATE ENABLE
ALTERNATE OUTPUT
Notes: When port input configuration associated alternate function enabled output, reading register will read alternate function output status. When port output configuration associated alternate function enabled input, alternate function reads status given register content.
48/183
ST72321B
PORTS (Cont'd) CAUTION: alternate function must activated long configured input with interrupt, order avoid generating spurious interrupts. Analog alternate function When used input, must configured floating input. analog multiplexer (controlled registers) switches analog voltage present selected common analog rail which connected input. recommended change voltage level loading port while conversion progress. Furthermore recommended have clocking pins located close selected analog pin. WARNING: analog input voltage level must within limits stated absolute maximum ratings. PORT IMPLEMENTATION hardware implementation each port depends settings registers specific feature port such Input true open drain. Switching these ports from state another should done sequence that prevents unwanted side effects. Recommended safe transitions illustrated Figure Other transitions potentially risky should avoided, since they likely present unwanted side-effects such spurious interrupt generation.
Figure Interrupt Port State Transition01
INPUT floating/pull-up interrupt
INPUT floating (reset state)
OUTPUT open-drain
OUTPUT push-pull
DDR,
POWER MODES
Mode WAIT HALT Description effect ports. External interrupts cause device exit from WAIT mode. effect ports. External interrupts cause device exit from HALT mode.
INTERRUPTS external interrupt event generates interrupt corresponding configuration selected with registers interrupt mask register active (RIM instruction).
Interrupt Event External interrupt selected external event Enable Event Control Flag DDRx Exit from Wait Exit from Halt
49/183
ST72321B
PORTS (Cont'd) 9.5.1 Port Implementation port register configurations summarised follows. Standard Ports PA5:4, PC7:0, PD7:0, PE7:34, PE1:0, PF7:3,
MODE floating input pull-up input open drain output push-pull output
PA3, PB7, PB3, (without pull-up)
MODE floating input floating interrupt input open drain output push-pull output
True Open Drain Ports PA7:6
MODE floating input open drain (high sink ports)
Interrupt Ports PA2:0, PB6:5, PB4, PB2:0, PF1:0 (with pull-up)
MODE floating input pull-up interrupt input open drain output push-pull output
Pull-up Input Port
MODE pull-up input
Table Port Configuration
Port name
PA7:6 PA5:4 PA2:0 PB7, Port Port Port Port PB6:5, PB4, PB2:0 PC7:0 PD7:0 PE7:3, PE1:0 PF7:3 PF1:0
Input
floating floating floating floating floating floating floating floating floating floating floating floating pull-up floating interrupt pull-up interrupt floating interrupt pull-up interrupt pull-up pull-up pull-up
Output
true open-drain open drain push-pull open drain push-pull open drain open drain open drain open drain open drain open drain push-pull push-pull push-pull push-pull push-pull push-pull push-pull push-pull push-pull
Port
pull-up input only pull-up open drain floating interrupt pull-up interrupt open drain open drain
Port
50/183
ST72321B
PORTS (Cont'd) Table Port Register Reset ValueAddress (Hex.) Register Label
Reset Value port registers 0000h PADR 0001h PADDR 0002h PAOR 0003h PBDR 0004h PBDDR 0005h PBOR 0006h PCDR 0007h PCDDR 0008h PCOR 0009h PDDR 000Ah PDDDR 000Bh PDOR 000Ch PEDR 000Dh PEDDR 000Eh PEOR 000Fh PFDR 0010h PFDDR 0011h PFOR
51/183
ST72321B
ON-CHIP PERIPHERALS
10.1 WATCHDOG TIMER (WDG) 10.1.1 Introduction Watchdog timer used detect occurrence software fault, usually generated external interference unforeseen logical conditions, which causes application program abandon normal sequence. Watchdog circuit generates reset expiry programmed time period, unless program refreshes counter's contents before becomes cleared. 10.1.2 Main Features Programmable free-running downcounter Programmable reset Reset watchdog activated) when reaches zero Optional reset HALT instruction (configurable option byte) Hardware Watchdog selectable option byte 10.1.3 Functional Description counter value stored Watchdog Control register (WDGCR bits T[6:0]), decremented every 16384 fOSC2 cycles (approx.), length timeout period programmed user increments. watchdog activated (the WDGA set) when 7-bit timer (bits T[6:0]) rolls over from becomes cleared), initiates reset cycle pulling reset typically 500ns. application program must write WDGCR register regular intervals during normal operation prevent reset. This downcounter free-running: counts down even watchdog disabled. value stored WDGCR register must between C0h: WDGA (watchdog enabled) prevent generating immediate reset T[5:0] bits contain number increments which represents time delay before watchdog produces reset (see Figure Approximate Timeout Duration). timing varies between minimum maximum value unknown status prescaler when writing WDGCR register (see Figure 34). Following reset, watchdog disabled. Once activated cannot disabled, except reset. used generate software reset (the WDGA cleared). watchdog activated, HALT instruction will generate Reset.
Figure Watchdog Block Diagram
RESET
fOSC2 MCC/RTC
WATCHDOG CONTROL REGISTER (WDGCR) WDGA
6-BIT DOWNCOUNTER (CNT)
12-BIT COUNTER
TB[1:0] bits (MCCSR Register)
PRESCALER
52/183
ST72321B
WATCHDOG TIMER (Cont'd) 10.1.4 Program Watchdog Timeout Figure shows linear relationship between 6-bit value loaded Watchdog Counter (CNT) resulting timeout duration milliseconds. This used quick calculation without taking timing variations into account. Figure Approximate Timeout Duration
more precision needed, formulae Figure Caution: When writing WDGCR register, always write avoid generating immediate reset.
Value (hex.)
Watchdog timeout (ms) MHz. fOSC2
53/183
ST72321B
WATCHDOG TIMER (Cont'd) Figure Exact Timeout Duration (tmin tmax) WHERE: tmin0 (LSB 128) tOSC2 tmax0 16384 tOSC2 tOSC2 125ns fOSC2=8 Value T[5:0] bits WDGCR register bits) values from table below depending timebase selected TB[1:0] bits MCCSR register
(MCCSR Reg.) (MCCSR Reg.) Selected MCCSR Timebase 10ms 25ms
calculate minimum Watchdog Timeout (tmin):
calculate maximum Watchdog Timeout (tmax):
Note: above formulae, division results must rounded down next integer value. Example: With timeout selected MCCSR register
Value T[5:0] Bits WDGCR Register (Hex.) Min. Watchdog Timeout (ms) tmin 1.496 Max. Watchdog Timeout (ms) tmax 2.048 128.552
54/183
ELSE tmax0 16384
THEN
tmax0
16384 tosc2 4CNT -MSB 4CNT -MSB osc2
ELSE tmin0 16384
THEN
tmin0
16384 osc2 -MSB 4CNT -MSB osc2
ST72321B
WATCHDOG TIMER (Cont'd) 10.1.5 Power Modes Mode SLOW WAIT Description effect Watchdog. effect Watchdog.
MCCSR register WDGHALT Option Byte Watchdog reset generated. enters Halt mode. Watchdog counter decremented once then stops counting longer able generate watchdog reset until receives external interrupt reset. external interrupt received, Watchdog restarts counting after 4096 clocks. reset generated, Watchdog disabled (reset state) unless Hardware Watchdog selected option byte. application recommendations Section 10.1.7 below. reset generated. reset generated. enters Active Halt mode. Watchdog counter decremented. stop counting. When receives oscillator interrupt external interrupt, Watchdog restarts counting immediately. When receives reset Watchdog restarts counting after 4096 clocks.
HALT
10.1.6 Hardware Watchdog Option Hardware Watchdog selected option byte, watchdog always active WDGA WDGCR used. Refer Option Byte description. 10.1.7 Using Halt Mode with (WDGHALT option) following recommendation applies Halt mode used when watchdog enabled. Before executing HALT instruction, refresh counter, avoid unexpected reset immediately after waking microcontroller. 10.1.8 Interrupts None.
10.1.9 Register Description CONTROL REGISTER (WDGCR) Read /Write Reset Value: 0111 1111 (7Fh)
WDGA
WDGA Activation bit. This software only cleared hardware after reset. When WDGA watchdog generate reset. Watchdog disabled Watchdog enabled Note: This used hardware watchdog option enabled option byte. T[6:0] 7-bit counter (MSB LSB). These bits contain value watchdog counter. decremented every 16384 fOSC2 cycles (approx.). reset produced when rolls over from becomes cleared).
55/183
ST72321B
Table Watchdog Timer Register Reset ValueAddress (Hex.) 002Ah Register Label WDGCR Reset Value WDGA
56/183
ST72321B
10.2 MAIN CLOCK CONTROLLER WITH REAL TIME CLOCK BEEPER (MCC/RTC) Main Clock Controller consists three different functions: programmable clock prescaler clock-out signal supply external devices real time clock timer with interrupt capability Each function used independently simultaneously. 10.2.1 Programmable Clock Prescaler programmable clock prescaler supplies clock internal peripherals. manages SLOW power saving mode (See Section SLOW MODE more details). prescaler selects fCPU main clock frequency controlled three bits MCCSR register: CP[1:0] SMS. 10.2.2 Clock-out Capability clock-out capability alternate function port that outputs OSC2 clock drive external devices. controlled MCCSR register. CAUTION: When selected, clock suspends clock during ACTIVE-HALT mode. 10.2.3 Real Time Clock Timer (RTC) counter real time clock timer allows interrupt generated based accurate real time clock. Four different time bases depending directly fOSC2 available. whole functionality controlled four bits MCCSR register: TB[1:0], OIF. When interrupt enabled (OIE set), enters ACTIVE-HALT mode when HALT instruction executed. Section ACTIVE-HALT HALT MODES more details. 10.2.4 Beeper beep function controlled MCCBCR register. output three selectable frequencies BEEP (I/O port alternate function).
Figure Main Clock Controller (MCC/RTC) Block Diagram
MCCBCR BEEP BEEP SIGNAL SELECTION
12-BIT COUNTER
WATCHDOG TIMER
MCCSR fOSC2
MCC/RTC INTERRUPT
fCPU
CLOCK PERIPHERALS
57/183
ST72321B
MAIN CLOCK CONTROLLER WITH REAL TIME CLOCK (Cont'd) 10.2.5 Power ModeMode WAIT Description effect MCC/RTC peripheral. MCC/RTC interrupt cause device exit from WAIT mode. effect MCC/RTC counter (OIE set), registers frozen. MCC/RTC interrupt cause device exit from ACTIVE-HALT mode. MCC/RTC counter registers frozen. MCC/RTC operation resumes when woken interrupt with "exit from HALT" capability.
CP[1:0] clock prescaler These bits select clock prescaler which applied different slow modes. Their action conditioned setting bit. These bits cleared software
fCPU SLOW mode fOSC2 fOSC2 fOSC2 fOSC2
ACTIVEHALT
HALT
10.2.6 Interrupts MCC/RTC interrupt event generates interrupt MCCSR register interrupt mask register active (RIM instruction).
Interrupt Event Time base overflow event Enable Event Control Flag Exit from Wait Exit from Halt
Slow mode select This cleared software. Normal mode. fCPU fOSC2 Slow mode. fCPU given CP1, Section SLOW MODE Section 10.2 MAIN CLOCK CONTROLLER WITH REAL TIME CLOCK BEEPER (MCC/RTC) more details. TB[1:0] Time base control These bits select programmable divider time base. They cleared software.
Time Base Counter Prescaler OSC2 =4MHz fOSC2=8MHz 16000 20ms 50ms 10ms 25ms 32000 80000 200000
Note: MCC/RTC interrupt wakes from ACTIVE-HALT mode, from HALT mode.
10.2.7 Register Description CONTROL/STATUS REGISTER (MCCSR) Read /Write Reset Value: 0000 0000 (00h
modification time base taken into account current period (previously set) avoid unwanted time shift. This allows this time base real time clock. Oscillator interrupt enable This cleared software. Oscillator interrupt disabled Oscillator interrupt enabled This interrupt used exit from ACTIVEHALT mode. When this set, calling software HALT instruction enters ACTIVE-HALT power saving mode.
Main clock selection This enables alternate function port. cleared software. alternate function disabled (I/O free general-purpose I/O) alternate function enabled (fCPU port) Note: reduce power consumption, function active ACTIVE-HALT mode.
58/183
ST72321B
MAIN CLOCK CONTROLLER WITH REAL TIME CLOCK (Cont'd) Oscillator interrupt flag This hardware cleared software reading MCCSR register. indicates when that main oscillator reached selected elapsed time (TB1:0). Timeout reached Timeout reached CAUTION: BRES BSET instructions must used MCCSR register avoid unintentionally clearing bit. BEEP CONTROL REGISTER (MCCBCR) Read /Write Reset Value: 0000 0000 (00h)
Reserved, must kept cleared. BC[1:0] Beep control These bits select beep capability.
~2-KHz ~1-KHz ~500-Hz Beep mode with fOSC2=8MHz Output Beep signal ~50% duty cycle
beep output signal available ACTIVEHALT mode disabled reduce consumption. Table Main Clock Controller Register Reset ValueAddress (Hex.) 002Bh 002Ch 002Dh Register Label SICSR Reset Value MCCSR Reset Value MCCBCR Reset Value AVDS AVDIE AVDF LVDRF CSSIE CSSD WDGRF
59/183
ST72321B
10.3 AUTO-RELOAD TIMER (ART) 10.3.1 Introduction Pulse Width Modulated Auto-Reload Timer on-chip peripheral consists 8-bit auto reload counter with compare/capture capabilities 7-bit prescaler clock source. These resources allow five possible operating modes: Generation independent signals Output compare Time base interrupt Figure Auto-Reload Timer Block Diagram
PWMCR OCRx REGISTER LOAD PWMx PORT ALTERNATE FUNCTION POLARITY CONTROL COMPARE DCRx REGISTER
input capture functions External event detector external interrupt sources three first modes used together with single counter frequency. timer used wake from WAIT HALT modes.
REGISTER
8-BIT COUNTER (CAR REGISTER)
LOAD
ARTICx
INPUT CAPTURE CONTROL
LOAD
ICRx REGISTER
ICSx
ICIEx
ICFx
ICCSR
ARTCLK
fEXT fCPU fCOUNTER
INTERRUPT
fINPUT
PROGRAMMABLE PRESCALER
EXCL
FCRL
ARTCSR
INTERRUPT
60/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) 10.3.2 Functional Description Counter free running 8-bit counter output prescaler, incremented every rising edge clock signal. possible read write contents counter reading writing Counter Access register (ARTCAR). When counter overflow occurs, counter automatically reloaded with contents ARTARR register (the prescaler affected). Counter clock prescaler counter clock frequency given fCOUNTER fINPUT 2CC[2:0] timer counter's input clock (fINPUT) feeds 7-bit programmable prescaler, which selects available taps prescaler, defined CC[2:0] bits Control/Status Register (ARTCSR). Thus division factor prescaler (where 1,.7). This fINPUT frequency source selected through EXCL ARTCSR register either fCPU external input frequency fEXT. clock input counter enabled (Timer Counter Enable) ARTCSR register. When reset, counter stopped prescaler counter contents frozen. When set, counter runs rate selected clock source. Figure Output compare control Counter Prescaler Initialization After RESET, counter prescaler cleared fINPUT fCPU. counter initialized Writing ARTARR register then setting FCRL (Force Counter Re-Load) (Timer Counter Enable) bits ARTCSR register. Writing ARTCAR counter access register, both cases 7-bit prescaler also cleared, whereupon counting will start from known value. Direct access prescaler possible. Output compare control timer compare function based four different comparisons with counter (one each PWMx output). Each comparison made between counter value output compare register (OCRx) value. This OCRx register accessed directly, loaded from duty cycle register (PWMDCRx) each overflow counter. This double buffering method avoids glitch generation when changing duty cycle fly.
fCOUNTER ARTARR=FDh COUNTER
OCRx
PWMDCRx
PWMx
61/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) Independent signal generation This mode allows four Pulse Width Modulated signals generated PWMx output pins with minimum core processing overhead. This function stopped during HALT mode. Each PWMx output signal selected independently using corresponding Control register (PWMCR). When this set, corresponding configured output push-pull alternate function. signals have same frequency which controlled counter period ARTARR register value. fPWM fCOUNTER (256 ARTARR) When counter overflow occurs, PWMx level changed depending corresponding (output polarity) PWMCR register. Figure Auto-reload Timer Function
DUTY CYCLE REGISTER (PWMDCRx)
When counter reaches value contained output compare register (OCRx) corresponding PWMx level restored. should noted that reload values will also affect value resolution duty cycle output signal. obtain signal PWMx pin, contents OCRx register must greater than contents ARTARR register. maximum available resolution PWMx duty cycle Resolution (256 ARTARR) Note: maximum resolution (1/256), ARTARR register must With this maximum resolution, 100% obtained changing polarity.
COUNTER
AUTO-RELOAD REGISTER (ARTARR)
PWMx OUTPUT
WITH OEx=1 OPx=0 WITH OEx=1 OPx=1
Figure Signal from 100% Duty Cycle
fCOUNTER ARTARR=FDh COUNTER
OCRx=FCh PWMx OUTPUT WITH OEx=1 OPx=0 OCRx=FDh OCRx=FEh OCRx=FFh
62/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) Output compare Time base interrupt overflow, flag ARTCSR register overflow interrupt request generated overflow interrupt enable bit, OIE, ARTCSR register, set. flag must reset user software. This interrupt used time base application. External clock event detector mode Using fEXT external prescaler input clock, auto-reload timer used external clock event detector. this mode, ARTARR register used select nEVENT number events counted before setting flag. nEVENT ARTARR Caution: external clock function available HALT mode. HALT mode used application, prior executing HALT instruction, counter must disabled clearing ARTCSR register avoid spurious counter increments.
Figure External Event Detector Example counts)
EXT=fCOUNTER ARTARR=FDh
COUNTER
ARTCSR READ INTERRUPT OIE=1 INTERRUPT OIE=1
ARTCSR READ
63/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) Input capture function This mode allows measurement external signal pulse widths through ARTICRx registers. Each input capture generate interrupt independently selected input signal transition. This event flagged corresponding bits Input Capture Control/Status register (ARTICCSR). These input capture interrupts enabled through CIEx bits ARTICCSR register. active transition (falling rising edge) software programmable through bits ARTICCSR register. read only input capture registers (ARTICRx) used latch auto-reload counter value when transition detected ARTICx (CFx ARTICCSR register). After fetching interrupt vector, flags read identify interrupt source. Note: After capture detection, data transfer ARTICRx register inhibited until read (clearing bit). timer interrupt remains pending while flag when interrupt enabled (CIEx set). This means, ARTICRx register read each capture event clear flag. timing resolution given auto-reload counter cycle time (1/fCOUNTER). Note: During HALT mode, both input capture external clock enabled, ARTICRx register value guaranteed input capture external clock change simultaneously. Figure Input Capture Timing Diagram
fCOUNTER
External interrupt capability This mode allows Input capture capabilities used external interrupt sources. interrupts generated edge ARTICx signal. edge sensitivity external interrupts programmable (CSx ARTICCSR register) they independently enabled through CIEx bits ARTICCSR register. After fetching interrupt vector, flags read identify interrupt source. During HALT mode, external interrupts used wake micro CIEx set).
COUNTER
ARTICx FLAG ICRx REGISTER
INTERRUPT
64/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) 10.3.3 Register Description CONTROL STATUS REGISTER (ARTCSR) Read /Write Reset Value: 0000 0000 (00h)
EXCL FCRL
transition reached Transition reached COUNTER ACCESS REGISTER (ARTCAR) Read /Write Reset Value: 0000 0000 (00h)
EXCL External Clock This cleared software. selects input clock 7-bit prescaler. clock. External clock. CC[2:0] Counter Clock Control These bits cleared software. They determine prescaler division ratio from fINPUT.
fCOUNTER fINPUT fINPUT fINPUT fINPUT fINPUT fINPUT fINPUT fINPUT With fINPUT=8 62.5
CA[7:0] Counter Access Data These bits cleared either hardware software. ARTCAR register used read write auto-reload counter fly" (while counting).
AUTO-RELOAD REGISTER (ARTARR) Read /Write Reset Value: 0000 0000 (00h)
Timer Counter Enable This cleared software. puts timer lowest power consumption mode. Counter stopped (prescaler counter frozen). Counter running. FCRL Force Counter Re-Load This write-only attempt read will yield logical zero. When set, causes contents ARTARR register loaded into counter, content prescaler register cleared order initialize timer before starting count. Overflow Interrupt Enable This cleared software. allows enable/disable interrupt which generated when set. Overflow Interrupt disable. Overflow Interrupt enable. Overflow Flag This hardware cleared software reading ARTCSR register. indicates transition counter from ARTARR value.
AR[7:0] Counter Auto-Reload Data These bits cleared software. They used hold auto-reload value which automatically loaded counter when overflow occurs. same time, output levels changed according corresponding PWMCR register. This register management functions: Adjusting frequency Setting duty cycle resolution Frequency Resolution:
ARTARR value 0.127 128.191 192.223 224.239 Resolution 8-bit 7-bit 6-bit 5-bit 4-bit ~0.244-KHz ~0.244-KHz ~0.488-KHz ~0.977-KHz ~1.953-KHz fPWM 31.25-KHz 62.5-KHz 125-KHz 250-KHz 500-KHz
65/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) CONTROL REGISTER (PWMCR) Read /Write Reset Value: 0000 0000 (00h)
DUTY CYCLE REGISTERS (PWMDCRx) Read /Write Reset Value: 0000 0000 (00h)
OE[3:0] Output Enable These bits cleared software. They enable disable output channels independently acting corresponding pin. output disabled. output enabled. OP[3:0] Output Polarity These bits cleared software. They independently select polarity four output signals.
PWMx output level Counter OCRx Counter OCRx
DC[7:0] Duty Cycle Data These bits cleared software. PWMDCRx register associated with OCRx register each channel determine second edge location signal (the first edge location common channels given ARTARR register). These PWMDCR registers allow duty cycle independently each channel.
Note: When modified, PWMx output signal polarity immediately reversed.
66/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) INPUT CAPTURE CONTROL STATUS REGISTER (ARTICCSR) Read /Write Reset Value: 0000 0000 (00h)
CIE2 CIE1
INPUT CAPTURE REGISTERS (ARTICRx) Read only Reset Value: 0000 0000 (00h)
Reserved, always read CS[2:1] Capture Sensitivity These bits cleared software. They determine trigger event polarity corresponding input capture channel. Falling edge triggers capture channel Rising edge triggers capture channel CIE[2:1] Capture Interrupt Enable These bits cleared software. They enable disable Input capture channel interrupts independently. Input capture channel interrupt disabled. Input capture channel interrupt enabled. CF[2:1] Capture Flag These bits hardware cleared software reading corresponding ARTICRx register. Each indicates that input capture occurred. input capture channel input capture occured channel
IC[7:0] Input Capture Data These read only bits cleared hardware. ARTICRx register contains 8-bit auto-reload counter value transferred input capture channel event.
67/183
ST72321B
AUTO-RELOAD TIMER (Cont'd) Table Auto-Reload Timer Register Reset ValueAddress (Hex.) 0073h Register Label PWMDCR3 Reset Value PWMDCR2 Reset Value PWMDCR1 Reset Value PWMDCR0 Reset Value PWMCR Reset Value ARTCSR Reset Value ARTCAR Reset Value ARTARR Reset Value ARTICCSR Reset Value ARTICR1 Reset Value ARTICR2 Reset Value EXCL CIE2 FCRL CIE1
0074h
0075h
0076h
0077h
0078h
0079h
007Ah
007Bh
007Ch
007Dh
68/183
ST72321B
10.4 16-BIT TIMER 10.4.1 Introduction timer consists 16-bit free-running counter driven programmable prescaler. used variety purposes, including pulse length measurement input signals (input capture) generation output waveforms (output compare PWM). Pulse lengths waveform periods modulated from microseconds several milliseconds using timer prescaler clock prescaler. Some devices have on-chip 16-bit timers. They completely independent, share resources. They synchronized after reset long timer clock frequencies modified. This description covers 16-bit timers. devices with timers, register names prefixed with (Timer (Timer 10.4.2 Main Features Programmable prescaler: fCPU divided Overflow status flag maskable interrupt External clock input (must least times slower than clock speed) with choice active edge Output Compare functions each with: dedicated 16-bit registers dedicated programmable signals dedicated status flags dedicated maskable interrupt Input Capture functions each with: dedicated 16-bit registers dedicated active edge selection signals dedicated status flags dedicated maskable interrupt Pulse width modulation mode (PWM) pulse mode Reduced Power Mode alternate functions ports (ICAP1, ICAP2, OCMP1, OCMP2, EXTCLK)* Block Diagram shown Figure *Note: Some timer pins available (not bonded) some devices. Refer device description. When reading input signal non-bonded pin, value will always `1'. 10.4.3 Functional Description 10.4.3.1 Counter main block Programmable Timer 16-bit free running upcounter associated 16-bit registers. 16-bit registers made 8-bit registers called high low. Counter Register (CR): Counter High Register (CHR) most significant byte Byte). Counter Register (CLR) least significant byte Byte). Alternate Counter Register (ACR) Alternate Counter High Register (ACHR) most significant byte Byte). Alternate Counter Register (ACLR) least significant byte Byte). These read-only 16-bit registers contain same value with difference that reading ACLR register does clear (Timer overflow flag), located Status register, (SR), (see note paragraph titled 16-bit read sequence). Writing register ACLR register resets free running counter FFFCh value. Both counters have reset value FFFCh (this only value which reloaded 16-bit timer). reset value both counters also FFFCh Pulse mode mode. timer clock depends clock control bits register, illustrated Table Clock Control Bits. value counter register repeats every 131072, 262144 524288 clock cycles depending CC[1:0] bits. timer frequency fCPU/2, fCPU/4, fCPU/8 external frequency.
69/183
ST72321B
16-BIT TIMER (Cont'd) Figure Timer Block Diagram
INTERNAL fCPU MCU-PERIPHERAL INTERFACE
high
8-bit buffer
high
high
high
high
EXEDG
EXTCLK COUNTER REGISTER ALTERNATE COUNTER REGISTER OUTPUT COMPARE REGISTER OUTPUT COMPARE REGISTER INPUT CAPTURE REGISTER INPUT CAPTURE REGISTER
CC[1:0] TIMER INTERNAL OVERFLOW DETECT CIRCUIT
OUTPUT COMPARE CIRCUIT
EDGE DETECT CIRCUIT1
ICAP1
EDGE DETECT CIRCUIT2
ICAP2
LATCH1
ICF1 OCF1 ICF2 OCF2 TIMD
OCMP1 OCMP2
LATCH2
(Control/Status Register)
ICIE OCIE TOIE FOLV2 FOLV1 OLVL2 IEDG1 OLVL1
OC1E OC2E
IEDG2 EXEDG
(Control Register
(Control Register
(See note) TIMER INTERRUPT
Note: interrupt requests have separate vectors then last present (See device Interrupt Vector Table)
70/183
ST72321B
16-BIT TIMER (Cont'd) 16-bit read sequence: (from either Counter Register Alternate Counter Register).
Beginning sequence
Read Byte Other instructions Read Byte
Returns buffered
Byte buffered
Byte value
Sequence completed
user must read Byte first, then Byte value buffered automatically. This buffered value remains unchanged until 16-bit read sequence completed, even user reads Byte several times. After complete reading sequence, only register ACLR register read, they return Byte count value time read. Whatever timer mode used (input capture, output compare, pulse mode mode) overflow occurs when counter rolls over from FFFFh 0000h then: register set. timer interrupt generated TOIE register register cleared. these conditions false, interrupt remains pending issued soon they both true.
Clearing overflow interrupt request done steps: Reading register while set. access (read write) register. Notes: cleared accesses ACLR register. advantage accessing ACLR register rather than register that allows simultaneous overflow function reading free running counter random times (for example, measure elapsed time) without risk clearing erroneously. timer affected WAIT mode. HALT mode, counter stops counting until mode exited. Counting then resumes from previous count (MCU awakened interrupt) from reset count (MCU awakened Reset). 10.4.3.2 External Clock external clock (where available) selected CC0=1 CC1=1 register. status EXEDG register determines type level transition external clock EXTCLK that will trigger free running counter. counter synchronized with falling edge internal clock. minimum four falling edges clock must occur between consecutive active edges external clock; thus external clock frequency must less than quarter clock frequency.
71/183
ST72321B
16-BIT TIMER (Cont'd) Figure Counter Timing Diagram, internal clock divided
CLOCK INTERNAL RESET TIMER CLOCK COUNTER REGISTER TIMER OVERFLOW FLAG (TOF) FFFD FFFE FFFF 0000 0001 0002 0003
Figure Counter Timing Diagram, internal clock divided
CLOCK INTERNAL RESET TIMER CLOCK COUNTER REGISTER TIMER OVERFLOW FLAG (TOF) FFFC FFFD 0000 0001
Figure Counter Timing Diagram, internal clock divided
CLOCK INTERNAL RESET TIMER CLOCK COUNTER REGISTER FFFC FFFD 0000
TIMER OVERFLOW FLAG (TOF)
Note: reset state when internal reset signal high, when running.
72/183
ST72321B
16-BIT TIMER (Cont'd) 10.4.3.3 Input Capture this section, index, because there input capture functions 16-bit timer. 16-bit input capture registers (IC1R IC2R) used latch value free running counter after transition detected ICAPi (see figure
ICiR Byte ICiHR Byte ICiLR
ICiR register read-only register. active transition software programmable through IEDGi Control Registers (CRi). Timing resolution count free running counter: (fCPU/CC[1:0]). Procedure: input capture function select following register: Select timer clock (CC[1:0]) (see Table Clock Control Bits). Select edge active transition ICAP2 with IEDG2 (the ICAP2 must configured floating input input with pull-up without interrupt this configuration available). select following register: ICIE generate interrupt after input capture coming from either ICAP1 ICAP2 Select edge active transition ICAP1 with IEDG1 (the ICAP1pin must configured floating input input with pullup without interrupt this configuration available).
When input capture occurs: ICFi set. register contains value free running counter active transition ICAPi (see Figure 47). timer interrupt generated ICIE cleared register. Otherwise, interrupt remains pending until both conditions become true. Clearing Input Capture interrupt request (i.e. clearing ICFi bit) done steps: Reading register while ICFi set. access (read write) ICiLR register. Notes: After reading ICiHR register, transfer input capture data inhibited ICFi will never until ICiLR register also read. ICiR register contains free running counter value which corresponds most recent input capture. input capture functions used together even timer also uses output compare functions. pulse Mode mode only Input Capture used. alternate inputs (ICAP1 ICAP2) always directly connected timer. transitions these pins activates input capture function. Moreover ICAPi pins configured input second output, interrupt generated user toggles output ICIE set. This avoided input capture function disabled reading (see note used with interrupt generation order measure events that beyond timer range (FFFFh).
73/183
ST72321B
16-BIT TIMER (Cont'd) Figure Input Capture Block Diagram
ICAP1 ICAP2 EDGE DETECT CIRCUIT2 EDGE DETECT CIRCUIT1
ICIE
(Control Register
IEDG1
(Status Register) IC2R Register IC1R Register
ICF1 ICF2
16-BIT 16-BIT FREE RUNNING COUNTER
(Control Register
IEDG2
Figure Input Capture Timing Diagram
TIMER CLOCK COUNTER REGISTER ICAPi ICAPi FLAG ICAPi REGISTER Note: rising edge active edge. FF03 FF01 FF02 FF03
74/183
ST72321B
16-BIT TIMER (Cont'd) 10.4.3.4 Output Compare this section, index, because there output compare functions 16-bit timer. This function used control output waveform indicate when period time elapsed. When match found between Output Compare register free running counter, output compare function: Assigns pins with programmable value OCiE Sets flag status register Generates interrupt enabled 16-bit registers Output Compare Register (OC1R) Output Compare Register (OC2R) contain value compared counter register each timer clock cycle.
OCiR Byte OCiHR Byte OCiLR
OCMPi takes OLVLi value (OCMPi latch forced during reset). timer interrupt generated OCIE register cleared register (CC). OCiR register value required specific timing application calculated using following formula:
OCiR
fCPU
PRESC
Where: Output compare period seconds) clock frequency hertz) fCPU PRESC Timer prescaler factor depending CC[1:0] bits, Table Clock Control Bits) timer clock external clock, formula
These registers readable writable affected timer hardware. reset event changes OCiR value 8000h. Timing resolution count free running counter: (fCPU/CC[1:0]). Procedure: output compare function, select following register: OCiE output needed then OCMPi dedicated output compare signal. Select timer clock (CC[1:0]) (see Table Clock Control Bits). select following register: Select OLVLi applied OCMP pins after match occurs. OCIE generate interrupt needed. When match found between OCRi register register: OCFi set.
OCiR fEXT
Where: Output compare period seconds) External timer clock frequency hertz) fEXT Clearing output compare interrupt request (i.e. clearing OCFi bit) done Reading register while OCFi set. access (read write) OCiLR register. following procedure recommended prevent OCFi from being between time read write OCiR register: Write OCiHR register (further compares inhibited). Read register (first step clearance OCFi bit, which already set). Write OCiLR register (enables output compare function clears OCFi bit).
75/183
ST72321B
16-BIT TIMER (Cont'd) Notes: After processor write cycle OCiHR register, output compare function inhibited until OCiLR register also written. OCiE set, OCMPi general port OLVLi will appear when match found interrupt could generated OCIE set. When timer clock fCPU/2, OCFi OCMPi while counter value equals OCiR register value (see Figure page 77). This behaviour same mode. When timer clock fCPU/4, fCPU/8 external clock mode, OCFi OCMPi while counter value equals register value plus (see Figure page 77). output compare functions used both generating external events OCMPi pins even input capture mode also used. value 16-bit OCiR register OLVi should changed after each successful comparison order control output waveform establish elapsed timeout. Figure Output Compare Block Diagram
Forced Compare Output capability When FOLVi software, OLVLi copied OCMPi pin. OLVi toggled order toggle OCMPi when enabled (OCiE bit=1). OCFi then hardware, thus interrupt request generated. FOLVLi bits have effect both pulse mode mode.
FREE RUNNING COUNTER
OC1E OC2E
16-bit
OUTPUT COMPARE CIRCUIT
(Control Register (Control Register
OCIE FOLV2 FOLV1 OLVL2 OLVL1 Latch
OCMP1 OCMP2
16-bit
16-bit
OC1R Register
OCF1 OCF2
Latch
OC2R Register (Status Register)
76/183
ST72321B
16-BIT TIMER (Cont'd) Figure Output Compare Timing Diagram, fTIMER =fCPU/2
INTERNAL CLOCK TIMER CLOCK COUNTER REGISTER OUTPUT COMPARE REGISTER (OCRi) OUTPUT COMPARE FLAG (OCFi) OCMPi (OLVLi=1) 2ECF 2ED0 2ED1 2ED2 2ED3 2ED4 2ED3
Figure Output Compare Timing Diagram, fTIMER =fCPU/4
INTERNAL CLOCK TIMER CLOCK COUNTER REGISTER OUTPUT COMPARE REGISTER (OCRi) COMPARE REGISTER LATCH OUTPUT COMPARE FLAG (OCFi) OCMPi (OLVLi=1) 2ECF 2ED0 2ED1 2ED2 2ED3 2ED4 2ED3
77/183
ST72321B
16-BIT TIMER (Cont'd) 10.4.3.5 Pulse Mode Pulse mode enables generation pulse when external event occurs. This mode selected register. pulse mode uses Input Capture1 function Output Compare1 function. Procedure: pulse mode: Load OC1R register with value corresponding length pulse (see formula opposite column). Select following register: Using OLVL1 bit, select level applied OCMP1 after pulse. Using OLVL2 bit, select level applied OCMP1 during pulse. Select edge active transition ICAP1 with IEDG1 (the ICAP1 must configured floating input). Select following register: OC1E bit, OCMP1 then dedicated Output Compare function. bit. Select timer clock CC[1:0] (see Table Clock Control Bits).
Clearing Input Capture interrupt request (i.e. clearing ICFi bit) done steps: Reading register while ICFi set. access (read write) ICiLR register. OC1R register value required specific timing application calculated using following formula: OCiR Value
fCPU
PRESC
Where: Pulse period seconds) fCPU clock frequency hertz) PRESC Timer prescaler factor depending CC[1:0] bits, Table Clock Control Bits) timer clock external clock formula OCiR fEXT Where: Pulse period seconds) fEXT External timer clock frequency hertz) When value counter equal value contents OC1R register, OLVL1 output OCMP1 pin, (See Figure 51). Notes: OCF1 cannot hardware pulse mode OCF2 generate Output Compare interrupt. When Pulse Width Modulation (PWM) Pulse Mode (OPM) bits both set, mode only active one. OLVL1=OLVL2 continuous signal will seen OCMP1 pin. ICAP1 used perform input capture. ICAP2 used perform input capture (ICF2 IC2R loaded) user must take care that counter reset each time valid edge occurs ICAP1 ICF1 also generates interrupt ICIE set. When pulse mode used OC1R dedicated this mode. Nevertheless OC2R OCF2 used indicate period time been elapsed cannot generate output waveform because level OLVL2 dedicated pulse mode.
pulse mode cycle
When event occurs ICAP1 ICR1 Counter OCMP1 OLVL2 Counter reset FFFCh ICF1 When Counter OC1R
OCMP1 OLVL1
Then, valid event ICAP1 pin, counter initialized FFFCh OLVL2 loaded OCMP1 pin, ICF1 value FFFDh loaded IC1R register. Because ICF1 when active edge occurs, interrupt generated ICIE set.
78/183
ST72321B
16-BIT TIMER (Cont'd) Figure Pulse Mode Timing Example
IC1R COUNTER ICAP1 OCMP1 OLVL2 OLVL1 OLVL2 01F8 FFFC FFFD FFFE 01F8 2ED0 2ED1 2ED2 2ED3 2ED3 FFFC FFFD
compare1 Note: IEDG1=1, OC1R=2ED0h, OLVL1=0, OLVL2=1
Figure Pulse Width Modulation Mode Timing Example with Output Compare Function
COUNTER 34E2 FFFC FFFD FFFE OCMP1
2ED0 2ED1 2ED2
34E2
FFFC
OLVL2
OLVL1
OLVL2
compare2
compare1
compare2
Note: OC1R=2ED0h, OC2R=34E2, OLVL1=0, OLVL2=
Note: timers with only Output Compare register, fixed frequency signal generated using output compare counter overflow define pulse length.
79/183
ST72321B<br

Other recent searches


TTC-5501 - TTC-5501   TTC-5501 Datasheet
SSM3J108TU - SSM3J108TU   SSM3J108TU Datasheet
IDT74CBTLVR16292 - IDT74CBTLVR16292   IDT74CBTLVR16292 Datasheet
HT82V169 - HT82V169   HT82V169 Datasheet
BZX84C2V4 - BZX84C2V4   BZX84C2V4 Datasheet
BZX84C47 - BZX84C47   BZX84C47 Datasheet
AN3771 - AN3771   AN3771 Datasheet

 

Privacy Policy | Disclaimer
© 2012 Datasheet Archive