C8051 F34 X
C8051 F34 X
C8051 F34 X
UART1*
A +
10-bit SPI Port 1
Ext. Memory I/F
M +
U
200 ksps - SMBus
ADC - Port 2
X PCA
4 Timers Port 3
TEMP VREG
VREF Port 4
SENSOR 48 Pin Only
C8051F340/1/2/34/5/6/7/A/B Only * C8051F340/1/4/5/8/A/B/C Only
2 Rev. 1.4
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Table of Contents
1. System Overview.................................................................................................... 17
2. Absolute Maximum Ratings .................................................................................. 24
3. Global DC Electrical Characteristics .................................................................... 25
4. Pinout and Package Definitions............................................................................ 28
5. 10-Bit ADC (ADC0, C8051F340/1/2/3/4/5/6/7/A/B Only)........................................ 41
5.1. Analog Multiplexer ............................................................................................ 42
5.2. Temperature Sensor ......................................................................................... 43
5.3. Modes of Operation .......................................................................................... 45
5.3.1. Starting a Conversion............................................................................... 45
5.3.2. Tracking Modes........................................................................................ 46
5.3.3. Settling Time Requirements ..................................................................... 47
5.4. Programmable Window Detector ...................................................................... 52
5.4.1. Window Detector In Single-Ended Mode ................................................. 54
5.4.2. Window Detector In Differential Mode...................................................... 55
6. Voltage Reference (C8051F340/1/2/3/4/5/6/7/A/B Only)....................................... 57
7. Comparators ........................................................................................................... 59
8. Voltage Regulator (REG0)...................................................................................... 69
8.1. Regulator Mode Selection................................................................................. 69
8.2. VBUS Detection ................................................................................................ 69
9. CIP-51 Microcontroller ........................................................................................... 73
9.1. Instruction Set ................................................................................................... 74
9.1.1. Instruction and CPU Timing ..................................................................... 74
9.1.2. MOVX Instruction and Program Memory ................................................. 75
9.2. Memory Organization........................................................................................ 79
9.2.1. Program Memory...................................................................................... 80
9.2.2. Data Memory............................................................................................ 81
9.2.3. General Purpose Registers ...................................................................... 81
9.2.4. Bit Addressable Locations........................................................................ 81
9.2.5. Stack ....................................................................................................... 81
9.2.6. Special Function Registers....................................................................... 82
9.2.7. Register Descriptions ............................................................................... 86
9.3. Interrupt Handler ............................................................................................... 88
9.3.1. MCU Interrupt Sources and Vectors ........................................................ 88
9.3.2. External Interrupts .................................................................................... 88
9.3.3. Interrupt Priorities ..................................................................................... 89
9.3.4. Interrupt Latency ...................................................................................... 89
9.3.5. Interrupt Register Descriptions................................................................. 90
9.4. Power Management Modes .............................................................................. 97
9.4.1. Idle Mode.................................................................................................. 97
9.4.2. Stop Mode ................................................................................................ 97
10. Prefetch Engine ...................................................................................................... 99
11. Reset Sources....................................................................................................... 100
11.1.Power-On Reset ............................................................................................. 101
Rev. 1.3 3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
4 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 5
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
6 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 7
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
List of Figures
1. System Overview
Figure 1.1. C8051F340/1/4/5 Block Diagram ........................................................... 19
Figure 1.2. C8051F342/3/6/7 Block Diagram ........................................................... 20
Figure 1.3. C8051F348/C Block Diagram................................................................. 21
Figure 1.4. C8051F349/D Block Diagram................................................................. 22
Figure 1.5. C8051F34A/B Block Diagram ................................................................ 23
4. Pinout and Package Definitions
Figure 4.1. TQFP-48 Pinout Diagram (Top View) .................................................... 31
Figure 4.2. TQFP-48 Package Diagram ................................................................... 32
Figure 4.3. TQFP-48 Recommended PCB Land Pattern ......................................... 33
Figure 4.4. LQFP-32 Pinout Diagram (Top View)..................................................... 34
Figure 4.5. LQFP-32 Package Diagram ................................................................... 35
Figure 4.6. LQFP-32 Recommended PCB Land Pattern ......................................... 36
Figure 4.7. QFN-32 Pinout Diagram (Top View) ...................................................... 37
5. 10-Bit ADC (ADC0, C8051F340/1/2/3/4/5/6/7/A/B Only)
Figure 5.1. ADC0 Functional Block Diagram............................................................ 41
Figure 5.2. Temperature Sensor Transfer Function ................................................. 43
Figure 5.3. Temperature Sensor Error with 1-Point Calibration (VREF = 2.40 V) .... 44
Figure 5.4. 10-Bit ADC Track and Conversion Example Timing .............................. 46
Figure 5.5. ADC0 Equivalent Input Circuits .............................................................. 47
Figure 5.6. ADC Window Compare Example: Right-Justified Single-Ended Data ... 54
Figure 5.7. ADC Window Compare Example: Left-Justified Single-Ended Data...... 54
Figure 5.8. ADC Window Compare Example: Right-Justified Differential Data........ 55
Figure 5.9. ADC Window Compare Example: Left-Justified Differential Data .......... 55
6. Voltage Reference (C8051F340/1/2/3/4/5/6/7/A/B Only)
Figure 6.1. Voltage Reference Functional Block Diagram........................................ 57
7. Comparators
Figure 7.1. Comparator Functional Block Diagram .................................................. 60
Figure 7.2. Comparator Hysteresis Plot ................................................................... 61
8. Voltage Regulator (REG0)
Figure 8.1. REG0 Configuration: USB Bus-Powered ............................................... 70
Figure 8.2. REG0 Configuration: USB Self-Powered ............................................... 70
Figure 8.3. REG0 Configuration: USB Self-Powered, Regulator Disabled............... 71
Figure 8.4. REG0 Configuration: No USB Connection ............................................. 71
9. CIP-51 Microcontroller
Figure 9.1. CIP-51 Block Diagram............................................................................ 73
Figure 9.2. On-Chip Memory Map for 64 kB Devices............................................... 79
Figure 9.3. On-Chip Memory Map for 32 kB Devices............................................... 80
11. Reset Sources
Figure 11.1. Reset Sources.................................................................................... 100
Figure 11.2. Power-On and VDD Monitor Reset Timing ........................................ 101
Rev. 1.3 8
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
9 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 10
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
List of Tables
1. System Overview
Table 1.1. Product Selection Guide ......................................................................... 18
2. Absolute Maximum Ratings
Table 2.1. Absolute Maximum Ratings* .................................................................. 24
3. Global DC Electrical Characteristics
Table 3.1. Global DC Electrical Characteristics ....................................................... 25
Table 3.2. Index to Electrical Characteristics Tables ............................................... 27
4. Pinout and Package Definitions
Table 4.1. Pin Definitions for the C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D ................. 28
Table 4.2. TQFP-48 Package Dimensions .............................................................. 32
Table 4.3. TQFP-48 PCB Land Pattern Dimensions ............................................... 33
Table 4.4. LQFP-32 Package Dimensions .............................................................. 35
Table 4.5. LQFP-32 PCB Land Pattern Dimensions ............................................... 36
5. 10-Bit ADC (ADC0, C8051F340/1/2/3/4/5/6/7/A/B Only)
Table 5.1. ADC0 Electrical Characteristics .............................................................. 56
6. Voltage Reference (C8051F340/1/2/3/4/5/6/7/A/B Only)
Table 6.1. Voltage Reference Electrical Characteristics ......................................... 58
7. Comparators
Table 7.1. Comparator Electrical Characteristics .................................................... 68
8. Voltage Regulator (REG0)
Table 8.1. Voltage Regulator Electrical Specifications ............................................ 69
9. CIP-51 Microcontroller
Table 9.1. CIP-51 Instruction Set Summary ............................................................ 75
Table 9.2. Special Function Register (SFR) Memory Map ...................................... 82
Table 9.3. Special Function Registers ..................................................................... 83
Table 9.4. Interrupt Summary .................................................................................. 90
11. Reset Sources
Table 11.1. Reset Electrical Characteristics .......................................................... 106
12. Flash Memory
Table 12.1. Flash Electrical Characteristics .......................................................... 109
13. External Data Memory Interface and On-Chip XRAM
Table 13.1. AC Parameters for External Memory Interface ................................... 130
14. Oscillators
Table 14.1. Oscillator Electrical Characteristics .................................................... 141
15. Port Input/Output
Table 15.1. Port I/O DC Electrical Characteristics ................................................. 158
16. Universal Serial Bus Controller (USB0)
Table 16.1. Endpoint Addressing Scheme ............................................................ 160
Table 16.2. USB0 Controller Registers ................................................................. 165
Table 16.3. FIFO Configurations ........................................................................... 168
Table 16.4. USB Transceiver Electrical Characteristics ........................................ 187
17. SMBus
Table 17.1. SMBus Clock Source Selection .......................................................... 192
Rev. 1.3 11
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Table 17.2. Minimum SDA Setup and Hold Times ................................................ 193
Table 17.3. Sources for Hardware Changes to SMB0CN ..................................... 197
Table 17.4. SMBus Status Decoding ..................................................................... 203
18. UART0
Table 18.1. Timer Settings for Standard Baud Rates
Using the Internal Oscillator ............................................................... 212
19. UART1 (C8051F340/1/4/5/8/A/B/C Only)
Table 19.1. Baud Rate Generator Settings for Standard Baud Rates ................... 214
20. Enhanced Serial Peripheral Interface (SPI0)
Table 20.1. SPI Slave Timing Parameters ............................................................ 234
22. Programmable Counter Array (PCA0)
Table 22.1. PCA Timebase Input Options ............................................................. 256
Table 22.2. PCA0CPM Register Settings for PCA Capture/Compare Modules .... 257
Table 22.3. Watchdog Timer Timeout Intervals1 ................................................... 265
12 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
List of Registers
SFR Definition 5.1. AMX0P: AMUX0 Positive Channel Select . . . . . . . . . . . . . . . . . . . 48
SFR Definition 5.2. AMX0N: AMUX0 Negative Channel Select . . . . . . . . . . . . . . . . . . 49
SFR Definition 5.3. ADC0CF: ADC0 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
SFR Definition 5.4. ADC0H: ADC0 Data Word MSB . . . . . . . . . . . . . . . . . . . . . . . . . . 50
SFR Definition 5.5. ADC0L: ADC0 Data Word LSB . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
SFR Definition 5.6. ADC0CN: ADC0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
SFR Definition 5.7. ADC0GTH: ADC0 Greater-Than Data High Byte . . . . . . . . . . . . . 52
SFR Definition 5.8. ADC0GTL: ADC0 Greater-Than Data Low Byte . . . . . . . . . . . . . . 52
SFR Definition 5.9. ADC0LTH: ADC0 Less-Than Data High Byte . . . . . . . . . . . . . . . . 53
SFR Definition 5.10. ADC0LTL: ADC0 Less-Than Data Low Byte . . . . . . . . . . . . . . . 53
SFR Definition 6.1. REF0CN: Reference Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
SFR Definition 7.1. CPT0CN: Comparator0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
SFR Definition 7.2. CPT0MX: Comparator0 MUX Selection . . . . . . . . . . . . . . . . . . . . 63
SFR Definition 7.3. CPT0MD: Comparator0 Mode Selection . . . . . . . . . . . . . . . . . . . . 64
SFR Definition 7.4. CPT1CN: Comparator1 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
SFR Definition 7.5. CPT1MX: Comparator1 MUX Selection . . . . . . . . . . . . . . . . . . . . 66
SFR Definition 7.6. CPT1MD: Comparator1 Mode Selection . . . . . . . . . . . . . . . . . . . . 67
SFR Definition 8.1. REG0CN: Voltage Regulator Control . . . . . . . . . . . . . . . . . . . . . . 72
SFR Definition 9.1. DPL: Data Pointer Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
SFR Definition 9.2. DPH: Data Pointer High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
SFR Definition 9.3. SP: Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
SFR Definition 9.4. PSW: Program Status Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
SFR Definition 9.5. ACC: Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
SFR Definition 9.6. B: B Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
SFR Definition 9.7. IE: Interrupt Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
SFR Definition 9.8. IP: Interrupt Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
SFR Definition 9.9. EIE1: Extended Interrupt Enable 1 . . . . . . . . . . . . . . . . . . . . . . . . 93
SFR Definition 9.10. EIP1: Extended Interrupt Priority 1 . . . . . . . . . . . . . . . . . . . . . . . 94
SFR Definition 9.11. EIE2: Extended Interrupt Enable 2 . . . . . . . . . . . . . . . . . . . . . . . 95
SFR Definition 9.12. EIP2: Extended Interrupt Priority 2 . . . . . . . . . . . . . . . . . . . . . . . 95
SFR Definition 9.13. IT01CF: INT0/INT1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . 96
SFR Definition 9.14. PCON: Power Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
SFR Definition 10.1. PFE0CN: Prefetch Engine Control . . . . . . . . . . . . . . . . . . . . . . . 99
SFR Definition 11.1. VDM0CN: VDD Monitor Control . . . . . . . . . . . . . . . . . . . . . . . . . 102
SFR Definition 11.2. RSTSRC: Reset Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
SFR Definition 12.1. PSCTL: Program Store R/W Control . . . . . . . . . . . . . . . . . . . . . 112
SFR Definition 12.2. FLKEY: Flash Lock and Key . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
SFR Definition 12.3. FLSCL: Flash Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
SFR Definition 13.1. EMI0CN: External Memory Interface Control . . . . . . . . . . . . . . 117
SFR Definition 13.2. EMI0CF: External Memory Configuration . . . . . . . . . . . . . . . . . 118
SFR Definition 13.3. EMI0TC: External Memory Timing Control . . . . . . . . . . . . . . . . 123
SFR Definition 14.1. OSCICN: Internal H-F Oscillator Control . . . . . . . . . . . . . . . . . . 132
SFR Definition 14.2. OSCICL: Internal H-F Oscillator Calibration . . . . . . . . . . . . . . . 133
Rev. 1.3 13
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
14 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
USB Register Definition 16.19. EINCSRL: USB0 IN Endpoint Control Low Byte . . . . 182
USB Register Definition 16.20. EINCSRH: USB0 IN Endpoint Control High Byte . . . 183
USB Register Definition 16.21. EOUTCSRL: USB0 OUT
Endpoint Control Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
USB Register Definition 16.22. EOUTCSRH: USB0 OUT
Endpoint Control High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
USB Register Definition 16.23. EOUTCNTL: USB0 OUT Endpoint Count Low . . . . . 186
USB Register Definition 16.24. EOUTCNTH: USB0 OUT Endpoint Count High . . . . 186
SFR Definition 17.1. SMB0CF: SMBus Clock/Configuration . . . . . . . . . . . . . . . . . . . 194
SFR Definition 17.2. SMB0CN: SMBus Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
SFR Definition 17.3. SMB0DAT: SMBus Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
SFR Definition 18.1. SCON0: Serial Port 0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . 210
SFR Definition 18.2. SBUF0: Serial (UART0) Port Data Buffer . . . . . . . . . . . . . . . . . 211
SFR Definition 19.1. SCON1: UART1 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
SFR Definition 19.2. SMOD1: UART1 Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
SFR Definition 19.3. SBUF1: UART1 Data Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
SFR Definition 19.4. SBCON1: UART1 Baud Rate Generator Control . . . . . . . . . . . 220
SFR Definition 19.5. SBRLH1: UART1 Baud Rate Generator High Byte . . . . . . . . . . 221
SFR Definition 19.6. SBRLL1: UART1 Baud Rate Generator Low Byte . . . . . . . . . . . 221
SFR Definition 20.1. SPI0CFG: SPI0 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 229
SFR Definition 20.2. SPI0CN: SPI0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
SFR Definition 20.3. SPI0CKR: SPI0 Clock Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
SFR Definition 20.4. SPI0DAT: SPI0 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
SFR Definition 21.1. TCON: Timer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
SFR Definition 21.2. TMOD: Timer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
SFR Definition 21.3. CKCON: Clock Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
SFR Definition 21.4. TL0: Timer 0 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
SFR Definition 21.5. TL1: Timer 1 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
SFR Definition 21.6. TH0: Timer 0 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
SFR Definition 21.7. TH1: Timer 1 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
SFR Definition 21.8. TMR2CN: Timer 2 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
SFR Definition 21.9. TMR2RLL: Timer 2 Reload Register Low Byte . . . . . . . . . . . . . 248
SFR Definition 21.10. TMR2RLH: Timer 2 Reload Register High Byte . . . . . . . . . . . 248
SFR Definition 21.11. TMR2L: Timer 2 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
SFR Definition 21.12. TMR2H Timer 2 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
SFR Definition 21.13. TMR3CN: Timer 3 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
SFR Definition 21.14. TMR3RLL: Timer 3 Reload Register Low Byte . . . . . . . . . . . . 254
SFR Definition 21.15. TMR3RLH: Timer 3 Reload Register High Byte . . . . . . . . . . . 254
SFR Definition 21.16. TMR3L: Timer 3 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
SFR Definition 21.17. TMR3H Timer 3 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
SFR Definition 22.1. PCA0CN: PCA Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
SFR Definition 22.2. PCA0MD: PCA Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
SFR Definition 22.3. PCA0CPMn: PCA Capture/Compare Mode . . . . . . . . . . . . . . . 268
SFR Definition 22.4. PCA0L: PCA Counter/Timer Low Byte . . . . . . . . . . . . . . . . . . . 269
SFR Definition 22.5. PCA0H: PCA Counter/Timer High Byte . . . . . . . . . . . . . . . . . . . 269
Rev. 1.3 15
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
SFR Definition 22.6. PCA0CPLn: PCA Capture Module Low Byte . . . . . . . . . . . . . . . 269
SFR Definition 22.7. PCA0CPHn: PCA Capture Module High Byte . . . . . . . . . . . . . . 270
C2 Register Definition 23.1. C2ADD: C2 Address . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
C2 Register Definition 23.2. DEVICEID: C2 Device ID . . . . . . . . . . . . . . . . . . . . . . . . 271
C2 Register Definition 23.3. REVID: C2 Revision ID . . . . . . . . . . . . . . . . . . . . . . . . . 272
C2 Register Definition 23.4. FPCTL: C2 Flash Programming Control . . . . . . . . . . . . 272
C2 Register Definition 23.5. FPDAT: C2 Flash Programming Data . . . . . . . . . . . . . . 272
16 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
1. System Overview
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D devices are fully integrated mixed-signal System-on-a-Chip MCUs.
Highlighted features are listed below. Refer to Table 1.1 for specific product feature selection.
With on-chip Power-On Reset, VDD monitor, Voltage Regulator, Watchdog Timer, and clock oscillator,
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D devices are truly stand-alone System-on-a-Chip solutions. The
Flash memory can be reprogrammed in-circuit, providing non-volatile data storage, and also allowing field
upgrades of the 8051 firmware. User software has complete control of all peripherals, and may individually
shut down any or all peripherals for power savings.
The on-chip Silicon Labs 2-Wire (C2) Development Interface allows non-intrusive (uses no on-chip
resources), full speed, in-circuit debugging using the production MCU installed in the final application. This
debug logic supports inspection and modification of memory and registers, setting breakpoints, single
stepping, run and halt commands. All analog and digital peripherals are fully functional while debugging
using C2. The two C2 interface pins can be shared with user functions, allowing in-system debugging with-
out occupying package pins.
Each device is specified for 2.7–5.25 V operation over the industrial temperature range (–40 to +85 °C).
For voltages above 3.6 V, the on-chip Voltage Regulator must be used. A minimum of 3.0 V is required for
USB communication. The Port I/O and RST pins are tolerant of input signals up to 5 V. C8051F340/1/2/3/
4/5/6/7/8/9/A/B/C/D devices are available in 48-pin TQFP, 32-pin LQFP, or 32-pin QFN packages. See
Table 1.1, “Product Selection Guide,” on page 18 for feature and package choices.
Rev. 1.3 17
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Analog Comparators
Temperature Sensor
Voltage Reference
Digital Port I/Os
Timers (16-bit)
Enhanced SPI
MIPS (Peak)
SMBus/I2C
Package
UARTs
RAM
18 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
D+ 2 Comparators
Controller
D- Full / Low
10-bit A VDD AIN0 - AIN19
Speed
200ksps M
VBUS Transceiver 1k Byte U Temp
RAM ADC
X Sensor
Rev. 1.3 19
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
D+ 2 Comparators
Controller
D- Full / Low
10-bit A VDD AIN0 - AIN20
Speed
200 ksps M
VBUS Transceiver U Temp
1 kB RAM ADC
X Sensor
20 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 21
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Analog Peripherals
USB Peripheral
CP0 +
-
D+
Controller CP1
D- Full / Low +
-
Speed
Transceiver 2 Comparators
VBUS 1 kB RAM
22 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
D+ 2 Comparators
Controller
D- Full / Low
10-bit A VDD AIN0 - AIN20
Speed
200 ksps M
VBUS Transceiver U Temp
1 kB RAM ADC
X Sensor
Rev. 1.3 23
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
*Note: Stresses above those listed under “Absolute Maximum Ratings” may cause permanent damage to the
device. This is a stress rating only and functional operation of the devices at those or any other conditions
above those indicated in the operation listings of this specification is not implied. Exposure to maximum rating
conditions for extended periods may affect device reliability.
24 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 25
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Other electrical characteristics tables are found in the data sheet section corresponding to the associated
peripherals. For more information on electrical characteristics for a specific peripheral, refer to the page
indicated in Table 3.2.
26 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 27
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
28 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 29
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
30 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
P0.6
P0.7
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
P2.0
P2.1
48
47
46
45
44
43
42
41
40
39
38
37
P0.5 1 36 P2.2
P0.4 2 35 P2.3
P0.3 3 34 P2.4
P0.2 4 33 P2.5
P0.1 5 32 P2.6
P0.0 6 C8051F340/1/4/5/8/C-GQ 31 P2.7
GND 7
Top View 30 P3.0
D+ 8 29 P3.1
D- 9 28 P3.2
VDD 10 27 P3.3
REGIN 11 26 P3.4
VBUS 12 25 P3.5
13
14
15
16
17
18
19
20
21
22
23
24
P4.7
P4.6
P4.5
P4.4
P4.3
P4.2
P4.1
P4.0
P3.7
P3.6
C2D
RST / C2CK
Rev. 1.3 31
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
32 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 33
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
P0.2
P0.3
P0.4
P0.5
P0.6
P0.7
P1.0
P1.1
32
31
30
29
28
27
26
25
P0.1 1 24 P1.2
P0.0 2 23 P1.3
GND 3 22 P1.4
D+ 4 C8051F342/3/6/7/9/A/B/D-GQ 21 P1.5
VDD 6 19 P1.7
REGIN 7 18 P2.0
VBUS 8 17 P2.1
10
11
12
13
14
15
16
9
P2.6
RST / C2CK
P2.7
P2.5
P2.4
P2.3
P2.2
P3.0 / C2D
34 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 35
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
36 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
P0.2
P0.3
P0.4
P0.5
P0.6
P0.7
P1.0
P1.1
32
31
30
29
28
27
26
25
P0.1 1 24 P1.2
P0.0 2 23 P1.3
GND 3 22 P1.4
D+ 4 21 P1.5
C8051F342/3/6/7/9/A/B-GM
D- 5
Top View 20 P1.6
VDD 6 19 P1.7
REGIN 7 18 P2.0
GND (optional)
VBUS 8 17 P2.1
10
11
12
13
14
15
16
9
P2.7
P2.6
P2.4
P2.3
RST / C2CK
P3.0 / C2D
P2.5
P2.2
Rev. 1.3 37
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
38 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 39
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
40 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
AMX0P ADC0CN
AD0BUSY
AD0WINT
AD0CM2
AD0CM1
AD0CM0
AMX0P4
AMX0P3
AMX0P2
AMX0P1
AMX0P0
AD0INT
AD0TM
AD0EN
Port I/O
VDD 000 AD0BUSY (W)
Pins* Start
Positive 001 Timer 0 Overflow
Conversion
Input 010 Timer 2 Overflow
VDD
(AIN+) 011 Timer 1 Overflow
AMUX 100 CNVSTR Input
ADC0L
Temp 101 Timer 3 Overflow
Sensor
AIN+
10-Bit
SAR
ADC
ADC0H
AIN-
Port I/O
Pins*
Negative
REF
SYSCLK
Input
VREF
(AIN-) AD0WINT
AMUX
GND Window
Compare
AD0LJST
AMX0N4
AMX0N3
AMX0N2
AMX0N1
AMX0N0
AD0SC4
AD0SC3
AD0SC2
AD0SC1
AD0SC0
32 Logic
ADC0LTH ADC0LTL
Rev. 1.3 41
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
The conversion code format differs between Single-ended and Differential modes. The registers ADC0H
and ADC0L contain the high and low bytes of the output conversion code from the ADC at the completion
of each conversion. Data can be right-justified or left-justified, depending on the setting of the AD0LJST bit
(ADC0CN.0). When in Single-ended Mode, conversion codes are represented as 10-bit unsigned integers.
Inputs are measured from ‘0’ to VREF x 1023/1024. Example codes are shown below for both right-justi-
fied and left-justified data. Unused bits in the ADC0H and ADC0L registers are set to ‘0’.
When in Differential Mode, conversion codes are represented as 10-bit signed 2’s complement numbers.
Inputs are measured from –VREF to VREF x 511/512. Example codes are shown below for both right-jus-
tified and left-justified data. For right-justified data, the unused MSBs of ADC0H are a sign-extension of the
data word. For left-justified data, the unused LSBs in the ADC0L register are set to ‘0’.
Important Note About ADC0 Input Configuration: Port pins selected as ADC0 inputs should be config-
ured as analog inputs, and should be skipped by the Digital Crossbar. To configure a Port pin for analog
input, set to ‘0’ the corresponding bit in register PnMDIN (for n = 0,1,2,3). To force the Crossbar to skip a
Port pin, set to ‘1’ the corresponding bit in register PnSKIP (for n = 0,1,2). See Section “15. Port Input/
Output” on page 142 for more Port I/O configuration details.
42 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Gain (V / deg C)
Voltage
Offset (V at 0 Celsius)
Temperature
Figure 5.2. Temperature Sensor Transfer Function
The uncalibrated temperature sensor output is extremely linear and suitable for relative temperature mea-
surements (see Table 5.1 for linearity specifications). For absolute temperature measurements, offset and/
or gain calibration is recommended. Typically a 1-point (offset) calibration includes the following steps:
Figure 5.3 shows the typical temperature sensor error assuming a 1-point calibration at 25 °C. Note that
parameters which affect ADC measurement, in particular the voltage reference value, will also
affect temperature measurement.
Rev. 1.3 43
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
5.0 5.0
0 0
4.0 4.0
0 0
3.0 3.0
0 0
2.0 2.0
0 0
Error (degrees C)
1.0 1.0
0 0
0.0 0.0
0-40.00 0.0 40.0 60.0 80.0 0
-20.00 20.0 0
0 0 0
0
-1.00 -1.00
-2.00 -2.00
-3.00 -3.00
-4.00 -4.00
-5.00 -5.00
Temperature (degrees C)
Figure 5.3. Temperature Sensor Error with 1-Point Calibration (VREF = 2.40 V)
44 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Writing a ‘1’ to AD0BUSY provides software control of ADC0 whereby conversions are performed
"on-demand". During conversion, the AD0BUSY bit is set to logic 1 and reset to logic 0 when the conver-
sion is complete. The falling edge of AD0BUSY triggers an interrupt (when enabled) and sets the ADC0
interrupt flag (AD0INT). Note: When polling for ADC conversion completions, the ADC0 interrupt flag
(AD0INT) should be used. Converted data is available in the ADC0 data registers, ADC0H:ADC0L, when
bit AD0INT is logic 1. Note that when Timer 2 or Timer 3 overflows are used as the conversion source, Low
Byte overflows are used if Timer 2/3 is in 8-bit mode; High byte overflows are used if Timer 2/3 is in 16-bit
mode. See Section “21. Timers” on page 235 for timer configuration.
Important Note About Using CNVSTR: The CNVSTR input pin also functions as a Port pin. When the
CNVSTR input is used as the ADC0 conversion source, the associated Port pin should be skipped by the
Digital Crossbar. To configure the Crossbar to skip a pin, set the corresponding bit in the PnSKIP register
to ‘1’. See Section “15. Port Input/Output” on page 142 for details on Port I/O configuration.
Rev. 1.3 45
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
1 2 3 4 5 6 7 8 9 10 11
SAR Clocks
SAR Clocks
Low Power
AD0TM=1 Track Convert Low Power Mode
or Convert
1 2 3 4 5 6 7 8 9 10 11
SAR Clocks
Track or
AD0TM=0 Convert Track
Convert
46 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Figure 5.5 shows the equivalent ADC0 input circuits for both Differential and Single-ended modes. Notice
that the equivalent time constant for both input circuits is the same. The required ADC0 settling time for a
given settling accuracy (SA) may be approximated by Equation 5.1. When measuring the Temperature
Sensor output or VDD with respect to GND, RTOTAL reduces to RMUX. See Table 5.1 for ADC0 minimum
settling time requirements.
n
t = ln ------- × R TOTAL C SAMPLE
2
SA
Equation 5.1. ADC0 Settling Time Requirements
Where:
SA is the settling accuracy, given as a fraction of an LSB (for example, 0.25 to settle within 1/4 LSB)
t is the required settling time in seconds
RTOTAL is the sum of the AMUX0 resistance and any external source resistance.
n is the ADC resolution in bits (10).
Px.x Px.x
RMUX = 5k RMUX = 5k
CSAMPLE = 5pF CSAMPLE = 5pF
CSAMPLE = 5pF
Px.x
RMUX = 5k
MUX Select
Rev. 1.3 47
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
48 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 49
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
AD0SC4 AD0SC3 AD0SC2 AD0SC1 AD0SC0 AD0LJST - - 11111000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xBC
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xBE
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xBD
50 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
AD0EN AD0TM AD0INT AD0BUSY AD0WINT AD0CM2 AD0CM1 AD0CM0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xE8
Rev. 1.3 51
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
The Window Detector registers must be written with the same format (left/right justified, signed/unsigned)
as that of the current ADC configuration (left/right justified, single-ended/differential).
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xC4
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xC3
52 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xC6
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xC5
Rev. 1.3 53
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
ADC0H:ADC0L ADC0H:ADC0L
Input Voltage Input Voltage
(Px.x - GND) (Px.x - GND)
AD0WINT
AD0WINT=1
not affected
0x0081 0x0081
VREF x (128/1024) 0x0080 ADC0LTH:ADC0LTL VREF x (128/1024) 0x0080 ADC0GTH:ADC0GTL
0x007F 0x007F
AD0WINT
AD0WINT=1
not affected
0x0041 0x0041
VREF x (64/1024) 0x0040 ADC0GTH:ADC0GTL VREF x (64/1024) 0x0040 ADC0LTH:ADC0LTL
0x003F 0x003F
AD0WINT AD0WINT=1
not affected
0 0x0000 0 0x0000
ADC0H:ADC0L ADC0H:ADC0L
Input Voltage Input Voltage
(Px.x - GND) (Px.x - GND)
AD0WINT
AD0WINT=1
not affected
0x2040 0x2040
VREF x (128/1024) 0x2000 ADC0LTH:ADC0LTL VREF x (128/1024) 0x2000 ADC0GTH:ADC0GTL
0x1FC0 0x1FC0
AD0WINT
AD0WINT=1
not affected
0x1040 0x1040
VREF x (64/1024) 0x1000 ADC0GTH:ADC0GTL VREF x (64/1024) 0x1000 ADC0LTH:ADC0LTL
0x0FC0 0x0FC0
AD0WINT AD0WINT=1
not affected
0 0x0000 0 0x0000
54 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
ADC0H:ADC0L ADC0H:ADC0L
Input Voltage Input Voltage
(Px.x - Px.x) (Px.x - Px.x)
AD0WINT
AD0WINT=1
not affected
0x0041 0x0041
VREF x (64/512) 0x0040 ADC0LTH:ADC0LTL VREF x (64/512) 0x0040 ADC0GTH:ADC0GTL
0x003F 0x003F
AD0WINT
AD0WINT=1
not affected
0x0000 0x0000
VREF x (-1/512) 0xFFFF ADC0GTH:ADC0GTL VREF x (-1/512) 0xFFFF ADC0LTH:ADC0LTL
0xFFFE 0xFFFE
AD0WINT AD0WINT=1
not affected
ADC0H:ADC0L ADC0H:ADC0L
Input Voltage Input Voltage
(Px.x - Px.x) (Px.x - Px.y)
AD0WINT
AD0WINT=1
not affected
0x1040 0x1040
VREF x (64/512) 0x1000 ADC0LTH:ADC0LTL VREF x (64/512) 0x1000 ADC0GTH:ADC0GTL
0x0FC0 0x0FC0
AD0WINT
AD0WINT=1
not affected
0x0000 0x0000
VREF x (-1/512) 0xFFC0 ADC0GTH:ADC0GTL VREF x (-1/512) 0xFFC0 ADC0LTH:ADC0LTL
0xFF80 0xFF80
AD0WINT AD0WINT=1
not affected
Rev. 1.3 55
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
56 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
The BIASE bit enables the internal ADC bias generator, which is used by the ADC and Internal Oscillator.
This enable is forced to logic 1 when either of the aforementioned peripherals is enabled. The ADC bias
generator may be enabled manually by writing a ‘1’ to the BIASE bit in register REF0CN; see SFR Defini-
tion 6.1 for REF0CN register details. The Reference bias generator (see Figure 6.1) is used by the Internal
Voltage Reference, Temperature Sensor, and Clock Multiplier. The Reference bias is automatically
enabled when any of the aforementioned peripherals are enabled. The electrical specifications for the volt-
age reference and bias circuits are given in Table 6.1.
Important Note About the VREF Pin: The VREF pin, when not using the on-chip voltage reference or an
external precision reference, can be configured as a GPIO Port pin. When using an external voltage refer-
ence or the on-chip reference, the VREF pin should be configured as analog pin and skipped by the Digital
Crossbar. To configure the VREF pin for analog mode, set the corresponding bit in the PnMDIN register to
‘0’. To configure the Crossbar to skip the VREF pin, set the corresponding bit in register PnSKIP to ‘1’.
Refer to Section “15. Port Input/Output” on page 142 for complete Port I/O configuration details.
The temperature sensor connects to the ADC0 positive input multiplexer (see Section “5.1. Analog Multi-
plexer” on page 42 for details). The TEMPE bit in register REF0CN enables/disables the temperature
sensor. While disabled, the temperature sensor defaults to a high impedance state and any ADC0 mea-
surements performed on the sensor result in meaningless data.
REF0CN
TEMPE
REFBE
REFSL
BIASE
AD0EN
EN To ADC,
ADC Bias
Internal Oscillator
IOSCEN
VDD External
Voltage EN
Reference Temp Sensor To Analog Mux
R1 Circuit
VREF
0
VREF
(to ADC)
GND
VDD 1
CLKMUL
Enable
EN Reference To Clock Multiplier,
TEMPE Bias Temp Sensor
REFBE
EN
Internal
Reference
Rev. 1.3 57
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - REFSL TEMPE BIASE REFBE 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xD1
58 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
7. Comparators
C8051F34x devices include two on-chip programmable voltage Comparators. A block diagram of the com-
parators is shown in Figure 7.1, where “n” is the comparator number (0 or 1). The two Comparators oper-
ate identically with the following exceptions: (1) Their input selections differ, and (2) Comparator0 can be
used as a reset source. For input selection details, refer to SFR Definition 7.2 and SFR Definition 7.5.
Each Comparator offers programmable response time and hysteresis, an analog input multiplexer, and two
outputs that are optionally available at the Port pins: a synchronous “latched” output (CP0, CP1), or an
asynchronous “raw” output (CP0A, CP1A). The asynchronous signal is available even when the system
clock is not active. This allows the Comparators to operate and generate an output with the device in
STOP mode. When assigned to a Port pin, the Comparator outputs may be configured as open drain or
push-pull (see Section “15.2. Port I/O Initialization” on page 147). Comparator0 may also be used as a
reset source (see Section “11.5. Comparator0 Reset” on page 103).
The Comparator0 inputs are selected in the CPT0MX register (SFR Definition 7.2). The CMX0P1-CMX0P0
bits select the Comparator0 positive input; the CMX0N1-CMX0N0 bits select the Comparator0 negative
input. The Comparator1 inputs are selected in the CPT1MX register (SFR Definition 7.5). The CMX-
1P1-CMX1P0 bits select the Comparator1 positive input; the CMX1N1-CMX1N0 bits select the Compara-
tor1 negative input.
Important Note About Comparator Inputs: The Port pins selected as Comparator inputs should be con-
figured as analog inputs in their associated Port configuration register, and configured to be skipped by the
Crossbar (for details on Port configuration, see Section “15.3. General Purpose Port I/O” on page 150).
Rev. 1.3 59
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
CPnEN
CPnOUT
CPnRIF VDD
CPTnCN
CPnFIF
CMXnN2 CPnHYP1
CMXnN1 CPn
CPTnMX
CPnHYP0
CMXnN0 Interrupt
CPnHYN1
CPnHYN0
CMXnP2
CMXnP1
CMXnP0
CPn CPn
Rising-edge Falling-edge
Interrupt CPnRIE
CPn +
Logic CPnFIE
+
D
SET
Q D
SET
Q CPn
- CLR Q CLR Q
Crossbar
(SYNCHRONIZER)
GND
CPnA
CPn -
CPnMD1
CPnMD0
Comparator outputs can be polled in software, used as an interrupt source, and/or routed to a Port pin.
When routed to a Port pin, Comparator outputs are available asynchronous or synchronous to the system
clock; the asynchronous output is available even in STOP mode (with no system clock active). When dis-
abled, the Comparator output (if assigned to a Port I/O pin via the Crossbar) defaults to the logic low state,
and supply current falls to less than 100 nA. See Section “15.1. Priority Crossbar Decoder” on
page 144 for details on configuring Comparator outputs via the digital Crossbar. Comparator inputs can be
externally driven from –0.25 V to (VDD) + 0.25 V without damage or upset. The complete Comparator elec-
trical specifications are given in Table 7.1.
Comparator response time may be configured in software via the CPTnMD registers (see SFR Definition
7.3 and SFR Definition 7.6). Selecting a longer response time reduces the Comparator supply current. See
Table 7.1 for complete timing and supply current specifications.
60 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
CP0+
VIN+ +
CP0 OUT
CP0- _
VIN-
CIRCUIT CONFIGURATION
VOH
OUTPUT
VOL
Negative Hysteresis Maximum
Disabled Negative Hysteresis
Comparator hysteresis is programmed using Bits3-0 in the Comparator Control Register CPTnCN (shown
in SFR Definition 7.1 and SFR Definition 7.4). The amount of negative hysteresis voltage is determined by
the settings of the CPnHYN bits. As shown in Figure 7.2, various levels of negative hysteresis can be
programmed, or negative hysteresis can be disabled. In a similar way, the amount of positive hysteresis is
determined by the setting the CPnHYP bits.
Comparator interrupts can be generated on both rising-edge and falling-edge output transitions. (For Inter-
rupt enable and priority control, see Section “9.3. Interrupt Handler” on page 88.) The CPnFIF flag is set
to ‘1’ upon a Comparator falling-edge, and the CPnRIF flag is set to ‘1’ upon the Comparator rising-edge.
Once set, these bits remain set until cleared by software. The output state of the Comparator can be
obtained at any time by reading the CPnOUT bit. The Comparator is enabled by setting the CPnEN bit to
‘1’, and is disabled by clearing this bit to ‘0’.
Rev. 1.3 61
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
62 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- CMX0N2 CMX0N1 CMX0N0 - CMX0P2 CMX0P1 CMX0P0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x9F
Note that the port pins used by the comparator depend on the package type (32-pin or 48-pin).
Rev. 1.3 63
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - CP0RIE CP0FIE - - CP0MD1 CP0MD0 00000010
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x9D
64 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 65
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- CMX1N2 CMX1N1 CMX1N0 - CMX1P2 CMX1P1 CMX1P0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x9E
Note that the port pins used by the comparator depend on the package type (32-pin or 48-pin).
66 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - CP1RIE CP1FIE - - CP1MD1 CP1MD0 00000010
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x9C
Rev. 1.3 67
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
68 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Note that the VBUS signal must be connected to the VBUS pin when using the device in a USB network.
The VBUS signal should only be connected to the REGIN pin when operating the device as a bus-powered
function. REG0 configuration options are shown in Figure 8.1–Figure 8.4.
Important Note: When USB is selected as a reset source, a system reset will be generated when the
VBUS signal matches the polarity selected by the VBPOL bit. See Section “11. Reset Sources” on
page 100 for details on selecting USB as a reset source
Rev. 1.3 69
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
VBUS
REGIN
5 V In Voltage Regulator (REG0)
3 V Out
To 3 V VDD Device
Power Net Power Net
VBUS
From VBUS
VBUS Sense
From 5 V REGIN
5 V In Voltage Regulator (REG0)
Power Net
3 V Out
To 3 V VDD Device
Power Net Power Net
70 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
VBUS
From VBUS
VBUS Sense
REGIN
5 V In Voltage Regulator (REG0)
3 V Out
VBUS
VBUS Sense
From 5 V REGIN
5 V In Voltage Regulator (REG0)
Power Net
3 V Out
To 3 V VDD Device
Power Net Power Net
Rev. 1.3 71
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
72 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
9. CIP-51 Microcontroller
The MCU system controller core is the CIP-51 microcontroller. The CIP-51 is fully compatible with the
MCS-51™ instruction set; standard 803x/805x assemblers and compilers can be used to develop soft-
ware. The MCU family has a superset of all the peripherals included with a standard 8051. Included are
four 16-bit counter/timers (see description in Section 21), an enhanced full-duplex UART (see description
in Section 18), an Enhanced SPI (see description in Section 20), 256 bytes of internal RAM, 128 byte
Special Function Register (SFR) address space (Section 9.2.6), and 25 Port I/O (see description in Sec-
tion 15). The CIP-51 also includes on-chip debug hardware (see description in Section 23), and interfaces
directly with the analog and digital subsystems providing a complete data acquisition or control-system
solution in a single integrated circuit.
The CIP-51 Microcontroller core implements the standard 8051 organization and peripherals as well as
additional custom peripherals and functions to extend its capability (see Figure 9.1 for a block diagram).
The CIP-51 includes the following features:
DATA BUS
D8
D8
D8
D8
D8
TMP1 TMP2
SRAM
PSW SRAM
ADDRESS
(256 X 8)
ALU REGISTER
D8
D8
D8
D8
DATA BUS
SFR_ADDRESS
BUFFER D8
SFR_CONTROL
SFR
D8 BUS SFR_WRITE_DATA
DATA POINTER D8
INTERFACE
SFR_READ_DATA
PC INCREMENTER
DATA BUS
D8 MEM_ADDRESS
PROGRAM COUNTER (PC)
MEM_CONTROL
MEMORY
PRGM. ADDRESS REG. A16 INTERFACE MEM_WRITE_DATA
MEM_READ_DATA
PIPELINE D8
RESET CONTROL
LOGIC SYSTEM_IRQs
CLOCK
INTERRUPT
D8
INTERFACE EMULATION_IRQ
STOP
POWER CONTROL
D8
IDLE REGISTER
Rev. 1.3 73
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Performance
The CIP-51 employs a pipelined architecture that greatly increases its instruction throughput over the stan-
dard 8051 architecture. In a standard 8051, all instructions except for MUL and DIV take 12 or 24 system
clock cycles to execute, and usually have a maximum system clock of 12 MHz. By contrast, the CIP-51
core executes 70% of its instructions in one or two system clock cycles, with no instructions taking more
than eight system clock cycles.
With the CIP-51's maximum system clock at 25 MHz, it has a peak throughput of 25 MIPS. The CIP-51 has
a total of 109 instructions. The table below shows the total number of instructions that for execution time.
The on-chip Silicon Labs 2-Wire (C2) Development Interface allows non-intrusive (uses no on-chip
resources), full speed, in-circuit debugging using the production MCU installed in the final application. This
debug logic supports inspection and modification of memory and registers, setting breakpoints, single
stepping, run and halt commands. All analog and digital peripherals are fully functional while debugging
using C2. The two C2 interface pins can be shared with user functions, allowing in-system debugging with-
out occupying package pins. C2 details can be found in Section “23. C2 Interface” on page 271.
The CIP-51 is supported by development tools from Silicon Labs and third party vendors. Silicon Labs pro-
vides an integrated development environment (IDE) including editor, debugger, and programmer. The
IDE's debugger and programmer interface to the CIP-51 via the C2 interface to provide fast and efficient
in-system device programming and debugging. An 8051 assembler, linker and evaluation ‘C’ compiler are
included in the Development Kit. Many third party macro assemblers and C compilers are also available,
which can be used directly with the IDE.
Due to the pipelined architecture of the CIP-51, most instructions execute in the same number of clock
cycles as there are program bytes in the instruction. Conditional branch instructions take two fewer clock
cycles to complete when the branch is not taken as opposed to when the branch is taken. Table 9.1 is the
CIP-51 Instruction Set Summary, which includes the mnemonic, number of bytes, and number of clock
cycles for each instruction.
74 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 75
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
76 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 77
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
rel - 8-bit, signed (two’s complement) offset relative to the first byte of the following instruction. Used by
SJMP and all conditional jumps.
direct - 8-bit internal data location’s address. This could be a direct-access Data RAM location
(0x00-0x7F) or an SFR (0x80-0xFF).
addr11 - 11-bit destination address used by ACALL and AJMP. The destination must be within the same
2K-byte page of program memory as the first byte of the following instruction.
addr16 - 16-bit destination address used by LCALL and LJMP. The destination may be anywhere within
the 8K-byte program memory space.
There is one unused opcode (0xA5) that performs the same function as NOP.
All mnemonics copyrighted © Intel Corporation 1980.
78 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Off-Chip XRAM
(Available only on devices
with EMIF)
0x1000
0x0FFF
0x0000
Rev. 1.3 79
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
0xFFFF
Off-Chip XRAM
(Available only on devices
with EMIF)
0x0800
0x07FF USB FIFOs 0x07FF
XRAM - 2048 Bytes 1024 Bytes
(Accessable using MOVX 0x0400
instruction)
0x0000
Program memory is normally assumed to be read-only. However, the CIP-51 can write to program memory
by setting the Program Store Write Enable bit (PSCTL.0) and using the MOVX instruction. This feature pro-
vides a mechanism for the CIP-51 to update program code and use the program memory space for
non-volatile data storage. Refer to Section “12. Flash Memory” on page 107 for further details.
80 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
The upper 128 bytes of data memory are accessible only by indirect addressing. This region occupies the
same address space as the Special Function Registers (SFR) but is physically separate from the SFR
space. The addressing mode used by an instruction when accessing locations above 0x7F determines
whether the CPU accesses the upper 128 bytes of data memory space or the SFRs. Instructions that use
direct addressing will access the SFR space. Instructions using indirect addressing above 0x7F access the
upper 128 bytes of data memory. Figure 9.2 illustrates the data memory organization of the CIP-51.
The MCS-51™ assembly language allows an alternate notation for bit addressing of the form XX.B where
XX is the byte address and B is the bit position within the byte. For example, the instruction:
MOV C, 22h.3
moves the Boolean value at 0x13 (bit 3 of the byte at location 0x22) into the Carry flag.
9.2.5. Stack
A programmer's stack can be located anywhere in the 256-byte data memory. The stack area is desig-
nated using the Stack Pointer (SP, 0x81) SFR. The SP will point to the last location used. The next value
pushed on the stack is placed at SP+1 and then SP is incremented. A reset initializes the stack pointer to
location 0x07. Therefore, the first value pushed on the stack is placed at location 0x08, which is also the
first register (R0) of register bank 1. Thus, if more than one register bank is to be used, the SP should be
initialized to a location in the data memory not being used for data storage. The stack depth can extend up
to 256 bytes.
Rev. 1.3 81
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
The SFR registers are accessed anytime the direct addressing mode is used to access memory locations
from 0x80 to 0xFF. SFRs with addresses ending in 0x0 or 0x8 (e.g. P0, TCON, SCON0, IE, etc.) are
bit-addressable as well as byte-addressable. All other SFRs are byte-addressable only. Unoccupied
addresses in the SFR space are reserved for future use. Accessing these areas will have an indeterminate
effect and should be avoided. Refer to the corresponding pages of the datasheet, as indicated in Table 9.3,
for a detailed description of each register.
82 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 83
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
84 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 85
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x82
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x83
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x81
86 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
ACC.7 ACC.6 ACC.5 ACC.4 ACC.3 ACC.2 ACC.1 ACC.0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xE0
Rev. 1.3 87
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
B.7 B.6 B.5 B.4 B.3 B.2 B.1 B.0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xF0
Bits7–0: B: B Register.
This register serves as a second accumulator for certain arithmetic operations.
If interrupts are enabled for the source, an interrupt request is generated when the interrupt-pending flag is
set. As soon as execution of the current instruction is complete, the CPU generates an LCALL to a prede-
termined address to begin execution of an interrupt service routine (ISR). Each ISR must end with an RETI
instruction, which returns program execution to the next instruction that would have been executed if the
interrupt request had not occurred. If interrupts are not enabled, the interrupt-pending flag is ignored by the
hardware and program execution continues as normal. (The interrupt-pending flag is set to logic 1 regard-
less of the interrupt's enable/disable state.)
Each interrupt source can be individually enabled or disabled through the use of an associated interrupt
enable bit in an SFR (IE-EIE2). However, interrupts must first be globally enabled by setting the EA bit
(IE.7) to logic 1 before the individual interrupt enables are recognized. Setting the EA bit to logic 0 disables
all interrupt sources regardless of the individual interrupt-enable settings.
Some interrupt-pending flags are automatically cleared by the hardware when the CPU vectors to the ISR.
However, most are not cleared by the hardware and must be cleared by software before returning from the
ISR. If an interrupt-pending flag remains set after the CPU completes the return-from-interrupt (RETI)
instruction, a new interrupt request will be generated immediately and the CPU will re-enter the ISR after
the completion of the next instruction.
88 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
INT0 and INT1 are assigned to Port pins as defined in the IT01CF register (see SFR Definition 9.13). Note
that INT0 and INT0 Port pin assignments are independent of any Crossbar assignments. INT0 and INT1
will monitor their assigned Port pins without disturbing the peripheral that was assigned the Port pin via the
Crossbar. To assign a Port pin only to INT0 and/or INT1, configure the Crossbar to skip the selected pin(s).
This is accomplished by setting the associated bit in register XBR0 (see Section “15.1. Priority Crossbar
Decoder” on page 144 for complete details on configuring the Crossbar). In the typical configuration, the
external interrupt pin should be skipped in the crossbar and configured as open-drain with the pin latch set
to '1'.
IE0 (TCON.1) and IE1 (TCON.3) serve as the interrupt-pending flags for the INT0 and INT1 external inter-
rupts, respectively. If an INT0 or INT1 external interrupt is configured as edge-sensitive, the corresponding
interrupt-pending flag is automatically cleared by the hardware when the CPU vectors to the ISR. When
configured as level sensitive, the interrupt-pending flag remains logic 1 while the input is active as defined
by the corresponding polarity bit (IN0PL or IN1PL); the flag remains logic 0 while the input is inactive. The
external interrupt source must hold the input active until the interrupt request is recognized. It must then
deactivate the interrupt request before execution of the ISR completes or another interrupt request will be
generated.
Note that the CPU is stalled during Flash write/erase operations and USB FIFO MOVX accesses (see
Section “13.2. Accessing USB FIFO Space” on page 115). Interrupt service latency will be increased for
interrupts occurring while the CPU is stalled. The latency for these situations will be determined by the
standard interrupt service procedure (as described above) and the amount of time the CPU is stalled.
Rev. 1.3 89
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Bit addressable?
Cleared by HW?
Interrupt Priority Enable Priority
Interrupt Source Pending Flag
Vector Order Flag Control
Always Always
Reset 0x0000 Top None N/A N/A
Enabled Highest
External Interrupt 0
0x0003 0 IE0 (TCON.1) Y Y EX0 (IE.0) PX0 (IP.0)
(INT0)
Timer 0 Overflow 0x000B 1 TF0 (TCON.5) Y Y ET0 (IE.1) PT0 (IP.1)
External Interrupt 1
0x0013 2 IE1 (TCON.3) Y Y EX1 (IE.2) PX1 (IP.2)
(INT1)
Timer 1 Overflow 0x001B 3 TF1 (TCON.7) Y Y ET1 (IE.3) PT1 (IP.3)
RI0 (SCON0.0)
UART0 0x0023 4 Y N ES0 (IE.4) PS0 (IP.4)
TI0 (SCON0.1)
TF2H (TMR2CN.7)
Timer 2 Overflow 0x002B 5 Y N ET2 (IE.5) PT2 (IP.5)
TF2L (TMR2CN.6)
SPIF (SPI0CN.7)
WCOL (SPI0CN.6) ESPI0 PSPI0
SPI0 0x0033 6 Y N
MODF (SPI0CN.5) (IE.6) (IP.6)
RXOVRN (SPI0CN.4)
ESMB0 PSMB0
SMB0 0x003B 7 SI (SMB0CN.0) Y N
(EIE1.0) (EIP1.0)
EUSB0 PUSB0
USB0 0x0043 8 Special N N
(EIE1.1) (EIP1.1)
ADC0 Window AD0WINT EWADC0 PWADC0
0x004B 9 Y N
Compare (ADC0CN.3) (EIE1.2) (EIP1.2)
ADC0 Conversion EADC0 PADC0
0x0053 10 AD0INT (ADC0CN.5) Y N
Complete (EIE1.3) (EIP1.3)
Programmable Counter CF (PCA0CN.7) EPCA0 PPCA0
0x005B 11 Y N
Array CCFn (PCA0CN.n) (EIE1.4) (EIP1.4)
CP0FIF (CPT0CN.4) ECP0 PCP0
Comparator0 0x0063 12 N N
CP0RIF (CPT0CN.5) (EIE1.5) (EIP1.5)
CP1FIF (CPT1CN.4) ECP1 PCP1
Comparator1 0x006B 13 N N
CP1RIF (CPT1CN.5) (EIE1.6) (EIP1.6)
TF3H (TMR3CN.7) ET3 PT3
Timer 3 Overflow 0x0073 14 N N
TF3L (TMR3CN.6) (EIE1.7) (EIP1.7)
EVBUS PVBUS
VBUS Level 0x007B 15 N/A N/A N/A
(EIE2.0) (EIP2.0)
RI1 (SCON1.0) ES1 PS1
UART1 0x0083 16 N N
TI1 (SCON1.1) (EIE2.1) (EIP2.1)
9.3.5. Interrupt Register Descriptions
The SFRs used to enable the interrupt sources and set their priority level are described below. Refer to the
datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt
conditions for the peripheral and the behavior of its interrupt-pending flag(s).
90 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
EA ESPI0 ET2 ES0 ET1 EX1 ET0 EX0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xA8
Rev. 1.3 91
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- PSPI0 PT2 PS0 PT1 PX1 PT0 PX0 10000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xB8
92 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
ET3 ECP1 ECP0 EPCA0 EADC0 EWADC0 EUSB0 ESMB0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xE6
Rev. 1.3 93
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
PT3 PCP1 PCP0 PPCA0 PADC0 PWADC0 PUSB0 PSMB0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF6
94 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - - - ES1 EVBUS 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xE7
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - - - PS1 PVBUS 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF7
Rev. 1.3 95
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
IN1PL IN1SL2 IN1SL1 IN1SL0 IN0PL IN0SL2 IN0SL1 IN0SL0 00000001
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xE4
Note: Refer to SFR Definition 21.1 for INT0/1 edge- or level-sensitive interrupt selection.
96 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Although the CIP-51 has Idle and Stop modes built in (as with any standard 8051 architecture), power
management of the entire MCU is better accomplished through system clock and individual peripheral
management. Each analog peripheral can be disabled when not in use and placed in low power mode.
Digital peripherals, such as timers or serial buses, draw little power when they are not in use. Turning off
the oscillators lowers power consumption considerably; however a reset is required to restart the MCU.
The internal oscillator can be placed in Suspend mode (see Section “14. Oscillators” on page 131). In
Suspend mode, the internal oscillator is stopped until a non-idle USB event is detected, or the VBUS input
signal matches the polarity selected by the VBPOL bit in register REG0CN (SFR Definition 8.1).
Idle mode is terminated when an enabled interrupt is asserted or a reset occurs. The assertion of an
enabled interrupt will cause the Idle Mode Selection bit (PCON.0) to be cleared and the CPU to resume
operation. The pending interrupt will be serviced and the next instruction to be executed after the return
from interrupt (RETI) will be the instruction immediately following the one that set the Idle Mode Select bit.
If Idle mode is terminated by an internal or external reset, the CIP-51 performs a normal reset sequence
and begins program execution at address 0x0000.
If enabled, the Watchdog Timer (WDT) will eventually cause an internal watchdog reset and thereby termi-
nate the Idle mode. This feature protects the system from an unintended permanent shutdown in the event
of an inadvertent write to the PCON register. If this behavior is not desired, the WDT may be disabled by
software prior to entering the Idle mode if the WDT was initially configured to allow this operation. This pro-
vides the opportunity for additional power savings, allowing the system to remain in the Idle mode indefi-
nitely, waiting for an external stimulus to wake up the system. Refer to Section “11.6. PCA Watchdog
Timer Reset” on page 103 for more information on the use and configuration of the WDT.
If enabled, the Missing Clock Detector will cause an internal reset and thereby terminate the Stop mode.
The Missing Clock Detector should be disabled if the CPU is to be put to in STOP mode for longer than the
MCD timeout of 100 µsec.
Rev. 1.3 97
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
GF5 GF4 GF3 GF2 GF1 GF0 STOP IDLE 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x87
98 Rev. 1.3
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
Rev. 1.3 99
C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D
All SFRs are reset to the predefined values noted in the SFR detailed descriptions. The contents of internal
data memory are unaffected during a reset; any previously stored data is preserved. However, since the
stack pointer SFR is reset, the stack is effectively lost even though the data on the stack is not altered.
The Port I/O latches are reset to 0xFF (all logic ones) in open-drain mode. Weak pull-ups are enabled
during and after the reset. For VDD Monitor and Power-On Resets, the RST pin is driven low until the
device exits the reset state.
On exit from the reset state, the program counter (PC) is reset, and the system clock defaults to the inter-
nal oscillator. Refer to Section “14. Oscillators” on page 131 for information on selecting and configuring
the system clock source. The Watchdog Timer is enabled with the system clock divided by 12 as its clock
source (Section “22.3. Watchdog Timer Mode” on page 264 details the use of the Watchdog Timer).
Program execution begins at location 0x0000.
VDD
Supply
Monitor
+ Enable
-
Power On
Reset '0' RST
Comparator 0 (wired-OR)
Px.x
+
-
Px.x C0RSEF
Missing
Clock
Detector Reset
(one- Funnel
shot) PCA
WDT Software Reset (SWRSF)
EN
Errant
EN FLASH
Enable
Internal LF Operation
Enable
Enable
WDT
MCD
Oscillator
Internal HF
Oscillator
System
Clock USB VBUS
Clock CIP-51 Controller Transition
Multiplier
Microcontroller System Reset
On exit from a power-on reset, the PORSF flag (RSTSRC.1) is set by hardware to logic 1. When PORSF is
set, all of the other reset flags in the RSTSRC Register are indeterminate (PORSF is cleared by all other
resets). Since all resets cause program execution to begin at the same location (0x0000) software can
read the PORSF flag to determine if a power-up was the cause of reset. The content of internal data mem-
ory should be assumed to be undefined after a power-on reset. The VDD monitor is enabled following a
power-on reset.
Software can force a power-on reset by writing ‘1’ to the PINRSF bit in register RSTSRC.
volts
VDD
2.70 VRST
2.4
2.0
D
VD
1.0
RST
Logic HIGH
TPORDelay
Logic LOW
VDD
Power-On Monitor
Reset Reset
See Figure 11.2 for VDD monitor timing. See Table 11.1 for complete electrical characteristics of the VDD
monitor.
• A Flash write or erase is attempted above user code space. This occurs when PSWE is set to “1”, and
a MOVX write operation is attempted above address 0x7FFF (32 kB Flash devices) or 0xFBFF (64 kB
Flash devices).
• A Flash read is attempted above user code space. This occurs when a MOVC operation is attempted
above address 0x7FFF (32 kB Flash devices) or 0xFBFF (64 kB Flash devices).
• A Program read is attempted above user code space. This occurs when user code attempts to branch
to an address above 0x7FFF (32 kB Flash devices) or 0xFBFF (64 kB Flash devices).
• A Flash read, write or erase attempt is restricted due to a Flash security setting (see Section
“12.3. Security Options” on page 109).
• A Flash Write or Erase is attempted when the VDD monitor is not enabled.
The FERROR bit (RSTSRC.6) is set following a Flash error reset. The state of the RST pin is unaffected by
this reset.
1. RESET signaling is detected on the USB network. The USB Function Controller (USB0) must
be enabled for RESET signaling to be detected. See Section “16. Universal Serial Bus Con-
troller (USB0)” on page 159 for information on the USB Function Controller.
2. The voltage on the VBUS pin matches the polarity selected by the VBPOL bit in register
REG0CN. See Section “8. Voltage Regulator (REG0)” on page 69 for details on the VBUS
detection circuit.
The USBRSF bit will read ‘1’ following a USB reset. The state of the RST pin is unaffected by this reset.
Note: For bits that act as both reset source enables (on a write) and reset indicator flags (on a
read), read-modify-write instructions read and modify the source enable only. This applies to
bits: USBRSF, C0RSEF, SWRSF, MCDRSF, PORSF.
To ensure the integrity of Flash contents, it is strongly recommended that the VDD monitor be left
enabled in any system which writes or erases Flash memory from code. It is also crucial to ensure
that the FLRT bit in register FLSCL be set to '1' if a clock speed higher than 25 MHz is being used
for the device.
A write to Flash memory can clear bits to logic 0 but cannot set them; only an erase operation can set bits
to logic 1 in Flash. A byte location to be programmed must be erased before a new value is written.
The Flash memory is organized in 512-byte pages. The erase operation applies to an entire page (setting
all bytes in the page to 0xFF). To erase an entire 512-byte page, perform the following steps:
For block Flash writes, the Flash write procedure is only performed after the last byte of each block is writ-
ten with the MOVX write instruction. A Flash write block is two bytes long, from even addresses to odd
addresses. Writes must be performed sequentially (i.e. addresses ending in 0b and 1b must be written in
order). The Flash write will be performed following the MOVX write that targets the address ending in 1b. If
a byte in the block does not need to be updated in Flash, it should be written to 0xFF. The recommended
procedure for writing Flash in blocks is:
A Security Lock Byte located at the last byte of Flash user space offers protection of the Flash program
memory from access (reads, writes, or erases) by unprotected code or the C2 interface. The Flash security
mechanism allows the user to lock n 512-byte Flash pages, starting at page 0 (addresses 0x0000 to
0x01FF), where n is the 1’s complement number represented by the Security Lock Byte. Note that the
page containing the Flash Security Lock Byte is also locked when any other Flash pages are locked. See
example below.
C8051F340/2/4/6/A/C/D
Reserved
0xFC00
Lock Byte 0xFBFF
Locked when any
0xFBFE other FLASH pages
are locked
0xFA00 C8051F341/3/5/7/8/9/B
FLASH memory Lock Byte 0x7FFF
organized in 512-byte
0x7FFE
pages
Unlocked FLASH Pages 0x7E00
0x0000 0x0000
The level of FLASH security depends on the FLASH access method. The three FLASH access methods
that can be restricted are reads, writes, and erases from the C2 debug interface, user firmware executing
on unlocked pages, and user firmware executing on locked pages.
1. Any unlocked page except the page containing the Lock Byte may be read, written, or erased.
2. Locked pages cannot be read, written, or erased.
3. The page containing the Lock Byte cannot be erased. It may be read or written only if it is
unlocked.
4. Reading the contents of the Lock Byte is always permitted.
5. Locking additional pages (changing ‘1’s to ‘0’s in the Lock Byte) is not permitted.
6. Unlocking FLASH pages (changing ‘0’s to ‘1’s in the Lock Byte) is not permitted.
7. The Reserved Area cannot be read, written, or erased. Any attempt to access the reserved
area, or any other locked page, will result in a FLASH Error device reset.
1. Any unlocked page except the page containing the Lock Byte may be read, written, or erased.
2. Any locked page except the page containing the Lock Byte may be read, written, or erased.
3. The page containing the Lock Byte cannot be erased. It may only be read or written.
4. Reading the contents of the Lock Byte is always permitted.
5. Locking additional pages (changing ‘1’s to ‘0’s in the Lock Byte) is not permitted.
6. Unlocking FLASH pages (changing ‘0’s to ‘1’s in the Lock Byte) is not permitted.
7. The Reserved Area cannot be read, written, or erased. Any attempt to access the reserved
area, or any other locked page, will result in a FLASH Error device reset.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - - Reserved PSEE PSWE 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x8F
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xB7
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
FOSE Reserved Reserved FLRT Reserved Reserved Reserved Reserved 10000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xB6
MOV DPTR, #1234h ; load DPTR with 16-bit address to read (0x1234)
MOVX A, @DPTR ; load contents of 0x1234 into accumulator A
The above example uses the 16-bit immediate MOV instruction to set the contents of DPTR. Alternately,
the DPTR can be accessed through the SFR registers DPH, which contains the upper 8-bits of DPTR, and
DPL, which contains the lower 8-bits of DPTR.
Unused areas of the USB FIFO space may be used as general purpose XRAM if necessary. The FIFO
block operates on the USB clock domain; thus the USB clock must be active when accessing FIFO space.
Note that the number of SYSCLK cycles required by the MOVX instruction is increased when accessing
USB FIFO space.
To access the FIFO RAM directly using MOVX instructions, the following conditions must be met: (1) the
USBFAE bit in register EMI0CF must be set to '1', and (2) the USB clock must be greater than or equal to
twice the SYSCLK (USBCLK > 2 x SYSCLK). When this bit is set, the USB FIFO space is mapped into
XRAM space at addresses 0x0400 to 0x07FF. The normal XRAM (on-chip or external) at the same
addresses cannot be accessed when the USBFAE bit is set to ‘1’.
Important Note: The USB clock must be active when accessing FIFO space.
0xFFFF
On/Off-Chip XRAM
0x0800
0x07FF
Endpoint0
(64 bytes)
0x07C0
0x07BF
Endpoint1
(128 bytes)
0x0740
0x073F
Endpoint2
(256 bytes)
0x0640 USB FIFO Space
(USB Clock Domain)
0x063F
Endpoint3
(512 bytes)
0x0440
0x043F
Free
(64 bytes)
0x0400
0x03FF
On/Off-Chip XRAM
0x0000
Figure 13.1. USB FIFO Space and XRAM Memory Map with USBFAE set to ‘1’
1. Configure the Output Modes of the associated port pins as either push-pull or open-drain
(push-pull is most common), and skip the associated pins in the crossbar.
2. Configure Port latches to “park” the EMIF pins in a dormant state (usually by setting them to
logic ‘1’).
3. Select Multiplexed mode or Non-multiplexed mode.
4. Select the memory mode (on-chip only, split mode without bank select, split mode with bank
select, or off-chip only).
5. Set up timing to interface with off-chip memory or peripherals.
Each of these five steps is explained in detail in the following sections. The Port selection, Multiplexed
mode selection, and Mode bits are located in the EMI0CF register shown in SFR Definition 13.2.
The External Memory Interface claims the associated Port pins for memory operations ONLY during the
execution of an off-chip MOVX instruction. Once the MOVX instruction has completed, control of the Port
pins reverts to the Port latches or to the Crossbar settings for those pins. See Section “15. Port Input/
Output” on page 142 for more information about the Crossbar and Port operation and configuration. The
Port latches should be explicitly configured to ‘park’ the External Memory Interface pins in a dor-
mant state, most commonly by setting them to a logic 1.
During the execution of the MOVX instruction, the External Memory Interface will explicitly disable the driv-
ers on all Port pins that are acting as Inputs (Data[7:0] during a READ operation, for example). The Output
mode of the Port pins (whether the pin is configured as Open-Drain or Push-Pull) is unaffected by the
External Memory Interface operation, and remains controlled by the PnMDOUT registers. In most cases,
the output modes of all EMIF pins should be configured for push-pull mode.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
PGSEL7 PGSEL6 PGSEL5 PGSEL4 PGSEL3 PGSEL2 PGSEL1 PGSEL0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xAA
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- USBFAE - EMD2 EMD1 EMD0 EALE1 EALE0 00000011
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0x85
In Multiplexed mode, the external MOVX operation can be broken into two phases delineated by the state
of the ALE signal. During the first phase, ALE is high and the lower 8-bits of the Address Bus are pre-
sented to AD[7:0]. During this phase, the address latch is configured such that the ‘Q’ outputs reflect the
states of the ‘D’ inputs. When ALE falls, signaling the beginning of the second phase, the address latch
outputs remain fixed and are no longer dependent on the latch inputs. Later in the second phase, the Data
Bus controls the state of the AD[7:0] port at the time RD or WR is asserted.
See Section “13.7.2. Multiplexed Mode” on page 127 for more information.
74HC373
ALE G
E
AD[7:0] ADDRESS/DATA BUS D Q A[7:0]
M VDD 64K X 8
SRAM
I 8
(Optional)
F I/O[7:0]
CE
WR WE
RD OE
M (Optional) 64K X 8
8 SRAM
I D[7:0] DATA BUS I/O[7:0]
F WR
CE
WE
RD OE
On-Chip XRAM
On-Chip XRAM On-Chip XRAM
On-Chip XRAM
0x0000 0x0000 0x0000 0x0000
• 8-bit MOVX operations use the contents of EMI0CN to determine the high-byte of the effective address
and R0 or R1 to determine the low-byte of the effective address.
• 16-bit MOVX operations use the contents of the 16-bit DPTR to determine the effective address.
13.6.2. Split Mode without Bank Select
When EMI0CF.[3:2] are set to ‘01’, the XRAM memory map is split into two areas, on-chip space and
off-chip space.
• Effective addresses below the internal XRAM size boundary will access on-chip XRAM space.
• Effective addresses above the internal XRAM size boundary will access off-chip space.
• 8-bit MOVX operations use the contents of EMI0CN to determine whether the memory access is
on-chip or off-chip. However, in the “No Bank Select” mode, an 8-bit MOVX operation will not drive the
upper 8-bits A[15:8] of the Address Bus during an off-chip access. This allows the user to manipulate
the upper address bits at will by setting the Port state directly via the port latches. This behavior is in
contrast with “Split Mode with Bank Select” described below. The lower 8-bits of the Address Bus
A[7:0] are driven, determined by R0 or R1.
• 16-bit MOVX operations use the contents of DPTR to determine whether the memory access is
on-chip or off-chip, and unlike 8-bit MOVX operations, the full 16-bits of the Address Bus A[15:0] are
driven during the off-chip transaction.
• Effective addresses below the internal XRAM size boundary will access on-chip XRAM space.
• Effective addresses above the internal XRAM size boundary will access off-chip space.
• 8-bit MOVX operations use the contents of EMI0CN to determine whether the memory access is
on-chip or off-chip. The upper 8-bits of the Address Bus A[15:8] are determined by EMI0CN, and the
lower 8-bits of the Address Bus A[7:0] are determined by R0 or R1. All 16-bits of the Address Bus
A[15:0] are driven in “Bank Select” mode.
• 16-bit MOVX operations use the contents of DPTR to determine whether the memory access is
on-chip or off-chip, and the full 16-bits of the Address Bus A[15:0] are driven during the off-chip trans-
action.
13.6.4. External Only
When EMI0CF[3:2] are set to ‘11’, all MOVX operations are directed to off-chip space. On-chip XRAM is
not visible to the CPU. This mode is useful for accessing off-chip memory located between 0x0000 and the
internal XRAM size boundary.
• 8-bit MOVX operations ignore the contents of EMI0CN. The upper Address bits A[15:8] are not driven
(identical behavior to an off-chip access in “Split Mode without Bank Select” described above). This
allows the user to manipulate the upper address bits at will by setting the Port state directly. The lower
8-bits of the effective address A[7:0] are determined by the contents of R0 or R1.
• 16-bit MOVX operations use the contents of DPTR to determine the effective address A[15:0]. The full
16-bits of the Address Bus A[15:0] are driven during the off-chip transaction.
13.7. Timing
The timing parameters of the External Memory Interface can be configured to enable connection to
devices having different setup and hold time requirements. The Address Setup time, Address Hold time,
RD and WR strobe widths, and in multiplexed mode, the width of the ALE pulse are all programmable in
units of SYSCLK periods through EMI0TC, shown in SFR Definition 13.3, and EMI0CF[1:0].
The timing for an off-chip MOVX instruction can be calculated by adding 4 SYSCLK cycles to the timing
parameters defined by the EMI0TC register. Assuming non-multiplexed operation, the minimum execution
time for an off-chip XRAM operation is 5 SYSCLK cycles (1 SYSCLK for RD or WR pulse + 4 SYSCLKs).
For multiplexed operations, the Address Latch Enable signal will require a minimum of 2 additional
SYSCLK cycles. Therefore, the minimum execution time for an off-chip XRAM operation in multiplexed
mode is 7 SYSCLK cycles (2 for ALE + 1 for RD or WR + 4). The programmable setup and hold times
default to the maximum delay settings after a reset. Table 13.1 lists the AC parameters for the External
Memory Interface, and Figure 13.5 through Figure 13.10 show the timing diagrams for the different Exter-
nal Memory Interface modes and MOVX operations.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
EAS1 EAS0 EWR3 EWR2 EWR1 EWR0 EAH1 EAH0 11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0x84
T T
WDS WDH
T T T
ACS ACW ACH
WR P1.7 P1.7
RD P1.6 P1.6
T T
RDS RDH
T T T
ACS ACW ACH
RD P1.6 P1.6
WR P1.7 P1.7
ADDR[15:8] P2
T T
WDS WDH
T T T
ACS ACW ACH
WR P1.7 P1.7
RD P1.6 P1.6
ADDR[15:8] P2
T T
RDS RDH
T T T
ACS ACW ACH
RD P1.6 P1.6
WR P1.7 P1.7
T T
ALEH ALEL
T T
WDS WDH
T T T
ACS ACW ACH
WR P1.7 P1.7
RD P1.6 P1.6
T T
ALEH ALEL T T
RDS RDH
T T T
ACS ACW ACH
RD P1.6 P1.6
WR P1.7 P1.7
T T
ALEH ALEL
T T
WDS WDH
T T T
ACS ACW ACH
WR P1.7 P1.7
RD P1.6 P1.6
T T
ALEH ALEL T T
RDS RDH
T T T
ACS ACW ACH
RD P1.6 P1.6
WR P1.7 P1.7
ADDR[15:8] P3
T T
ALEH ALEL
T T
WDS WDH
T T T
ACS ACW ACH
WR P1.7 P1.7
RD P1.6 P1.6
ADDR[15:8] P3
T T
ALEH ALEL T T
RDS RDH
T T T
ACS ACW ACH
RD P1.6 P1.6
WR P1.7 P1.7
T T
ALEH ALEL
T T
WDS WDH
T T T
ACS ACW ACH
WR P1.7 P1.7
RD P1.6 P1.6
T T
ALEH ALEL T T
RDS RDH
T T T
ACS ACW ACH
RD P1.6 P1.6
WR P1.7 P1.7
14. Oscillators
C8051F34x devices include a programmable internal high-frequency oscillator, a programmable internal
low-frequency oscillator (C8051F340/1/2/3/4/5/8/9/A/B/C/D), an external oscillator drive circuit, and a 4x
Clock Multiplier. The internal high-frequency and low-frequency oscillators can be enabled/disabled and
adjusted using the special function registers, as shown in Figure 14.1. The system clock (SYSCLK) can be
derived from either of the internal oscillators, the external oscillator circuit, or the 4x Clock Multiplier divided
by 2. The USB clock (USBCLK) can be derived from the internal oscillator, external oscillator, or 4x Clock
Multiplier. Oscillator electrical specifications are given in Table 14.1.
SUSPEND
OSCLRDY
USBCLK2
USBCLK1
USBCLK0
OSCLEN
OSCLD1
OSCLD0
OSCLF3
OSCLF2
OSCLF1
OSCLF0
IOSCEN
CLKSL2
CLKSL1
CLKSL0
IFRDY
IFCN1
IFCN0
Option 2
VDD Option 3
XTAL2
EN
Programmable High- IOSC
n
XTAL2 Frequency Oscillator
OSCLF3-0
EN n
Programmable Low-
Frequency Oscillator
(C8051F340/1/2/3/4/5/8/9/ SYSCLK
Option 1 A/B/C/D)
XTAL1
Input EXOSC
10MΩ OSC
Circuit
XTAL2 IOSC
XTLVLD
EXOSC x2 x2
Option 4
XTAL2 IOSC / 2
EXOSC / 2 Clock Multiplier
EXOSC
USBCLK
XOSCMD2
XOSCMD1
XOSCMD0
MULSEL1
MULSEL0
MULRDY
EXOSC / 2
MULINIT
XTLVLD
MULEN
XFCN2
XFCN1
XFCN0
EXOSC / 3
EXOSC / 4
OSCXCN CLKMUL
USBCLK2-0
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - OSCCAL Variable
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xB3
Note: The contents of this register are undefined when Clock Recovery is enabled. See Section
“16.4. USB Clock Configuration” on page 166 for details on Clock Recovery.
Important Note on External Oscillator Usage: Port pins must be configured when using the external
oscillator circuit. When the external oscillator drive circuit is enabled in crystal/resonator mode, Port pins
P0.6 and P0.7 (C8051F340/1/4/5/8) or P0.2 and P0.3 (C8051F342/3/6/7/9/A/B) are used as XTAL1 and
XTAL2 respectively. When the external oscillator drive circuit is enabled in capacitor, RC, or CMOS clock
mode, Port pin P0.7 (C8051F340/1/4/5/8) or P0.3 (C8051F342/3/6/7/9/A/B) is used as XTAL2. The Port I/
O Crossbar should be configured to skip the Port pins used by the oscillator circuit; see Section
“15.1. Priority Crossbar Decoder” on page 144 for Crossbar configuration. Additionally, when using the
external oscillator circuit in crystal/resonator, capacitor, or RC mode, the associated Port pins should be
configured as analog inputs. In CMOS clock mode, the associated pin should be configured as a digital
input. See Section “15.2. Port I/O Initialization” on page 147 for details on Port input mode selection.
When the crystal oscillator is first enabled, the oscillator amplitude detection circuit requires a settling time
to achieve proper bias. Introducing a delay of 1 ms between enabling the oscillator and checking the
XTLVLD bit will prevent a premature switch to the external oscillator as the system clock. Switching to the
external oscillator before the crystal oscillator has stabilized can result in unpredictable behavior. The rec-
ommended procedure is:
Important Note on External Crystals: Crystal oscillator circuits are quite sensitive to PCB layout. The
crystal should be placed as close as possible to the XTAL pins on the device. The traces should be as
short as possible and shielded with ground plane from any other traces which could introduce noise or
interference.
3 3
1.23 ( 10 ) 1.23 ( 10 )
f = ------------------------ = -------------------------- = 0.1 MHz = 100 kHz
RC [ 246 × 50 ]
Referring to the table in SFR Definition 14.4, the required XFCN setting is 010b. Programming XFCN to a
higher setting in RC mode will improve frequency accuracy at an increased external oscillator supply cur-
rent.
14.3.4. External Capacitor Example
If a capacitor is used as an external oscillator for the MCU, the circuit should be configured as shown in
Figure 14.1, Option 3. The capacitor should be no greater than 100 pF; however for very small capacitors,
the total capacitance may be dominated by parasitic capacitance in the PCB layout. To determine the
required External Oscillator Frequency Control value (XFCN) in the OSCXCN Register, select the capaci-
tor to be used and find the frequency of oscillation from the equations below. Assume VDD = 3.0 V and C =
50 pF:
KF KF
f = ------------------------- = --------------------------------
( C × VDD ) ( 50 x 3 )MHz
KF
f = ----------------------
150 MHz
If a frequency of roughly 150 kHz is desired, select the K Factor from the table in SFR Definition 14.4 as
KF = 22:
22
f = --------- = 0.146 MHz, or 146 kHz
150
Therefore, the XFCN value to use in this example is 011b.
The 4x Clock Multiplier is configured via the CLKMUL register. The procedure for configuring and enabling
the 4x Clock Multiplier is as follows:
Important Note: When using an external oscillator as the input to the 4x Clock Multiplier, the exter-
nal source must be enabled and stable before the Multiplier is initialized. See Section 14.5 for
details on selecting an external oscillator source.
Some example USB clock configurations for Full and Low Speed mode are given below:
Internal Oscillator
Clock Signal Input Source Selection Register Bit Settings
USB Clock Clock Multiplier USBCLK = 000b
Clock Multiplier Input Internal Oscillator* MULSEL = 00b
Internal Oscillator Divide by 1 IFCN = 11b
External Oscillator
Clock Signal Input Source Selection Register Bit Settings
USB Clock Clock Multiplier USBCLK = 000b
Clock Multiplier Input External Oscillator MULSEL = 01b
Crystal Oscillator Mode XOSCMD = 110b
External Oscillator
12 MHz Crystal XFCN = 111b
*Note: Clock Recovery must be enabled for this configuration.
Internal Oscillator
Clock Signal Input Source Selection Register Bit Settings
USB Clock Internal Oscillator / 2 USBCLK = 001b
Internal Oscillator Divide by 1 IFCN = 11b
External Oscillator
Clock Signal Input Source Selection Register Bit Settings
Internal Oscillator
Clock Signal Input Source Selection Register Bit Settings
USB Clock External Oscillator / 4 USBCLK = 101b
Crystal Oscillator Mode XOSCMD = 110b
External Oscillator
24 MHz Crystal XFCN = 111b
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- USBCLK - CLKSL 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address
0xA9
The Crossbar assigns the selected internal digital resources to the I/O pins based on the Priority Decoder
(Figure 15.3 and Figure 15.4). The registers XBR0, XBR1, and XBR2 defined in SFR Definition 15.1, SFR
Definition 15.2, and SFR Definition 15.3, are used to select internal digital functions.
All Port I/Os are 5 V tolerant (refer to Figure 15.2 for the Port cell circuit). The Port I/O cells are configured
as either push-pull or open-drain in the Port Output Mode registers (PnMDOUT, where n = 0,1,2,3,4). Com-
plete Electrical Specifications for Port I/O are given in Table 15.1 on page 158.
Priority
Decoder
Highest 2
UART0
Priority
4 P0.0
SPI 8 P0
2 I/O
SMBus Cells P0.7
(Internal Digital Signals)
CP0 2
Outputs P1 P1.0
Digital 8
I/O
CP1 2 Crossbar Cells P1.7
Outputs
SYSCLK
P2 P2.0
8
I/O
6
PCA Cells P2.7
2
T0, T1 P3 P3.0
8
Lowest 2 I/O
UART1** Cells P3.7*
Priority
8
P0 (P0.0-P0.7)
8
(Port Latches)
P1 (P1.0-P1.7)
Figure 15.1. Port I/O Functional Block Diagram (Port 0 through Port 3)
W E A K -P U LLU P
P U S H -P U LL VDD VDD
P O R T -O U T E N A B LE
(W E A K )
PORT
PAD
P O R T -O U T P U T
GND
A nalog S elect
A N A LO G IN P U T
P O R T -IN P U T
Important Note on Crossbar Configuration: If a Port pin is claimed by a peripheral without use of the
Crossbar, its corresponding PnSKIP bit should be set. This applies to the VREF signal, external oscillator
pins (XTAL1, XTAL2), the ADC’s external conversion start signal (CNVSTR), EMIF control signals, and any
selected ADC or Comparator inputs. The PnSKIP registers may also be used to skip pins to be used as
GPIO. The Crossbar skips selected pins as if they were already assigned, and moves to the next unas-
signed pin. Figure 15.3 shows all the possible pins available to each peripheral. Figure 15.4 shows the
Crossbar Decoder priority with no Port pins skipped. Figure 15.5 shows a Crossbar example with pins
P0.2, P0.3, and P1.0 skipped.
P0 P1 P2 P3
CNVSTR
XTAL1
XTAL2
SF Signals
VREF
P3.1-P3.7 unavailable on
(32-pin
the 32-pin packages
Package)
CNVSTR
XTAL1
XTAL2
SF Signals
VREF
ALE
WR
RD
(48-pin
Package)
PIN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
TX0
RX0
SCK
MISO
MOSI
NSS*
SDA
SCL
CP0
CP0A
CP1
CP1A
SYSCLK
CEX0
CEX1
CEX2
CEX3
CEX4
ECI
T0
T1
TX1**
RX1**
Port pin potentially available to peripheral **UART1 available only on C8051F340/1/4/5/8/A/B devices
SF Signals Special Function Signals are not assigned by the Crossbar. When these signals are *NSS is only pinned out in 4-wire SPI mode
enabled, the Crossbar must be manually configured to skip their corresponding port pins.
P0 P1 P2 P3
CNVSTR
XTAL1
XTAL2
SF Signals
VREF
P3.1-P3.7 unavailable on
(32-pin
the 32-pin packages
Package)
CNVSTR
XTAL1
XTAL2
SF Signals
VREF
ALE
WR
RD
(48-pin
Package)
PIN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
TX0
RX0
SCK
MISO
MOSI
NSS* *NSS is only pinned out in 4-wire SPI mode
SDA
SCL
CP0
CP0A
CP1
CP1A
SYSCLK
CEX0
CEX1
CEX2
CEX3
CEX4
ECI
T0
T1
TX1** **UART1 available only on C8051F340/1/4/5/8/A/B devices
RX1**
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
P0SKIP[0:7] P1SKIP[0:7] P2SKIP[0:7] P3SKIP[0:7]
P0 P1 P2 P3
CNVSTR
XTAL1
XTAL2
S F Signa ls
VREF
P3.1-P3.7 una va ila ble on
(32-pin
the 32-pin pa cka ge s
P a cka ge )
CNVSTR
XTAL1
XTAL2
S F Signa ls
VREF
ALE
WR
RD
(48-pin
P a cka ge )
P IN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
TX 0
RX0
S CK
M ISO
M OSI
NSS* *NSS is only pinned out in 4-wire S PI m ode
S DA
S CL
CP0
CP0A
CP1
CP1A
S YSCLK
CEX0
CEX1
CEX2
CEX3
CEX4
ECI
T0
T1
TX 1** **UA RT1 available only on C8051F340/1/4/5/8/A /B devices
RX1**
0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
P 0SKIP[0:7] P1S KIP[0:7] P2SKIP[0:7] P3SKIP [0:7]
Registers XBR0, XBR1, and XBR2 are used to assign the digital I/O resources to the physical I/O Port
pins. Note that when the SMBus is selected, the Crossbar assigns both pins associated with the SMBus
(SDA and SCL); when either UART is selected, the Crossbar assigns both pins associated with the UART
(TX and RX). UART0 pin assignments are fixed for bootloading purposes: UART TX0 is always assigned
to P0.4; UART RX0 is always assigned to P0.5. Standard Port I/Os appear contiguously after the prioritized
functions have been assigned.
Important Note: The SPI can be operated in either 3-wire or 4-wire modes, depending on the state of the
NSSMD1-NSSMD0 bits in register SPI0CN. According to the SPI mode, the NSS signal may or may not be
routed to a Port pin.
Step 1. Select the input mode (analog or digital) for all Port pins, using the Port Input Mode
register (PnMDIN).
Step 2. Select the output mode (open-drain or push-pull) for all Port pins, using the Port Output
Mode register (PnMDOUT).
Step 3. Select any pins to be skipped by the I/O Crossbar using the Port Skip registers (PnSKIP).
Step 4. Assign Port pins to desired peripherals (XBR0, XBR1).
Step 5. Enable the Crossbar (XBARE = ‘1’).
All Port pins must be configured as either analog or digital inputs. Any pins to be used as Comparator or
ADC inputs should be configured as an analog inputs. When a pin is configured as an analog input, its
weak pull-up, digital driver, and digital receiver are disabled. This process saves power and reduces noise
on the analog input. Pins configured as digital inputs may still be used by analog peripherals; however this
practice is not recommended. To configure a Port pin for digital input, write ‘0’ to the corresponding bit in
register PnMDOUT, and write ‘1’ to the corresponding Port latch (register Pn).
Additionally, all analog input pins should be configured to be skipped by the Crossbar (accomplished by
setting the associated bits in PnSKIP). Port input mode is set in the PnMDIN register, where a ‘1’ indicates
a digital input, and a ‘0’ indicates an analog input. All pins default to digital inputs on reset.
The output driver characteristics of the I/O pins are defined using the Port Output Mode registers (PnMD-
OUT). Each Port Output driver can be configured as either open drain or push-pull. This selection is
required even for the digital resources selected in the XBRn registers, and is not automatic. The only
exception to this is the SMBus (SDA, SCL) pins, which are configured as open-drain regardless of the
PnMDOUT settings. When the WEAKPUD bit in XBR1 is ‘0’, a weak pull-up is enabled for all Port I/O con-
figured as open-drain. WEAKPUD does not affect the push-pull Port I/O. Furthermore, the weak pull-up is
turned off on an output that is driving a ‘0’ to avoid unnecessary power dissipation.
Registers XBR0 and XBR1 must be loaded with the appropriate values to select the digital I/O functions
required by the design. Setting the XBARE bit in XBR1 to ‘1’ enables the Crossbar. Until the Crossbar is
enabled, the external pins remain as standard Port I/O (in input mode), regardless of the XBRn Register
settings. For given XBRn Register settings, one can determine the I/O pin-out using the Priority Decode
Table; as an alternative, the Configuration Wizard utility of the Silicon Labs IDE software will determine the
Port I/O pin-assignments based on the XBRn Register settings.
Important Note: The Crossbar must be enabled to use Ports P0, P1, P2, and P3 as standard Port I/O in
output mode. These Port output drivers are disabled while the Crossbar is disabled. Port 4 always func-
tions as standard GPIO.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
CP1AE CP1E CP0AE CP0E SYSCKE SMB0E SPI0E URT0E 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xE1
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
WEAKPUD XBARE T1E T0E ECIE PCA0ME 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xE2
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
URT1E 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xE3
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0 11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0x80
Bits7–0: P0.[7:0]
Write - Output appears on I/O pins per Crossbar Registers (when XBARE = ‘1’).
0: Logic Low Output.
1: Logic High Output (high impedance if corresponding P0MDOUT.n bit = 0).
Read - Always reads ‘0’ if selected as analog input in register P0MDIN. Directly reads Port
pin when configured as digital input.
0: P0.n pin is logic low.
1: P0.n pin is logic high.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF1
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xA4
Bits7–0: Output Configuration Bits for P0.7–P0.0 (respectively): ignored if corresponding bit in regis-
ter P0MDIN is logic 0.
0: Corresponding P0.n Output is open-drain.
1: Corresponding P0.n Output is push-pull.
(Note: When SDA and SCL appear on any of the Port I/O, each are open-drain regardless
of the value of P0MDOUT).
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xD4
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0x90
Bits7–0: P1.[7:0]
Write - Output appears on I/O pins per Crossbar Registers (when XBARE = ‘1’).
0: Logic Low Output.
1: Logic High Output (high impedance if corresponding P1MDOUT.n bit = 0).
Read - Always reads ‘0’ if selected as analog input in register P1MDIN. Directly reads Port
pin when configured as digital input.
0: P1.n pin is logic low.
1: P1.n pin is logic high.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF2
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xA5
Bits7–0: Output Configuration Bits for P1.7–P1.0 (respectively): ignored if corresponding bit in regis-
ter P1MDIN is logic 0.
0: Corresponding P1.n Output is open-drain.
1: Corresponding P1.n Output is push-pull.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xD5
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xA0
Bits7–0: P2.[7:0]
Write - Output appears on I/O pins per Crossbar Registers (when XBARE = ‘1’).
0: Logic Low Output.
1: Logic High Output (high impedance if corresponding P2MDOUT.n bit = 0).
Read - Always reads ‘0’ if selected as analog input in register P2MDIN. Directly reads Port
pin when configured as digital input.
0: P2.n pin is logic low.
1: P2.n pin is logic high.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF3
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xA6
Bits7–0: Output Configuration Bits for P2.7–P2.0 (respectively): ignored if corresponding bit in regis-
ter P2MDIN is logic 0.
0: Corresponding P2.n Output is open-drain.
1: Corresponding P2.n Output is push-pull.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xD6
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0 11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xB0
Bits7–0: P3.[7:0]
Write - Output appears on I/O pins.
0: Logic Low Output.
1: Logic High Output (high impedance if corresponding P3MDOUT.n bit = 0).
Read - Always reads ‘0’ if selected as analog input in register P3MDIN. Directly reads Port
pin when configured as digital input.
0: P3.n pin is logic low.
1: P3.n pin is logic high.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF4
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xA7
Bits7–0: Output Configuration Bits for P3.7–P3.0 (respectively); ignored if corresponding bit in regis-
ter P3MDIN is logic 0.
0: Corresponding P3.n Output is open-drain.
1: Corresponding P3.n Output is push-pull.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xDF
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
P4.7 P4.6 P4.5 P4.4 P4.3 P4.2 P4.1 P4.0 11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xC7
Bits7–0: P4.[7:0]
Write - Output appears on I/O pins.
0: Logic Low Output.
1: Logic High Output (high impedance if corresponding P4MDOUT.n bit = 0).
Read - Always reads ‘0’ if selected as analog input in register P4MDIN. Directly reads Port
pin when configured as digital input.
0: P4.n pin is logic low.
1: P4.n pin is logic high.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
11111111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF5
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xAE
Bits7–0: Output Configuration Bits for P4.7–P4.0 (respectively); ignored if corresponding bit in regis-
ter P4MDIN is logic 0.
0: Corresponding P4.n Output is open-drain.
1: Corresponding P4.n Output is push-pull.
Endpoint0
VDD
IN/OUT
D+
USB
Data Control, CIP-51 Core
Transfer Endpoint1 Status, and
Control Endpoint2 Interrupt
Registers
D- IN Endpoint3
OUT
IN OUT
IN OUT
USB FIFOs
(1k RAM)
Important Note: The USB clock should be active before the Transceiver is enabled.
PHYTST[1:0] Mode D+ D–
00b Mode 0: Normal (non-test mode) X X
01b Mode 1: Differential ‘1’ Forced 1 0
10b Mode 2: Differential ‘0’ Forced 0 1
11b Mode 3: Single-Ended ‘0’ Forced 0 0
Endpoint control/status registers are accessed by first writing the USB register INDEX with the target end-
point number. Once the target endpoint number is written to the INDEX register, the control/status registers
associated with the target endpoint may be accessed. See the “Indexed Registers” section of Table 16.2
for a list of endpoint control/status registers.
Important Note: The USB clock must be active when accessing USB registers.
FIFO
Access
Common
Registers
USB0DAT Index
Register
Endpoint0 Control/
Status Registers
Endpoint1 Control/
Status Registers
Endpoint2 Control/
Status Registers
USB0ADR
Endpoint3 Control/
Status Registers
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
BUSY AUTORD USBADDR 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x96
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
USB0DAT 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x97
Write Procedure:
1. Poll for BUSY (USB 0ADR.7) => ‘0’.
2. Load the target USB0 register address into the USBADDR bits in register USB0ADR.
3. Write data to USB0DAT.
4. Repeat (Step 2 may be skipped when writing to the same USB0 register).
Read Procedure:
1. Poll for BUSY (USB 0ADR.7) => ‘0’.
2. Load the target USB0 register address into the USBADDR bits in register USB0ADR.
3. Write ‘1’ to the BUSY bit in register USB0ADR (steps 2 and 3 can be performed in the
same write).
4. Poll for BUSY (USB 0ADR.7) => ‘0’.
5. Read data from USB0DAT.
6. Repeat from Step 2 (Step 2 may be skipped when reading the same USB0 register; Step 3
may be skipped when the AUTORD bit (USB0ADR.6) is logic 1).
Clock Recovery circuitry uses the incoming USB data stream to adjust the internal oscillator; this allows
the internal oscillator (and 4x Clock Multiplier) to meet the requirements for USB clock tolerance. Clock
Recovery should be used in the following configurations:
When operating USB0 as a Low Speed function with Clock Recovery, software must write ‘1’ to the
CRLOW bit to enable Low Speed Clock Recovery. Clock Recovery is typically not necessary in Low Speed
mode.
Single Step Mode can be used to help the Clock Recovery circuitry to lock when high noise levels are pres-
ent on the USB network. This mode is not required (or recommended) in typical USB environments.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
CRE CRSSEN CRLOW Reserved 00001001
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x0F
Note: The USB transceiver must be enabled before enabling Clock Recovery.
0x07FF
Endpoint0
(64 bytes)
0x07C0
0x07BF
Endpoint1
(128 bytes)
0x0740
0x073F
Endpoint2 Configurable as
(256 bytes) IN, OUT, or both (Split
Mode)
0x0640
0x063F
Endpoint3
(512 bytes)
0x0440
0x043F
Free
(64 bytes)
0x0400
USB Clock Domain
If an endpoint FIFO is not configured for Split Mode, that endpoint IN/OUT pair’s FIFOs are combined to
form a single IN or OUT FIFO. In this case only one direction of the endpoint IN/OUT pair may be used at
a time. The endpoint direction (IN/OUT) is determined by the DIRSEL bit in the corresponding endpoint’s
EINCSRH register (see SFR Definition 16.20).
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
FIFODATA 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x20 - 0x23
Writing to the FIFO address loads data into the IN FIFO for the corresponding endpoint.
Reading from the FIFO address unloads data from the OUT FIFO for the corresponding
endpoint.
Writing a ‘1’ to the USBRST bit will generate an asynchronous USB0 reset. All USB registers are reset to
their default values following this asynchronous reset.
Suspend Mode: With Suspend Detection enabled (SUSEN = ‘1’), USB0 will enter Suspend Mode when
Suspend signaling is detected on the bus. An interrupt will be generated if enabled (SUSINTE = ‘1’). The
Suspend Interrupt Service Routine (ISR) should perform application-specific configuration tasks such as
disabling appropriate peripherals and/or configuring clock sources for low power modes. See Section
“14. Oscillators” on page 131 for more details on internal oscillator configuration, including the Suspend
ISO Update: When software writes ‘1’ to the ISOUP bit (POWER.7), the ISO Update function is enabled.
With ISO Update enabled, new packets written to an ISO IN endpoint will not be transmitted until a new
Start-Of-Frame (SOF) is received. If the ISO IN endpoint receives an IN token before a SOF, USB0 will
transmit a zero-length packet. When ISOUP = ‘1’, ISO Update is enabled for all ISO endpoints.
USB Enable: USB0 is disabled following a Power-On-Reset (POR). USB0 is enabled by clearing the
USBINH bit (POWER.4). Once written to ‘0’, the USBINH can only be set to ‘1’ by one of the following: (1)
a Power-On-Reset (POR), or (2) an asynchronous USB0 reset generated by writing ‘1’ to the USBRST bit
(POWER.3).
Software should perform all USB0 configuration before enabling USB0. The configuration sequence
should be performed as follows:
R R R R R R R R Reset Value
Frame Number Low 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x0C
R R R R R R R R Reset Value
- - - - - Frame Number High 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x0D
16.8. Interrupts
The read-only USB0 interrupt flags are located in the USB registers shown in USB Register
Definition 16.11 through USB Register Definition 16.13. The associated interrupt enable bits are located in
the USB registers shown in USB Register Definition 16.14 through USB Register Definition 16.16. A USB0
interrupt is generated when any of the USB interrupt flags is set to ‘1’. The USB0 interrupt is enabled via
the EIE1 SFR (see Section “9.3. Interrupt Handler” on page 88).
Important Note: Reading a USB interrupt flag register resets all flags in that register to ‘0’.
R R R R R R R R Reset Value
- - - - IN3 IN2 IN1 EP0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x02
R R R R R R R R Reset Value
- - - - OUT3 OUT2 OUT1 - 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x04
R R R R R R R R Reset Value
- - - - SOF RSTINT RSUINT SUSINT 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x06
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - IN3E IN2E IN1E EP0E 00001111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x07
USB Register Definition 16.15. OUT1IE: USB0 Out Endpoint Interrupt Enable
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - OUT3E OUT2E OUT1E - 00001110
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x09
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
- - - - SOFE RSTINTE RSUINTE SUSINTE 00000110
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x0B
The SIE will not interrupt the processor when corrupted/erroneous packets are received.
16.10. Endpoint0
Endpoint0 is managed through the USB register E0CSR (USB Register Definition 16.17). The INDEX reg-
ister must be loaded with 0x00 to access the E0CSR register.
1. A data packet (OUT or SETUP) has been received and loaded into the Endpoint0 FIFO. The
OPRDY bit (E0CSR.0) is set to ‘1’ by hardware.
2. An IN data packet has successfully been unloaded from the Endpoint0 FIFO and transmitted
to the host; INPRDY is reset to ‘0’ by hardware.
3. An IN transaction is completed (this interrupt generated during the status stage of the transac-
tion).
4. Hardware sets the STSTL bit (E0CSR.2) after a control transaction ended due to a protocol
violation.
5. Hardware sets the SUEND bit (E0CSR.4) because a control transfer ended before firmware
sets the DATAEND bit (E0CSR.3).
The E0CNT register (USB Register Definition 16.18) holds the number of received data bytes in the End-
point0 FIFO.
Hardware will automatically detect protocol errors and send a STALL condition in response. Firmware may
force a STALL condition to abort the current transfer. When a STALL condition is generated, the STSTL bit
will be set to ‘1’ and an interrupt generated. The following conditions will cause hardware to generate a
STALL condition:
1. The host sends an OUT token during a OUT data phase after the DATAEND bit has been set
to ‘1’.
2. The host sends an IN token during an IN data phase after the DATAEND bit has been set to
‘1’.
3. The host sends a packet that exceeds the maximum packet size for Endpoint0.
4. The host sends a non-zero length DATA1 packet during the status phase of an IN transaction.
5. Firmware sets the SDSTL bit (E0CSR.5) to ‘1’.
16.10.1.Endpoint0 SETUP Transactions
All control transfers must begin with a SETUP packet. SETUP packets are similar to OUT packets, contain-
ing an 8-byte data field sent by the host. Any SETUP packet containing a command field of anything other
than 8 bytes will be automatically rejected by USB0. An Endpoint0 interrupt is generated when the data
from a SETUP packet is loaded into the Endpoint0 FIFO. Software should unload the command from the
Endpoint0 FIFO, decode the command, perform any necessary tasks, and set the SOPRDY bit to indicate
that it has serviced the OUT packet.
16.10.2.Endpoint0 IN Transactions
When a SETUP request is received that requires USB0 to transmit data to the host, one or more IN
requests will be sent by the host. For the first IN transaction, firmware should load an IN packet into the
Endpoint0 FIFO, and set the INPRDY bit (E0CSR.1). An interrupt will be generated when an IN packet is
transmitted successfully. Note that no interrupt will be generated if an IN request is received before firm-
ware has loaded a packet into the Endpoint0 FIFO. If the requested data exceeds the maximum packet
size for Endpoint0 (as reported to the host), the data should be split into multiple packets; each packet
should be of the maximum packet size excluding the last (residual) packet. If the requested data is an inte-
ger multiple of the maximum packet size for Endpoint0, the last data packet should be a zero-length packet
signaling the end of the transfer. Firmware should set the DATAEND bit to ‘1’ after loading into the End-
point0 FIFO the last data packet for a transfer.
Upon reception of the first IN token for a particular control transfer, Endpoint0 is said to be in Transmit
Mode. In this mode, only IN tokens should be sent by the host to Endpoint0. The SUEND bit (E0CSR.4) is
set to ‘1’ if a SETUP or OUT token is received while Endpoint0 is in Transmit Mode.
Endpoint0 will remain in Transmit Mode until any of the following occur:
Firmware should set the DATAEND bit (E0CSR.3) to ‘1’ when performing (2) and (3) above.
The SIE will transmit a NAK in response to an IN token if there is no packet ready in the IN FIFO (INPRDY
= ‘0’).
If the amount of data required for the transfer exceeds the maximum packet size for Endpoint0, the data
will be split into multiple packets. If the requested data is an integer multiple of the maximum packet size
for Endpoint0 (as reported to the host), the host will send a zero-length data packet signaling the end of the
transfer.
Upon reception of the first OUT token for a particular control transfer, Endpoint0 is said to be in Receive
Mode. In this mode, only OUT tokens should be sent by the host to Endpoint0. The SUEND bit (E0CSR.4)
is set to ‘1’ if a SETUP or IN token is received while Endpoint0 is in Receive Mode.
Firmware should set the DATAEND bit (E0CSR.3) to ‘1’ when the expected amount of data has been
received. The SIE will transmit a STALL condition if the host sends an OUT packet after the DATAEND bit
has been set by firmware. An interrupt will be generated with the STSTL bit (E0CSR.2) set to ‘1’ after the
STALL is transmitted.
R R R R R R R R Reset Value
- E0CNT 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x16
Endpoints1-3 can be configured as IN, OUT, or both IN/OUT (Split Mode) as described in Section 16.5.1.
The endpoint mode (Split/Normal) is selected via the SPLIT bit in register EINCSRH.
When SPLIT = ‘1’, the corresponding endpoint FIFO is split, and both IN and OUT pipes are available.
When SPLIT = ‘0’, the corresponding endpoint functions as either IN or OUT; the endpoint direction is
selected by the DIRSEL bit in register EINCSRH.
Writing ‘1’ to INPRDY without writing any data to the endpoint FIFO will cause a zero-length packet to be
transmitted upon reception of the next IN token.
A Bulk or Interrupt pipe can be shut down (or Halted) by writing ‘1’ to the SDSTL bit (EINCSRL.4). While
SDSTL = ‘1’, hardware will respond to all IN requests with a STALL condition. Each time hardware gener-
ates a STALL condition, an interrupt will be generated and the STSTL bit (EINCSRL.5) set to ‘1’. The
STSTL bit must be reset to ‘0’ by firmware.
Hardware will automatically reset INPRDY to ‘0’ when a packet slot is open in the endpoint FIFO. Note that
if double buffering is enabled for the target endpoint, it is possible for firmware to load two packets into the
IN FIFO at a time. In this case, hardware will reset INPRDY to ‘0’ immediately after firmware loads the first
packet into the FIFO and sets INPRDY to ‘1’. An interrupt will not be generated in this case; an interrupt will
only be generated when a data packet is transmitted.
When firmware writes ‘1’ to the FCDT bit (EINCSRH.3), the data toggle for each IN packet will be toggled
continuously, regardless of the handshake received from the host. This feature is typically used by Inter-
rupt endpoints functioning as rate feedback communication for Isochronous endpoints. When FCDT = ‘0’,
the data toggle bit will only be toggled when an ACK is sent from the host in response to an IN packet.
Hardware will automatically reset INPRDY (EINCSRL.0) to ‘0’ when a packet slot is open in the endpoint
FIFO. Note that if double buffering is enabled for the target endpoint, it is possible for firmware to load two
packets into the IN FIFO at a time. In this case, hardware will reset INPRDY to ‘0’ immediately after firm-
ware loads the first packet into the FIFO and sets INPRDY to ‘1’. An interrupt will not be generated in this
case; an interrupt will only be generated when a data packet is transmitted.
If there is not a data packet ready in the endpoint FIFO when USB0 receives an IN token from the host,
USB0 will transmit a zero-length data packet and set the UNDRUN bit (EINCSRL.2) to ‘1’.
The ISO Update feature (see Section 16.7) can be useful in starting a double buffered ISO IN endpoint. If
the host has already set up the ISO IN pipe (has begun transmitting IN tokens) when firmware writes the
first data packet to the endpoint FIFO, the next IN token may arrive and the first data packet sent before
firmware has written the second (double buffered) data packet to the FIFO. The ISO Update feature
ensures that any data packet written to the endpoint FIFO will not be transmitted during the current frame;
the packet will only be sent after a SOF signal has been received.
USB Register Definition 16.19. EINCSRL: USB0 IN Endpoint Control Low Byte
USB Register Definition 16.20. EINCSRH: USB0 IN Endpoint Control High Byte
A Bulk or Interrupt pipe can be shut down (or Halted) by writing ‘1’ to the SDSTL bit (EOUTCSRL.5). While
SDSTL = ‘1’, hardware will respond to all OUT requests with a STALL condition. Each time hardware gen-
erates a STALL condition, an interrupt will be generated and the STSTL bit (EOUTCSRL.6) set to ‘1’. The
STSTL bit must be reset to ‘0’ by firmware.
Hardware will automatically set OPRDY when a packet is ready in the OUT FIFO. Note that if double buff-
ering is enabled for the target endpoint, it is possible for two packets to be ready in the OUT FIFO at a time.
In this case, hardware will set OPRDY to ‘1’ immediately after firmware unloads the first packet and resets
OPRDY to ‘0’. A second interrupt will be generated in this case.
Each time a data packet is received, hardware will load the received data packet into the endpoint FIFO,
set the OPRDY bit (EOUTCSRL.0) to ‘1’, and generate an interrupt (if enabled). Firmware would typically
use this interrupt to unload the data packet from the endpoint FIFO and reset the OPRDY bit to ‘0’.
If a data packet is received when there is no room in the endpoint FIFO, an interrupt will be generated and
the OVRUN bit (EOUTCSRL.2) set to ‘1’. If USB0 receives an ISO data packet with a CRC error, the data
packet will be loaded into the endpoint FIFO, OPRDY will be set to ‘1’, an interrupt (if enabled) will be gen-
erated, and the DATAERR bit (EOUTCSRL.3) will be set to ‘1’. Software should check the DATAERR bit
each time a data packet is unloaded from an ISO OUT endpoint FIFO.
USB Register Definition 16.21. EOUTCSRL: USB0 OUT Endpoint Control Low Byte
USB Register Definition 16.22. EOUTCSRH: USB0 OUT Endpoint Control High Byte
USB Register Definition 16.23. EOUTCNTL: USB0 OUT Endpoint Count Low
R R R R R R R R Reset Value
EOCL 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x16
USB Register Definition 16.24. EOUTCNTH: USB0 OUT Endpoint Count High
R R R R R R R R Reset Value
- - - - - - E0CH 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 USB Address:
0x17
17. SMBus
The SMBus I/O interface is a two-wire, bi-directional serial bus. The SMBus is compliant with the System
Management Bus Specification, version 1.1, and compatible with the I2C serial bus. Reads and writes to
the interface by the system controller are byte oriented with the SMBus interface autonomously controlling
the serial transfer of the data. Data can be transferred at up to 1/20th of the system clock as a master or
slave (this can be faster than allowed by the SMBus specification, depending on the system clock used). A
method of extending the clock-low duration is available to accommodate devices with different speed
capabilities on the same bus.
The SMBus interface may operate as a master and/or slave, and may function on a bus with multiple mas-
ters. The SMBus provides control of SDA (serial data), SCL (serial clock) generation and synchronization,
arbitration logic, and START/STOP control and generation. Three SFRs are associated with the SMBus:
SMB0CF configures the SMBus; SMB0CN controls the status of the SMBus; and SMB0DAT is the data
register, used for both transmitting and receiving SMBus data and slave addresses.
SMB0CN SMB0CF
MT S S A A A S E I B E S S S S
A X T T CRC I N N U XMMMM
SMAOK B K S HS T B B B B
T O R L M Y H T F CC
E D QO B OO T S S
R E S L E E 1 0
T D
00 T0 Overflow
01 T1 Overflow
10 TMR2H Overflow
11 TMR2L Overflow
SCL
SMBUS CONTROL LOGIC FILTER
Arbitration
Interrupt SCL Synchronization SCL
Request N C
SCL Generation (Master Mode) Control R
SDA Control
Data Path SDA O
IRQ Generation
Control Control S
S Port I/O
B
A
R
SMB0DAT
SDA
7 6 5 4 3 2 1 0 FILTER
SDA
SCL
A typical SMBus transaction consists of a START condition followed by an address byte (Bits7-1: 7-bit
slave address; Bit0: R/W direction bit), one or more bytes of data, and a STOP condition. Each byte that is
received (by a master or slave) must be acknowledged (ACK) with a low SDA during a high SCL (see
Figure 17.3). If the receiving device does not ACK, the transmitting device will read a NACK (not acknowl-
edge), which is a high SDA during a high SCL.
The direction bit (R/W) occupies the least-significant bit position of the address byte. The direction bit is set
to logic 1 to indicate a "READ" operation and cleared to logic 0 to indicate a "WRITE" operation.
All transactions are initiated by a master, with one or more addressed slave devices as the target. The
master generates the START condition and then transmits the slave address and direction bit. If the trans-
action is a WRITE operation from the master to the slave, the master transmits the data a byte at a time
waiting for an ACK from the slave at the end of each byte. For READ operations, the slave transmits the
data waiting for an ACK from the master at the end of each byte. At the end of the data transfer, the master
generates a STOP condition to terminate the transaction and free the bus. Figure 17.3 illustrates a typical
SMBus transaction.
SCL
SDA
SLA6 SLA5-0 R/W D7 D6-0
17.3.1. Arbitration
A master may start a transfer only if the bus is free. The bus is free after a STOP condition or after the SCL
and SDA lines remain high for a specified time (see Section “17.3.4. SCL High (SMBus Free) Timeout”
on page 191). In the event that two or more devices attempt to begin a transfer at the same time, an arbi-
tration scheme is employed to force one master to give up the bus. The master devices continue transmit-
ting until one attempts a HIGH while the other transmits a LOW. Since the bus is open-drain, the bus will
be pulled LOW. The master attempting the HIGH will detect a LOW SDA and lose the arbitration. The win-
ning master continues its transmission without interruption; the losing master becomes a slave and
receives the rest of the transfer if addressed. This arbitration scheme is non-destructive: one device
always wins, and no data is lost.
When the SMBTOE bit in SMB0CF is set, Timer 3 is used to detect SCL low timeouts. Timer 3 is forced to
reload when SCL is high, and allowed to count when SCL is low. With Timer 3 enabled and configured to
overflow after 25 ms (and SMBTOE set), the Timer 3 interrupt service routine can be used to reset (disable
and re-enable) the SMBus in the event of an SCL low timeout.
SMBus interrupts are generated for each data byte or slave address that is transferred. When transmitting,
this interrupt is generated after the ACK cycle so that software may read the received ACK value; when
receiving data, this interrupt is generated before the ACK cycle so that software may define the outgoing
ACK value. See Section “17.5. SMBus Transfer Modes” on page 198 for more details on transmission
sequences.
Interrupts are also generated to indicate the beginning of a transfer when a master (START generated), or
the end of a transfer when a slave (STOP detected). Software should read the SMB0CN (SMBus Control
register) to find the cause of the SMBus interrupt. The SMB0CN register is described in Section
“17.4.2. SMB0CN Control Register” on page 195; Table 17.4 provides a quick SMB0CN decoding refer-
ence.
These options are selected in the SMB0CF register, as described in Section “17.4.1. SMBus Configura-
tion Register” on page 192.
The SMBCS1-0 bits select the SMBus clock source, which is used only when operating as a master or
when the Free Timeout detection is enabled. When operating as a master, overflows from the selected
source determine the absolute minimum SCL low and high times as defined in Equation 17.1. Note that the
selected clock source may be shared by other peripherals so long as the timer is left running at all times.
For example, Timer 1 overflows may generate the SMBus and UART baud rates simultaneously. Timer
configuration is covered in Section “21. Timers” on page 235.
1
T HighMin = T LowMin = ----------------------------------------------
f ClockSourceOverflow
f ClockSourceOverflow
BitRate = ----------------------------------------------
3
Equation 17.2. Typical SMBus Bit Rate
Figure 17.4 shows the typical SCL generation described by Equation 17.2. Notice that THIGH is typically
twice as large as TLOW. The actual SCL output may vary due to other devices on the bus (SCL may be
extended low by slower slave devices, or driven low by contending master devices). The bit rate when
operating as a master will never exceed the limits defined by equation Equation 17.1.
Timer Source
Overflows
SCL
Setting the EXTHOLD bit extends the minimum setup and hold times for the SDA line. The minimum SDA
setup time defines the absolute minimum time that SDA is stable before SCL transitions from low-to-high.
The minimum SDA hold time defines the absolute minimum time that the current SDA value remains stable
after SCL transitions from high-to-low. EXTHOLD should be set so that the minimum setup and hold times
meet the SMBus Specification requirements of 250 ns and 300 ns, respectively. Table 17.2 shows the min-
imum setup and hold times for the two EXTHOLD settings. Setup and hold time extensions are typically
necessary when SYSCLK is above 10 MHz.
With the SMBTOE bit set, Timer 3 should be configured to overflow after 25 ms in order to detect SCL low
timeouts (see Section “17.3.3. SCL Low Timeout” on page 191). The SMBus interface will force Timer 3
to reload while SCL is high, and allow Timer 3 to count when SCL is low. The Timer 3 interrupt service rou-
tine should be used to reset SMBus communication by disabling and re-enabling the SMBus.
SMBus Free Timeout detection can be enabled by setting the SMBFTE bit. When this bit is set, the bus will
be considered free if SDA and SCL remain high for more than 10 SMBus clock source periods (see
Figure 17.4). When a Free Timeout is detected, the interface will respond as if a STOP was detected (an
interrupt will be generated, and STO will be set).
STA and STO indicate that a START and/or STOP has been detected or generated since the last SMBus
interrupt. STA and STO are also used to generate START and STOP conditions when operating as a mas-
ter. Writing a ‘1’ to STA will cause the SMBus interface to enter Master Mode and generate a START when
the bus becomes free (STA is not cleared by hardware after the START is generated). Writing a ‘1’ to STO
while in Master Mode will cause the interface to generate a STOP and end the current transfer after the
next ACK cycle. If STO and STA are both set (while in Master Mode), a STOP followed by a START will be
generated.
As a receiver, writing the ACK bit defines the outgoing ACK value; as a transmitter, reading the ACK bit
indicates the value received on the last ACK cycle. ACKRQ is set each time a byte is received, indicating
that an outgoing ACK value is needed. When ACKRQ is set, software should write the desired outgoing
value to the ACK bit before clearing SI. A NACK will be generated if software does not write the ACK bit
before clearing SI. SDA will reflect the defined ACK value immediately following a write to the ACK bit;
however SCL will remain low until SI is cleared. If a received slave address is not acknowledged, further
slave events will be ignored until the next START is detected.
The ARBLOST bit indicates that the interface has lost an arbitration. This may occur anytime the interface
is transmitting (master or slave). A lost arbitration while operating as a slave indicates a bus error condi-
tion. ARBLOST is cleared by hardware each time SI is cleared.
The SI bit (SMBus Interrupt Flag) is set at the beginning and end of each transfer, after each byte frame, or
when an arbitration is lost; see Table 17.3 for more details.
Important Note About the SI Bit: The SMBus interface is stalled while SI is set; thus SCL is held low, and
the bus is stalled until software clears SI.
Table 17.3 lists all sources for hardware changes to the SMB0CN bits. Refer to Table 17.4 for SMBus sta-
tus decoding using the SMB0CN register.
Data in SMB0DAT is always shifted out MSB first. After a byte has been received, the first bit of received
data is located at the MSB of SMB0DAT. While data is being shifted out, data on the bus is simultaneously
being shifted in. SMB0DAT always contains the last data byte present on the bus. In the event of lost arbi-
tration, the transition from master transmitter to slave receiver is made with the correct data or address in
SMB0DAT.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xC2
Interrupt
Interrupt
ACK
ACK
STA
STo
Load slave address + R/W
1110 0 0 X A master START was generated. 0 0 X
into SMB0DAT.
A master data or address byte Set STA to restart transfer. 1 0 X
0 0 0
was transmitted; NACK received. Abort transfer. 0 1 X
Master Transmitter
ARBLOST
ACKRQ Current SMbus State Typical Response Options
Vector
Status
ACK
ACK
STA
STo
A slave byte was transmitted; No action required (expect-
0 0 0 0 0 X
NACK received. ing STOP condition).
Slave Transmitter
18. UART0
UART0 is an asynchronous, full duplex serial port offering modes 1 and 3 of the standard 8051 UART.
Enhanced baud rate support allows a wide range of clock sources to generate standard baud rates (details
in Section “18.1. Enhanced Baud Rate Generation” on page 206). Received data buffering allows
UART0 to start reception of a second incoming data byte before software has finished reading the previous
data byte.
UART0 has two associated SFRs: Serial Control Register 0 (SCON0) and Serial Data Buffer 0 (SBUF0).
The single SBUF0 location provides access to both transmit and receive registers. Writes to SBUF0
always access the Transmit register. Reads of SBUF0 always access the buffered Receive register;
it is not possible to read data from the Transmit register.
With UART0 interrupts enabled, an interrupt is generated each time a transmit is completed (TI0 is set in
SCON0), or a data byte has been received (RI0 is set in SCON0). The UART0 interrupt flags are not
cleared by hardware when the CPU vectors to the interrupt service routine. They must be cleared manually
by software, allowing software to determine the cause of the UART0 interrupt (transmit complete or receive
complete).
SFR Bus
Write to
SBUF0
TB80
SET
SBUF0
D Q (TX Shift)
TX0
CLR
Crossbar
Zero Detector
SCON
TI0
UART0 Baud Serial
S0MODE
RB80
TB80
RI0
TI0
Interrupt
RI0
Rx IRQ
Rx Clock
Rx Control
Load
Start
Shift 0x1FF RB80 SBUF0
Load SBUF0
SBUF0
(RX Latch)
Read
SBUF0
Timer 1 UART
Overflow
TL1 2 TX Clock
TH1
Start
Detected
Overflow
RX Timer 2 RX Clock
Timer 1 should be configured for Mode 2, 8-bit auto-reload (see Section “21.1.3. Mode 2: 8-bit Counter/
Timer with Auto-Reload” on page 237). The Timer 1 reload value should be set so that overflows will
occur at two times the desired UART baud rate frequency. Note that Timer 1 may be clocked by one of six
sources: SYSCLK, SYSCLK / 4, SYSCLK / 12, SYSCLK / 48, the external oscillator clock / 8, or an exter-
nal input T1. For any given Timer 1 clock source, the UART0 baud rate is determined by Equation 18.1.
T1 CLK 1
UartBaudRate = ------------------------------- × ---
( 256 – T1H ) 2
TX
RS-232 RS-232
LEVEL RX C8051Fxxx
XLTR
OR
TX TX
MCU C8051Fxxx
RX RX
Data transmission begins when software writes a data byte to the SBUF0 register. The TI0 Transmit Inter-
rupt Flag (SCON0.1) is set at the end of the transmission (the beginning of the stop-bit time). Data recep-
tion can begin any time after the REN0 Receive Enable bit (SCON0.4) is set to logic 1. After the stop bit is
received, the data byte will be loaded into the SBUF0 receive register if the following conditions are met:
RI0 must be logic 0, and if MCE0 is logic 1, the stop bit must be logic 1. In the event of a receive data over-
run, the first received 8 bits are latched into the SBUF0 receive register and the following overrun data bits
are lost.
If these conditions are met, the eight bits of data is stored in SBUF0, the stop bit is stored in RB80 and the
RI0 flag is set. If these conditions are not met, SBUF0 and RB80 will not be loaded and the RI0 flag will not
be set. An interrupt will occur if enabled when either TI0 or RI0 is set.
MARK START
BIT D0 D1 D2 D3 D4 D5 D6 D7 STOP
SPACE BIT
BIT TIMES
BIT SAMPLING
Data transmission begins when an instruction writes a data byte to the SBUF0 register. The TI0 Transmit
Interrupt Flag (SCON0.1) is set at the end of the transmission (the beginning of the stop-bit time). Data
reception can begin any time after the REN0 Receive Enable bit (SCON0.4) is set to ‘1’. After the stop bit
is received, the data byte will be loaded into the SBUF0 receive register if the following conditions are met:
(1) RI0 must be logic 0, and (2) if MCE0 is logic 1, the 9th bit must be logic 1 (when MCE0 is logic 0, the
state of the ninth data bit is unimportant). If these conditions are met, the eight bits of data are stored in
SBUF0, the ninth bit is stored in RB80, and the RI0 flag is set to ‘1’. If the above conditions are not met,
SBUF0 and RB80 will not be loaded and the RI0 flag will not be set to ‘1’. A UART0 interrupt will occur if
enabled when either TI0 or RI0 is set to ‘1’.
MARK START
BIT D0 D1 D2 D3 D4 D5 D6 D7 D8 STOP
SPACE BIT
BIT TIMES
BIT SAMPLING
Setting the MCE0 bit (SCON0.5) of a slave processor configures its UART such that when a stop bit is
received, the UART will generate an interrupt only if the ninth bit is logic 1 (RB80 = 1) signifying an address
byte has been received. In the UART interrupt handler, software will compare the received address with
the slave's own assigned 8-bit address. If the addresses match, the slave will clear its MCE0 bit to enable
interrupts on the reception of the following data byte(s). Slaves that weren't addressed leave their MCE0
bits set and do not generate interrupts on the reception of the following data bytes, thereby ignoring the
data. Once the entire message is received, the addressed slave resets its MCE0 bit to ignore all transmis-
sions until it receives the next address byte.
Multiple addresses can be assigned to a single slave and/or a single address can be assigned to multiple
slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. The master
processor can be configured to receive all transmissions or a protocol can be implemented such that the
master/slave role is temporarily reversed to enable half-duplex transmission between the original master
and slave(s).
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0x99
Table 18.1. Timer Settings for Standard Baud Rates Using the Internal Oscillator
Target Actual Baud Oscillator Timer Clock SCA1-SCA0 T1M* Timer 1
Baud Baud Rate Error Divide Source (pre-scale Reload
Rate (bps) Rate (bps) Factor select* Value (hex)
230400 230769 0.16% 52 SYSCLK XX 1 0xE6
115200 115385 0.16% 104 SYSCLK XX 1 0xCC
SYSCLK = 12 MHz
UART1 has six associated SFRs. Three are used for the Baud Rate Generator (SBCON1, SBRLH1, and
SBRLL1), two are used for data formatting, control, and status functions (SCON1, SMOD1), and one is
used to send and receive data (SBUF1). The single SBUF1 location provides access to both the transmit
holding register and the receive FIFO. Writes to SBUF1 always access the Transmit Holding Register.
Reads of SBUF1 always access the first byte of the Receive FIFO; it is not possible to read data
from the Transmit Holding Register.
With UART1 interrupts enabled, an interrupt is generated each time a transmit is completed (TI1 is set in
SCON1), or a data byte has been received (RI1 is set in SCON1). The UART1 interrupt flags are not
cleared by hardware when the CPU vectors to the interrupt service routine. They must be cleared manually
by software, allowing software to determine the cause of the UART1 interrupt (transmit complete or receive
complete). Note that if additional bytes are available in the Receive FIFO, the RI1 bit cannot be cleared by
software.
Data Formatting TX
Baud Rate Generator Logic TX1
SMOD1
SBRLH1 SBRLL1
MCE1
S1PT1
S1PT0
PE1
S1DL1
S1DL0
XBE1
SBL1
Overflow
TX Holding
SYSCLK Pre-Scaler Register
Timer (16-bit)
EN (1, 4, 12, 48) Write to SBUF1
SBUF1
Control / Status Read of SBUF1
SB1RUN
SB1PS1
SB1PS0
SCON1 RX FIFO
OVR1
PERR1
THRE1
REN1
RBX1
TI1
RI1
TBX1
(3 Deep)
SBCON1
RX
Logic RX1
UART1
Interrupt
The baud rate generator is configured using three registers: SBCON1, SBRLH1, and SBRLL1. The
UART1 Baud Rate Generator Control Register (SBCON1, SFR Definition 19.4) enables or disables the
baud rate generator, and selects the prescaler value for the timer. The baud rate generator must be
enabled for UART1 to function. Registers SBRLH1 and SBRLL1 contain a 16-bit reload value for the dedi-
cated 16-bit timer. The internal timer counts up from the reload value on every clock tick. On timer over-
flows (0xFFFF to 0x0000), the timer is reloaded. For reliable UART operation, it is recommended that the
UART baud rate is not configured for baud rates faster than SYSCLK/16. The baud rate for UART1 is
defined in Equation 19.1.
SYSCLK 1 1
Baud Rate = --------------------------------------------------------------------------- × --- × ----------------------
( 65536 – (SBRLH1:SBRLL1) ) 2 Prescaler
Equation 19.1. UART1 Baud Rate
A quick reference for typical baud rates and system clock frequencies is given in Table 19.1.
Table 19.1. Baud Rate Generator Settings for Standard Baud Rates
Target Baud Actual Baud Baud Rate Oscillator SB1PS[1:0] Reload Value in
Rate (bps) Rate (bps) Error Divide (Prescaler Bits) SBRLH1:SBRLL1
Factor
230400 230769 0.16% 52 11 0xFFE6
115200 115385 0.16% 104 11 0xFFCC
SYSCLK = 12 MHz
MARK START
BIT D0 D1 DN-2 DN-1 STOP STOP
SPACE BIT 1 BIT 2
BIT TIMES
Optional
N bits; N = 5, 6, 7, or 8
MARK START
BIT D0 D1 DN-2 DN-1 PARITY STOP STOP
SPACE BIT 1 BIT 2
BIT TIMES
Optional
N bits; N = 5, 6, 7, or 8
MARK START
BIT D0 D1 DN-2 DN-1 EXTRA STOP STOP
SPACE BIT 1 BIT 2
BIT TIMES
Optional
N bits; N = 5, 6, 7, or 8
In typical UART communications, The transmit (TX) output of one device is connected to the receive (RX)
input of the other device, either directly or through a bus transceiver, as shown in Figure 19.5.
TX
PC RS-232 RS-232
LEVEL RX C8051Fxxx
COM Port TRANSLATOR
OR
TX TX
MCU C8051Fxxx
RX RX
If the extra bit function is enabled (XBE1 = ‘1’) and the parity function is disabled (PE1 = ‘0’), the value of
the TBX1 (SCON1.3) bit will be sent in the extra bit position. When the parity function is enabled (PE1 =
‘1’), hardware will generate the parity bit according to the selected parity type (selected with S1PT[1:0]),
and append it to the data field. Note: when parity is enabled, the extra bit function is not available.
space is made available in the FIFO for another incoming byte. If enabled, an interrupt will occur when RI1
is set. RI1 can only be cleared to '0' by software when there is no more information in the FIFO. The rec-
ommended procedure to empty the FIFO contents is as follows:
If the extra bit function is enabled (XBE1 = ‘1’) and the parity function is disabled (PE1 = ‘0’), the extra bit
for the oldest byte in the FIFO can be read from the RBX1 bit (SCON1.2). If the extra bit function is not
enabled, the value of the stop bit for the oldest FIFO byte will be presented in RBX1. When the parity func-
tion is enabled (PE1 = ‘1’), hardware will check the received parity bit against the selected parity type
(selected with S1PT[1:0]) when receiving data. If a byte with parity error is received, the PERR1 flag will be
set to ‘1’. This flag must be cleared by software. Note: when parity is enabled, the extra bit function is not
available.
Setting the MCE1 bit (SMOD1.7) of a slave processor configures its UART such that when a stop bit is
received, the UART will generate an interrupt only if the extra bit is logic 1 (RBX1 = 1) signifying an
address byte has been received. In the UART interrupt handler, software will compare the received
address with the slave's own assigned address. If the addresses match, the slave will clear its MCE1 bit to
enable interrupts on the reception of the following data byte(s). Slaves that weren't addressed leave their
MCE1 bits set and do not generate interrupts on the reception of the following data bytes, thereby ignoring
the data. Once the entire message is received, the addressed slave resets its MCE1 bit to ignore all trans-
missions until it receives the next address byte.
Multiple addresses can be assigned to a single slave and/or a single address can be assigned to multiple
slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. The master
processor can be configured to receive all transmissions or a protocol can be implemented such that the
master/slave role is temporarily reversed to enable half-duplex transmission between the original master
and slave(s).
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
MCE1 S1PT1 S1PT0 PE1 S1DL1 S1DL0 XBE1 SBL1 00001100
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xE5
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xD3
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
Reserved SB1RUN Reserved Reserved Reserved Reserved SB1PS1 SB1PS0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xAC
SFR Definition 19.5. SBRLH1: UART1 Baud Rate Generator High Byte
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xB5
Bits7–0: SBRLH1[7:0]: High Byte of reload value for UART1 Baud Rate Generator.
SFR Definition 19.6. SBRLL1: UART1 Baud Rate Generator Low Byte
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xB4
Bits7–0: SBRLL1[7:0]: Low Byte of reload value for UART1 Baud Rate Generator.
SFR Bus
RXOVRN
NSSMD1
NSSMD0
SLVSEL
SPIBSY
CKPHA
MSTEN
RXBMT
CKPOL
TXBMT
NSSIN
WCOL
SPIEN
MODF
SRMT
SCR7
SCR6
SCR5
SCR4
SCR3
SCR2
SCR1
SCR0
SPIF
Clock Divide
SYSCLK
Logic
Tx Data MOSI
C
SPI0DAT R
SCK
Transmit Data Buffer O
Pin
S
Control Port I/O
Shift Register Logic S
Rx Data MISO
7 6 5 4 3 2 1 0 B
A
R
Receive Data Buffer NSS
Write Read
SPI0DAT SPI0DAT
SFR Bus
1. NSSMD[1:0] = 00: 3-Wire Master or 3-Wire Slave Mode: SPI0 operates in 3-wire mode, and
NSS is disabled. When operating as a slave device, SPI0 is always selected in 3-wire mode.
Since no select signal is present, SPI0 must be the only slave on the bus in 3-wire mode. This
is intended for point-to-point communication between a master and one slave.
2. NSSMD[1:0] = 01: 4-Wire Slave or Multi-Master Mode: SPI0 operates in 4-wire mode, and
NSS is enabled as an input. When operating as a slave, NSS selects the SPI0 device. When
operating as a master, a 1-to-0 transition of the NSS signal disables the master function of
SPI0 so that multiple master devices can be used on the same SPI bus.
3. NSSMD[1:0] = 1x: 4-Wire Master Mode: SPI0 operates in 4-wire mode, and NSS is enabled as
an output. The setting of NSSMD0 determines what logic level the NSS pin will output. This
configuration should only be used when operating SPI0 as a master device.
See Figure 20.2, Figure 20.3, and Figure 20.4 for typical connection diagrams of the various operational
modes. Note that the setting of NSSMD bits affects the pinout of the device. When in 3-wire master or
3-wire slave mode, the NSS pin will not be mapped by the crossbar. In all other modes, the NSS signal will
be mapped to a pin on the device. See Section “15. Port Input/Output” on page 142 for general purpose
port I/O and crossbar information.
When configured as a master, SPI0 can operate in one of three different modes: multi-master mode, 3-wire
single-master mode, and 4-wire single-master mode. The default, multi-master mode is active when NSS-
MD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 1. In this mode, NSS is an input to the device, and is
used to disable the master SPI0 when another master is accessing the bus. When NSS is pulled low in this
mode, MSTEN (SPI0CFG.6) and SPIEN (SPI0CN.0) are set to 0 to disable the SPI master device, and a
Mode Fault is generated (MODF, SPI0CN.5 = 1). Mode Fault will generate an interrupt if enabled. SPI0
must be manually re-enabled in software under these circumstances. In multi-master systems, devices will
typically default to being slave devices while they are not acting as the system master device. In multi-mas-
ter mode, slave devices can be addressed individually (if needed) using general-purpose I/O pins.
Figure 20.2 shows a connection diagram between two master devices in multiple-master mode.
3-wire single-master mode is active when NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 0. In this
mode, NSS is not used, and is not mapped to an external port pin through the crossbar. Any slave devices
that must be addressed in this mode should be selected using general-purpose I/O pins. Figure 20.3
shows a connection diagram between a master device in 3-wire master mode and a slave device.
4-wire single-master mode is active when NSSMD1 (SPI0CN.3) = 1. In this mode, NSS is configured as an
output pin, and can be used as a slave-select signal for a single SPI device. In this mode, the output value
of NSS is controlled (in software) with the bit NSSMD0 (SPI0CN.2). Additional slave devices can be
addressed using general-purpose I/O pins. Figure 20.4 shows a connection diagram for a master device in
4-wire master mode and two slave devices.
NSS GPIO
MISO MISO
Master MOSI MOSI
Master
Device 1 SCK SCK
Device 2
GPIO NSS
Master Slave
Device MISO MISO Device
MOSI MOSI
SCK SCK
Figure 20.3. 3-Wire Single Master and Slave Mode Connection Diagram
MISO Slave
MOSI Device
SCK
NSS
Figure 20.4. 4-Wire Single Master Mode and Slave Mode Connection Diagram
When configured as a slave, SPI0 can be configured for 4-wire or 3-wire operation. The default, 4-wire
slave mode, is active when NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 1. In 4-wire mode, the
NSS signal is routed to a port pin and configured as a digital input. SPI0 is enabled when NSS is logic 0,
and disabled when NSS is logic 1. The bit counter is reset on a falling edge of NSS. Note that the NSS sig-
nal must be driven low at least 2 system clocks before the first active edge of SCK for each byte transfer.
Figure 20.4 shows a connection diagram between two slave devices in 4-wire slave mode and a master
device.
3-wire slave mode is active when NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 0. NSS is not
used in this mode, and is not mapped to an external port pin through the crossbar. Since there is no way of
uniquely addressing the device in 3-wire slave mode, SPI0 must be the only slave device present on the
bus. It is important to note that in 3-wire slave mode there is no external means of resetting the bit counter
that determines when a full byte has been received. The bit counter can only be reset by disabling and
re-enabling SPI0 with the SPIEN bit. Figure 20.3 shows a connection diagram between a slave device in
3-wire slave mode and a master device.
1. The SPI Interrupt Flag, SPIF (SPI0CN.7) is set to logic 1 at the end of each byte transfer. This
flag can occur in all SPI0 modes.
2. The Write Collision Flag, WCOL (SPI0CN.6) is set to logic 1 if a write to SPI0DAT is attempted
when the transmit buffer has not been emptied to the SPI shift register. When this occurs, the
write to SPI0DAT will be ignored, and the transmit buffer will not be written.This flag can occur
in all SPI0 modes.
3. The Mode Fault Flag MODF (SPI0CN.5) is set to logic 1 when SPI0 is configured as a master,
and for multi-master mode and the NSS pin is pulled low. When a Mode Fault occurs, the
MSTEN and SPIEN bits in SPI0CN are set to logic 0 to disable SPI0 and allow another master
device to access the bus.
4. The Receive Overrun Flag RXOVRN (SPI0CN.4) is set to logic 1 when configured as a slave,
and a transfer is completed and the receive buffer still holds an unread byte from a previous
transfer. The new byte is not transferred to the receive buffer, allowing the previously received
data byte to be read. The data byte which caused the overrun is lost.
The SPI0 Clock Rate Register (SPI0CKR) as shown in SFR Definition 20.3 controls the master mode
serial clock frequency. This register is ignored when operating in slave mode. When the SPI is configured
as a master, the maximum data transfer rate (bits/sec) is one-half the system clock frequency or 12.5 MHz,
whichever is slower. When the SPI is configured as a slave, the maximum data transfer rate (bits/sec) for
full-duplex operation is 1/10 the system clock frequency, provided that the master issues SCK, NSS (in
4-wire slave mode), and the serial input data synchronously with the slave’s system clock. If the master
issues SCK, NSS, and the serial input data asynchronously, the maximum data transfer rate (bits/sec)
must be less than 1/10 the system clock frequency. In the special case where the master only wants to
transmit data to the slave and does not need to receive data from the slave (i.e. half-duplex operation), the
SPI slave can receive data at a maximum data transfer rate (bits/sec) of 1/4 the system clock frequency.
This is provided that the master issues SCK, NSS, and the serial input data synchronously with the slave’s
system clock.
SCK
(CKPOL=0, CKPHA=0)
SCK
(CKPOL=0, CKPHA=1)
SCK
(CKPOL=1, CKPHA=0)
SCK
(CKPOL=1, CKPHA=1)
SCK
(CKPOL=0, CKPHA=0)
SCK
(CKPOL=1, CKPHA=0)
SCK
(CKPOL=0, CKPHA=1)
SCK
(CKPOL=1, CKPHA=1)
*Note: In slave mode, data on MOSI is sampled in the center of each data bit. In master mode, data on MISO is
sampled one SYSCLK before the end of each data bit, to provide maximum settling time for the slave device.
See Table 20.1 for timing parameters.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
SCR7 SCR6 SCR5 SCR4 SCR3 SCR2 SCR1 SCR0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xA2
SYSCLK
f SCK = -------------------------------------------------
2 × ( SPI0CKR + 1 )
2000000
f SCK = --------------------------
2 × (4 + 1)
f SCK = 200kHz
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
SFR Address: 0xA3
SCK*
T T
MCKH MCKL
T T
MIS MIH
MISO
MOSI
* SCK is shown for CKPOL = 0. SCK is the opposite polarity for CKPOL = 1.
SCK*
T T
MCKH MCKL
T T
MIS MIH
MISO
MOSI
* SCK is shown for CKPOL = 0. SCK is the opposite polarity for CKPOL = 1.
NSS
T T T
SE CKL SD
SCK*
T
CKH
T T
SIS SIH
MOSI
T T T
SEZ SOH SDZ
MISO
* SCK is shown for CKPOL = 0. SCK is the opposite polarity for CKPOL = 1.
NSS
T T T
SE CKL SD
SCK*
T
CKH
T T
SIS SIH
MOSI
T T T T
SEZ SOH SLH SDZ
MISO
* SCK is shown for CKPOL = 0. SCK is the opposite polarity for CKPOL = 1.
21. Timers
Each MCU includes four counter/timers: two are 16-bit counter/timers compatible with those found in the
standard 8051, and two are 16-bit auto-reload timer for use with the ADC, SMBus, USB (frame measure-
ments), Low-Frequency Oscillator (period measurements), or for general purpose use. These timers can
be used to measure time intervals, count external events and generate periodic interrupt requests. Timer 0
and Timer 1 are nearly identical and have four primary modes of operation. Timer 2 and Timer 3 offer
16-bit and split 8-bit timer functionality with auto-reload.
Timers 0 and 1 may be clocked by one of five sources, determined by the Timer Mode Select bits
(T1M-T0M) and the Clock Scale bits (SCA1-SCA0). The Clock Scale bits define a pre-scaled clock from
which Timer 0 and/or Timer 1 may be clocked (See SFR Definition 21.3 for pre-scaled clock selection).
Timer 0/1 may then be configured to use this pre-scaled clock signal or the system clock. Timer 2 and
Timer 3 may be clocked by the system clock, the system clock divided by 12, or the external oscillator
clock source divided by 8.
Timer 0 and Timer 1 may also be operated as counters. When functioning as a counter, a counter/timer
register is incremented on each high-to-low transition at the selected input pin (T0 or T1). Events with a fre-
quency of up to one-fourth the system clock's frequency can be counted. The input signal need not be peri-
odic, but it should be held at a given level for at least two full system clock cycles to ensure the level is
properly sampled.
The TH0 register holds the eight MSBs of the 13-bit counter/timer. TL0 holds the five LSBs in bit positions
TL0.4-TL0.0. The three upper bits of TL0 (TL0.7-TL0.5) are indeterminate and should be masked out or
ignored when reading. As the 13-bit timer register increments and overflows from 0x1FFF (all ones) to
0x0000, the timer overflow flag TF0 (TCON.5) is set and an interrupt will occur if Timer 0 interrupts are
enabled.
The C/T0 bit (TMOD.2) selects the counter/timer's clock source. When C/T0 is set to logic 1, high-to-low
transitions at the selected Timer 0 input pin (T0) increment the timer register (Refer to Section
“15.1. Priority Crossbar Decoder” on page 144 for information on selecting and configuring external I/O
pins). Clearing C/T selects the clock defined by the T0M bit (CKCON.3). When T0M is set, Timer 0 is
clocked by the system clock. When T0M is cleared, Timer 0 is clocked by the source selected by the Clock
Scale bits in CKCON (see SFR Definition 21.3).
Setting the TR0 bit (TCON.4) enables the timer when either GATE0 (TMOD.3) is logic 0 or the input signal
INT0 is active as defined by bit IN0PL in register INT01CF (see SFR Definition 9.13). Setting GATE0 to ‘1’
allows the timer to be controlled by the external input signal INT0 (see Section “9.3.5. Interrupt Register
Descriptions” on page 90), facilitating pulse width measurements.
TL1 and TH1 form the 13-bit register for Timer 1 in the same manner as described above for TL0 and TH0.
Timer 1 is configured and controlled using the relevant TCON and TMOD bits just as with Timer 0. The
input signal INT1 is used with Timer 1; the INT1 polarity is defined by bit IN1PL in register INT01CF (see
SFR Definition 9.13).
Pre-scaled Clock 0
SYSCLK 1
1
TF1
T0 TR1
TCLK TL0 TH0 TF0 Interrupt
TR0 TR0
(5 bits) (8 bits) IE1
TCON
GATE0 IT1
Crossbar IE0
IT0
IN0PL XOR
INT0
Both counter/timers are enabled and configured in Mode 2 in the same manner as Mode 0. Setting the
TR0 bit (TCON.4) enables the timer when either GATE0 (TMOD.3) is logic 0 or when the input signal INT0
is active as defined by bit IN0PL in register INT01CF (see Section “9.3.2. External Interrupts” on
page 88 for details on the external input signals INT0 and INT1).
Pre-scaled Clock 0
SYSCLK 1
T0 TF1
TCLK TL0 TR1
TF0 Interrupt
(8 bits) TR0
IE1
TCON
TR0 IT1
Crossbar IE0
GATE0 IT0
TH0 Reload
(8 bits)
IN0PL XOR
INT0
Timer 1 is inactive in Mode 3. When Timer 0 is operating in Mode 3, Timer 1 can be operated in Modes 0,
1 or 2, but cannot be clocked by external signals nor set the TF1 flag and generate an interrupt. However,
the Timer 1 overflow can be used to generate baud rates for the SMBus and/or UART, and/or initiate ADC
conversions. While Timer 0 is operating in Mode 3, Timer 1 run control is handled through its mode set-
tings. To run Timer 1 while Timer 0 is in Mode 3, set the Timer 1 Mode as 0, 1, or 2. To disable Timer 1,
configure it for Mode 3.
CKCON TMOD
T T T T T T S S G C T T G C T T
3 3 2 2 1 0 C C A / 1 1 A / 0 0
MMMMMMA A T T M M T T M M
E 1 1 0 E 0 1 0
H L H L 1 0
1 0
Pre-scaled Clock 0
TR1 TH0
TF1 Interrupt
(8 bits) TR1
TF0 Interrupt
SYSCLK 1 TR0
0 IE1
TCON
IT1
IE0
IT0
T0
TL0
(8 bits)
TR0
Crossbar GATE0
IN0PL XOR
INT0
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0x88
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
GATE1 C/T1 T1M1 T1M0 GATE0 C/T0 T0M1 T0M0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x89
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
T3MH T3ML T2MH T2ML T1M T0M SCA1 SCA0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x8E
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x8A
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x8B
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x8C
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x8D
21.2. Timer 2
Timer 2 is a 16-bit timer formed by two 8-bit SFRs: TMR2L (low byte) and TMR2H (high byte). Timer 2 may
operate in 16-bit auto-reload mode, (split) 8-bit auto-reload mode, USB Start-of-Frame (SOF) capture
mode, or Low-Frequency Oscillator (LFO) Falling Edge capture mode. The Timer 2 operation mode is
defined by the T2SPLIT (TMR2CN.3), T2CE (TMR2CN.4) bits, and T2CSS (TMR2CN.1) bits.
Timer 2 may be clocked by the system clock, the system clock divided by 12, or the external oscillator
source divided by 8. The external clock mode is ideal for real-time clock (RTC) functionality, where the
internal oscillator drives the system clock while Timer 2 (and/or the PCA) is clocked by an external preci-
sion oscillator. Note that the external oscillator source divided by 8 is synchronized with the system clock.
CKCON
TTTTTTSS
3 3 2 2 1 0 CC
T2XCLK MMMMMM A A
HLHL 1 0
To ADC,
SYSCLK / 12 0 To SMBus
TL2 SMBus
Overflow
0
TR2 TCLK
External Clock / 8 TMR2L TMR2H TF2H Interrupt
1 TF2L
TMR2CN
TF2LEN
SYSCLK 1 T2CE
T2SPLIT
TR2
T2CSS
T2XCLK
TMR2RLL TMR2RLH
Reload
Each 8-bit timer may be configured to use SYSCLK, SYSCLK divided by 12, or the external oscillator clock
source divided by 8. The Timer 2 Clock Select bits (T2MH and T2ML in CKCON) select either SYSCLK or
the clock defined by the Timer 2 External Clock Select bit (T2XCLK in TMR2CN), as follows:
T2MH T2XCLK TMR2H Clock Source T2ML T2XCLK TMR2L Clock Source
0 0 SYSCLK / 12 0 0 SYSCLK / 12
0 1 External Clock / 8 0 1 External Clock / 8
1 X SYSCLK 1 X SYSCLK
The TF2H bit is set when TMR2H overflows from 0xFF to 0x00; the TF2L bit is set when TMR2L overflows
from 0xFF to 0x00. When Timer 2 interrupts are enabled, an interrupt is generated each time TMR2H over-
flows. If Timer 2 interrupts are enabled and TF2LEN (TMR2CN.5) is set, an interrupt is generated each
time either TMR2L or TMR2H overflows. When TF2LEN is enabled, software must check the TF2H and
TF2L flags to determine the source of the Timer 2 interrupt. The TF2H and TF2L interrupt flags are not
cleared by hardware and must be manually cleared by software.
CKCON
TTTTTTSS
T2XCLK
3 3 2 2 1 0 CC
MMMMMM A A Reload
HLHL 1 0 TMR2RLH To SMBus
SYSCLK / 12 0
0
External Clock / 8 1 TCLK
TR2 TMR2H TF2H Interrupt
TF2L
1 TF2LEN
TMR2CN
T2CE
T2SPLIT
Reload TR2
TMR2RLL T2CSS
SYSCLK T2XCLK
1
TCLK To ADC,
TMR2L
SMBus
TMR2CN
T T TT TTTT
F F F 2 2R2 2
2 2 2C S2CX
H L LE P SC CKCON
E L SL TTTTTTSS
N I K 3 3 2 2 1 0 CC
T
MMMMMM A A
HLHL 1 0
SYSCLK / 12 0 To SMBus
TL2
Overflow
0
TR2 TCLK To ADC,
External Clock / 8 TMR2L TMR2H SMBus
1
SYSCLK 1
Enable Interrupt
T2CSS
When T2SPLIT = ‘1’, the Timer 2 registers (TMR2H and TMR2L) act as two 8-bit counters. Each counter
counts up independently and overflows from 0xFF to 0x00. Each time a capture event is received, the con-
tents of the Timer 2 registers are latched into the Timer 2 Reload registers (TMR2RLH and TMR2RLL). A
Timer 2 interrupt is generated if enabled.
TMR2CN
T T TT TTTT
F F F 2 2R2 2
2 2 2C S2CX
H L LE P SC
E L SL CKCON
N I K TTTTTTSS
T 3 3 2 2 1 0CC
MMMMMM A A Capture Enable Interrupt
HLHL 1 0 TMR2RLH
SYSCLK / 12 0
0
External Clock / 8 1 TCLK
TR2 TMR2H To SMBus
1
Capture
TMR2RLL
SYSCLK
1
TCLK To ADC,
TMR2L
SMBus
0
USB Start-of-Frame (SOF) 0
Low-Frequency Oscillator
1
Falling Edge
T2CSS
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
TF2H TF2L TF2LEN T2CE T2SPLIT TR2 T2CSS T2XCLK 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xC8
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xCA
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xCB
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xCC
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xCD
21.3. Timer 3
Timer 3 is a 16-bit timer formed by two 8-bit SFRs: TMR3L (low byte) and TMR3H (high byte). Timer 3 may
operate in 16-bit auto-reload mode, (split) 8-bit auto-reload mode, USB Start-of-Frame (SOF) capture
mode, or Low-Frequency Oscillator (LFO) Rising Edge capture mode. The Timer 3 operation mode is
defined by the T3SPLIT (TMR3CN.3), T3CE (TMR3CN.4) bits, and T3CSS (TMR3CN.1) bits.
Timer 3 may be clocked by the system clock, the system clock divided by 12, or the external oscillator
source divided by 8. The external clock mode is ideal for real-time clock (RTC) functionality, where the
internal oscillator drives the system clock while Timer 3 (and/or the PCA) is clocked by an external preci-
sion oscillator. Note that the external oscillator source divided by 8 is synchronized with the system clock.
CKCON
TTTTTTSS
3 3 2 2 1 0CC
T3XCLK MMMMMM A A
HLHL 1 0
SYSCLK / 12 0 To ADC
0
TR3 TCLK
External Clock / 8 TMR3L TMR3H TF3H Interrupt
1 TF3L
TMR3CN
TF3LEN
SYSCLK 1 T3CE
T3SPLIT
TR3
T3CSS
T3XCLK
TMR3RLL TMR3RLH
Reload
Each 8-bit timer may be configured to use SYSCLK, SYSCLK divided by 12, or the external oscillator clock
source divided by 8. The Timer 3 Clock Select bits (T3MH and T3ML in CKCON) select either SYSCLK or
the clock defined by the Timer 3 External Clock Select bit (T3XCLK in TMR3CN), as follows:
T3MH T3XCLK TMR3H Clock Source T3ML T3XCLK TMR3L Clock Source
0 0 SYSCLK / 12 0 0 SYSCLK / 12
0 1 External Clock / 8 0 1 External Clock / 8
1 X SYSCLK 1 X SYSCLK
The TF3H bit is set when TMR3H overflows from 0xFF to 0x00; the TF3L bit is set when TMR3L overflows
from 0xFF to 0x00. When Timer 3 interrupts are enabled, an interrupt is generated each time TMR3H over-
flows. If Timer 3 interrupts are enabled and TF3LEN (TMR3CN.5) is set, an interrupt is generated each
time either TMR3L or TMR3H overflows. When TF3LEN is enabled, software must check the TF3H and
TF3L flags to determine the source of the Timer 3 interrupt. The TF3H and TF3L interrupt flags are not
cleared by hardware and must be manually cleared by software.
CKCON
TTTTTTSS
T3XCLK
3 3 2 2 1 0 CC
MMMMMM A A Reload
HLHL 1 0 TMR3RLH
SYSCLK / 12 0
To ADC
0
External Clock / 8 1 TCLK
TR3 TMR3H TF3H Interrupt
TF3L
1 TF3LEN
TMR3CN
T3CE
T3SPLIT
Reload TR3
TMR3RLL T3CSS
SYSCLK T3XCLK
1
TCLK TMR3L
TMR3CN
T T TT TTTT
F F F 3 3R3 3
3 3 3C S 3CX
H L LE P SC CKCON
E L SL TTTTTTSS
N I K 3 3 2 2 1 0 CC
T
MMMMMM A A
HLHL 1 0
SYSCLK / 12 0
0
TR3 TCLK
External Clock / 8 TMR3L TMR3H To ADC
1
SYSCLK 1
Enable Interrupt
T3CSS
When T3SPLIT = ‘1’, the Timer 3 registers (TMR3H and TMR3L) act as two 8-bit counters. Each counter
counts up independently and overflows from 0xFF to 0x00. Each time a capture event is received, the con-
tents of the Timer 3 registers are latched into the Timer 3 Reload registers (TMR3RLH and TMR3RLL). A
Timer 3 interrupt is generated if enabled.
TMR3CN
T T TT TTTT
F F F 3 3R3 3
3 3 3C S 3CX
H L LE P SC
E L SL CKCON
N I K TTTTTTSS
T 3 3 2 2 1 0CC
MMMMMM A A Capture Enable Interrupt
HLHL 1 0 TMR3RLH
SYSCLK / 12 0
0
External Clock / 8 1 TCLK
TR3 TMR3H To ADC
1
Capture
TMR3RLL
SYSCLK
1
TCLK TMR3L
0
USB Start-of-Frame (SOF) 0
Low-Frequency Oscillator
1
Falling Edge
T3CSS
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
TF3H TF3L TF3LEN T3CE T3SPLIT TR3 T3CSS T3XCLK 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x91
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x92
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x93
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x94
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0x95
Important Note: The PCA Module 4 may be used as a watchdog timer (WDT), and is enabled in this mode
following a system reset. Access to certain PCA registers is restricted while WDT mode is enabled. See
Section 22.3 for details.
SYSCLK/12
SYSCLK/4
Timer 0 Overflow PCA
CLOCK 16-Bit Counter/Timer
ECI
MUX
SYSCLK
External Clock/8
CEX1
CEX2
CEX3
CEX4
ECI
Crossbar
Port I/O
When the counter/timer overflows from 0xFFFF to 0x0000, the Counter Overflow Flag (CF) in PCA0MD is
set to logic 1 and an interrupt request is generated if CF interrupts are enabled. Setting the ECF bit in
PCA0MD to logic 1 enables the CF flag to generate an interrupt request. The CF bit is not automatically
cleared by hardware when the CPU vectors to the interrupt service routine, and must be cleared by soft-
ware (Note: PCA0 interrupts must be globally enabled before CF interrupts are recognized. PCA0 inter-
rupts are globally enabled by setting the EA bit (IE.7) and the EPCA0 bit in EIE1 to logic 1). Clearing the
CIDL bit in the PCA0MD register allows the PCA to continue normal operation while the CPU is in Idle
mode.
IDLE
PCA0MD PCA0CN
CWW C C CE CC C C C C C
I D D P P PC FR C C C C C
D T L S S SF F F F F F
L E C 2 1 0 4 3 2 1 0 To SFR Bus
K PCA0L
read
Snapshot
Register
SYSCLK/12
000
SYSCLK/4
001
Timer 0 Overflow
010 0
Overflow
ECI PCA0H PCA0L To PCA Interrupt System
011 1
SYSCLK CF
100
External Clock/8
101
To PCA Modules
Table 22.2 summarizes the bit settings in the PCA0CPMn registers used to select the PCA capture/com-
pare module’s operating modes. Setting the ECCFn bit in a PCA0CPMn register enables the module's
CCFn interrupt. Note: PCA0 interrupts must be globally enabled before individual CCFn interrupts are rec-
ognized. PCA0 interrupts are globally enabled by setting the EA bit and the EPCA0 bit to logic 1. See
Figure 22.3 for details on the PCA interrupt configuration.
(for n = 0 to 4)
PCA0CPMn PCA0CN PCA0MD
P ECCMT P E CC CCCCC C WW CCCE
WCA A AOWC FR CCCCC I DD PPPC
MOP P TGMC FFFFF DT L SSSF
1 MP N n n n F 4 3 2 1 0 LEC 2 1 0
6 n n n n K
n
PCA Counter/ 0
Timer Overflow 1
ECCF0
PCA Module 0 0 EPCA0 EA
(CCF0) 1 0 0 Interrupt
Priority
1 1
Decoder
ECCF1
PCA Module 1 0
(CCF1) 1
ECCF2
PCA Module 2 0
(CCF2) 1
ECCF3
PCA Module 3 0
(CCF3) 1
ECCF4
PCA Module 4 0
(CCF4) 1
PCA Interrupt
PCA0CPMn
P E CCMT P E PCA0CN
WC A A AOWC CC CCCCC
MOPP TGMC FR CCCCC
1 MPN n n n F FFFFF
6 n n n n 4 3 2 1 0
n
x 0 0 0 0 x
(to CCFn)
PCA0CPLn PCA0CPHn
0
1
CEXn Capture
Port I/O Crossbar
0
1
PCA
Timebase
PCA0L PCA0H
Note: The CEXn input signal must remain high or low for at least 2 system clock cycles to be recognized by
the hardware.
Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/
Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit
to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’.
Write to
PCA0CPLn 0
ENB
Reset
Write to
PCA0CPHn ENB PCA Interrupt
1
PCA0CPMn
P ECCMT P E PCA0CN
WC A A AOWC CC CCCCC
MOP P TGMC PCA0CPLn PCA0CPHn FR CCCCC
1 MP N n n n F FFFFF
6 n n n n 4 3 2 1 0
n
x 0 0 0 0 x
0
Enable Match
16-bit Comparator
1
PCA
Timebase
PCA0L PCA0H
Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/
Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit
to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’.
Write to
PCA0CPLn 0
ENB
Reset
PCA0CPMn
Write to
PCA0CPHn ENB P ECCMT P E
1 WC A A A OWC
MOPP TGMC
1 MP N n n n F
6 n n n n
n
x 0 0 0 x
PCA Interrupt
PCA0CN
CC CCCCC
PCA0CPLn PCA0CPHn FR CCCCC
FFFFF
4 3 2 1 0
0
Enable Match
16-bit Comparator
1
TOGn
Toggle
0 CEXn
Crossbar Port I/O
1
PCA
Timebase
PCA0L PCA0H
F PCA
F CEXn = -----------------------------------------
2 × PCA0CPHn
Note: A value of 0x00 in the PCA0CPHn register is equal to 256 for this equation.
Write to
PCA0CPLn 0
ENB
Reset
PCA0CPMn
Write to P ECCMT P E
PCA0CPHn ENB WC A A AOWC
PCA0CPLn 8-bit Adder PCA0CPHn
1 MOPP TGMC
1 MP N n n n F
Adder
6 nnn n Enable
n TOGn
x 0 0 0 x Toggle
0 CEXn
Enable 8-bit match Crossbar Port I/O
Comparator 1
PCA Timebase
PCA0L
Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/
Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit
to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’.
( 256 – PCA0CPHn )
DutyCycle = ---------------------------------------------------
256
Write to
PCA0CPLn 0
ENB PCA0CPHn
Reset
Write to
PCA0CPHn ENB
1
PCA0CPMn
P ECCMT P E
WC A A AOWC
PCA0CPLn
MOPP TGMC
1 MP N n n n F
6 n n n n
n
0 0 0 x 0 x
R CLR
Q
PCA Timebase
PCA0L
Overflow
Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/
Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit
to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’.
( 65536 – PCA0CPn )
DutyCycle = -----------------------------------------------------
65536
Write to
PCA0CPLn 0
ENB
Reset
Write to
PCA0CPHn ENB
1
PCA0CPMn
P ECCMT P E
WC A A AOWC
PCA0CPHn PCA0CPLn
MOPP TGMC
1 MP N n n n F
6 n n n n
n
1 0 0 x 0 x
R CLR
Q
PCA Timebase
PCA0H PCA0L
Overflow
With the WDTE and/or WDLCK bits set to ‘1’ in the PCA0MD register, Module 4 operates as a watchdog
timer (WDT). The Module 4 high byte is compared to the PCA counter high byte; the Module 4 low byte
holds the offset to be used when WDT updates are performed. The Watchdog Timer is enabled on
reset. Writes to some PCA registers are restricted while the Watchdog Timer is enabled.
While the WDT is enabled, writes to the CR bit will not change the PCA counter state; the counter will run
until the WDT is disabled. The PCA counter run control (CR) will read zero if the WDT is enabled but user
software has not enabled the PCA counter. If a match occurs between PCA0CPH4 and PCA0H while the
WDT is enabled, a reset will be generated. To prevent a WDT reset, the WDT may be updated with a write
of any value to PCA0CPH4. Upon a PCA0CPH4 write, PCA0H plus the offset held in PCA0CPL4 is loaded
into PCA0CPH4 (See Figure 22.10).
PCA0MD
CWW CCCE
I DD PPPC PCA0CPH4
DT L SSSF
L E C 2 1 0
K
8-bit Match
Reset
Enable Comparator
PCA0L Overflow
PCA0CPL4 8-bit Adder PCA0H
Adder
Write to Enable
PCA0CPH4
Note that the 8-bit offset held in PCA0CPH4 is compared to the upper byte of the 16-bit PCA counter. This
offset value is the number of PCA0L overflows before a reset. Up to 256 PCA clocks may pass before the
first PCA0L overflow occurs, depending on the value of the PCA0L when the update is performed. The
total offset is then given (in PCA clocks) by Equation 22.4, where PCA0L is the value of the PCA0L register
at the time of the update.
The PCA clock source and Idle mode select cannot be changed while the WDT is enabled. The watchdog
timer is enabled by setting the WDTE or WDLCK bits in the PCA0MD register. When WDLCK is set, the
WDT cannot be disabled until the next system reset. If WDLCK is not set, the WDT is disabled by clearing
the WDTE bit.
The WDT is enabled following any reset. The PCA0 counter clock defaults to the system clock divided by
12, PCA0L defaults to 0x00, and PCA0CPL4 defaults to 0x00. Using Equation 22.4, this results in a WDT
timeout interval of 256 PCA clocks. Table 22.3 lists some example timeout intervals for typical system
clocks.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
CF CR - CCF4 CCF3 CCF2 CCF1 CCF0 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
(bit addressable) 0xD8
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
CIDL WDTE WDLCK - CPS2 CPS1 CPS0 ECF 01000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xD9
Note: When the WDTE bit is set to ‘1’, the PCA0MD register cannot be modified. To change the
contents of the PCA0MD register, the Watchdog Timer must first be disabled.
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
PWM16n ECOMn CAPPn CAPNn MATn TOGn PWMn ECCFn 00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xDA, 0xDB,
0xDC, 0xDD,
0xDE
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xF9
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xFA
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xFB, 0xE9,
0xEB, 0xED,
0xFD
R/W R/W R/W R/W R/W R/W R/W R/W Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address:
0xFC, 0xEA,
0xEC,0xEE,
0xFE
23. C2 Interface
C8051F34x devices include an on-chip Silicon Labs 2-Wire (C2) debug interface to allow Flash program-
ming and in-system debugging with the production part installed in the end application. The C2 interface
uses a clock signal (C2CK) and a bi-directional C2 data signal (C2D) to transfer information between the
device and a host system. See the C2 Interface Specification for details on the C2 protocol.
Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Bits7–0: The C2ADD register is accessed via the C2 interface to select the target Data register for
C2 Data Read and Data Write commands.
Address Description
0x00 Selects the Device ID register for Data Read instructions
0x01 Selects the Revision ID register for Data Read instructions
0x02 Selects the C2 Flash Programming Control register for Data Read/Write instructions
0xAD Selects the C2 Flash Programming Data register for Data Read/Write instructions
Reset Value
00001111
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
This read-only register returns the 8-bit device ID: 0x0F (C8051F340/1/2/3/4/5/6/7/8/9/A/B/C/D).
Reset Value
Variable
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Reset Value
00000000
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
Code Command
0x06 Flash Block Read
0x07 Flash Block Write
0x08 Flash Page Erase
0x03 Device Erase
C8051Fxxx
Output (c)
C2 Interface Master
1. The user input (b) cannot change state while the target device is halted.
2. The RST pin on the target device is used as an input only.
NOTES:
Disclaimer
Silicon Laboratories intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers
using or intending to use the Silicon Laboratories products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific
device, and "Typical" parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Laboratories
reserves the right to make changes without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy
or completeness of the included information. Silicon Laboratories shall have no liability for the consequences of use of the information supplied herein. This document does not imply
or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products must not be used within any Life Support System without the specific
written consent of Silicon Laboratories. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected
to result in significant personal injury or death. Silicon Laboratories products are generally not intended for military applications. Silicon Laboratories products shall under no
circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons.
Trademark Information
Silicon Laboratories Inc., Silicon Laboratories, Silicon Labs, SiLabs and the Silicon Labs logo, CMEMS®, EFM, EFM32, EFR, Energy Micro, Energy Micro logo and combinations
thereof, "the world’s most energy friendly microcontrollers", Ember®, EZLink®, EZMac®, EZRadio®, EZRadioPRO®, DSPLL®, ISOmodem ®, Precision32®, ProSLIC®, SiPHY®,
USBXpress® and others are trademarks or registered trademarks of Silicon Laboratories Inc. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of
ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand names mentioned herein are trademarks of their respective holders.
http://www.silabs.com