The EFM8SB2, part of the Sleepy Bee family of MCUs, is the
world’s most energy friendly 8-bit microcontrollers with a comprehensive feature set in small packages.
These devices offer lowest power consumption by combining innovative low energy techniques and short wakeup times from energy saving modes into small packages, making
them well-suited for any battery operated applications. With an efficient 8051 core, 6-bit
current reference, and precision analog, the EFM8SB2 family is also optimal for embedded applications.
EFM8SB2 applications include the following:
• Hand-held devices
Industrial controls
•
CIP-51 8051 Core
Flash Program
Memory
(up to 64 KB)
Core / MemoryClock Management
(25 MHz)
RAM Memory
(4352 bytes)
• Battery-operated consumer electronics
•
Sensor interfaces
External
Oscillator
Debug Interface
with C2
External 32 kHz
RTC Oscillator
Low Power 20
MHz RC
Oscillator
High Frequency
24.5 MHz RC
Oscillator
ENERGY FRIENDLY FEATURES
• Lowest MCU sleep current with supply
brownout detection (50 nA)
•
Lowest MCU active current with these
features (170 μA / MHz at 24.5 MHz clock
rate)
• Lowest MCU sleep current using internal
RTC operating and supply brownout
detection (<300 nA)
• Ultra-fast wake up for digital and analog
peripherals (< 2 μs)
• Integrated low drop out (LDO) voltage
regulator to maintain ultra-low active
current at all voltages
Energy Management
Internal LDO
Regulator
Brown-Out Detector
Power-On Reset
8-bit SFR bus
Serial InterfacesTimers and TriggersAnalog Interfaces
internal circuitry draws power from the VDD supply pin. External I/O pins are powered from the VIO supply voltage (or VDD on devi-
All
ces without a separate VIO connection), while most of the internal circuitry is supplied by an on-chip LDO regulator. Control over the
device power can be achieved by enabling/disabling individual peripherals as needed. Each analog peripheral can be disabled when
not in use and placed in low power mode. Digital peripherals, such as timers and serial buses, have their clocks gated off and draw little
power when they are not in use.
Table 1.1. Power Modes
Power ModeDetailsMode EntryWake-Up Sources
NormalCore and all peripherals clocked and fully operational——
Idle• Core halted
•
All peripherals clocked and fully operational
Set IDLE bit in PCON0Any interrupt
• Code resumes execution on wake event
Suspend• Core and digital peripherals halted
•
Internal oscillators disabled
• Code resumes execution on wake event
1. Switch SYSCLK to
HFOSC0 or LPOSC0
2.
Set SUSPEND bit in
PMU0CF
• RTC0 Alarm Event
• RTC0 Fail Event
• Port Match Event
• Comparator 0 Rising
Edge
Sleep• Most internal power nets shut down
•
Select circuits remain powered
• Pins retain state
• All RAM and SFRs retain state
• Code resumes execution on wake event
1. Disable unused analog peripherals
2.
Set SLEEP bit in
PMU0CF
• RTC0 Alarm Event
• RTC0 Fail Event
• Port Match Event
• Comparator 0 Rising
Edge
1.3 I/O
Digital
and analog resources are externally available on the device’s multi-purpose I/O pins. Port pins P0.0-P2.6 can be defined as general-purpose I/O (GPIO), assigned to one of the internal digital resources through the crossbar or dedicated channels, or assigned to an
analog function. Port pin P2.7 can be used as GPIO. Additionally, the C2 Interface Data signal (C2D) is shared with P2.7.
• Up to 24 multi-functions I/O pins, supporting digital and analog functions.
• Flexible priority crossbar decoder for digital peripheral assignment.
• Two drive strength settings for each pin.
• Two direct-pin interrupt sources with dedicated interrupt vectors (INT0 and INT1).
• Up to 16 direct-pin interrupt sources with shared interrupt vector (Port Match).
1.4 Clocking
The CPU core and peripheral subsystem may be clocked by both internal and external oscillator resources. By default, the system
clock comes up running from the 20 MHz low power oscillator divided by 8.
• Provides clock to core and peripherals.
• 20 MHz low power oscillator (LPOSC0), accurate to +/- 10% over supply and temperature corners.
• 24.5 MHz internal oscillator (HFOSC0), accurate to +/- 2% over supply and temperature corners.
RTC is an ultra low power, 36 hour 32-bit independent time-keeping Real Time Clock with alarm. The RTC has a dedicated 32 kHz
The
oscillator. No external resistor or loading capacitors are required, and a missing clock detector features alerts the system if the external
crystal fails. The on-chip loading capacitors are programmable to 16 discrete levels allowing compatibility with a wide range of crystals.
The RTC module includes the following features:
• Up to 36 hours (32-bit) of independent time keeping.
• Support for external 32 kHz crystal or internal self-oscillate mode.
• Internal crystal loading capacitors with 16 levels.
• Operation in the lowest power mode and across the full supported voltage range.
• Alarm and oscillator failure events to wake from the lowest power mode or reset the device.
Programmable Counter Array (PCA0)
The programmable counter array (PCA) provides multiple channels of enhanced timer and PWM functionality while requiring less CPU
intervention than standard counter/timers. The PCA consists of a dedicated 16-bit counter/timer and one 16-bit capture/compare module for each channel. The counter/timer is driven by a programmable timebase that has flexible external and internal clocking options.
Each capture/compare module may be configured to operate independently in one of five modes: Edge-Triggered Capture, Software
Timer, High-Speed Output, Frequency Output, or Pulse-Width Modulated (PWM) Output. Each capture/compare module has its own
associated I/O line (CEXn) which is routed through the crossbar to port I/O when enabled.
• 16-bit time base.
• Programmable clock divisor and clock source selection.
• Compare function for arbitrary waveform generation.
• Software timer (internal compare) mode.
• Integrated watchdog timer.
Timers (Timer 0, Timer 1, Timer 2, and Timer 3)
Several counter/timers are included in the device: two are 16-bit counter/timers compatible with those found in the standard 8051, and
the rest are 16-bit auto-reload timers for timing peripherals 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. The other timers offer both 16-bit and split 8-bit timer functionality with auto-reload and capture capabilities.
Timer 0 and Timer 1 include the following features:
• Standard 8051 timers, supporting backwards-compatibility with firmware and hardware.
• Clock sources include SYSCLK, SYSCLK divided by 12, 4, or 48, the External Clock divided by 8, or an external pin.
• 8-bit auto-reload counter/timer mode
• 13-bit counter/timer mode
• 16-bit counter/timer mode
• Dual 8-bit counter/timer mode (Timer 0)
Timer 2 and Timer 3 are 16-bit timers including the following features:
• Clock sources include SYSCLK, SYSCLK divided by 12, or the External Clock divided by 8.
device includes a programmable watchdog timer (WDT) integrated within the PCA0 peripheral. A WDT overflow forces the MCU
The
into the reset state. To prevent the reset, the WDT must be restarted by application software before overflow. If the system experiences
a software or hardware malfunction preventing the software from restarting the WDT, the WDT overflows and causes a reset. Following
a reset, the WDT is automatically enabled and running with the default maximum time interval. If needed, the WDT can be disabled by
system software. The state of the RSTb pin is unaffected by this reset.
The Watchdog Timer integrated in the PCA0 peripheral has the following features:
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. Received data buffering allows UART0 to start reception of a
second incoming data byte before software has finished reading the previous data byte.
The UART module provides the following features:
• Asynchronous transmissions and receptions
• Baud rates up to SYSCLK/2 (transmit) or SYSCLK/8 (receive)
• 8- or 9-bit data
• Automatic start and stop generation
Serial Peripheral Interface (SPI0 and SPI1)
The serial peripheral interface (SPI) module provides access to a flexible, full-duplex synchronous serial bus. The SPI can operate as a
master or slave device in both 3-wire or 4-wire modes, and supports multiple masters and slaves on a single SPI bus. The slave-select
(NSS) signal can be configured as an input to select the SPI in slave mode, or to disable master mode operation in a multi-master
environment, avoiding contention on the SPI bus when more than one master attempts simultaneous data transfers. NSS can also be
configured as a firmware-controlled chip-select output in master mode, or disabled to reduce the number of pins required. Additional
general purpose port I/O pins can be used to select multiple slave devices in master mode.
The SPI module includes the following features:
• Supports 3- or 4-wire operation in master or slave modes.
• Supports external clock frequencies up to SYSCLK / 2 in master mode and SYSCLK / 10 in slave mode.
• Support for four clock phase and polarity options.
• 8-bit dedicated clock clock rate generator.
• Support for multiple masters on the same data lines.
System Management Bus / I2C (SMB0)
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.
The SMBus module includes the following features:
• Standard (up to 100 kbps) and Fast (400 kbps) transfer speeds.
• Support for master, slave, and multi-master modes.
• Hardware synchronization and arbitration for multi-master mode.
• Clock low extending (clock stretching) to interface with faster masters.
• Hardware support for 7-bit slave and general call address recognition.
• Firmware support for 10-bit slave address decoding.
External Memory Interface (EMIF) enables access of off-chip memories and memory-mapped devices connected to the GPIO
The
ports. The external memory space may be accessed using the external move instruction (MOVX) with the target address specified in
either 8-bit or 16-bit formats.
• Supports multiplexed memory access.
• Four external memory modes:
• Internal only.
• Split mode without bank select.
• Split mode with bank select.
• External only
• Configurable ALE (address latch enable) timing.
• Configurable address setup and hold times.
• Configurable write and read pulse widths.
16/32-bit CRC (CRC0)
The cyclic redundancy check (CRC) module performs a CRC using a 16-bit or 32-bit polynomial. CRC0 accepts a stream of 8-bit data
and posts the result to an internal register. In addition to using the CRC block for data manipulation, hardware can automatically CRC
the flash contents of the device.
The CRC module is designed to provide hardware calculations for flash memory verification and communications protocols. The CRC
module includes the following features:
• Support for CCITT-16 polynomial (0x1021).
• Support for CRC-32 polynomial (0x04C11DB7).
• Byte-level bit reversal.
• Automatic CRC of flash contents on one or more 1024-byte blocks.
• Initial seed selection of 0x0000/0x00000000 or 0xFFFF/0xFFFFFFFF.
1.7 Analog
Programmable Current Reference (IREF0)
The programmable current reference (IREF0) module enables current source or sink with two output current settings: Low Power Mode
and High Current Mode. The maximum current output in Low Power Mode is 63 µA (1 µA steps) and the maximum current output in
High Current Mode is 504 µA (8 µA steps).
The IREF module includes the following features:
• Capable of sourcing or sinking current in programmable steps.
• Two operational modes: Low Power Mode and High Current Mode.
ADC is a successive-approximation-register (SAR) ADC with 10- and 8-bit modes, integrated track-and hold and a programmable
The
window detector. The ADC is fully configurable under software control via several registers. The ADC may be configured to measure
different signals using the analog multiplexer. The voltage reference for the ADC is selectable between internal and external reference
sources.
• Up to 22 external inputs.
• Single-ended 10-bit mode.
• Supports an output update rate of 300 ksps samples per second.
• Operation in low power modes at lower conversion speeds.
• Asynchronous hardware conversion trigger, selectable between software, external I/O and internal timer sources.
• Output data window comparator allows automatic range checking.
• Support for burst mode, which produces one set of accumulated data per conversion-start trigger with programmable power-on settling and tracking time.
• Conversion complete and window compare interrupts supported.
• Flexible output data formatting.
• Includes an internal 1.65 V fast-settling reference and support for external reference.
• Integrated temperature sensor.
Low Current Comparators (CMP0, CMP1)
Analog comparators are used to compare the voltage of two analog inputs, with a digital output indicating which input voltage is higher.
External input connections to device I/O pins and internal connections are available through separate multiplexers on the positive and
negative inputs. Hysteresis, response time, and current consumption may be programmed to suit the specific needs of the application.
The comparator module includes the following features:
• Up to 12 external positive inputs.
• Up to 11 external negative inputs.
• Additional input options:
• Capacitive Sense Comparator output.
• VDD.
• VDD divided by 2.
• Internal connection to LDO output.
• Direct connection to GND.
• Synchronous and asynchronous outputs can be routed to pins via crossbar.
• Programmable hysteresis between 0 and +/-20 mV.
• Programmable response time.
• Interrupts generated on rising, falling, or both edges.
Reset circuitry allows the controller to be easily placed in a predefined default condition. On entry to this reset state, the following occur:
The core halts program execution.
•
• Module registers are initialized to their defined reset values unless the bits reset only with a power-on reset.
• External port pins are forced to a known state.
• Interrupts and timers are disabled.
All registers are reset to the predefined values noted in the register descriptions unless the bits only reset with a power-on reset. The
contents of RAM are unaffected during a reset; any previously stored data is preserved as long as power is not lost. The Port I/O latches are reset to 1 in open-drain mode. Weak pullups are enabled during and after the reset. For Supply Monitor and power-on resets,
the RSTb 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 an internal oscillator. The Watchdog Timer is enabled, and program execution begins at location 0x0000.
Reset sources on the device include the following:
• Power-on reset
• External reset pin
• Comparator reset
• Software-triggered reset
• Supply monitor reset (monitors VDD supply)
• Watchdog timer reset
• Missing clock detector reset
• Flash error reset
• RTC0 alarm or oscillator failure
1.9 Debugging
The EFM8SB2 devices include an on-chip Silicon Labs 2-Wire (C2) debug interface to allow flash programming 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.
1.10 Bootloader
All devices come pre-programmed with a UART bootloader. This bootloader resides in flash and can be erased if it is not needed.
The memory organization of the CIP-51 System Controller is similar to that of a standard 8051. There are two separate memory
spaces: program memory and data memory. Program and data memory share the same address space but are accessed via different
instruction types. Program memory consists of a non-volatile storage area that may be used for either program code or non-volatile
data storage. The data memory, consisting of "internal" and "external" data space, is implemented as RAM, and may be used only for
data storage. Program execution is not supported from the data memory space.
2.2 Program Memory
The CIP-51 core has a 64 KB program memory space. The product family implements some of this program memory space as in-system, re-programmable flash memory. Flash security is implemented by a user-programmable location in the flash block and provides
read, write, and erase protection. All addresses not specified in the device memory map are reserved and may not be used for code or
data storage.
MOVX Instruction and Program Memory
The MOVX instruction in an 8051 device is typically used to access external data memory. On the devices, the MOVX instruction is
normally used to read and write on-chip XRAM, but can be re-configured to write and erase on-chip flash memory space. MOVC instructions are always used to read flash memory, while MOVX write instructions are used to erase and write flash. This flash access
feature provides a mechanism for the product to update program code and use the program memory space for non-volatile data storage.
2.3 Data Memory
The RAM space on the chip includes both an "internal" RAM area which is accessed with MOV instructions, and an on-chip "external"
RAM area which is accessed using MOVX instructions. Total RAM varies, based on the specific device. The device memory map has
more details about the specific amount of RAM available in each area for the different device variants.
Internal RAM
There are 256 bytes of internal RAM mapped into the data memory space from 0x00 through 0xFF. The lower 128 bytes of data memory are used for general purpose registers and scratch pad memory. Either direct or indirect addressing may be used to access the lower
128 bytes of data memory. Locations 0x00 through 0x1F are addressable as four banks of general purpose registers, each bank consisting of eight byte-wide registers. The next 16 bytes, locations 0x20 through 0x2F, may either be addressed as bytes or as 128 bit
locations accessible with the direct addressing mode.
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.
General Purpose Registers
The lower 32 bytes of data memory, locations 0x00 through 0x1F, may be addressed as four banks of general-purpose registers. Each
bank consists of eight byte-wide registers designated R0 through R7. Only one of these banks may be enabled at a time. Two bits in
the program status word (PSW) register, RS0 and RS1, select the active register bank. This allows fast context switching when entering
subroutines and interrupt service routines. Indirect addressing modes use registers R0 and R1 as index registers.
addition to direct access to data memory organized as bytes, the sixteen data memory locations at 0x20 through 0x2F are also ac-
In
cessible as 128 individually addressable bits. Each bit has a bit address from 0x00 to 0x7F. Bit 0 of the byte at 0x20 has bit address
0x00 while bit 7 of the byte at 0x20 has bit address 0x07. Bit 7 of the byte at 0x2F has bit address 0x7F. A bit access is distinguished
from a full byte access by the type of instruction used (bit source or destination operands as opposed to a byte source or destination).
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, 22.3h
moves the Boolean value at 0x13 (bit 3 of the byte at location 0x22) into the Carry flag.
Stack
A
programmer's stack can be located anywhere in the 256-byte data memory. The stack area is designated using the Stack Pointer
(SP) 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.
External RAM
On devices with more than 256 bytes of on-chip RAM, the additional RAM is mapped into the external data memory space (XRAM).
Addresses in XRAM area accessed using the external move (MOVX) instructions.
Note: The 16-bit MOVX write instruction is also used for writing and erasing the flash memory. More details may be found in the flash
memory section.
The direct-access data memory locations from 0x80 to 0xFF constitute the special function registers (SFRs). The SFRs provide control
and data exchange with the CIP-51's resources and peripherals. The CIP-51 duplicates the SFRs found in a typical 8051 implementation as well as implementing additional SFRs used to configure and access the sub-systems unique to the MCU. This allows the addi-
tion of new functionality while retaining compatibility with the MCS-51 ™ instruction set.
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.
SFR Paging
The CIP-51 features SFR paging, allowing the device to map many SFRs into the 0x80 to 0xFF memory address space. The SFR
memory space has 256 pages. In this way, each memory location from 0x80 to 0xFF can access up to 256 SFRs. The EFM8SB2
devices utilize multiple SFR pages. All of the common 8051 SFRs are available on all pages. Certain SFRs are only available on a
subset of pages. SFR pages are selected using the SFRPAGE register. The procedure for reading and writing an SFR is as follows:
1. Select the appropriate SFR page using the SFRPAGE register.
2. Use direct accessing mode to read or write the special function register (MOV instruction).
The SFRPAGE register only needs to be changed in the case that the SFR to be accessed does not exist on the currently-selected
page. See the SFR memory map for details on the locations of each SFR. It is good practice inside of interrupt service routines to save
the current SFRPAGE at the beginning of the ISR and restore this value at the end.
Interrupts and SFR Paging
In any system which changes the SFRPAGE while interrupts are active, it is good practice to save the current SFRPAGE value upon
ISR entry, and then restore the SFRPAGE before exiting the ISR. This ensures that SFRPAGE will remain at the desired setting when
returning from the ISR.
On-chip, re-programmable flash memory is included for program code and non-volatile data storage. The flash memory is organized in
1024-byte pages. It can be erased and written through the C2 interface or from firmware by overloading the MOVX instruction. Any
individual byte in flash memory must only be written once between page erase operations.
CIP-51 provides security options to protect the flash memory from inadvertent modification by software as well as to prevent the
The
viewing of proprietary program code and constants. The Program Store Write Enable (bit PSWE in register PSCTL) and the Program
Store Erase Enable (bit PSEE in register PSCTL) bits protect the flash memory from accidental modification by software. PSWE must
be explicitly set to 1 before software can modify the flash memory; both PSWE and PSEE must be set to 1 before software can erase
flash memory. Additional security features prevent proprietary program code and data constants from being read or altered across the
C2 interface.
A Security Lock Byte located in flash user space offers protection of the flash program memory from access (reads, writes, or erases)
by unprotected code or the C2 interface. See the specific device memory map for the location of the security byte. The flash security
mechanism allows the user to lock "n" flash pages, starting at page 0, where "n" is the 1s complement number represented by the
Security Lock Byte.
Note: The page containing the flash Security Lock Byte is unlocked when no other flash pages are locked (all bits of the Lock Byte are
1) and locked when any other flash pages are locked (any bit of the Lock Byte is 0).
Target Area for Read / Write / ErasePermissions from C2 interface
[R] = Read permitted
[W] = Write permitted
[E] = Erase permitted
Device Erase Only = No read, write, or individual page erase is allowed. Must erase entire flash space.
None = Read, write and erase are not permitted
4.3.2 Programming the Flash Memory
Writes
to flash memory clear bits from logic 1 to logic 0 and can be performed on single byte locations. Flash erasures set bits back to
logic 1 and occur only on full pages. The write and erase operations are automatically timed by hardware for proper execution; data
polling to determine the end of the write/erase operation is not required. Code execution is stalled during a flash write/erase operation.
The simplest means of programming the flash memory is through the C2 interface using programming tools provided by Silicon Labs or
a third party vendor. Firmware may also be loaded into the device to implement code-loader functions or allow non-volatile data storage. To ensure the integrity of flash contents, it is strongly recommended that the on-chip supply monitor be enabled in any system that
includes code that writes and/or erases flash memory from software.
4.3.2.1 Flash Lock and Key Functions
Flash writes and erases by user software are protected with a lock and key function. The FLKEY register must be written with the correct key codes, in sequence, before flash operations may be performed. The key codes are 0xA5 and 0xF1. The timing does not matter, but the codes must be written in order. If the key codes are written out of order or the wrong codes are written, flash writes and
erases will be disabled until the next system reset. Flash writes and erases will also be disabled if a flash write or erase is attempted
before the key codes have been written properly. The flash lock resets after each write or erase; the key codes must be written again
before another flash write or erase operation can be performed.
4.3.2.2 Flash Page Erase Procedure
The flash memory is erased one page at a time by firmware using the MOVX write instruction with the address targeted to any byte
within the page. Before erasing a page of flash memory, flash write and erase operations must be enabled by setting the PSWE and
PSEE bits in the PSCTL register to logic 1 (this directs the MOVX writes to target flash memory and enables page erasure) and writing
the flash key codes in sequence to the FLKEY register. The PSWE and PSEE bits remain set until cleared by firmware.
Erase operation applies to an entire page (setting all bytes in the page to 0xFF). To erase an entire page, perform the following steps:
1. Disable interrupts (recommended).
2. Write the first key code to FLKEY: 0xA5.
3. Write the second key code to FLKEY: 0xF1.
4. Set the PSEE bit (register PSCTL).
5. Set the PSWE bit (register PSCTL).
6. Using the MOVX instruction, write a data byte to any location within the page to be erased.
7. Clear the PSWE and PSEE bits.
4.3.2.3 Flash Byte Write Procedure
The flash memory is written by firmware using the MOVX write instruction with the address and data byte to be programmed provided
as normal operands in DPTR and A. Before writing to flash memory using MOVX, flash write operations must be enabled by setting the
PSWE bit in the PSCTL register to logic 1 (this directs the MOVX writes to target flash memory) and writing the flash key codes in
sequence to the FLKEY register. The PSWE bit remains set until cleared by firmware. A write to flash memory can clear bits to logic 0
but cannot set them. A byte location to be programmed should be erased (already set to 0xFF) before a new value is written.
To write a byte of flash, perform the following steps:
1. Disable interrupts (recommended).
2. Write the first key code to FLKEY: 0xA5.
3. Write the second key code to FLKEY: 0xF1.
4. Set the PSWE bit (register PSCTL).
5. Clear the PSEE bit (register PSCTL).
6. Using the MOVX instruction, write a single data byte to the desired location within the desired page.
system which contains routines which write or erase flash memory from software involves some risk that the write or erase routines
Any
will execute unintentionally if the CPU is operating outside its specified operating range of supply voltage, system clock frequency or
temperature. This accidental execution of flash modifying code can result in alteration of flash memory contents causing a system failure that is only recoverable by re-flashing the code in the device.
To help prevent the accidental modification of flash by firmware, hardware restricts flash writes and erasures when the supply monitor is
not active and selected as a reset source. As the monitor is enabled and selected as a reset source by default, it is recommended that
systems writing or erasing flash simply maintain the default state.
The following sections provide general guidelines for any system which contains routines which write or erase flash from code. Additional flash recommendations and example code can be found in AN201: Writing to Flash From Firmware, available from the Silicon
Laboratories website.
Voltage Supply Maintenance and the Supply Monitor
• If the system power supply is subject to voltage or current "spikes," add sufficient transient protection devices to the power supply to
ensure that the supply voltages listed in the Absolute Maximum Ratings table are not exceeded.
• Make certain that the minimum supply rise time specification is met. If the system cannot meet this rise time specification, then add
an external supply brownout circuit to the RSTb pin of the device that holds the device in reset until the voltage supply reaches the
lower limit, and re-asserts RSTb if the supply drops below the low supply limit.
• Do not disable the supply monitor. If the supply monitor must be disabled in the system, firmware should be added to the startup
routine to enable the on-chip supply monitor and enable the supply monitor as a reset source as early in code as possible. This
should be the first set of instructions executed after the reset vector. For C-based systems, this may involve modifying the startup
code added by the C compiler. See your compiler documentation for more details. Make certain that there are no delays in software
between enabling the supply monitor and enabling the supply monitor as a reset source.
Note: The supply monitor must be enabled and enabled as a reset source when writing or erasing flash memory. A flash error reset
will occur if either condition is not met.
• As an added precaution if the supply monitor is ever disabled, explicitly enable the supply monitor and enable the supply monitor as
a reset source inside the functions that write and erase flash memory. The supply monitor enable instructions should be placed just
after the instruction to set PSWE to a 1, but before the flash write or erase operation instruction.
• Make certain that all writes to the RSTSRC (Reset Sources) register use direct assignment operators and explicitly do not use the
bit-wise operators (such as AND or OR). For example, "RSTSRC = 0x02" is correct. "RSTSRC |= 0x02" is incorrect.
• Make certain that all writes to the RSTSRC register explicitly set the PORSF bit to a 1. Areas to check are initialization code which
enables other reset sources, such as the Missing Clock Detector or Comparator, for example, and instructions which force a Software Reset. A global search on "RSTSRC" can quickly verify this.
PSWE Maintenance
• Reduce the number of places in code where the PSWE bit (in register PSCTL) is set to a 1. There should be exactly one routine in
code that sets PSWE to a 1 to write flash bytes and one routine in code that sets PSWE and PSEE both to a 1 to erase flash pages.
• Minimize the number of variable accesses while PSWE is set to a 1. Handle pointer address updates and loop variable maintenance
outside the "PSWE = 1;... PSWE = 0;" area.
• Disable interrupts prior to setting PSWE to a 1 and leave them disabled until after PSWE has been reset to 0. Any interrupts posted
during the flash write or erase operation will be serviced in priority order after the flash operation has been completed and interrupts
have been re-enabled by software.
• Make certain that the flash write and erase pointer variables are not located in XRAM. See your compiler documentation for instructions regarding how to explicitly locate variables in different memory areas.
• Add address bounds checking to the routines that write or erase flash memory to ensure that a routine called with an illegal address
does not result in modification of the flash.
System Clock
• If operating from an external crystal-based source, be advised that crystal performance is susceptible to electrical interference and is
sensitive to layout and to changes in temperature. If the system is operating in an electrically noisy environment, use the internal
oscillator or use an external CMOS clock.
• If operating from the external oscillator, switch to the internal oscillator during flash write or erase operations. The external oscillator
can continue to run, and the CPU can switch back to the external oscillator after the flash operation has completed.
The flash memory is responsible for a substantial portion of the total digital supply current when the device is executing code. Below are
suggestions to minimize flash read current.
Use low power modes while waiting for an interrupt, rather than polling the interrupt flag.
1.
2. Disable the one-shot timer.
3. Reduce the number of toggling address lines for short code loops.
Using Low Power Modes
To reduce flash read current, use idle, suspend, or sleep modes while waiting for an interrupt, rather than polling the interrupt flag. Idle
mode is particularly well-suited for use in implementing short pauses, since the wake-up time is no more than three system clock cycles. See the Power Management chapter for details on the various low-power operating modes.
Disabling the One-Shot Timer
The flash has a one-shot timer that saves power when operating at system clock frequencies of 10 MHz or less. The one-shot timer
generates a minimum-duration enable signal for the flash sense amps on each clock cycle in which the flash memory is accessed. This
allows the flash to remain in a low power state for the remainder of the long clock cycle.
At clock frequencies above 10 MHz, the system clock cycle becomes short enough that the one-shot timer no longer provides a power
benefit. Disabling the one-shot timer at higher frequencies reduces power consumption. The one-shot is enabled by default, and it can
be disabled (bypassed) by setting the BYPASS bit in the FLSCL register. To reenable the one-shot, clear the BYPASS bit to logic 0.
Reduce Toggling Lines in Loops
Flash read current depends on the number of address lines that toggle between sequential flash read operations. In most cases, the
difference in power is relatively small (on the order of 5%).
The flash memory is organized in rows of 128 bytes. A substantial current increase can be detected when the read address jumps from
one row in the flash memory to another. Consider a 3-cycle loop (e.g., SJMP $, or while(1);) which straddles a flash row boundary. The
flash address jumps from one row to another on two of every three clock cycles. This can result in a current increase of up 30% when
compared to the same 3-cycle loop contained entirely within a single row.
To minimize the power consumption of small loops, it is best to locate them within a single row, if possible. To check if a loop is contained within a flash row, divide the starting address of the first instruction in the loop by 128. If the remainder (result of modulo operation) plus the length of the loop is less than 127, then the loop fits inside a single flash row. Otherwise, the loop will be straddling two
adjacent flash rows. If a loop executes in 20 or more clock cycles, then the transitions from one row to another will occur on relatively
few clock cycles, and any resulting increase in operating current will be negligible.
4.3.5 Scratchpad
An additional scratchpad area is available for non-volatile data storage. It is accessible at addresses 0x0000 to 0x03FF when the SFLE
bit is set to 1. The scratchpad area cannot be used for code execution. The scratchpad is locked when all other flash pages are locked,
and it is erased when a Flash Device Erase command is performed.
When this bit is set, flash MOVC reads and MOVX writes from user software are directed to the Scratchpad flash sector.
Flash accesses outside the address range 0x0000-0x01FF should not be attempted and may yield undefined results when
SFLE is set to 1.
ValueNameDescription
0SCRATCHPAD_DISA-
Flash access from user software directed to the Program/Data Flash sector.
BLED
1SCRATCHPAD_ENA-
Flash access from user software directed to the Scratchpad sector.
BLED
1PSEE0RWProgram Store Erase Enable.
Setting this bit (in combination with PSWE) allows an entire page of flash program memory to be erased. If this bit is logic 1
and
flash writes are enabled (PSWE is logic 1), a write to flash memory using the MOVX instruction will erase the entire
page that contains the location addressed by the MOVX instruction. The value of the data byte written does not matter.
ValueNameDescription
0ERASE_DISABLEDFlash program memory erasure disabled.
1ERASE_ENABLEDFlash program memory erasure enabled.
0PSWE0RWProgram Store Write Enable.
Setting this bit allows writing a byte of data to the flash program memory using the MOVX write instruction. The flash location should be erased before writing data.
ValueNameDescription
0WRITE_DISABLEDWrites to flash program memory disabled.
1WRITE_ENABLEDWrites to flash program memory enabled; the MOVX write instruction targets flash
register provides a lock and key function for flash erasures and writes. Flash writes and erases are enabled by writing
0xA5 followed by 0xF1 to the FLKEY register. Flash writes and erases are automatically disabled after the next write or
erase is complete. If any writes to FLKEY are performed incorrectly, or if a flash write or erase operation is attempted while
these operations are disabled, the flash will be permanently locked from writes or erasures until the next device reset. If an
application never writes to flash, it can intentionally lock the flash by writing a non-0xA5 value to FLKEY from firmware.
Read:
When read, bits 1-0 indicate the current flash lock state.
00: Flash is write/erase locked.
01: The first key code has been written (0xA5).
10: Flash is unlocked (writes/erases allowed).
11: Flash writes/erases are disabled until the next reset.
4.4.3 FLSCL: Flash Scale
Bit76543210
NameReservedBYPASSReserved
AccessRRWR
Reset000x00
SFR Page = 0x0; SFR Address: 0xB6
BitNameResetAccessDescription
7ReservedMust write reset value.
6BYPASS0RWFlash Read Timing One-Shot Bypass.
ValueNameDescription
0ONE_SHOTThe one-shot determines the flash read time. This setting should be used for op-
erating frequencies less than 14 MHz.
1SYSCLKThe system clock determines the flash read time. This setting should be used for
frequencies greater than 14 MHz.
5:0ReservedMust write reset value.
When changing the BYPASS bit from 1 to 0, the third opcode byte fetched from program memory is indeterminate. Therefore, the
operation which clears the BYPASS bit should be immediately followed by a benign 3-byte instruction whose third byte is a don't care.
An
example of such an instruction is a 3-byte MOV that targets the CRC0FLIP register. When programming in C, the dummy value
written to CRC0FLIP should be a non-zero value to prevent the compiler from generating a 2-byte MOV instruction.
A 32-bit unique identifier (UID) is pre-loaded upon device reset into the last four bytes of the XRAM area on all devices. The UID can be
read by firmware using MOVX instructions and through the debug port.
As the UID appears in RAM, firmware can overwrite the UID during normal operation. The bytes in memory will be automatically reinitialized with the UID value after any device reset. Firmware using this area of memory should always initialize the memory to a known
value, as any previous data stored at these locations will be overwritten and not retained through a reset.
The MCU core includes an extended interrupt system supporting multiple interrupt sources and priority levels. The allocation of interrupt
sources between on-chip peripherals and external input pins varies according to the specific version of the device.
Interrupt sources may have one or more associated interrupt-pending flag(s) located in an SFR local to the associated peripheral.
When a peripheral or external source meets a valid interrupt condition, the associated interrupt-pending flag is set to logic 1.
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 predetermined 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 regardless of whether the interrupt is enabled.
Each interrupt source can be individually enabled or disabled through the use of an associated interrupt enable bit in the IE and EIEn
registers. However, interrupts must first be globally enabled by setting the EA bit 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 or by other hardware conditions. However, most are not cleared by the hardware and must be cleared by software before returning from the ISR. If an interruptpending 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.
6.2 Interrupt Sources and Vectors
The CIP51 core supports interrupt sources for each peripheral on the device. Software can simulate an interrupt for many peripherals
by setting any interrupt-pending flag to logic 1. If interrupts are enabled for the flag, an interrupt request will be generated and the CPU
will vector to the ISR address associated with the interrupt-pending flag. Refer to the data sheet section associated with a particular onchip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s).
6.2.1 Interrupt Priorities
Each interrupt source can be individually programmed to one of two priority levels: low or high. A low priority interrupt service routine
can be preempted by a high priority interrupt. A high priority interrupt cannot be preempted. Each interrupt has an associated interrupt
priority bit in the IP and EIPn registers, which are used to configure its priority level. Low priority is the default. If two interrupts are
recognized simultaneously, the interrupt with the higher priority is serviced first. If both interrupts have the same priority level, a fixed
order is used to arbitrate, based on the interrupt source's location in the interrupt vector table. Interrupts with a lower number in the
vector table have priority.
6.2.2 Interrupt Latency
Interrupt response time depends on the state of the CPU when the interrupt occurs. Pending interrupts are sampled and priority decoded on every system clock cycle. Therefore, the fastest possible response time is 5 system clock cycles: 1 clock cycle to detect the
interrupt and 4 clock cycles to complete the LCALL to the ISR. If an interrupt is pending when a RETI is executed, a single instruction is
executed before an LCALL is made to service the pending interrupt. Therefore, the maximum response time for an interrupt (when no
other interrupt is currently being serviced or the new interrupt is of greater priority) occurs when the CPU is performing an RETI instruction followed by a DIV as the next instruction. In this case, the response time is 18 system clock cycles: 1 clock cycle to detect the
interrupt, 5 clock cycles to execute the RETI, 8 clock cycles to complete the DIV instruction and 4 clock cycles to execute the LCALL to
the ISR. If the CPU is executing an ISR for an interrupt with equal or higher priority, the new interrupt will not be serviced until the
current ISR completes, including the RETI and following instruction. If more than one interrupt is pending when the CPU exits an ISR,
the CPU will service the next highest priority interrupt that is pending.
All internal circuitry draws power from the VDD supply pin. External I/O pins are powered from the VIO supply voltage (or VDD on devices without a separate VIO connection), while most of the internal circuitry is supplied by an on-chip LDO regulator. Control over the
device power can be achieved by enabling/disabling individual peripherals as needed. Each analog peripheral can be disabled when
not in use and placed in low power mode. Digital peripherals, such as timers and serial buses, have their clocks gated off and draw little
power when they are not in use.
Power Distribution
VDD
Core LDO
GND
1.8V
Normal/Idle/
Suspend/
Shutdown
Sleep
CPU Core
RTC
RAMFlash
Digital I/O
Interface
Port I/O Pins
Oscillators
Peripheral
Logic
PMU
Analog
Muxes
Figure 7.1. Power System Block Diagram
Table 7.1. Power Modes
Power ModeDetailsMode EntryWake-Up Sources
NormalCore and all peripherals clocked and fully operational——
• Normal mode: Core and all peripherals fully operational.
• Idle mode: Core halted, peripherals fully operational, core waiting for interrupt to continue.
• Suspend mode: Similar to Sleep mode, with faster wake-up times, but higher current consumption. Code resumes execution at
the next instruction.
• Sleep mode: Ultra low power mode with flexible wake-up sources. Code resumes execution at the next instruction.
Note: Legacy 8051 Stop mode is also supported, but Suspend and Sleep offer more functionality with better power consumption.
• Fully internal core LDO supplies power to majority of blocks.
7.3 Idle Mode
In idle mode, CPU core execution is halted while any enabled peripherals and clocks remain active. Power consumption in idle mode is
dependent upon the system clock frequency and any active peripherals.
Setting the IDLE bit in the PCON0 register causes the hardware to halt the CPU and enter idle mode as soon as the instruction that
sets the bit completes execution. All internal registers and memory maintain their original data. All analog and digital peripherals can
remain active during idle mode.
Idle mode is terminated when an enabled interrupt is asserted or a reset occurs. The assertion of an enabled interrupt will cause the
IDLE bit 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 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.
Note: If the instruction following the write of the IDLE bit is a single-byte instruction and an interrupt occurs during the execution phase
of the instruction that sets the IDLE bit, the CPU may not wake from idle mode when a future interrupt occurs. Therefore, instructions
that set the IDLE bit should be followed by an instruction that has two or more opcode bytes. For example:
// in ‘C’:
PCON0 |= 0x01; // set IDLE bit
PCON0 = PCON0; // ... followed by a 3-cycle dummy instruction
; in assembly:
ORL PCON0, #01h ; set IDLE bit
MOV PCON0, PCON0 ; ... followed by a 3-cycle dummy instruction
enabled, the Watchdog Timer (WDT) will eventually cause an internal watchdog reset and thereby terminate the Idle mode. This fea-
If
ture protects the system from an unintended permanent shutdown in the event of an inadvertent write to the PCON0 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 provides the opportunity for additional power savings, allowing the system to remain in the idle mode indefinitely, waiting for an external stimulus to wake up the system.
Note: To ensure the MCU enters a low power state upon entry into Idle mode, the one-shot circuit should be enabled by clearing the
BYPASS bit in the FLSCL register.
7.4 Stop Mode
In stop mode, the CPU is halted and peripheral clocks are stopped. Analog peripherals remain in their selected states.
Setting the STOP bit in the PCON0 register causes the controller core to enter stop mode as soon as the instruction that sets the bit
completes execution. Before entering stop mode, the system clock must be sourced by HFOSC0. In stop mode, the CPU and internal
clocks are stopped. Analog peripherals may remain enabled, but will not be provided a clock. Each analog peripheral may be shut down
individually by firmware prior to entering stop mode. Stop mode can only be terminated by an internal or external reset. On reset, the
device performs the normal reset sequence and begins program execution at address 0x0000.
If enabled as a reset source, the missing clock detector will cause an internal reset and thereby terminate the stop mode. If this reset is
undesirable in the system, and the CPU is to be placed in stop mode for longer than the missing clock detector timeout, the missing
clock detector should be disabled in firmware prior to setting the STOP bit.
Note: To ensure the MCU enters a low power state upon entry into Stop mode, the one-shot circuit should be enabled by clearing the
BYPASS bit in the FLSCL register.
mode is entered by setting the SUSPEND bit while operating from the internal 24.5 MHz oscillator (HFOSC0) or the internal
20 MHz oscillator (LPOSC0). Upon entry into suspend mode, the hardware halts all of the internal oscillators and goes into a low power
state as soon as the instruction that sets the bit completes execution. All internal registers and memory maintain their original data.
Note: When entering Suspend mode, the global clock divider must be set to "divide by 1" using the CLKDIV field in the CLKSEL register.
Note: The one-shot circuit should be enabled by clearing the BYPASS bit in the FLSCL register to logic 0.
Note: Upon wake-up from Suspend, the power management unit requires two system clocks in order to update the PMU0CF wake-up
flags. All flags will read back a value of 0 during the first two system clocks following a wake-up from Suspend.
Note: The instruction placing the device in Suspend mode should be immediately followed by four NOP instructions. This will ensure
the PMU resynchronizes with the core.
Suspend mode is terminated by any enabled wake or reset source. When suspend mode is terminated, the device will continue execution on the instruction following the one that set the SUSPEND bit. If the wake event was configured to generate an interrupt, the interrupt will be serviced upon waking the device. If suspend mode is terminated by an internal or external reset, the CIP-51 performs a
normal reset sequence and begins program execution at address 0x0000.
In addition, a noise glitch on RSTb that is not long enough to reset the device will cause the device to exit Suspend. In order for the
MCU to respond to the pin reset event, software must not place the device back into suspend mode for a period of 15 μs. The PMU0CF
register may be checked to determine if the wake-up was due to a falling edge on the RSTb pin. If the wake-up source is not due to a
falling edge on RSTb, there is no time restriction on how soon software may place the device back into suspend mode. A 4.7 kΩ pullup
resistor to VDD is recommend for RSTb to prevent noise glitches from waking the device.
the sleep mode select bit in the PMU0CF register turns off the internal 1.8 V core LDO regulator and switches the power supply
of all on-chip RAM to the VDD pin. Power to most digital logic on the chip is disconnected; only the power management unit and RTC
remain powered. Only the comparators remain functional when the device enters Sleep mode. All other analog peripherals (ADC0,
IREF0, External Oscillator, etc.) should be disabled prior to entering Sleep mode.
Note: The system clock source must be set to the low power internal oscillator (LPOSC0) with the clock divider set to 1 prior to entering
Sleep mode.
Note: The instruction placing the device in Sleep mode should be immediately followed by four NOP instructions. This will ensure the
PMU resynchronizes with the core.
The precision internal oscillator may potentially lock up after exiting Sleep mode. Systems using Sleep mode and the precision oscillator (HPOSC0) should switch to the low power oscillator prior to entering Sleep:
1. Switch the system clock to the low power oscillator.
2. Turn off the precision oscillator.
3. Enter Sleep.
4. Exit Sleep.
5. Wait 4 NOP instructions.
6. Turn on the precision oscillator.
7. Switch the system clock to the precision oscillator.
GPIO pins configured as digital outputs will retain their output state during sleep mode and maintain the same current drive capability in
sleep mode as they have in normal mode. GPIO pins configured as digital inputs can be used during sleep mode as wakeup sources
using the port match feature and will maintain the same input level specs in Sleep mode as they have in normal mode.
RAM and SFR register contents are preserved in Sleep as long as the voltage on VDD does not fall below V
. The PC counter and
POR
all other volatile state information is preserved allowing the device to resume code execution upon waking up from sleep mode.
The following wake-up sources can be configured to wake the device from sleep mode:
• RTC oscillator fail
• RTC alarm
• Port match event
• Comparator 0 rising edge
The comparator requires a supply voltage of at least 1.8 V to operate properly. In addition, any falling edge on RSTb (due to a pin reset
or a noise glitch) will cause the device to exit Sleep In order for the MCU to respond to the pin reset event, software must not place the
device back into Sleep for a period of 15 μs. The PMU0CF register may be checked to determine if the wake-up was due to a falling
edge on the RSTb pin. If the wake-up source is not due to a falling edge on RSTb, there is no time restriction on how soon software
may place the device back into sleep mode. A 4.7 kΩ pullup resistor to VDD is recommend for RSTb to prevent noise glitches from
waking the device.
7.6.1 Configuring Wakeup Sources
Before placing the device in a low power mode, firmware should enable one or more wakeup sources so that the device does not remain in the low power mode indefinitely. For Idle mode, this includes enabling any interrupt. For Stop mode, this includes enabling any
reset source or relying on the RSTb pin to reset the device.
Wake-up sources for Suspend and Sleep modes are configured through the PMU0CF register. Wake-up sources are enabled by writing
1 to the corresponding wake-up source enable bit. Wake-up sources must be re-enabled each time the device is placed in Suspend or
Sleep mode in the same write that places the device in the low power mode.
The reset pin is always enabled as a wake-up source. The device will awaken from Sleep mode on the falling edge of RSTb. The device must remain awake for more than 15 μs in order for the reset to take place.
7.6.2 Determining the Event that Caused the Last Wakeup
waking from Idle mode, the CPU will vector to the interrupt which caused it to wake up. When waking from Stop mode, the
When
RSTSRC register may be read to determine the cause of the last reset.
Upon exit from Suspend or Sleep mode, the wake-up flags in the power management registers can be read to determine the event
which caused the device to wake up. After waking up, the wake-up flags will continue to be updated if any of the wake-up events occur.
Wake-up flags are always updated, even if they are not enabled as wake-up sources.
All wake-up flags enabled as wake-up sources in the power management registers must be cleared before the device can enter Suspend or Sleep mode. After clearing the wake-up flags, each of the enabled wake-up events should be checked in the individual peripherals to ensure that a wake-up event did not occur while the wake-up flags were being cleared.
7.7 Power Management Control Registers
7.7.1 PCON0: Power Control 0
Bit76543210
NameGF5GF4GF3GF2GF1GF0STOPIDLE
AccessRWRWRWRWRWRWRWRW
Reset00000000
SFR Page = ALL; SFR Address: 0x87
BitNameResetAccessDescription
7GF50RWGeneral Purpose Flag 5.
This flag is a general purpose flag for use under firmware control.
6GF40RWGeneral Purpose Flag 4.
This flag is a general purpose flag for use under firmware control.
5GF30RWGeneral Purpose Flag 3.
This flag is a general purpose flag for use under firmware control.
4GF20RWGeneral Purpose Flag 2.
This flag is a general purpose flag for use under firmware control.
3GF10RWGeneral Purpose Flag 1.
This flag is a general purpose flag for use under firmware control.
2GF00RWGeneral Purpose Flag 0.
This flag is a general purpose flag for use under firmware control.
1STOP0RWStop Mode Select.
Setting this bit will place the CIP-51 in Stop mode. This bit will always be read as 0.
0IDLE0RWIdle Mode Select.
Setting this bit will place the CIP-51 in Idle mode. This bit will always be read as 0.
To ensure the MCU enters a low power state upon entry into Idle or Stop mode, the one-shot circuit should be enabled by clearing the
BYPASS bit in the FLSCL register.
Writing a 1 to this bit places the device in Sleep mode.
6SUSPEND 0WSuspend Mode Select.
Writing a 1 to this bit places the device in Suspend mode.
5CLEAR0WWake-up Flag Clear.
Writing a 1 to this bit clears all wake-up flags.
4RSTWKVariesRReset Pin Wake-up Flag.
This bit is set to 1 if a glitch has been detected on RSTb.
3RTCFWKVariesRWRTC Oscillator Fail Wake-up Source Enable and Flag.
Read: Hardware sets this bit to 1 if the RTC oscillator failed.
Write: Write this bit to 1 to enable wake-up on an RTC oscillator failure.
2RTCAWKVariesRWRTC Alarm Wake-up Source Enable and Flag.
Read: Hardware sets this bit to 1 if the RTC Alarm occured.
Write: Write this bit to 1 to enable wake-up on an RTC Alarm.
1PMATWKVariesRWPort Match Wake-up Source Enable and Flag.
Read: Hardware sets this bit to 1 if Port Match event occured.
Write: Write this bit to 1 to enable wake-up on a Port Match event.
0CPT0WKVariesRWComparator0 Wake-up Source Enable and Flag.
Read: Hardware sets this bit to 1 if a Comparator 0 rising edge caused the last wake-up.
Write: Write this bit to 1 to enable wake-up on a Comparator 0 rising edge.
Read-modify-write operations (ORL, ANL, etc.) should not be used on this register. Wake-up sources must be re-enabled each time
the SLEEP or SUSPEND bits are written to 1.
The Low Power Internal Oscillator cannot be disabled and the MCU cannot be placed in Suspend or Sleep Mode if any wake-up flags
are set to 1. Software should clear all wake-up sources after each reset and after each wake-up from Suspend or Sleep Modes.
PMU0
requires two system clocks to update the wake-up source flags after waking from Suspend mode. The wake-up source flags
will read 0 during the first two system clocks following the wake from Suspend mode.
The CPU core and peripheral subsystem may be clocked by both internal and external oscillator resources. By default, the system
clock comes up running from the 20 MHz low power oscillator divided by 8.
Clock Control
Low Power
Oscillator
(LPOSC0)
24.5 MHz
Oscillator
(HFOSC0)
External Oscillator
Input (EXTCLK)
/8
Programmable
Divider:
1, 2, 4...128
To core and peripherals
SYSCLK
RTC Oscillator
(RTCOSC)
Figure 8.1. Clock Control Block Diagram
8.2 Features
Provides clock to core and peripherals.
•
• 20 MHz low power oscillator (LPOSC0), accurate to +/- 10% over supply and temperature corners.
• 24.5 MHz internal oscillator (HFOSC0), accurate to +/- 2% over supply and temperature corners.
• Clock divider with eight settings for flexible clock scaling: Divide the selected clock source by 1, 2, 4, 8, 16, 32, 64, or 128.
8.3 Functional Description
8.3.1 Clock Selection
The CLKSEL register is used to select the clock source for the system (SYSCLK). The CLKSL field selects which oscillator source is
used as the system clock, while CLKDIV controls the programmable divider. When an internal oscillator source is selected as the
SYSCLK, the external oscillator may still clock certain peripherals. In these cases, the external oscillator source is synchronized to the
SYSCLK source. The system clock may be switched on-the-fly between any of the oscillator sources so long as the selected clock
source is enabled and has settled, and CLKDIV may be changed at any time.
Note: Some device families do place restrictions on the difference in operating frequency when switching clock sources. Please see the
CLKSEL register description for details.
8.3.2 LPOSC0 20 MHz Internal Oscillator
LPOSC0 is a programmable internal low power oscillator that is factory-calibrated to 20 MHz. The oscillator is automatically enabled
when selected as the system clock and disabled when not in use. This oscillator tolerance is ±10%.
8.3.3 HFOSC0 24.5 MHz Internal Oscillator
HFOSC0 is a programmable internal high-frequency oscillator that is factory-calibrated to 24.5 MHz. The oscillator is automatically enabled when it is requested. The oscillator period can be adjusted via the HFO0CAL register to obtain other frequencies.
system clock can be derived from the RTC0 oscillator, which can run from either an external 32 kHz crystal or an internal 16.4 kHz
The
±20% low frequency oscillator (LFOSC0). No loading capacitors are required for the crystal, and it can be connected directly to the
XTAL3 and XTAL4 pins.
a crystal or ceramic resonator is used as the external oscillator, the crystal/resonator and a 10 MΩ resistor must be wired across the
If
XTAL1 and XTAL2 pins. Appropriate loading capacitors should be added to XTAL1 and XTAL2, and both pins should be configured for
analog I/O with the digital output drivers disabled.
The capacitors shown in the external crystal configuration provide the load capacitance required by the crystal for correct oscillation.
These capacitors are “in series” as seen by the crystal and “in parallel” with the stray capacitance of the XTAL1 and XTAL2 pins.
Note: The recommended load capacitance depends upon the crystal and the manufacturer. Refer to the crystal data sheet when completing these calculations.
The equation for determining the load capacitance for two capacitors is as follows:
CA× C
CA+ C
B
+ C
S
B
CL=
Figure 8.2. External Oscillator Load Capacitance
Where:
CA and CB are the capacitors connected to the crystal leads.
•
• CS is the total stray capacitance of the PCB.
• The stray capacitance for a typical layout where the crystal is as close as possible to the pins is 2-5 pF per pin.
If CA and CB are the same (C), then the equation becomes the following:
C
CL=
+ C
S
2
Figure 8.3. External Oscillator Load Capacitance with Equal Capacitors
For example, a tuning-fork crystal of 25 MHz has a recommended load capacitance of 12.5 pF. With a stray capacitance of 3 pF per pin
(6 pF total), the 13 pF capacitors yield an equivalent capacitance of 12.5 pF across the crystal.
15 pF
XTAL1
25 MHz
10 M
XTAL2
15 pF
Figure 8.4. 25 MHz External Crystal Example
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. When using an external crystal, the external oscillator drive circuit must be configured by firmware for Crystal Oscillator
Mode or Crystal Oscillator Mode with divide by 2 stage. The divide by 2 stage ensures that the clock derived from the external oscillator
has a duty cycle of 50%. The External Oscillator Frequency Control value (XFCN) must also be specified based on the crystal frequency. For example, a 25 MHz crystal requires an XFCN setting of 111b.
An RC network connected to the XTAL2 pin can be used as a basic oscillator. XTAL1 is not affected in RC mode.
VDD
XTAL1
XTAL2
Figure 8.5. External RC Oscillator Configuration
The capacitor should be no greater than 100 pF; however, for very small capacitors, the total capacitance may be dominated by parasit-
capacitance in the PCB layout. To determine the required XFCN field value, first select the RC network value to produce the desired
ic
frequency of oscillation, according to , where f = the frequency of oscillation in MHz, C = the capacitor value in pF, and R = the pull-up
resistor value in kΩ.
3
R × C
f =
1.23 × 10
Figure 8.6. RC Mode Oscillator Frequency
For example, if the frequency desired is 100 kHz, let R = 246 kΩ and C = 50 pF:
f =
1.23 × 10
R × C
3
=
1.23 × 10
246 × 50
3
= 100 kHz
Figure 8.7. RC Mode Oscillator Example
Referencing , the recommended XFCN setting for 100 kHz is 010.
the RC oscillator is first enabled, the external oscillator valid detector allows firmware to determine when oscillation has stabi-
When
lized. The recommended procedure for starting the RC oscillator is as follows:
1. Configure XTAL2 for analog I/O and disable the digital output drivers.
2. Configure and enable the external oscillator.
3. Poll for XCLKVLD = 1.
4. Switch the system clock to the external oscillator.
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. The oscillation frequency and the required XFCN field value determined by the following equation,
where f is the frequency in MHz, C is the capacitor value on XTAL2 in pF, and VDD is the power supply voltage in Volts:
KF
f =
C × V
DD
Figure 8.9. C Mode Oscillator Frequency
For example, assume VDD = 3.0 V and f = 150 kHz. Since a frequency of roughly 150 kHz is desired, select the K Factor from as KF =
22:
KF
f =
C × V
DD
0.150 MHz =
C =
0.150 MHz × 3.0
22
C × 3.0
22
C = 48.8 pF
Figure 8.10. C Mode Oscillator Example
Therefore, the XFCN value to use in this example is 011 and C is approximately 50 pF. The recommended startup procedure for C
mode is the same as RC mode.
Table 8.2. Recommended XFCN Settings for RC and C Modes
EFM8SB2 Reference Manual
Clocking and Oscillators
XFCN Field SettingApproximate Frequency
Range
K Factor (C Mode)Actual Measured Frequency
(C Mode)
000f ≤ 25 kHzK Factor = 0.87f = 11 kHz, C = 33 pF
00125 kHz < f ≤ 50 kHzK Factor = 2.6f = 33 kHz, C = 33 pF
01050 kHz < f ≤ 100 kHzK Factor = 7.7f = 98 kHz, C = 33 pF
011100 kHz < f ≤ 200 kHzK Factor = 22f = 270 kHz, C = 33 pF
100200 kHz < f ≤ 400 kHzK Factor = 65f = 310 kHz, C = 46 pF
101400 kHz < f ≤ 800 kHzK Factor = 180f = 890 kHz, C = 46 pF
110800 kHz < f ≤ 1.6 MHzK Factor = 664f = 2.0 MHz, C = 46 pF
1111.6 MHz < f ≤ 3.2 MHzK Factor = 1590f = 6.8 MHz, C = 46 pF
8.3.7 External CMOS
An
external CMOS clock source is also supported as a core clock source. The XTAL2/EXTCLK pin on the device serves as the external
clock input when running in this mode. When not selected as the SYSCLK source, the EXTCLK input is always re-synchronized to
SYSCLK. XTAL1 is not used in external CMOS clock mode.
Note: When selecting the EXTCLK pin as a clock input source, the pin should be skipped in the crossbar and configured as a digital
input. Firmware should ensure that the external clock source is present or enable the missing clock detector before switching the
CLKSL field.
The external oscillator valid detector will always return zero when the external oscillator is configured to External CMOS Clock mode.
These bits determine the internal oscillator period. When set to 00000000b, the oscillator operates at its fastest setting.
When set to 11111111b, the oscillator operates at its slowest setting. The reset value is factory calibrated to generate an
internal oscillator frequency of 24.5 MHz.
8.4.3 HFO0CN: High Frequency Oscillator Control
Bit76543210
NameIOSCENIFRDYReserved
AccessRWRRW
Reset000x0F
SFR Page = 0x0; SFR Address: 0xB2
BitNameResetAccessDescription
7IOSCEN0RWHigh Frequency Oscillator Enable.
ValueNameDescription
0DISABLEDHigh Frequency Oscillator disabled.
1ENABLEDHigh Frequency Oscillator enabled.
6IFRDY0RInternal Oscillator Frequency Ready Flag.
ValueNameDescription
0NOT_SETHigh Frequency Oscillator is not running at its programmed frequency.
1SETHigh Frequency Oscillator is running at its programmed frequency.
5:0ReservedMust write reset value.
Read-modify-write operations such as ORL and ANL must be used to set or clear the enable bit of this register to avoid modifing the
reserved field.
Provides External Oscillator status and is valid at all times for all modes of operation except External CMOS Clock Mode
and External CMOS Clock Mode with divide by 2. In these modes, XCLKVLD always returns 0.
ValueNameDescription
0NOT_SETExternal Oscillator is unused or not yet stable.
1SETExternal Oscillator is running and stable.
6:4XOSCMD0x0RWExternal Oscillator Mode.
ValueNameDescription
0x0DISABLEDExternal Oscillator circuit disabled.
0x2CMOSExternal CMOS Clock Mode.
0x3CMOS_DIV_2External CMOS Clock Mode with divide by 2 stage.
0x4RCRC Oscillator Mode.
0x5CCapacitor Oscillator Mode.
0x6CRYSTALCrystal Oscillator Mode.
0x7CRYSTAL_DIV_2Crystal Oscillator Mode with divide by 2 stage.
3ReservedMust write reset value.
2:0XFCN0x0RWExternal Oscillator Frequency Control.
Controls the external oscillator bias current. The value selected for this field depends on the frequency range of the external
oscillator.
The RTC is an ultra low power, 36 hour 32-bit independent time-keeping Real Time Clock with alarm. The RTC has a dedicated 32 kHz
oscillator. No external resistor or loading capacitors are required, and a missing clock detector features alerts the system if the external
crystal fails. The on-chip loading capacitors are programmable to 16 discrete levels allowing compatibility with a wide range of crystals.
RTC0
Low
Frequency
Oscillator
LFOSC0
XTAL3
XTAL4
Programmable
Loading
Capacitors
RTC Oscillator
State Machine
Alarm Wakeup / Interrupt
Oscillator Failure Wakeup / Interrupt
32-bit Timer
Figure 9.1. RTC Block Diagram
9.2 Features
The RTC module includes the following features:
Up to 36 hours (32-bit) of independent time keeping.
•
• Support for external 32 kHz crystal or internal self-oscillate mode.
• Internal crystal loading capacitors with 16 levels.
• Operation in the lowest power mode and across the full supported voltage range.
• Alarm and oscillator failure events to wake from the lowest power mode or reset the device.
RTCOUT
ALRM
OSCFAIL
9.3 Functional Description
9.3.1 Interface
The RTC Interface consists of three registers: RTC0KEY, RTC0ADR, and RTC0DAT. These interface registers are located on the SFR
map and provide access to the RTC internal registers. The RTC internal registers can only be accessed indirectly through the RTC
interface.
The RTC interface is protected with a lock and key function. The RTC lock and key register (RTC0KEY) must be written with the correct
key codes, in sequence, before firmware and read and write the RTC0ADR and RTC0DAT registers. The key codes are: 0xA5, 0xF1.
There are no timing restrictions, but the key codes must be written in order. If the key codes are written out of order, the wrong codes
are written, or an indirect register read or write is attempted while the interface is locked, the RTC interface will be disabled, and the
RTC0ADR and RTC0DAT registers will become inaccessible until the next system reset. Once the RTC interface is unlocked, software
may perform any number of accesses to the RTC registers until the interface is re-locked or the device is reset. Any write to RTC0KEY
while the RTC interface is unlocked will re-lock the interface. Reading the RTC0KEY register at any time will provide the RTC Interface
status and will not interfere with the sequence that is being written.
RTC internal registers can be read and written using RTC0ADR and RTC0DAT. The RTC0ADR register selects the RTC internal
The
register that will be targeted by subsequent reads or writes. Recommended instruction timing is provided in this section. If the recommended instruction timing is not followed, then firmware should check the BUSY bit prior to each read or write operation to make sure
the RTC interface is not busy performing the previous read or write operation. An RTC write operation is initiated by writing to the
RTC0DAT register:
1. Poll BUSY until it returns 0 or follow the recommended instruction timing.
2. Write the desired register address to RTC0ADR.
3. Write the desired value to RTC0DAT. This will transfer the data to the selected internal register.
An RTC read operation is initiated by setting the BUSY bit, which transfers the contents of the internal register selected by RTC0ADR to
RTC0DAT. The transferred data will remain in RTC0DAT until the next read or write operation. To read an RTC register:
1. Poll BUSY until it returns 0 or follow the recommended instruction timing.
2. Write the desired register address to RTC0ADR.
3. Write 1 to BUSY. This initiates the transfer of data from the selected register to RTC0DAT.
4. Poll BUSY until it returns 0 or follow the recommend instruction timing.
5. Read the data from RTC0DAT.
Note: The RTC0ADR and RTC0DAT registers will retain their state upon a device reset.
Short Strobe Feature
Reads and writes to indirect RTC registers normally take 7 system clock cycles. To minimize the indirect register access time, the short
strobe feature decreases the read and write access time to 6 system clocks. The short strobe feature is automatically enabled on reset
and can be manually enabled/disabled using the SHORT control bit in the RTC0ADR register. The recommended instruction timing for
a single register read with short strobe enabled is as follows:
mov RTC0ADR, #095h
nop
nop
nop
mov A, RTC0DAT
The recommended instruction timing for a single register write with short strobe enabled is as follows:
mov RTC0ADR, #015h
mov RTC0DAT, #000h
nop
Autoread Feature
When autoread is enabled, each read from RTC0DAT initiates the next indirect read operation on the RTC internal register selected by
RTC0ADR. Firmware should set the BUSY bit once at the beginning of each series of consecutive reads. Firmware should follow recommended instruction timing or check if the RTC interface is busy prior to reading RTC0DAT. Autoread is enabled by setting AUTORD
to 1 in the RTC0ADR register.
ease of reading and writing the 32-bit CAPTURE and ALARM values, RTC0ADR automatically increments after each read or write
For
to a CAPTUREn or ALARMn register. This speeds up the process of setting an alarm or reading the current RTC timer value. Autoincrement is always enabled. The recommended instruction timing for a multi-byte register read with short strobe and auto read enabled
is as follows:
mov RTC0ADR, #0d0h
nop
nop
nop
mov A, RTC0DAT
nop
nop
mov A, RTC0DAT
nop
nop
mov A, RTC0DAT
nop
nop
mov A, RTC0DAT
The recommended instruction timing for a multi-byte register write with short strobe enabled is as follows:
using crystal mode, a 32.768 kHz crystal should be connected between XTAL3 and XTAL4. No other external components are
When
required. The following steps show how to start the RTC crystal oscillator in software:
1. If XTAL3 and XTAL4 are shared with standard GPIO functionality, set these pins to analog mode. If they XTAL3 and XTAL4 are
dedicated pins, skip this step.
2. Set RTC to crystal mode (XMODE = 1).
3. Disable automatic gain control (AGCEN) and enable bias doubling (BIASX2) for fast crystal startup.
4. Set the desired loading capacitance (RTC0XCF).
5. Enable power to the RTC oscillator circuit (RTC0EN = 1).
6. Wait 20 ms.
7. Poll the RTC clock valid flag (CLKVLD) until the crystal oscillator stabilizes.
8. Poll the RTC load capacitance ready flag (LOADRDY) until the load capacitance reaches its programmed value.
9. Enable automatic gain control (AGCEN) and disable bias doubling (BIASX2) for maximum power savings.
10. Enable the RTC missing clock detector.
11. Wait 2 ms.
12. Clear the PMU0CF wake-up source flags.
While configured for crystal mode, the RTC oscillator may be driven by an external CMOS clock. The CMOS clock should be applied to
XTAL3, while XTAL4 should be left floating. The RTC oscillator should be configured to its lowest bias setting with AGC disabled. The
CLKVLD bit is indeterminate when using a CMOS clock, but the OSCFAIL flag may be checked 2 ms after the RTC oscillator is powered on to ensure that there is a valid clock on XTAL3.
For devices with a dedicated XTAL3 pin, the input low voltage (VIL) and input high voltage (VIH) for XTAL3 when used with an external
CMOS clock are 0.1 and 0.8 V, respectively.
For devices where XTAL3 is shared with standard GPIO functionality, bias levels closer to VDD will result in lower I/O power consumption because the XTAL3 pin has a built-in weak pull-up. In this mode, the external CMOS clock is ac coupled into the RTC and should
have a minimum voltage swing of 400 mV. The CMOS clock signal voltage should not exceed VDD or drop below GND.
using self-oscillate mode, the XTAL3 and XTAL4 pins should be shorted together. The RTC0PIN register can be used to internal-
When
ly short XTAL3 and XTAL4. To configure the RTC for self-oscillate mode:
1. Write 0xE7 to RTC0PIN to short XTAL3 and XTAL4 together internally.
2. Set RTC to Self-Oscillate Mode (XMODE = 0).
3. Set the desired oscillation frequency:
• For oscillation at about 20 kHz, set BIASX2 = 0.
• For oscillation at about 40 kHz, set BIASX2 = 1.
4. The oscillator starts oscillating instantaneously.
5. Fine tune the oscillation frequency by adjusting the load capacitance (RTC0XCF).
Programmable Load Capacitance
The programmable load capacitance has 16 values to support crystal oscillators with a wide range of recommended load capacitance.
If automatic load capacitance stepping is enabled, the crystal load capacitors start at the smallest setting to allow a fast startup time,
then slowly increase the capacitance until the final programmed value is reached. The final programmed loading capacitor value is
specified using the LOADCAP field in the RTC0XCF register. The LOADCAP setting specifies the amount of on-chip load capacitance
and does not include any stray PCB capacitance. Once the final programmed loading capacitor value is reached, hardware will set the
LOADRDY flag to 1.
When using the RTC oscillator in self-oscillate mode, the programmable load capacitance can be used to fine tune the oscillation frequency. In most cases, increasing the load capacitor value will result in a decrease in oscillation frequency.
Table 9.1. RTC Load Capacitance Settings
LOADCAP FieldCrystal Load CapacitanceEquivalent Capacitance seen on XTAL3 and
Automatic Gain Control (Crystal Mode Only) and Bias Doubling
EFM8SB2 Reference Manual
Real Time Clock (RTC0)
Automatic
gain control (AGC) allows the RTC oscillator to trim the oscillation amplitude of a crystal in order to achieve the lowest possible power consumption. Automatic gain control automatically detects when the oscillation amplitude has reached a point where it safe
to reduce the drive current, so it may be enabled during crystal startup. It is recommended to enable AGC in most systems which use
the RTC oscillator in crystal mode. The following are recommended crystal specifications and operating conditions when AGC is enabled:
• ESR < 50 kΩ
• Load Capacitance < 10 pF
• Supply Voltage < 3.0 V
• Temperature > –20 °C
When using AGC, it is recommended to perform an oscillation robustness test to ensure that the chosen crystal will oscillate under the
worst case condition to which the system will be exposed. The worst case condition that should result in the least robust oscillation is at
the following system conditions: lowest temperature, highest supply voltage, highest ESR, highest load capacitance, and lowest bias
current (AGC enabled, bias doubling disabled).
To perform the oscillation robustness test, the RTC oscillator should be enabled and selected as the system clock source. Next, the
SYSCLK signal should be routed to a port pin configured as a push-pull digital output. The positive duty cycle of the output clock can be
used as an indicator of oscillation robustness. Duty cycles less than 55% indicate a robust oscillation. As the duty cycle approaches
60%, oscillation becomes less reliable and the risk of clock failure increases. Increasing the bias current (by disabling AGC) will always
improve oscillation robustness and will reduce the output clock’s duty cycle. This test should be performed at the worst case system
conditions, as results at very low temperatures or high supply voltage will vary from results taken at room temperature or low supply
voltage.
Safe Operating Zone
Low Risk of
Clock Failure
High Risk of Clock
Failure
25%
55%60%
Duty Cycle
Figure 9.2. Interpreting Oscillation Robustness (Duty Cycle) Test Results
As an alternative to performing the oscillation robustness test, AGC may be disabled at the cost of increased power consumption (approximately
200 nA). Disabling AGC will provide the crystal oscillator with higher immunity against external factors which may lead to
clock failure. AGC must be disabled if using the RTC oscillator in self-oscillate mode. The RTC bias doubling feature allows the selfoscillation frequency to be increased (almost doubled) and allows a higher crystal drive strength in crystal mode. High crystal drive
strength is recommended when the crystal is exposed to poor environmental conditions such as excessive moisture. RTC bias doubling
is enabled by setting BIASX2 to 1.
missing RTC detector is a one-shot circuit enabled by setting MCLKEN to 1. When the RTC missing clock detector is enabled,
The
OSCFAIL is set by hardware if the RTC oscillator remains high or low for more than 100 μs. An RTC missing clock detector timeout can
trigger an interrupt, wake the device from a low power mode, or reset the device.
Note: The RTC missing clock detector should be disabled when making changes to the oscillator settings in RTC0XCN0.
Oscillator Crystal Valid Detector
The RTC oscillator crystal valid detector is an oscillation amplitude detector circuit used during crystal startup to determine when oscillation has started and is nearly stable. The output of this detector can be read from the CLKVLD bit.
Note: The CLKVLD bit has a blanking interval of 2 ms. During the first 2 ms after turning on the crystal oscillator, the output of CLKVLD
is not valid.
Note: This RTC crystal valid detector (CLKVLD) is not intended for detecting an oscillator failure. The missing RTC detector (OSCFAIL)
should be used for this purpose.
9.3.3 Timer and Alarm
The RTC timer is a 32-bit counter that, when running (RTC0TR = 1), is incremented every RTC oscillator cycle. The timer has an alarm
function that can be set to generate an interrupt, wake the device from a low power mode, or reset the device at a specific time.
The RTC timer includes an auto reset feature, which automatically resets the timer to zero one RTC cycle after the alarm signal is deasserted. When using auto reset, the Alarm match value should always be set to 1 count less than the desired match value. Auto reset
can be enabled by writing a 1 to ALRM.
Setting and Reading the RTC Timer
The 32-bit RTC timer can be set or read using the CAPTUREn internal registers. Note that the timer does not need to be stopped before reading or setting its value. The following steps can be used to set the timer value:
1. Write the desired 32-bit set value to the CAPTUREn registers.
2. Write 1 to RTC0SET. This will transfer the contents of the CAPTUREn registers to the RTC timer.
3. The operation is complete when RTC0SET is cleared to 0 by hardware.
To read the current timer value:
1. Write 1 to RTC0CAP. This will transfer the contents of the timer to the CAPTUREn registers.
2. Poll RTC0CAP until it is cleared to 0 by hardware.
3. A snapshot of the timer value can be read from the CAPTUREn registers
Setting an RTC Alarm
The RTC alarm function compares the 32-bit value of the RTC timer to the value of the ALARMn registers. An alarm event is triggered if
the RTC timer is equal to the ALARMn registers. If auto reset is enabled, the 32-bit timer will be cleared to zero one RTC cycle after the
alarm event. The RTC alarm event can be configured to reset the MCU, wake it up from a low power mode, or generate an interrupt. To
set up an RTC alarm:
1. Disable RTC Alarm Events (RTC0AEN = 0).
2. Set the ALARMn registers to the desired value.
3. Enable RTC Alarm Events (RTC0AEN = 1).
Note: The ALRM bit, which is used as the RTC Alarm event flag, is cleared by disabling RTC Alarm events (RTC0AEN = 0).
Note: If auto reset is disabled, disabling (RTC0AEN = 0) then re-enabling alarm events (RTC0AEN = 1) after an RTC Alarm without
modifying ALARMn registers will automatically schedule the next alarm after 232 RTC cycles (approximately 36 hours using a 32.768
kHz crystal).
Note: The RTC Alarm event flag will remain asserted for a maximum of one RTC cycle. When using the RTC in conjunction with low
power modes, the PMU must be used to determine the cause of the last wake event.
The RTC timer and alarm have two operating modes to suit varying applications:
Mode 1
first mode uses the RTC timer as a perpetual timebase which is never reset to zero. Every 36 hours, the timer is allowed to over-
The
flow without being stopped or disrupted. The alarm interval is software managed and is added to the ALRMn registers by software after
each alarm. This allows the alarm match value to always stay ahead of the timer by one software managed interval. If software uses
32-bit unsigned addition to increment the alarm match value, then it does not need to handle overflows since both the timer and the
alarm match value will overflow in the same manner. This mode is ideal for applications which have a long alarm interval (e.g., 24 or 36
hours) and/or have a need for a perpetual timebase. An example of an application that needs a perpetual timebase is one whose wakeup interval is constantly changing. For these applications, software can keep track of the number of timer overflows in a 16-bit variable,
extending the 32-bit (36 hour) timer to a 48-bit (272 year) perpetual timebase.
Mode 2
The second mode uses the RTC timer as a general purpose up counter which is auto reset to zero by hardware after each alarm. The
alarm interval is managed by hardware and stored in the ALRMn registers. Software only needs to set the alarm interval once during
device initialization. After each alarm, software should keep a count of the number of alarms that have occurred in order to keep track of
time. This mode is ideal for applications that require minimal software intervention and/or have a fixed alarm interval. This mode is the
most power efficient since it requires less CPU time per alarm.
9.4 Clocking and Oscillator Control Registers
9.4.1 RTC0KEY: RTC Lock and Key
Bit76543210
NameRTC0ST
AccessRW
Reset0x00
SFR Page = 0x0; SFR Address: 0xAE
BitNameResetAccessDescription
7:0RTC0ST0x00RWRTC Interface Lock/Key and Status.
Writing to this field locks or unlocks the RTC0 Interface. Reading this field provides the current RTC0 Interface lock status.
0x00: RTC Interface is locked. Writing 0xA5 followed by 0xF1 unlocks the RTC interface.
0x01: RTC Interface is locked, but 0xA5 has already been written. Writing any value other than the second key code (0xF1)
will change this field to 3 and disable the RTC interface until the next system reset.
0x02: RTC Interface is unlocked. Any write to the RTC0KEY register will lock the RTC Interface.
0x03: RTC Interface is disabled until the next system reset. Any writes to RTC0KEY have no effect.
This bit indicates the RTC interface status. Writing a 1 to this bit initiates an indirect read.
6AUTORD0RWRTC Interface Autoread Enable.
When autoread is enabled, firmware should set the BUSY bit once at the beginning of each series of consecutive reads.
Firmware must check if the RTC Interface is busy prior to reading RTC0DAT.
ValueNameDescription
0DISABLEDDisable autoread. Firmware must write the BUSY bit for each RTC indirect read
operation.
1ENABLEDEnable autoread. The next RTC indirect read operation is initiated when firmware
reads the RTC0DAT register.
5ReservedMust write reset value.
4SHORT0RWShort Strobe Enable.
Enables/disables the Short Strobe feature.
ValueNameDescription
0DISABLEDDisable short strobe.
1ENABLEDEnable short strobe.
3:0ADDR0x0RWRTC Indirect Register Address.
Sets the currently-selected RTC internal register.
The ADDR bits increment after each indirect read/write operation that targets a CAPTUREn or ALARMn internal RTC register.
9.4.3 RTC0DAT: RTC Data
Bit76543210
NameRTC0DAT
AccessRW
Reset0x00
SFR Page = 0x0; SFR Address: 0xAD
BitNameResetAccessDescription
7:0RTC0DAT 0x00RWRTC Data.
Holds data transferred to/from the internal RTC register selected by RTC0ADR.
Read-modify-write instructions (orl, anl, etc.) should not be used on this register.
Enables/disables the RTC oscillator and associated bias currents.
ValueNameDescription
0DISABLEDDisable RTC oscillator.
1ENABLEDEnable RTC oscillator.
6MCLKEN0RWMissing RTC Detector Enable.
Enables/disables the missing RTC detector.
ValueNameDescription
0DISABLEDDisable missing RTC detector.
1ENABLEDEnable missing RTC detector.
5OSCFAILVariesRWRTC Oscillator Fail Event Flag.
Set by hardware when a missing RTC detector timeout occurs. Must be cleared by firmware. The value of this bit is not
defined when the RTC oscillator is disabled.
4RTC0TR0RWRTC Timer Run Control.
Controls if the RTC timer is running or stopped (holds current value).
ValueNameDescription
0STOPRTC timer is stopped.
1RUNRTC timer is running.
3RTC0AEN 0RWRTC Alarm Enable.
Enables/disables the RTC alarm function. Also clears the ALRM flag.
ValueNameDescription
0DISABLEDDisable RTC alarm.
1ENABLEDEnable RTC alarm.
2ALRM0RWRTC Alarm Event Flag and Auto Reset Enable.
Reads return the state of the alarm event flag.
Writes enable/disable the Auto Reset function.
ValueNameDescription
0NOT_SETAlarm event flag is not set or disable the auto reset function.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
9.4.7 CAPTURE0: RTC Timer Capture 0
Bit76543210
NameCAPTURE0
AccessRW
Reset0x00
Indirect Address: 0x00
BitNameResetAccessDescription
7:0CAP-
0x00RWRTC Timer Capture 0.
TURE0
The CAPTURE3-CAPTURE0 registers are used to read or set the 32-bit RTC timer. Data is transferred to or from the RTC
timer when the RTC0SET or RTC0CAP bits are set.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
The CAPTURE3-CAPTURE0 registers are used to read or set the 32-bit RTC timer. Data is transferred to or from the RTC
timer when the RTC0SET or RTC0CAP bits are set.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
9.4.9 CAPTURE2: RTC Timer Capture 2
Bit76543210
NameCAPTURE2
AccessRW
Reset0x00
Indirect Address: 0x02
BitNameResetAccessDescription
7:0CAP-
0x00RWRTC Timer Capture 2.
TURE2
The CAPTURE3-CAPTURE0 registers are used to read or set the 32-bit RTC timer. Data is transferred to or from the RTC
timer when the RTC0SET or RTC0CAP bits are set.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
9.4.10 CAPTURE3: RTC Timer Capture 3
Bit76543210
NameCAPTURE3
AccessRW
Reset0x00
Indirect Address: 0x03
BitNameResetAccessDescription
7:0CAP-
0x00RWRTC Timer Capture 3.
TURE3
The CAPTURE3-CAPTURE0 registers are used to read or set the 32-bit RTC timer. Data is transferred to or from the RTC
timer when the RTC0SET or RTC0CAP bits are set.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
The ALARM3-ALARM0 registers are used to set an alarm event for the RTC timer. The RTC alarm should be disabled
(RTC0AEN=0) when updating these registers.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
9.4.12 ALARM1: RTC Alarm Programmed Value 1
Bit76543210
NameALARM1
AccessRW
Reset0x00
Indirect Address: 0x09
BitNameResetAccessDescription
7:0ALARM10x00RWRTC Alarm Programmed Value 1.
The ALARM3-ALARM0 registers are used to set an alarm event for the RTC timer. The RTC alarm should be disabled
(RTC0AEN=0) when updating these registers.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
9.4.13 ALARM2: RTC Alarm Programmed Value 2
Bit76543210
NameALARM2
AccessRW
Reset0x00
Indirect Address: 0x0A
BitNameResetAccessDescription
7:0ALARM20x00RWRTC Alarm Programmed Value 2.
The ALARM3-ALARM0 registers are used to set an alarm event for the RTC timer. The RTC alarm should be disabled
(RTC0AEN=0) when updating these registers.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
The ALARM3-ALARM0 registers are used to set an alarm event for the RTC timer. The RTC alarm should be disabled
(RTC0AEN=0) when updating these registers.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
9.4.15 RTC0PIN: RTC Pin Configuration
Bit76543210
NameRTCPIN
AccessW
Reset0x67
Indirect Address: 0x07
BitNameResetAccessDescription
7:0RTCPIN0x67WRTC Pin Configuration.
Writing 0xE7 to this field forces XTAL3 and XTAL4 to be internally shorted for use with self-oscillate mode. Writing 0x67
returns XTAL3 and XTAL4 to their normal configuration.
This register is accessed indirectly using the RTC0ADR and RTC0DAT registers.
Reset circuitry allows the controller to be easily placed in a predefined default condition. On entry to this reset state, the following occur:
• The core halts program execution.
• Module registers are initialized to their defined reset values unless the bits reset only with a power-on reset.
• External port pins are forced to a known state.
• Interrupts and timers are disabled.
All registers are reset to the predefined values noted in the register descriptions unless the bits only reset with a power-on reset. The
contents of RAM are unaffected during a reset; any previously stored data is preserved as long as power is not lost. The Port I/O latches are reset to 1 in open-drain mode. Weak pullups are enabled during and after the reset. For Supply Monitor and power-on resets,
the RSTb 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 an internal oscillator. The Watchdog Timer is enabled, and program execution begins at location 0x0000.
Reset Sources
RSTb
Supply Monitor or
Power-up
Missing Clock Detector
Watchdog Timer
Software Reset
Comparator 0
Flash Error
RTC Reset
Figure 10.1. Reset Sources Block Diagram
10.2 Features
Reset sources on the device include the following:
Upon entering a reset state from any source, the following events occur:
The processor core halts program execution.
•
• Special Function Registers (SFRs) are initialized to their defined reset values.
• External port pins are placed in a known state.
• Interrupts and timers are disabled.
SFRs are reset to the predefined reset values noted in the detailed register 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 pullups are enabled during and after the reset. For
Supply Monitor and power-on resets, the RSTb pin is driven low until the device exits the reset state.
Note: During a power-on event, there may be a short delay before the POR circuitry fires and the RSTb pin is driven low. During that
time, the RSTb pin will be weakly pulled to the supply pin.
On exit from the reset state, the program counter (PC) is reset, the watchdog timer is enabled, and the system clock defaults to an
internal oscillator. Program execution begins at location 0x0000.
power-up, the POR circuit fires. When POR fires, the device is held in a reset state and the RSTb pin is high-impedance with the
During
weak pull-up either on or off until the supply voltage settles above V
. Two delays are present during the supply ramp time. First, a
RST
delay occurs before the POR circuitry fires and pulls the RSTb pin low. A second delay occurs before the device is released from reset;
the delay decreases as the supply ramp time increases (supply ramp time is defined as how fast the supply pin ramps from 0 V to
V
). For ramp times less than 1 ms, the power-on reset time (T
RST
reach V
before the POR circuit releases the device from reset.
RST
) is typically less than 0.3 ms. Additionally, the power supply must
POR
On exit from a power-on reset, the PORSF flag 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 memory should be assumed to be undefined after a power-on reset. The supply monitor is enabled following a power-on reset.
supply monitor senses the voltage on the device's supply pin and can generate a reset if the supply drops below the corresponding
The
threshold. This monitor is enabled and enabled as a reset source after initial power-on to protect the device until the supply is an adequate and stable voltage. When enabled and selected as a reset source, any power down transition or power irregularity that causes
the supply to drop below the reset threshold will drive the RSTb pin low and hold the core in a reset state. When the supply returns to a
level above the reset threshold, the monitor will release the core from the reset state. The reset status can then be read using the
device reset sources module. After a power-fail reset, the PORF flag reads 1 and all of the other reset flags in the RSTSRC register are
indeterminate. The power-on reset delay (t
invalid after a supply monitor reset. The enable state of the supply monitor and its selection as a reset source is not altered by device
resets. For example, if the supply monitor is de-selected as a reset source and disabled by software using the VDMEN bit in the
VDM0CN register, and then firmware performs a software reset, the supply monitor will remain disabled and de-selected after the reset.
To protect the integrity of flash contents, the supply monitor must be enabled and selected as a reset source if software contains routines that erase or write flash memory. If the supply monitor is not enabled, any erase or write performed on flash memory will be ignored.
) is not incurred after a supply monitor reset. The contents of RAM should be presumed
POR
Reset Threshold
(V
RST
RSTb
volts
)
Supply Monitor
Reset
Supply Voltage
t
Figure 10.3. Reset Sources
10.3.4 External Reset
The
external RSTb pin provides a means for external circuitry to force the device into a reset state. Asserting an active-low signal on
the RSTb pin generates a reset; an external pullup and/or decoupling of the RSTb pin may be necessary to avoid erroneous noiseinduced resets. The PINRSF flag is set on exit from an external reset.
10.3.5 Missing Clock Detector Reset
The Missing Clock Detector (MCD) is a one-shot circuit that is triggered by the system clock. If the system clock remains high or low for
more than the MCD time window, the one-shot will time out and generate a reset. After a MCD reset, the MCDRSF flag will read 1,
signifying the MCD as the reset source; otherwise, this bit reads 0. Writing a 1 to the MCDRSF bit enables the Missing Clock Detector;
writing a 0 disables it. The state of the RSTb pin is unaffected by this reset.
10.3.6 Comparator (CMP0) Reset
Comparator0 can be configured as a reset source by writing a 1 to the C0RSEF flag. Comparator0 should be enabled and allowed to
settle prior to writing to C0RSEF to prevent any turn-on chatter on the output from generating an unwanted reset. The Comparator0
reset is active-low: if the non-inverting input voltage (on CP0+) is less than the inverting input voltage (on CP0–), the device is put into
the reset state. After a Comparator0 reset, the C0RSEF flag will read 1 signifying Comparator0 as the reset source; otherwise, this bit
reads 0. The state of the RSTb pin is unaffected by this reset.
programmable watchdog timer (WDT) function of the programmable counter array (PCA) can be used to prevent software from
The
running out of control during a system malfunction. The PCA WDT function can be enabled or disabled by software as described in the
PCA documentation. The WDT is enabled and clocked by SYSCLK/12 following any reset. If a system malfunction prevents user software from updating the WDT, a reset is generated and the WDTRSF bit in RSTSRC is set to 1. The state of the RSTb pin is unaffected
by this reset.
10.3.8 Flash Error Reset
If a flash read/write/erase or program read targets an illegal address, a system reset is generated. This may occur due to any of the
following:
• A flash write or erase is attempted above user code space.
• A flash read is attempted above user code space.
• A program read is attempted above user code space (i.e., a branch instruction to the reserved area).
• A flash read, write or erase attempt is restricted due to a flash security setting.
The FERROR bit is set following a flash error reset. The state of the RSTb pin is unaffected by this reset.
10.3.9 Software Reset
Software may force a reset by writing a 1 to the SWRSF bit. The SWRSF bit will read 1 following a software forced reset. The state of
the RSTb pin is unaffected by this reset.
10.3.10 RTC Reset
The RTC can generate a system reset on two events: RTC oscillator fail or RTC alarm. The RTC oscillator fail event occurs when the
RTC missing clock detector is enabled and the RTC clock is below approximately 20 kHz. A RTC alarm event occurs when the RTC
alarm is enabled and the RTC timer value matches the ALARMn registers. The RTC can be configured as a reset source by writing a 1
to the RTC0RE flag in the RSTSRC register. The RTC reset remains functional even when the device is in the low power Suspend or
Sleep mode. The state of the RSTb pin is unaffected by this reset.
Read: This bit reads 1 anytime a power-on or supply monitor reset has occurred.
Write: Writing a 1 to this bit enables the supply monitor as a reset source.
0PINRSFVariesRHW Pin Reset Flag.
This read-only bit is set to '1' if the RSTb pin caused the last reset.
Reads and writes of the RSTSRC register access different logic in the device. Reading the register always returns status information
to indicate the source of the most recent reset. Writing to the register activates certain options as reset sources. It is recommended to
not use any kind of read-modify-write operation on this register.
When the PORSF bit reads back '1' all other RSTSRC flags are indeterminate.
Writing '1' to the PORSF bit when the supply monitor is not enabled and stabilized may cause a system reset.
This bit turns the VDD supply monitor circuit on/off. The VDD Supply Monitor cannot generate system resets until it is also
selected as a reset source in register RSTSRC.
The CIP-51 microcontroller core is a high-speed, pipelined, 8-bit core utilizing the standard MCS-51™ instruction set. Any standard
803x/805x assemblers and compilers can be used to develop software. The MCU family has a superset of all the peripherals included
with a standard 8051. The CIP-51 includes on-chip debug hardware and interfaces directly with the analog and digital subsystems providing a complete data acquisition or control system solution.
CIP-51 employs a pipelined architecture that greatly increases its instruction throughput over the standard 8051 architecture. The
The
CIP-51 core executes 76 of its 109 instructions in one or two clock cycles, with no instructions taking more than eight clock cycles. The
table below shows the distribution of instructions vs. the number of clock cycles required for execution.
Table 11.1. Instruction Execution Timing
Clocks to
122 or 333 or 444 or 558
Execute
Number of
265051473121
Instructions
Notes:
1.
Conditional branch instructions (indicated by "2 or 3", "3 or 4" and "4 or 5") require an extra clock cycle if the branch is taken.
11.2 Features
CIP-51 Microcontroller core implements the standard 8051 organization and peripherals as well as additional custom peripherals
The
and functions to extend its capability. The CIP-51 includes the following features:
• Fast, efficient, pipelined architecture.
• Fully compatible with MCS-51 instruction set.
• 0 to 25 MHz operating clock frequency.
• 25 MIPS peak throughput with 25 MHz clock.
• Extended interrupt handler.
• Power management modes.
• On-chip debug logic.
• Program and data memory security.
11.3 Functional Description
11.3.1 Programming and Debugging Support
In-system programming of the flash program memory and communication with on-chip debug support logic is accomplished via the Silicon Labs 2-Wire development interface (C2).
The on-chip debug support logic facilitates full speed in-circuit debugging, allowing the setting of hardware breakpoints, starting, stopping and single stepping through program execution (including interrupt service routines), examination of the program's call stack, and
reading/writing the contents of registers and memory. This method of on-chip debugging is completely non-intrusive, requiring no RAM,
stack, timers, or other on-chip resources.
The CIP-51 is supported by development tools from Silicon Labs and third party vendors. Silicon Labs provides 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. Third party macro assemblers and C compilers are also available.
instruction set of the CIP-51 System Controller is fully compatible with the standard MCS-51™ instruction set. Standard 8051 de-
The
velopment tools can be used to develop software for the CIP-51. All CIP-51 instructions are the binary and functional equivalent of their
MCS-51™ counterparts, including opcodes, addressing modes and effect on PSW flags. However, instruction timing is much faster
than that of the standard 8051.
All instruction timing on the CIP-51 controller is based directly on the core clock timing. This is in contrast to many other 8-bit architectures, where a distinction is made between machine cycles and clock cycles, with machine cycles taking multiple core clock cycles.
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 one less clock cycle to complete when the branch is not taken as opposed
to when the branch is taken. The following table summarizes the instruction set, including the mnemonic, number of bytes, and number
of clock cycles for each instruction.
Table 11.2. CIP-51 Instruction Set Summary
MnemonicDescriptionBytesClock Cycles
Arithmetic Operations
ADD A, RnAdd register to A11
ADD A, directAdd direct byte to A22
ADD A, @RiAdd indirect RAM to A12
ADD A, #dataAdd immediate to A22
ADDC A, RnAdd register to A with carry11
ADDC A, directAdd direct byte to A with carry22
ADDC A, @RiAdd indirect RAM to A with carry12
ADDC A, #dataAdd immediate to A with carry22
SUBB A, RnSubtract register from A with borrow11
SUBB A, directSubtract direct byte from A with borrow22
SUBB A, @RiSubtract indirect RAM from A with borrow12
SUBB A, #dataSubtract immediate from A with borrow22
CJNE A, direct, relCompare direct byte to A and jump if not equal33 or 4
CJNE A, #data, relCompare immediate to A and jump if not equal33 or 4
CJNE Rn, #data, relCompare immediate to Register and jump if not equal33 or 4
CJNE @Ri, #data, relCompare immediate to indirect and jump if not equal34 or 5
DJNZ Rn, relDecrement Register and jump if not zero22 or 3
DJNZ direct, relDecrement direct byte and jump if not zero33 or 4
NOPNo operation11
Notes:
• Rn: Register R0–R7 of the currently selected register bank.
• @Ri: Data RAM location addressed indirectly through R0 or R1.
• rel: 8-bit, signed (twos 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).
• #data: 8-bit constant.
• #data16: 16-bit constant.
• bit: Direct-accessed bit in Data RAM or SFR.
• addr11: 11-bit destination address used by ACALL and AJMP. The destination must be within the same 2 KB 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 8 KB program memory
space.
The DPH register is the high byte of the 16-bit DPTR. DPTR is used to access indirectly addressed flash memory or XRAM.
11.4.3 SP: Stack Pointer
Bit76543210
NameSP
AccessRW
Reset0x07
SFR Page = ALL; SFR Address: 0x81
BitNameResetAccessDescription
7:0SP0x07RWStack Pointer.
The Stack Pointer holds the location of the top of the stack. The stack pointer is incremented before every PUSH operation.
The SP register defaults to 0x07 after reset.
This bit is set when the last arithmetic operation resulted in a carry (addition) or a borrow (subtraction). It is cleared to logic
0 by all other arithmetic operations.
6AC0RWAuxiliary Carry Flag.
This bit is set when the last arithmetic operation resulted in a carry into (addition) or a borrow from (subtraction) the high
order nibble. It is cleared to logic 0 by all other arithmetic operations.
5F00RWUser Flag 0.
This is a bit-addressable, general purpose flag for use under firmware control.
4:3RS0x0RWRegister Bank Select.
These bits select which register bank is used during register accesses.
ValueNameDescription
0x0BANK0Bank 0, Addresses 0x00-0x07
0x1BANK1Bank 1, Addresses 0x08-0x0F
0x2BANK2Bank 2, Addresses 0x10-0x17
0x3BANK3Bank 3, Addresses 0x18-0x1F
2OV0RWOverflow Flag.
This bit is set to 1 under the following circumstances:
1. An ADD, ADDC, or SUBB instruction causes a sign-change overflow.
2. A MUL instruction results in an overflow (result is greater than 255).
3. A DIV instruction causes a divide-by-zero condition.
The OV bit is cleared to 0 by the ADD, ADDC, SUBB, MUL, and DIV instructions in all other cases.
1F10RWUser Flag 1.
This is a bit-addressable, general purpose flag for use under firmware control.
0PARITY0RParity Flag.
This bit is set to logic 1 if the sum of the eight bits in the accumulator is odd and cleared if the sum is even.
Port I/O, Crossbar, External Interrupts, and Port Match
12. Port I/O, Crossbar, External Interrupts, and Port Match
12.1 Introduction
Digital and analog resources are externally available on the device’s multi-purpose I/O pins. Port pins P0.0-P2.6 can be defined as general-purpose I/O (GPIO), assigned to one of the internal digital resources through the crossbar or dedicated channels, or assigned to an
analog function. Port pin P2.7 can be used as GPIO. Additionally, the C2 Interface Data signal (C2D) is shared with P2.7.
Port I/O, Crossbar, External Interrupts, and Port Match
12.3 Functional Description
12.3.1 Port I/O Modes of Operation
pins are configured by firmware as digital or analog I/O using the special function registers. Port I/O initialization consists of the
Port
following general steps:
1. Select the input mode (analog or digital) for all port pins, using the Port Input Mode register (PnMDIN).
2. Select the output mode (open-drain or push-pull) for all port pins, using the Port Output Mode register (PnMDOUT).
3. Select any pins to be skipped by the I/O crossbar using the Port Skip registers (PnSKIP).
4. Assign port pins to desired peripherals.
5. Enable the crossbar (XBARE = 1).
A diagram of the port I/O cell is shown in the following figure.
WEAKPUD
eak Pull-Up Disable)
(W
PxMDOUT.x
(1 for push-pull)
(0 for open-drain)
XBARE
(Crossbar
Enable)
Px.x – Output
Logic Value
(Port Latch or
Crossbar)
To/From Analog
Peripheral
Px.x – Input Logic Value
(Reads
PxMDIN.x
(1 for digital)
(0 for analog)
0 when pin is configured as an analog I/O)
VDD
GND
VDD
(WEAK)
PORT
PAD
Figure 12.2. Port I/O Cell Block Diagram
Configuring Port Pins For Analog Modes
Any
pins to be used for analog functions should be configured for analog mode. When a pin is configured for analog I/O, its weak pullup, digital driver, and digital receiver are disabled. This saves power by eliminating crowbar current, 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. Port pins
configured for analog functions will always read back a value of 0 in the corresponding Pn Port Latch register. To configure a pin as
analog, the following steps should be taken:
1. Clear the bit associated with the pin in the PnMDIN register to 0. This selects analog mode for the pin.
2. Set the bit associated with the pin in the Pn register to 1.
3. Skip the bit associated with the pin in the PnSKIP register to ensure the crossbar does not attempt to assign a function to the pin.
Port I/O, Crossbar, External Interrupts, and Port Match
Configuring Port Pins For Digital Modes
pins to be used by digital peripherals or as GPIO should be configured as digital I/O (PnMDIN.n = 1). For digital I/O pins, one of
Any
two output modes (push-pull or open-drain) must be selected using the PnMDOUT registers.
Push-pull outputs (PnMDOUT.n = 1) drive the port pad to the supply rails based on the output logic value of the port pin. Open-drain
outputs have the high side driver disabled; therefore, they only drive the port pad to the lowside rail when the output logic value is 0 and
become high impedance inputs (both high low drivers turned off) when the output logic value is 1.
When a digital I/O cell is placed in the high impedance state, a weak pull-up transistor pulls the port pad to the high side rail to ensure
the digital input is at a defined logic state. Weak pull-ups are disabled when the I/O cell is driven low to minimize power consumption,
and they may be globally disabled by setting WEAKPUD to 1. The user should ensure that digital I/O are always internally or externally
pulled or driven to a valid logic state to minimize power consumption. Port pins configured for digital I/O always read back the logic
state of the port pad, regardless of the output logic value of the port pin.
To configure a pin as a digital input:
1. Set the bit associated with the pin in the PnMDIN register to 1. This selects digital mode for the pin.
2. lear the bit associated with the pin in the PnMDOUT register to 0. This configures the pin as open-drain.
3. Set the bit associated with the pin in the Pn register to 1. This tells the output driver to “drive” logic high. Because the pin is configured as open-drain, the high-side driver is disabled, and the pin may be used as an input.
Open-drain outputs are configured exactly as digital inputs. The pin may be driven low by an assigned peripheral, or by writing 0 to the
associated bit in the Pn register if the signal is a GPIO.
To configure a pin as a digital, push-pull output:
1. Set the bit associated with the pin in the PnMDIN register to 1. This selects digital mode for the pin.
2. Set the bit associated with the pin in the PnMDOUT register to 1. This configures the pin as push-pull.
If a digital pin is to be used as a general-purpose I/O, or with a digital function that is not part of the crossbar, the bit associated with the
pin in the PnSKIP register can be set to 1 to ensure the crossbar does not attempt to assign a function to the pin. The crossbar must be
enabled to use port pins as standard port I/O in output mode. Port output drivers of all I/O pins are disabled whenever the crossbar is
disabled.
12.3.1.1 Pin Drive Strength
Pin drive strength can be controlled on a pin-by-pin basis using the PnDRV registers. Each pin has a bit in the corresponding PnDRV
register to select the high or low drive strengh setting. By default, all port pins are configured for low drive strength.
12.3.2 Analog and Digital Functions
12.3.2.1 Port I/O Analog Assignments
The following table displays the potential mapping of port I/O to each analog function.
Table 12.1. Port I/O Assignment for Analog Functions
Analog FunctionPotentially Assignable Port PinsSFR(s) Used For Assignment
Port I/O, Crossbar, External Interrupts, and Port Match
12.3.3 Priority Crossbar Decoder
priority crossbar decoder assigns a priority to each I/O function, starting at the top with UART0. The XBRn registers are used to
The
control which crossbar resources are assigned to physical I/O port pins.
When a digital resource is selected, the least-significant unassigned port pin is assigned to that resource (excluding UART0, which is
always assigned to dedicated pins). If a port pin is assigned, the crossbar skips that pin when assigning the next selected resource.
Additionally, the the PnSKIP registers allow software to skip port pins that are to be used for analog functions, dedicated digital functions, or GPIO. If a port pin is to be used by a function which is not assigned through the crossbar, its corresponding PnSKIP bit should
be set to 1 in most cases. The crossbar skips these pins as if they were already assigned, and moves to the next unassigned pin.
It is possible for crossbar-assigned peripherals and dedicated functions to coexist on the same pin. For example, the port match function could be configured to watch for a falling edge on a UART RX line and generate an interrupt or wake up the device from a lowpower state. However, if two functions share the same pin, the crossbar will have control over the output characteristics of that pin and
the dedicated function will only have input access. Likewise, it is possible for firmware to read the logic state of any digital I/O pin assigned to a crossbar peripheral, but the output state cannot be directly modified.
Figure 12.3 Crossbar Priority Decoder Example Assignments on page 96 shows an example of the resulting pin assignments of the
device with UART0 and SPI0 enabled and P0.3 skipped (P0SKIP = 0x08). UART0 is the highest priority and it will be assigned first.
The UART0 pins can only appear at fixed locations (in this example, P0.4 and P0.5), so it occupies those pins. The next-highest enabled peripheral is SPI0. P0.0, P0.1 and P0.2 are free, so SPI0 takes these three pins. The fourth pin, NSS, is routed to P0.6 because
P0.3 is skipped and P0.4 and P0.5 are already occupied by the UART. Any other pins on the device are available for use as generalpurpose digital I/O or analog functions.
P0Port
Pin Number
01234567
UART0-TX
UART0-RX
SPI0-SCK
SPI0-MISO
SPI0-MOSI
SPI0-NSS
0000000
1
Pin Skip Settings
P0SKIP
UART0 is assigned to fixed pins and has priority over SPI0.
SPI0 is assigned to available, un-skipped pins.
Port pins assigned to the associated peripheral.
P0.3 is skipped by setting P0SKIP.3 to 1.
Figure 12.3. Crossbar Priority Decoder Example Assignments
Port I/O, Crossbar, External Interrupts, and Port Match
12.3.3.1 Crossbar Functional Map
12.4 Full Crossbar Map on page 98 shows all of the potential peripheral-to-pin assignments available to the crossbar. Note
Figure
that this does not mean any peripheral can always be assigned to the highlighted pins. The actual pin assignments are determined by
the priority of the enabled peripherals.
Port I/O, Crossbar, External Interrupts, and Port Match
P0Port
Pin Number01234567
01234567
P1
QFN-24 Package
QFN-32 Package
VREF
AGND
XTAL1
XTAL2
IREF0
CNVSTR
AD0m — AD7m, A8 — A11
QFP-32 Package
UART0-TX
UART0-RX
SPI1-SCK
SPI1-MISO
SPI1-MOSI
SPI1-NSS*
SPI0-SCK
SPI0-MISO
SPI0-MOSI
SPI0-NSS*
SMB0-SDA
SMB0-SCL
CMP0-CP0
CMP0-CP0A
CMP1-CP1
CMP1-CP1A
SYSCLK
PCA0-CEX0
PCA0-CEX1
PCA0-CEX2
PCA0-CEX3
PCA0-CEX4
PCA0-CEX5
PCA0-ECI
Timer0-T0
Timer1-T1
00000000
00000000
Pin Skip Settings
P0SKIP
P1SKIP
0123
0000
P2SKIP
P2
4567
ALE
RDb
000X
C2D
WRb
Pin Not Available on Crossbar
The crossbar peripherals are assigned in priority order from top to bottom.
These boxes represent Port pins which can potentially be assigned to a peripheral.
Special Function Signals are not assigned by the crossbar. When these signals are enabled, the Crossbar should
be manually configured to skip the corresponding port pins.
Pins can be “skipped” by setting the corresponding bit in PnSKIP to 1.
* NSS is only pinned out when the SPI is in 4-wire mode.
Port I/O, Crossbar, External Interrupts, and Port Match
12.3.4 INT0 and INT1
direct-pin digital interrupt sources (INT0 and INT1) are included, which can be routed to port 0 pins. Additional I/O interrupts are
Two
available through the port match function. As is the case on a standard 8051 architecture, certain controls for these two interrupt sources are available in the Timer0/1 registers. Extensions to these controls which provide additional functionality are available in the
IT01CF register. INT0 and INT1 are configurable as active high or low, edge- or level-sensitive. The IN0PL and IN1PL bits in the
IT01CF register select active high or active low; the IT0 and IT1 bits in TCON select level- or edge-sensitive. The table below lists the
possible configurations.
Table 12.3. INT0/INT1 configuration
IT0 or IT1IN0PL or IN1PLINT0 or INT1 Interrupt
10Interrupt on falling edge
11Interrupt on rising edge
00Interrupt on low level
01Interrupt on high level
INT0 and INT1 are assigned to port pins as defined in the IT01CF register. INT0 and INT1 port pin assignments are independent of any
crossbar
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).
assignments, and may be assigned to pins used by crossbar peripherals. INT0 and INT1 will monitor their assigned port pins
IE0 and IE1 in the TCON register serve as the interrupt-pending flags for the INT0 and INT1 external interrupts, 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.
12.3.5 Port Match
Port match functionality allows system events to be triggered by a logic value change on one or more port I/O pins. A software controlled value stored in the PnMATCH registers specifies the expected or normal logic values of the associated port pins (for example,
P0MATCH.0 would correspond to P0.0). A port mismatch event occurs if the logic levels of the port’s input pins no longer match the
software controlled value. This allows software to be notified if a certain change or pattern occurs on the input pins regardless of the
XBRn settings.
The PnMASK registers can be used to individually select which pins should be compared against the PnMATCH registers. A port mismatch event is generated if (Pn & PnMASK) does not equal (PnMATCH & PnMASK) for all ports with a PnMAT and PnMASK register.
A port mismatch event may be used to generate an interrupt or wake the device from low power modes. See the interrupts and power
options chapters for more details on interrupt and wake-up sources.
12.3.6 Direct Port I/O Access (Read/Write)
All port I/O are accessed through corresponding special function registers. When writing to a port, the value written to the SFR is latched to maintain the output data value at each pin. When reading, the logic levels of the port's input pins are returned regardless of the
XBRn settings (i.e., even when the pin is assigned to another signal by the crossbar, the port register can always read its corresponding
port I/O pin). The exception to this is the execution of the read-modify-write instructions that target a Port Latch register as the destination. The read-modify-write instructions when operating on a port SFR are the following: ANL, ORL, XRL, JBC, CPL, INC, DEC, DJNZ
and MOV, CLR or SETB, when the destination is an individual bit in a port SFR. For these instructions, the value of the latch register
(not the pin) is read, modified, and written back to the SFR.