No part of this material may be reproduced or duplicated in any form or by any means without the written permission of Seiko
Epson. Seiko Epson reserves the right to make changes to this material without notice. Seiko Epson does not assume any liability
of any kind arising out of any inaccuracies contained in this material or due to its application or use in any product or circuit and,
further, there is no representation that this material is applicable to products requiring high level reliability, such as, medical products. Moreover, no license to any intellectual property rights is granted by implication or otherwise, and there is no representation
or warranty that anything made in accordance with this material will be free from any patent or copyright infringement of a third
party. When exporting the products or technology described in this material, you should comply with the applicable export control
laws and regulations and follow the procedures required by such laws and regulations. You are requested not to use, to resell, to
export and/or to otherwise dispose of the products (and any technical information furnished, if any) for the development and/or
manufacture of weapon of mass destruction or for other military purposes.
All brands or product names mentioned herein are trademarks and/or registered trademarks of their respective companies.
This is a technical manual for designers and programmers who develop a product using the S1C17M20/M21/
M22/M23/M24/M25. This document describes the functions of the IC, embedded peripheral circuit operations,
and their control methods.
For the CPU functions and instructions, refer to the “S1C17 Family S1C17 Core Manual.” For the functions
and operations of the debugging tools, refer to the respective tool manuals. (Our “Products: Document Downloads” website provides the downloadable manuals.)
Notational conventions and symbols in this manual
Register address
Peripheral circuit chapters do not provide control register addresses. Refer to “Peripheral Circuit Area” in
the “Memory and Bus” chapter or “List of Peripheral Circuit Control Registers” in the Appendix.
Register and control bit names
In this manual, the register and control bit names are described as shown below to distinguish from signal
and pin names.
XXX register: Represents a register including its all bits.
XXX.YYY bit: Represents the one control bit YYY in the XXX register.
XXX.ZZZ[1:0] bits: Represents the two control bits ZZZ1 and ZZZ0 in the XXX register.
Register table contents and symbols
Initial: Value set at initialization
Reset: Initialization condition. The initialization condition depends on the reset group (H0, H1, or S0).
For more information on the reset groups, refer to “Initialization Conditions (Reset Groups)” in the
“Power Supply, Reset, and Clocks” chapter.
R/W: R = Read only bit
W = Write only bit
WP = Write only bit with a write protection using the MSCPROT.PROT[15:0] bits
R/W = Read/write bit
R/WP = Read/write bit with a write protection using the MSCPROT.PROT[15:0] bits
Control bit read/write values
This manual describes control bit values in a hexadecimal notation except for one-bit values (and except
when decimal or binary notation is required in terms of explanation). The values are described as shown
below according to the control bit width.
1 bit: 0 or 1
2 to 4 bits: 0x0 to 0xf
5 to 8 bits: 0x00 to 0xff
9 to 12 bits: 0x000 to 0xfff
13 to 16 bits: 0x0000 to 0xffff
Decimal: 0 to 9999...
Binary: 0b0000... to 0b1111...
Channel number
Multiple channels may be implemented in some peripheral circuits (e.g., 16-bit timer, etc.). The peripheral
circuit chapters use ‘n’ as the value that represents the channel number in the register and pin names regard-
less of the number of channel actually implemented. Normally, the descriptions are applied to all channels.
If there is a channel that has different functions from others, the channel number is specified clearly.
Example) T16_nCTL register of the 16-bit timer
If one channel is implemented (Ch.0 only): T16_nCTL = T16_0CTL only
If two channels are implemented (Ch.0 and Ch.1): T16_nCTL = T16_0CTL and T16_1CTL
For the number of channels implemented in the peripheral circuits of this IC, refer to “Features” in the
The S1C17M20/M21/M22/M23/M24/M25 is a 16-bit embedded Flash MCU that features low power consumption. The embedded Flash memory can also be used as an EEPROM emulation data memory via software. The
S1C17M20/M21/M22/M23/M24/M25 includes various serial interfaces, an A/D converter, and various timers as
well as a high-performance 16-bit CPU. It is suitable for applications that require an A/D conversion function, such
as household equipment and FA products.
1.1 Features
Table 1.1.1 Features
ModelS1C17M20/M23S1C17M21/M24S1C17M22/M25
CPU
CPU coreSeiko Epson original 16-bit RISC CPU core S1C17
OtherOn-chip debugger
Embedded Flash memory
Capacity
(for both instructions and data)
Erase/program count1,000 times (min.) * Programming by the debugging tool ICDmini
OtherSecurity function to protect from reading/programming by ICDmini
Embedded RAM
Capacity2K bytes
Clock generator (CLG)
System clock source4 sources (IOSC/OSC1/OSC3/EXOSC)
System clock frequency
(operating frequency)
IOSC oscillator circuit
(boot clock source)
OSC1 oscillator circuit
Baud-rate generator included, IrDA1.0 supported
Open drain output, signal polarity, and baud rate division ratio are configurable.
Infrared communication carrier modulation output function
Synchronous serial interface
(SPIA)
2
I
C (I2C)1 channel
2 channels
2 to 16-bit variable data length
The 16-bit timer (T16) can be used for the baud-rate generator in master mode.
Baud-rate generator included
Sound generator (SNDA)
Buzzer output function512 Hz to 16 kHz output frequencies
One-shot output function
Melody generation functionPitch: 128 Hz to 16 kHz ≈ C3 to C6
Duration: 7 notes/rests (Half note/rest to thirty-second note/rest)
Tempo: 16 tempos (30 to 480)
Tie/slur may be specified.
IR remote controller (REMC3)
Number of transmitter channels1 channel
OtherEL lamp drive waveform can be generated for an application example.
Output inversion function
R/F converter (RFC)
Conversion method–CR oscillation type
with 24-bit counters
Number of conversion channels2 channels (Up to two sensors
can be connected to each
channel.)
Supported sensors
DC-bias resistive sensors
12-bit A/D converter (ADC12A)
Conversion methodSuccessive approximation type
Resolution12 bits
Number of conversion channels1 channel
Number of analog signal input ports
4 ports6 ports8 ports
Multiplier/divider (COPRO2)
Arithmetic functions16-bit × 16-bit multiplier
16-bit × 16-bit + 32-bit multiply and accumulation unit
32-bit ÷ 32-bit divider
Reset
#RESET pinReset when the reset pin is set to low.
Power-on resetReset at power on.
Brownout resetReset when the power supply voltage drops.
Key entry resetReset when the P00 to P01/P02/P03 keys are pressed simultaneously (can be enabled/disabled
using a register).
Watchdog timer resetReset when the watchdog timer overflows (can be enabled/disabled using a register).
Supply voltage detector reset
Reset when
the supply voltage detector
detects the set voltage level (can be enabled/disabled us-
Assigned signal: The signal listed at the top of each pin is assigned in the initial state. The pin function must be
switched via software to assign another signal (see the “I/O Ports” chapter).
I/O: I = Input
O = Output
I/O = Input/output
P = Power supply
A = Analog signal
Hi-Z = High impedance state
Initial state: I (Pull-up) = Input with pulled up
I (Pull-down) = Input with pulled down
Hi-Z = High impedance state
O (H) = High level output
O (L) = Low level output
Tolerant fail-safe structure:
✓= Over voltage tolerant fail-safe type I/O cell included (see the “I/O Ports” chapter)
The power supply, reset, and clocks in this IC are managed by the embedded power generator, system reset controller, and clock generator, respectively.
2.1 Power Generator (PWG)
2.1.1 Overview
PWG is the power generator that controls the internal power supply system to drive this IC with stability and low
power. The main features of PWG are outlined below.
• Embedded V
- The V
consumption constant independent of the V
- The V
lator into economy mode at light loads helps achieve low-power operations.
Figure 2.1.1.1 shows the PWG configuration.
D1 regulator
D1 regulator generates the VD1 voltage to drive internal circuits, this makes it possible to keep current
DD voltage level.
D1 regulator supports two operation modes, normal mode and economy mode, and setting the VD1 regu-
PWG
REGMODE[1:0]
CPW1
CPW2
VDD
+
VD1
VSS
Figure 2.1.1.1 PWG Configuration
VD1
regulator
VD1
Internal circuits
2.1.2 Pins
Table 2.1.2.1 lists the PWG pins.
Table 2.1.2.1 List of PWG Pins
Pin nameI/OInitial statusFunction
VDDP–Power supply (+)
V
SSP–GND
V
D1A–Embedded regulator output pin
For the VDD operating voltage range and recommended external parts, refer to “Recommended Operating Conditions, Power supply voltage V
DD” in the “Electrical Characteristics” chapter and the “Basic External Connection
Diagram” chapter, respectively.
2.1.3 VD1 Regulator Operation Mode
The VD1 regulator supports two operation modes, normal mode and economy mode. Setting the VD1 regulator into
economy mode at light loads helps achieve low-power operations. Table 2.1.3.1 lists examples of light load conditions in which economy mode can be set.
Table 2.1.3.1 Examples of Light Load Conditions in which Economy Mode Can be Set
Light load conditionExceptions
SLEEP mode (when all oscillators are stopped, or OSC1 only is active) When a clock source except for OSC1 is
HALT mode (when OSC1 only is active)
RUN mode (when OSC1 only is active)
active
The VD1 regulator also supports automatic mode in which the hardware detects a light load condition and automatically switches between normal mode and economy mode. Use the V
SRC is the system reset controller that resets the internal circuits according to the requests from the reset sources to
archive steady IC operations. The main features of SRC are outlined below.
• Embedded reset hold circuit maintains reset state to boot the system safely while the internal power supply is unstable after power on or the oscillation frequency is unstable after the clock source is initiated.
• Supports reset requests from multiple reset sources.
- #RESET pin
- POR and BOR
- Key-entry reset
- Watchdog timer reset
- Supply voltage detector reset
- Peripheral circuit software reset (supports some peripheral circuits only)
• The CPU registers and peripheral circuit control bits will be reset with an appropriate initialization condition according to changes in status.
Figure 2.2.1.1 shows the SRC configuration.
Clock generator
#RESET
Key-entry reset
Watchdog timer reset
oltage detector reset
Software reset 0
Software reset n
SRC
V
VSS
DD
Reset request
signals
Noise filter
POR
BOR
Boot clock
IOSCCLK
Reset hold
circuit
Reset
decoder
Internal reset signals
(Reset group)
SYSRST_H0
SYSRST_H1
SYSRST_S0_0
SYSRST_S0_n
To CPU and per
To CPU and per
To peripheral circuit 0
To peripheral circuit n
Figure 2.2.1.1 SRC Configuration
2.2.2 Input Pin
Table 2.2.2.1 shows the SRC pin.
Table 2.2.2.1 SRC Pin
Pin nameI/OInitial statusFunction
#RESET II (Pull-up)Reset input
The #RESET pin is connected to the noise filter that removes pulses not conforming to the requirements. An internal pull-up resistor is connected to the #RESET pin, so the pin can be left open. For the #RESET pin characteristics, refer to “#RESET pin characteristics” in the “Electrical Characteristics” chapter.
The reset source refers to causes that request system initialization. The following shows the reset sources.
#RESET pin
Inputting a reset signal with a certain low level period to the #RESET pin issues a reset request.
POR and BOR
POR (Power On Reset) issues a reset request when the rise of VDD is detected. BOR (Brownout Reset) issues
a reset request when a certain V
system will be reset properly when the power is turned on and the supply voltage is out of the operating voltage
range. Figure 2.2.3.1 shows an example of POR and BOR internal reset operation according to variations in V
DD voltage level is detected. Reset requests from these circuits ensure that the
Figure 2.2.3.1 Example of Internal Reset by POR and BOR
VRST+
For the POR and BOR electrical specifications, refer to “POR/BOR characteristics” in the “Electrical Charac-
teristics” chapter.
Key-entry reset
Inputting a low level signal of a certain period to the I/O port pins configured to a reset input issues a reset re-
quest. This function must be enabled using an I/O port register. For more information, refer to the “I/O Ports”
chapter.
Watchdog timer reset
Setting the watchdog timer into reset mode will issue a reset request when the counter overflows. This helps return the runaway CPU to a normal operating state. For more information, refer to the “Watchdog timer” chapter.
Supply voltage detector reset
By enabling the low power supply voltage detection reset function, the supply voltage detector will issue a reset
request when a drop in the power supply voltage is detected. This makes it possible to put the system into reset
state if the IC must be stopped under a low voltage condition. For more information, refer to the “Supply Voltage Detector” chapter.
Peripheral circuit software reset
Some peripheral circuits provide a control bit for software reset (MODEN or SFTRST). Setting this bit initial-
izes the peripheral circuit control bits. Note, however, that the software reset operations depend on the peripheral circuit. For more information, refer to “Control Registers” in each peripheral circuit chapter.
Note: The MODEN bit of some peripheral circuits does not issue software reset.
2.2.4 Initialization Conditions (Reset Groups)
A different initialization condition is set for the CPU registers and peripheral circuit control bits, individually. The
reset group refers to an initialization condition. Initialization is performed when a reset source included in a reset
group issues a reset request. Table 2.2.4.1 lists the reset groups. For the reset group to initialize the registers and control bits, refer to the “CPU and Debugger” chapter or “Control Registers” in each peripheral circuit chapter.
POR and BOR
Key-entry reset
Supply voltage detector reset
Watchdog timer reset
H1#RESET pin
POR and BOR
S0Peripheral circuit software reset
(MODEN and SFTRST bits. The
software reset operations depend on the peripheral circuit.
Reset state is maintained for the reset
hold time t
canceled.
Reset state is canceled immediately
after the reset request is canceled.
RSTR after the reset request is
2.3 Clock Generator (CLG)
2.3.1 Overview
CLG is the clock generator that controls the clock sources and manages clock supply to the CPU and the peripheral
circuits. The main features of CLG are outlined below.
• Supports multiple clock sources.
- IOSC oscillator circuit that oscillates with a fast startup and no external parts required
- Low-power OSC1 oscillator circuit in which the oscillator type can be specified from high-precision 32.768
kHz crystal oscillator (an external resonator is required) and internal oscillator
- High-speed OSC3 oscillator circuit in which the oscillator type can be specified from crystal/ceramic oscillator (an external resonator is required) and internal oscillator
- EXOSC clock input circuit that allows input of square wave and sine wave clock signals
• The system clock (SYSCLK), which is used as the operating clock for the CPU and bus, and the peripheral circuit operating clocks can be configured individually by selecting the suitable clock source and division ratio.
• IOSCCLK output from the IOSC oscillator circuit is used as the boot clock for fast booting.
• Controls the oscillator and clock input circuits to enable/disable according to the operating mode, RUN or
SLEEP mode.
• Provides a flexible system clock switching function at SLEEP mode cancelation.
- The clock sources to be stopped in SLEEP mode can be selected.
- SYSCLK to be used at SLEEP mode cancelation can be selected from all clock sources.
- The oscillator and clock input circuit on/off state can be maintained or changed at SLEEP mode cancelation.
•
Provides the FOUT function to output an internal clock for driving external ICs or for monitoring the internal state.
Figure 2.3.1.1 shows the CLG configuration.
Table 2.3.1.1 CLG Configuration of S1C17M20/M21/M22/M23/M24/M25
* Indicates the status when the pin is configured for CLG.
If the port is shared with the CLG input/output function and other functions, the CLG function must be assigned to
the port. For more information, refer to the “I/O Ports” chapter.
2.3.3 Clock Sources
IOSC oscillator circuit
The IOSC oscillator circuit features a fast startup and no external parts are required for oscillating. Figure 2.3.3.1
shows the configuration of the IOSC oscillator circuit.
The IOSC oscillator circuit output clock IOSCCLK is used as SYSCLK at booting. For the oscillation charac-
teristics, refer to “IOSC oscillator circuit characteristics” in the “Electrical Characteristics” chapter.
OSC1 oscillator circuit
The OSC1 oscillator circuit is a low-power oscillator circuit that allows software to select the oscillator type
from two different types shown below. Figure 2.3.3.2 shows the configuration of the OSC1 oscillator circuit.
Crystal oscillator
This oscillator circuit includes a gain-controlled oscillation inverter and a variable gate capacitor allowing use
of various crystal resonators (32.768 kHz typ.) with ranges from cylinder type through surface-mount type.
The oscillator circuit also includes a feedback resistor and a drain resistor, so no external parts are required
except for a crystal resonator. The embedded oscillation stop detector, which detects oscillation stop and restarts the oscillator, allows the system to operate in safety under adverse environments that may stop the oscillation. The oscillation startup control circuit operates for a set period of time after the oscillation is enabled to
assist the oscillator in initiating, this mak
Note: Depending on the circuit board or the crystal resonator type used, an external gate capacitor C
and a drain capacitor C
D1 may be required.
es it possible to use a low-power resonator that is difficult to start up.
G1
Internal oscillator
This 32 kHz oscillator circuit operates without any external parts.
When the internal oscillator circuit is used, the OSC1 and OSC3 pins must be left open.
The OSC3 oscillator circuit is a high-speed oscillator circuit that allows software to select the oscillator type
from two different types shown below. Figure 2.3.3.3 shows the configuration of the OSC3 oscillator circuit.
Crystal/ceramic oscillator
This oscillator circuit includes a feedback resistor and a drain resistor, so no external part is required except
for a crystal/ceramic resonator. The embedded gain-controlled inverter allows selection of the resonator
from a wide frequency range.
Internal oscillator
This oscillator circuit features a fast startup and no external parts are required for oscillating. The
OSC3CLK frequency can be selected using the CLGOSC3.OSC3FQ[1:0] bits. This oscillator circuit
is equipped with an auto-trimming function that automatically adjusts the frequency. This helps reduce
frequency deviation due to unevenness in manufacturing quality, temperature, and changes in voltage. For
more information on the auto-trimming function, refer to “OSC3 oscillation auto-trimming function” in this
chapter.
For the recommended parts and the oscillation characteristics, refer to the “Basic External Connection Diagram”
chapter and “OSC3 oscillator circuit characteristics” in the “Electrical Characteristics” chapter, respectively.
EXOSC clock input
EXOSC is an external clock input circuit that supports square wave and sine wave clocks. Figure 2.3.3.4 shows
the configuration of the EXOSC clock input circuit.
EXOSC clock
input circuit
EXOSCEN
EXOSC
Input control
Internal data bus
circuit
Figure 2.3.3.4 EXOSC Clock Input Circuit
EXOSC has no oscillation stabilization waiting circuit included, therefore, it must be enabled when a stabilized
clock is being supplied. For the input clock characteristics, refer to “EXOSC external clock input characteristics” in the “Electrical Characteristics” chapter.
Oscillation start time and oscillation stabilization waiting time
The oscillation start time refers to the time after the oscillator circuit is enabled until the oscillation signal is ac-
tually sent to the internal circuits. The oscillation stabilization waiting time refers to the time it takes the clock
to stabilize after the oscillation starts. To avoid malfunctions of the internal circuits due to an unstable clock
during this period, the oscillator circuit includes an oscillation stabilization waiting circuit that can disable supplying the clock to the system until the designated time has elapsed. Figure 2.3.4.1 shows the relationship between the oscillation start time and the oscillation stabilization waiting time.
Oscillator circuit enable
(∗OSC∗EN)
Oscillation waveform
Digitized oscillation waveform
Oscillator circuit output clock
(∗OSC∗CLK)
aiting completion flag
(∗OSC∗STAIF)
Figure 2.3.4.1 Oscillation Start Time and Oscillation Stabilization Waiting Time
Oscillation start time
The oscillation stabilization waiting times for the OSC1 and OSC3 oscillator circuits can be set using the
CLGOSC1.OSC1WT[1:0] bits and CLGOSC3.OSC3WT[2:0] bits, respectively. To check whether the oscillation stabilization waiting time is set properly and the clock is stabilized immediately after the oscillation starts
or not, monitor the oscillation clock using the FOUT output function. The oscillation stabilization waiting time
for the IOSC oscillator circuit is fixed at 16 IOSCCLK clocks. The oscillation stabilization waiting time for the
OSC1 oscillator circuit should be set to 16,384 OSC1CLK clocks or more when crystal oscillator is selected, or
4,096 OSC1CLK clocks or more when internal oscillator is selected. The oscillation stabilization waiting time
for the OSC3 oscillator circuit should be set to 1,024 OSC3CLK clocks or more when crystal/ceramic oscillator
is selected, or four OSC3CLK clocks or more when internal oscillator is selected.
When the oscillation stabilization waiting operation has completed, the oscillator circuit sets the oscillation sta-
bilization waiting completion flag and starts clock supply to the internal circuits.
Note: The oscillation stabilization waiting time is always expended at start of oscillation even if the os-
cillation stabilization waiting completion flag has not be cleared to 0.
When the oscillation startup control circuit in the OSC1 crystal oscillator circuit is enabled by setting the
CLGOSC1.OSC1BUP bit to 1, it uses the high-gain oscillation inverter for a set period of time (startup boosting
operation) after the oscillator circuit is enabled (by setting the CLGOSC.OSC1EN bit to 1) to reduce oscillation
start time. Note, however, that the oscillation operation may become unstable if there is a large gain differential
between normal operation and startup boosting operation. Furthermore, the oscillation start time being actually
reduced depends on the characteristics of the resonator used. Figure 2.3.4.2 shows an operation example when the
oscillation startup control circuit is used.
(1) CLGOSC1.OSC1BUP bit = 0 (startup boosting operation disabled)
- CLGOSC1.INV1B[1:0] bits (Set oscillation inverter gain for startup boosting period)
- CLGOSC1.OSC1BUP bit (Enable/disable oscillation startup control circuit)
5. Write a value other than 0x0096 to the MSCPROT.PROT[15:0] bits. (Set system protection)
6. Write 1 to the CLGOSC.OSC1EN bit. (Start oscillation)
7. OSC1CLK can be used if the CLGINTF.OSC1STAIF bit = 1 after an interrupt occurs.
The setting values of the CLGOSC1.INV1N[1:0], CLGOSC1.CGI1[2:0], CLGOSC1.OSC1WT[1:0], and
CLGOSC1.INV1B[1:0] bits should be determined after performing evaluation using the populated circuit board.
Note: Make sure the CLGOSC.OSC1EN bit is set to 0 (while the OSC3 oscillation is halted) when
switching the oscillator within two types.
Oscillation start procedure for the OSC3 oscillator circuit
Follow the procedure shown below to start oscillation of the OSC3 oscillator circuit.
5. Write a value other than 0x0096 to the MSCPROT.PROT[15:0] bits. (Set system protection)
6. When using the crystal/ceramic oscillator, assign the OSC3 oscillator input/output functions to the ports.
(Refer to the “I/O Ports” chapter.)
7. Write 1 to the CLGOSC.OSC3EN bit. (Start oscillation)
8. OSC3CLK can be used if the CLGINTF.OSC3STAIF bit = 1 after an interrupt occurs.
The setting values of the CLGOSC3.OSC3INV[1:0] and CLGOSC3.OSC3WT[2:0] bits should be determined
after performing evaluation using the populated circuit board.
Note: Make sure the CLGOSC.OSC3EN bit is set to 0 (while the OSC3 oscillation is halted) when
switching the oscillator within two types.
System clock switching
The CPU boots using IOSCCLK as SYSCLK. After booting, the clock source of SYSCLK can be switched according to the processing speed required. The SYSCLK frequency can also be set by selecting the clock source
vision ratio, this makes it possible to run the CPU at the most suitable performance for the process to be ex-
di
ecuted. The CLGSCLK.CLKSRC[1:0] and CLGSCLK.CLKDIV[1:0] bits are used for this control.
The CLGSCLK register bits are protected against writings by the system protect function, therefore, the system
protection must be removed by writing 0x0096 to the MSCPROT.PROT[15:0] bits before the register setting can
be altered. For the transition between the operating modes including the system clock switching, refer to “Oper
ating Mode.”
Clock control in SLEEP mode
The CPU enters SLEEP mode when it executes the slp instruction. Whether the clock sources being operated
are stopped or not at this point can be selected in each source individually. This allows the CPU to fast switch
between SLEEP mode and RUN mode, and the peripheral circuits to continue operating without disabling
the clock in SLEEP mode. The CLGOSC.IOSCSLPC, CLGOSC.OSC1SLPC, CLGOSC.OSC3SLPC, and
CLGOSC.EXOSCSLPC bits are used for this control. Figure 2.3.4.3 shows a control example.
(CPU operating clock)
When the CLGOSC.OSC1SLPC bit = 0
(CPU operating clock)
SYSCLK
RTCA
operating clock
SYSCLK
RTCA
operating clock
Oscillation stabilization waiting time
IOSCCLKIOSCCLK
Executing the
slp instruction
OSC1CLKOSC1CLK
IOSCCLKIOSCCLK
Executing the
slp instruction
SLEEP mode
(CPU stop, CLK stop)
(CLK stop)
∗ The RTCA stops counting in
SLEEP mode as the clock stops.
SLEEP mode
(CPU stop, CLK stop)
OSC1CLK
∗ The RTCA continues counting in
IOSCCLK
(Unstable)
Interrupt
(Wake-up)
OSC1CLK
(Unstable)
IOSCCLK
(Unstable)
Interrupt
(Wake-up)
-
Figure 2.3.4.3 Clock Control Example in SLEEP Mode
The SYSCLK condition (clock source and division ratio) at wake-up from SLEEP mode to RUN mode can also
be configured. This allows flexible clock control according to the wake-up process. Configure the clock using
the CLGSCLK.WUPSRC[1:0] and CLGSCLK.WUPDIV[1:0] bits, and write 1 to the CLGSCLK.WUPMD bit
to enable this function.
Figure 2.3.4.4 Clock Control Example at SLEEP Cancelation
Clock external output (FOUT)
The FOUT pin can output the clock generated by a clock source or its divided clock to outside the IC. This al-
lows monitoring the oscillation frequency of the oscillator circuit or supplying an operating clock to external
ICs. Follow the procedure shown below to start clock external output.
1. Assign the FOUT function to the port. (Refer to the “I/O Ports” chapter.)
- Set the CLGFOUT.FOUTEN bit to 1. (Enable clock external output)
OSC3 oscillation auto-trimming function
The OSC3 internal oscillator circuit has the auto-trimming function that adjusts the OSC3CLK clock frequency
by trimming the clock with reference to the high precision OSC1CLK clock generated by the OSC1 crystal oscillator circuit. Follow the procedure shown below to enable the auto-trimming function.
1.
After enabling the OSC1 oscillation, check if the stabilized clock is supplied (CLGINTF.OSC1STAIF bit = 1).
2.
After enabling the OSC3 oscillation, check if the stabilized clock is supplied (CLGINTF.OSC3STAIF bit = 1).
3. Write 0x0096 to the MSCPROT.PROT[15:0] bits. (Remove system protection)
4. If the SYSCLK clock source is OSC3, set the CLGSCLK.CLKSRC[1:0] bits to a value other than 0x2
(OSC3).
5. Write 1 to the CLGINTF.OSC3TEDIF bit. (Clear interrupt flag)
6. Write 1 to the CLGINTE.OSC3TEDIE bit. (Enable interrupt)
7. Write 1 to the CLGOSC3.OSC3STM bit. (Enable OSC3 oscillation auto-trimming)
8. Write a value other than 0x0096 to the MSCPROT.PROT[15:0] bits. (Set system protection)
9. The trimmed OSC3CLK can be used if the CLGINTF.OSC3TEDIF bit = 1 after an interrupt occurs.
After the trimming operation has completed, the CLGOSC3.OSC3STM bit automatically reverts to 0.
the trimming time depends on the temperature, an average of several 10 ms is required.
When OSC3CLK is be-
ing used as the system clock or a peripheral circuit clock, do not use the auto-trimming function.
The oscillation stop detection function restarts the OSC1 oscillator circuit when it detects oscillation stop under
adverse environments that may stop the oscillation. Follow the procedure shown below to enable the oscillation
stop detection function.
1.
After enabling the OSC1 oscillation, check if the stabilized clock is supplied (CLGINTF.OSC1STAIF bit = 1).
2. Write 1 to the CLGINTF.OSC1STPIF bit. (Clear interrupt flag)
3. Write 1 to the CLGINTE.OSC1STPIE bit. (Enable interrupt)
4. Write 0x0096 to the MSCPROT.PROT[15:0] bits. (Remove system protection)
5. Set the following CLGOSC1 register bits:
- Set the CLGOSC1.OSDRB bit to 1. (Enable OSC1 restart function)
- Set the CLGOSC1.OSDEN bit to 1. (Enable oscillation stop detection function)
6. Write a value other than 0x0096 to the MSCPROT.PROT[15:0] bits. (Set system protection)
7. The OSC1 oscillation stops if the CLGINTF.OSC1STPIF bit = 1 after an interrupt occurs.
If the CLGOSC1.OSDRB bit = 1, the hardware restarts the OSC1 oscillator circuit.
Note: Enabling the oscillation stop detection function increase the oscillation stop detector current
(I
OSD1).
2.4 Operating Mode
2.4.1 Initial Boot Sequence
Figure 2.4.1.1 shows the initial boot sequence after power is turned on.
VDD
IOSCCLK
(Initial SYSCLK)
Internal reset signal
SYSRST, H0, H1
S1C17 core
program counter (PC)
Undefined
Undefined
Figure 2.4.1.1 Initial Boot Sequence
Cancel reset request
Cancel reset request
Reset hold time t
RSTR
∗1
∗2
∗1: Reset vector (reset handler start address)
Note: The reset cancelation time at power-on varies according to the power rise time and reset request
cancelation time.
For the reset hold time t
RSTR, refer to “Reset hold circuit characteristics” in the “Electrical Characteristics” chapter.
2.4.2 Transition between Operating Modes
State transitions between operating modes shown in Figure 2.4.2.1 take place in this IC.
RUN mode
RUN mode refers to the state in which the CPU is executing the program. A transition to this mode takes place
when the system reset request from the system reset controller is canceled. RUN mode is classified into “IOSC
RUN,” “OSC1 RUN,” “OSC3 RUN,” and “EXOSC RUN” by the SYSCLK clock source.
HALT mode
When the CPU executes the halt instruction, it suspends program execution and stops operating. This state is
HALT mode. In this mode, the clock sources and peripheral circuits keep operating. This mode can be set while
no software processing is required and it reduces power consumption as compared with RUN mode. HALT
mode is classified into “IOSC HALT,” “OSC1 HALT,” “OSC3 HALT,” and “EXOSC HALT” by the SYSCLK
clock source.
When the CPU executes the slp instruction, it suspends program execution and stops operating. This state is
SLEEP mode. In this mode, the clock sources stop operating as well. However, the clock source in which the
CLGOSC.IOSCSLPC/OSC1SLPC/OSC3SLPC/EXOSCSLPC bit is set to 0 keeps operating, so the peripheral
circuits with the clock being supplied can also operate. By setting this mode when no software processing and
peripheral circuit operations are required, power consumption can be less than HALT mode.
Note: The current consumption when a clock source is active in SLEEP mode by setting the CLGOSC.
IOSCSLPC/OSC1SLPC/OSC3SLPC/EXOSCSLPC bit to 0 is equivalent to the value in HALT
mode with the same clock source condition (refer to “Current Consumption, Current consumption in HALT mode I
HALT1, IHALT2, and IHALT3” in the “Electrical Characteristics” chapter).
DEBUG mode
When a debug interrupt occurs, the CPU enters DEBUG mode. DEBUG mode is canceled when the retd in-
struction is executed. For more information on DEBUG mode, refer to “Debugger” in the “CPU and Debugger”
chapter.
RESET
(Initial state)
Transition takes place automatically by the
initial boot sequence after a request from
the reset source is canceled.
IOSC
HALT
signal
HALT/SLEEP
cancelation
IOSC
halt instruction
RUN
CLGSCLK.CLKSRC[1:0] = 0x3
CLGSCLK.CLKSRC[1:0] = 0x0
RUNSLEEP
RUN/
HALT/
SLEEP
slp instruction
HALT/SLEEP
cancelation signal
(wake-up)
Debug interrupt
retd instruction
DEBUG
OSC1
HALT
halt instruction
HALT/SLEEP
cancelation signal
CLGSCLK.CLKSRC[1:0] = 0x1
OSC1
CLGSCLK.CLKSRC[1:0] = 0x0
RUN
CLGSCLK.CLKSRC[1:0] = 0x3
CLGSCLK.CLKSRC[1:0] = 0x2
CLGSCLK.CLKSRC[1:0] = 0x1
halt instruction
OSC3
HALT
CLGSCLK.CLKSRC[1:0] = 0x2
CLGSCLK.CLKSRC[1:0] = 0x1
CLGSCLK.CLKSRC[1:0] = 0x0
OSC3
RUN
HALT/SLEEP
CLGSCLK.CLKSRC[1:0] = 0x2
CLGSCLK.CLKSRC[1:0] = 0x3
∗ In RUN and HALT modes, the clock sources not used
as SYSCLK can be all disabled.
Figure 2.4.2.1 Operating Mode-to-Mode State Transition Diagram
CLGINTF.IOSCSTAIFWhen the IOSC oscillation stabilization waiting
operation has completed after the oscillation starts
CLGINTF.OSC1STAIF When the OSC1 oscillation stabilization waiting
operation has completed after the oscillation starts
CLGINTF.OSC3STAIF When the OSC3 oscillation stabilization waiting
operation has completed after the oscillation starts
When OSC1CLK is stopped, or when the CLGOSC.
OSC1EN or CLGOSC1.OSDEN bit setting is altered from 1 to 0.
CLGINTF.OSC3TEDIF When the OSC3 oscillation auto-trimming opera-
tion has completed
Writing 1
Writing 1
Writing 1
Writing 1
Writing 1
CLG provides interrupt enable bits corresponding to each interrupt flag. An interrupt request is sent to the interrupt
controller only when the interrupt flag, of which interrupt has been enabled by the interrupt enable bit, is set. For
more information on interrupt control, refer to the “Interrupt Controller” chapter.
2.6 Control Registers
Note: Do not alter the initial values of the control bits for the functions that are not supported in the
model to be used.
PWG VD1 Regulator Control Register
Register nameBitBit nameInitialResetR/WRemarks
PWGVD1CTL15–8 –0x00–R–
7–2 –0x00–R
1–0 REGMODE[1:0]0x0H0R/WP
Bits 15–2 Reserved
Bits 1–0 REGMODE[1:0]
These bits control the internal regulator operating mode.
This bit enables the SYSCLK switching function at wake-up.
1 (R/WP): Enable
0 (R/WP): Disable
When the CLGSCLK.WUPMD bit = 1, setting values of the CLGSCLK.WUPSRC[1:0] bits and the
CLGSCLK.WUPDIV[1:0] bits are loaded to the CLGSCLK.CLKSRC[1:0] bits and the CLGSCLK.
CLKDIV[1:0] bits, respectively, at wake-up from SLEEP mode to switch SYSCLK. When the CLGSCLK.WUPMD bit = 0, the CLGSCLK.CLKSRC[1:0] and CLGSCLK.CLKDIV[1:0] bits are not
altered at wake-up.
Note: When the CLGSCLK.WUPMD bit = 1, the clock source enable bits (CLGOSC.EXOSCEN,
CLGOSC.OSC1EN, CLGOSC.OSC3EN, CLGOSC.IOSCEN) except for the SYSCLK source
selected by the CLGSCLK.CLKSRC[1:0] bits will be cleared to 0 to stop the clocks after a
system wake-up. However, the enable bit of the clock source being operated during SLEEP
mode by setting the CLGOSC.****SLPC bit retains 1 after a wake-up.
Bit 14 Reserved
Bits 13–12 WUPDIV[1:0]
These bits select the SYSCLK division ratio for resetting the CLGSCLK.CLKDIV[1:0] bits at wake-up.
This setting is ineffective when the CLGSCLK.WUPMD bit = 0.
Bits 11–10 Reserved
Bits 9–8 WUPSRC[1:0]
These bits select the SYSCLK clock source for resetting the CLGSCLK.CLKSRC[1:0] bits at wake-up.
When a currently stopped clock source is selected, it will automatically start oscillating or clock input
at wake-up. However, this setting is ineffective when the CLGSCLK.WUPMD bit = 0.
Table 2.6.2 SYSCLK Clock Source and Division Ratio Settings at Wake-up
CLGSCLK.
WUPDIV[1:0] bits
0x31/8Reserved
0x21/4Reserved
0x11/21/2
0x01/11/1
0x00x10x20x3
IOSCCLKOSC1CLKOSC3CLKEXOSCCLK
CLGSCLK.WUPSRC[1:0] bits
1/8
1/4
1/2
1/1
Reserved
Reserved
Reserved
1/1
Bits 7–6 Reserved
Bits 5–4 CLKDIV[1:0]
These bits set the division ratio of the clock source to determine the SYSCLK frequency.
Bits 3–2 Reserved
Bits 1–0 CLKSRC[1:0]
These bits select the SYSCLK clock source.
When a currently stopped clock source is selected, it will automatically start oscillating or clock input.
This bit enables the OSC1 oscillator circuit restart function by the oscillation stop detector when
OSC1 crystal oscillation stop is detected.
1 (R/WP): Enable (Restart the OSC1 oscillator circuit when oscillation stop is detected.)
0 (R/WP): Disable
Bit 13 OSDEN
This bit controls the oscillation stop detector in the OSC1 oscillator circuit.
1 (R/WP): OSC1 oscillation stop detector on
0 (R/WP): OSC1 oscillation stop detector off
Note: Do not write 1 to the CLGOSC1.OSDEN bit before stabilized OSC1CLK is supplied. Further-
more, the CLGOSC1.OSDEN bit should be set to 0 when the CLGOSC.OSC1EN bit is set to 0.
Bit 12 OSC1BUP
This bit enables the oscillation startup control circuit in the OSC1 crystal oscillator circuit.
1 (R/WP): Enable (Activate booster operation at startup.)
0 (R/WP): Disable
Bit 11 OSC1SELCR
This bit selects an oscillator type of the OSC1 oscillator circuit.
1 (R/WP): Internal oscillator
0 (R/WP): Crystal oscillator
Bits 10–8 CGI1[2:0]
These bits set the internal gate capacitance in the OSC1 crystal oscillator circuit.
Bit 5 OSC1STPIF
Bit 4 OSC3TEDIF
Bit 2 OSC3STAIF
Bit 1 OSC1STAIF
Bit 0 IOSCSTAIF
These bits indicate the CLG interrupt cause occurrence statuses.
1 (R): Cause of interrupt occurred
0 (R): No cause of interrupt occurred
1 (W): Clear flag
0 (W): Ineffective
Each bit corresponds to the interrupt as follows:
CLGINTF.OSC1STPIF bit: OSC1 oscillation stop interrupt
CLGINTF.OSC3TEDIF bit: OSC3 oscillation auto-trimming completion interrupt
CLGINTF.OSC3STAIF bit: OSC3 oscillation stabilization waiting completion interrupt
CLGINTF.OSC1STAIF bit: OSC1 oscillation stabilization waiting completion interrupt
CLGINTF.IOSCSTAIF bit: IOSC oscillation stabilization waiting completion interrupt
Note: The CLGINTF.IOSCSTAIF bit is 0 after system reset is canceled, but IOSCCLK has already
been stabilized.
CLG Interrupt Enable Register
Register nameBitBit nameInitialResetR/WRemarks
CLGINTE15–8 –0x00–R–
7–0–R
6(reserved)0H0R
5OSC1STPIE0H0R/W
4OSC3TEDIE0H0R/W
3–0–R
2OSC3STAIE0H0R/W
1OSC1STAIE0H0R/W
0IOSCSTAIE0H0R/W
Bits 15–6, 3 Reserved
Bit 5 OSC1STPIE
Bit 4 OSC3TEDIE
Bit 2 OSC3STAIE
Bit 1 OSC1STAIE
Bit 0 IOSCSTAIE
These bits enable the CLG interrupts.
1 (R/W): Enable interrupts
0 (R/W): Disable interrupts
Each bit corresponds to the interrupt as follows:
CLGINTE.OSC1STPIE bit: OSC1 oscillation stop interrupt
CLGINTE.OSC3TEDIE bit: OSC3 oscillation auto-trimming completion interrupt
CLGINTE.OSC3STAIE bit: OSC3 oscillation stabilization waiting completion interrupt
CLGINTE.OSC1STAIE bit: OSC1 oscillation stabilization waiting completion interrupt
CLGINTE.IOSCSTAIE bit: IOSC oscillation stabilization waiting completion interrupt
The CPU includes eight general-purpose registers and three special registers (Table 3.2.1.1).
Table 3.2.1.1 Initialization of CPU Registers
CPU register nameInitialReset
General-purpose registersR0 to R70x000000H0
Special
registers
For details on the CPU registers, refer to the “S1C17 Family S1C17 Core Manual.” For more information on the
reset vector, refer to the “Interrupt Controller” chapter.
3.2.2 Instruction Set
The CPU instruction codes are all fixed to 16 bits in length which, combined with pipelined processing, allows the
most important instructions to be executed in one cycle. For details on the instructions, refer to the “S1C17 Family
S1C17 Core Manual.”
3.2.3 Reading PSR
Program counterPCThe reset vector is automatically loaded.H0
Stack pointerSP0x000000H0
Processor status registerPSR0x00H0
The PSR contents can be read through the MSCPSR register. Note, however, that data cannot be written to PSR
through the MSCPSR register.
3.2.4 I/O Area Reserved for the S1C17 Core
The address range from 0xfffc00 to 0xffffff is the I/O area reserved for the S1C17 core. Do not access this area except when it is required.
3.3 Debugger
3.3.1 Debugging Functions
The debugger provides the following functions:
• Instruction break: A debug interrupt is generated immediately before the set instruction address is executed. An
instruction break can be set at up to four addresses.
• Single step: A debug interrupt is generated after each instruction has been executed.
• Forcible break: A debug interrupt is generated using an external input signal.
• Software break: A debug interrupt is generated when the brk instruction is executed.
When a debug interrupt occurs, the CPU enters DEBUG mode. The peripheral circuit operations in DEBUG mode
depend on the setting of the DBRUN bit provided in the clock control register of each peripheral circuit. For more
information on the DBRUN bit, refer to “Clock Supply in DEBUG Mode” in each peripheral circuit chapter. DEBUG mode continues until a cancel command is sent from the personal computer or the CPU executes the retd instruction. Neither hardware interrupts nor NMI are accepted during DEBUG mode.
3.3.2 Resource Requirements and Debugging Tools
Debugging work area
Debugging requires a 64-byte debugging work area. For more information on the work area location, refer to
the “Memory and Bus” chapter. The start address of this debugging work area can be read from the DBRAM
register.
To perform debugging, connect ICDmini (S5U1C17001H) to the input/output pin for the debugger embedded
in this IC and control it from the personal computer. This requires the tools shown below.
• S1C17 Family In-Circuit Debugger ICDmini (S5U1C17001H)
• S1C17 Family C Compiler Package (e.g., S5U1C17001C)
3.3.3 List of Debugger Input/Output Pins
Table 3.3.3.1 lists the debug pins.
Table 3.3.3.1 List of Debug Pins
Pin nameI/OInitial stateFunction
DCLKOOOn-chip debugger clock output pin
Outputs a clock to the ICDmini (S5U1C17001H).
DSIOI/OIOn-chip debugger data input/output pin
Used to input/output debugging data and input the break signal.
DST2OOOn-chip debugger status output pin
Outputs the processor status during debugging.
The debugger input/output pins are shared with general-purpose I/O ports and are initially set as the debug pins. If
the debugging function is not used, these pins can be switched to general-purpose I/O port pins. For details, refer to
the “I/O Ports” chapter.
Note: Do not drive the DCLK pin with a high level from outside (e.g. pulling up with a resistor). Also, do
not connect (short-circuit) between the DCLK pin and another GPIO port. In the both cases, the
IC may not start up normally due to unstable pin input/output status at power on.
3.3.4 External Connection
Figure 3.3.4.1 shows a connection example between this IC and ICDmini when performing debugging.
DCLK
VDD
DSIO
DST2
Figure 3.3.4.1 External Connection
DCLK
ICDmini
RDBG
DSIO
DST2
For the recommended pull-up resistor value, refer to “Recommended Operating Conditions, DSIO pull-up resistor R
DBG” in the “Electrical Characteristics” chapter. RDBG is not required when using the DSIO pin as a general-
purpose I/O port pin.
3.3.5 Flash Security Function
This IC provides a security function to protect the internal Flash memory from unauthorized reading and tampering
by using the debugger through ICDmini. Figure 3.3.5.1 shows a Flash security function setting flow.
Figure 3.3.5.1 Shipment of IC with ROM Data Programmed and Flash Security Function Setting Flow
3-3
Page 48
3 CPU AND DEBUGGER
The following shows the status of the IC with protected Flash:
• The Flash memory data is undefined if it is read from the debugger.
• An error occurs if an attempt is made to program the Flash memory through ICDmini.
However, the Flash security function can be disabled by entering the unprotecting password predefined to GNU17
IDE (the security function will take effect again after a reset). For setting the password, refer to the “(S1C17 Family
C Compiler Package) S5U1C17001C Manual.”
Note: Disable the Flash security function before debugging an IC with protected Flash via ICDmini. The
debugging functions may not run normally if the Flash security function is enabled.
This IC supports up to 16M bytes of accessible memory space for both instructions and data.
The features are listed below.
• Embedded Flash memory that supports on-board programming
• All memory and control registers are accessible in 16-bit width and one cycle.
• Write-protect function to protect system control registers
Figure 4.1.1 shows the memory map.
4 MEMORY AND BUS
0xff ffff
0xff fc000xff fc00
0xff fbff
0x00 c000
0x00 bfff
0x00 80000x00 8000
0x00 7fff
0x00 60000x00 6000
0x00 5fff
0x00 40000x00 4000
0x00 3fff
0x00 08000x00 0800
0x00 07ff
0x00 07c0
0x00 07bf
0x00 00000x00 0000
S1C17M20/M21/M22S1C17M23/M24/M25
Reserved for core I/O area
(1K bytes)
(Device size: 32 bits)
Reserved
Flash area
(16K bytes)
(Device size: 16 bits)
Reserved
Peripheral circuit area
(8K bytes)
(Device size: 16 bits)
Reserved
Debug RAM area (64 bytes)
RAM area
(2K bytes)
(Device size: 32 bits)
0xff ffff
0xff fbff
0x01 0000
0x00 ffff
0x00 7fff
0x00 5fff
0x00 3fff
0x00 07ff
0x00 07c0
0x00 07bf
Figure 4.1.1 Memory Map
Reserved for core I/O area
(1K bytes)
(Device size: 32 bits)
Reserved
Flash area
(32K bytes)
(Device size: 16 bits)
Reserved
Peripheral circuit area
(8K bytes)
(Device size: 16 bits)
Reserved
Debug RAM area (64 bytes)
RAM area
(2K bytes)
(Device size: 32 bits)
4.2 Bus Access Cycle
The CPU uses the system clock for bus access operations. First, “Bus access cycle,” “Device size,” and “Access
size” are defined as follows:
• Bus access cycle: One system clock period = 1 cycle
• Device size: Bit width of the memory and peripheral circuits that can be accessed in one cycle
• Access size: Access size designated by the CPU instructions (e.g., ld %rd, [%rb] → 16-bit data transfer)
Table 4.2.1 lists numbers of bus access cycles by different device size and access size. The peripheral circuits can
be accessed with an 8-bit, 16-bit, or 32-bit instruction.
Note: When data is transferred to a memory in 32-bit access, the eight high-order bits are written to
the memory as 0x00 since the bit width of the S1C17 core general-purpose registers is 24 bits.
Conversely when sending from a memory to a register, the eight high-order bits are ignored.
The CPU performs 32-bit access for stack operations in an interrupt handling. In this case, the
CPU read/write 32-bit data that consists of the PSR value as the eight high-order bits and the
return address as the 24 low-order bits. For more information, refer to the “S1C17 Family S1C17
Core Manual.”
The CPU adopts Harvard architecture that allows simultaneous processing of an instruction fetch and a data access. However, they are not performed simultaneously under one of the conditions listed below. This prolongs the
instruction fetch cycle for the number of data area bus cycles.
• When the CPU executes an instruction stored in the Flash area and accesses data in the Flash area
• When the CPU executes an instruction stored in the internal RAM area and accesses data in the internal RAM
area
4.3 Flash Memory
The Flash memory is used to store application programs and data. Address 0x8000 in the Flash area is defined as
the vector table base address by default, therefore a vector table must be located beginning from this address. For
more information on the vector table, refer to “Vector Table” in the “Interrupt Controller” chapter.
4.3.1 Flash Memory Pin
Table 4.3.1.1 shows the Flash memory pin.
Table 4.3.1.1 Flash Memory Pin
Pin nameI/OInitial statusFunction
VPPP–Flash programming power supply
For the VPP voltage, refer to “Recommended Operating Conditions, Flash programming voltage VPP” in the “Electrical Characteristics” chapter.
Note: Always leave the V
4.3.2 Flash Bus Access Cycle Setting
There is a limit of frequency to access the Flash memory with no wait cycle, therefore, the number of bus access
cycles for reading must be changed according to the system clock frequency. The number of bus access cycles for
reading can be configured using the FLASHCWAIT.RDWAIT[1:0] bits. Select a setting for higher frequency than
the system clock.
PP pin open except when programming the Flash memory.
The Flash memory supports on-board programming, so it can be programmed with the ROM data by using the debugger through an ICDmini. Figure 4.3.3.1 shows connection diagrams for on-board programming.
DCLK
VDD
DSIO
DST2
VPP
RDBG
CVPP
DCLK
ICDmini
(S5U1C17001H)
DSIO
DST2
CC OUT
Flash V
Figure 4.3.3.1 External Connection
DCLK
S1C17
DSIO
DST2
DCLK
VDD
DBG
R
PP
V
CVPP
ICDmini
DSIO
DST2
The VPP pin must be left open except when programming the Flash memory. However, it is not necessary to disconnect the wire when using ICDmini to supply the V
be supplied during Flash programming only. The V
generating the Flash programming voltage. Be sure to connect C
PP voltage, as ICDmini controls the power supply so that it will
PP voltage can also be generated by the internal power supply for
VPP for stabilizing the voltage when the VPP voltage
is supplied externally or for generating the voltage when the internal power supply is used.
For detailed information on ROM data programming method, refer to the “(S1C17 Family C Compiler Package)
S5U1C17001C Manual.” The IC can also be shipped after being programmed in the factory with the ROM data
developed. Should you desire to ship the IC with ROM data programmed from the factory, please contact our customer support.
Notes: • When programming the Flash memory by supplying the V
V
DD voltage is required.
• When programming the Flash memory by generating the V
V
DD voltage is required.
• Be sure to avoid using the V
PP pin output for driving external circuits when the VPP voltage is
PP voltage externally, 2.4 V or more
PP voltage internally, 2.7 V or more
generated internally.
4.4 RAM
The RAM can be used to execute the instruction codes copied from another memory as well as storing variables or
other data. This allows higher speed processing and lower power consumption than Flash memory.
Note: The 64 bytes at the end of the RAM is reserved as the debug RAM area. When using the debug
functions under application development, do not access this area from the application program.
This area can be used for applications of mass-produced devices that do not need debugging.
The RAM size used by the application can be configured to equal or less than the implemented size using the
MSCIRAMSZ.IRAMSZ[2:0] bits. For example, this function can be used to prevent creating programs that seek
to access areas outside the RAM area of the target model when developing an application for a model in which the
RAM size is smaller than this IC.
in the same operation (undefined value is read out) as when a reserved area is accessed.
4.5 Peripheral Circuit Control Registers
The control registers for the peripheral circuits are located in the 8K-byte area beginning with address 0x4000.
Table 4.5.1 shows the control register map. For details of each control register, refer to “List of Peripheral Circuit
Registers” in the appendix or “Control Registers” in each peripheral circuit chapter.
I/O ports (PPORT)0x4216 P1INTFP1 Port Interrupt Flag Register
0x4218 P1INTCTLP1 Port Interrupt Control Register
0x421a P1CHATENP1 Port Chattering Filter Enable Register
0x421c P1MODSELP1 Port Mode Select Register
0x421e P1FNCSELP1 Port Function Select Register
0x4220 P2DATP2 Port Data Register
0x4222 P2IOENP2 Port Enable Register
0x4224 P2RCTLP2 Port Pull-up/down Control Register
0x4226 P2INTFP2 Port Interrupt Flag Register
0x4228 P2INTCTLP2 Port Interrupt Control Register
0x422a P2CHATENP2 Port Chattering Filter Enable Register
0x422c P2MODSELP2 Port Mode Select Register
0x422e P2FNCSELP2 Port Function Select Register
0x4230 P3DATP3 Port Data Register
0x4232 P3IOENP3 Port Enable Register
0x4234 P3RCTLP3 Port Pull-up/down Control Register
0x4236 P3INTFP3 Port Interrupt Flag Register
0x4238 P3INTCTLP3 Port Interrupt Control Register
0x423a P3CHATENP3 Port Chattering Filter Enable Register
0x423c P3MODSELP3 Port Mode Select Register
0x423e P3FNCSELP3 Port Function Select Register
0x4240 P4DATP4 Port Data Register
0x4242 P4IOENP4 Port Enable Register
*1 *2 *3
*1 *2 *3
0x4244 P4RCTLP4 Port Pull-up/down Control Register
0x4246 P4INTFP4 Port Interrupt Flag Register
*1 *2 *3
0x4248 P4INTCTLP4 Port Interrupt Control Register
0x424a P4CHATENP4 Port Chattering Filter Enable Register
0x424c P4MODSELP4 Port Mode Select Register
0x424e P4FNCSELP4 Port Function Select Register
*1 *2 *3
*1 *2 *3
0x42d0 PDDATPd Port Data Register
0x42d2 PDIOENPd Port Enable Register
0x42d4 PDRCTLPd Port Pull-up/down Control Register
0x42dc PDMODSELPd Port Mode Select Register
0x42de PDFNCSELPd Port Function Select Register
0x42e0 PCLKP Port Clock Control Register
0x42e2 PINTFGRPP Port Interrupt Flag Group Register
Universal port multiplexer
(UPMUX)
0x4300 P0UPMUX0
0x4302 P0UPMUX1
0x4304 P0UPMUX2
0x4306 P0UPMUX3
0x4308 P1UPMUX0
0x430a P1UPMUX1
0x430c P1UPMUX2
0x430e P1UPMUX3
0x4310 P2UPMUX0
0x4312 P2UPMUX1
0x4314 P2UPMUX2
0x4316 P2UPMUX3
0x4318 P3UPMUX0
0x431a P3UPMUX1
0x431c P3UPMUX2
0x431e P3UPMUX3
P00–01 Universal Port Multiplexer Setting Register
P02–03 Universal Port Multiplexer Setting Register
P04–05 Universal Port Multiplexer Setting Register
P06–07 Universal Port Multiplexer Setting Register
P10–11 Universal Port Multiplexer Setting Register
P12–13 Universal Port Multiplexer Setting Register
P14–15 Universal Port Multiplexer Setting Register
P16–17 Universal Port Multiplexer Setting Register
P20–21 Universal Port Multiplexer Setting Register
P22–23 Universal Port Multiplexer Setting Register
P24–25 Universal Port Multiplexer Setting Register
P26–27 Universal Port Multiplexer Setting Register
P30–31 Universal Port Multiplexer Setting Register
P32–33 Universal Port Multiplexer Setting Register
P34–35 Universal Port Multiplexer Setting Register
P36–37 Universal Port Multiplexer Setting Register
UART (UART3) Ch.00x4380 UA0CLKUART3 Ch.0 Clock Control Register
0x4382 UA0MODUART3 Ch.0 Mode Register
0x4384 UA0BRUART3 Ch.0 Baud-Rate Register
0x4386 UA0CTLUART3 Ch.0 Control Register
0x4388 UA0TXDUART3 Ch.0 Transmit Data Register
0x438a UA0RXDUART3 Ch.0 Receive Data Register
0x438c UA0INTFUART3 Ch.0 Status and Interrupt Flag Register
0x5270 SPI1MODSPIA Ch.1 Mode Register
0x5272 SPI1CTLSPIA Ch.1 Control Register
0x5274 SPI1TXDSPIA Ch.1 Transmit Data Register
0x5276 SPI1RXDSPIA Ch.1 Receive Data Register
0x5278 SPI1INTFSPIA Ch.1 Interrupt Flag Register
0x527a SPI1INTESPIA Ch.1 Interrupt Enable Register
Sound generator (SNDA)0x5300 SNDCLKSNDA Clock Control Register
0x5302 SNDSELSNDA Select Register
0x5304 SNDCTLSNDA Control Register
0x5306 SNDDATSNDA Data Register
0x5308 SNDINTFSNDA Interrupt Flag Register
0x530a SNDINTESNDA Interrupt Enable Register
IR remote controller (REMC3)0x5320 REMCLKREMC3 Clock Control Register
0x5322 REMDBCTLREMC3 Data Bit Counter Control Register
0x5324 REMDBCNTREMC3 Data Bit Counter Register
0x5326 REMAPLENREMC3 Data Bit Active Pulse Length Register
0x5328 REMDBLENREMC3 Data Bit Length Register
0x532a REMINTFREMC3 Status and Interrupt Flag Register
0x532c REMINTEREMC3 Interrupt Enable Register
0x5330 REMCARRREMC3 Carrier Waveform Register
0x5332 REMCCTLREMC3 Carrier Modulation Control Register
R/F converter (RFC) Ch.00x5440 RFC0CLKRFC Ch.0 Clock Control Register
0x5442 RFC0CTLRFC Ch.0 Control Register
*1 *2 *3
0x5444 RFC0TRGRFC Ch.0 Oscillation Trigger Register
0x5446 RFC0MCLRFC Ch.0 Measurement Counter Low Register
0x5448 RFC0MCHRFC Ch.0 Measurement Counter High Register
0x544a RFC0TCLRFC Ch.0 Time Base Counter Low Register
0x544c RFC0TCHRFC Ch.0 Time Base Counter High Register
0x544e RFC0INTFRFC Ch.0 Interrupt Flag Register
0x5450 RFC0INTERFC Ch.0 Interrupt Enable Register
R/F converter (RFC) Ch.10x5460 RFC1CLKRFC Ch.1 Clock Control Register
0x5462 RFC1CTLRFC Ch.1 Control Register
*1 *2 *3
0x5464 RFC1TRGRFC Ch.1 Oscillation Trigger Register
0x5466 RFC1MCLRFC Ch.1 Measurement Counter Low Register
0x5468 RFC1MCHRFC Ch.1 Measurement Counter High Register
0x546a RFC1TCLRFC Ch.1 Time Base Counter Low Register
0x546c RFC1TCHRFC Ch.1 Time Base Counter High Register
0x546e RFC1INTFRFC Ch.1 Interrupt Flag Register
0x5470 RFC1INTERFC Ch.1 Interrupt Enable Register
16-bit timer (T16) Ch.30x5480 T16_3CLKT16 Ch.3 Clock Control Register
0x5482 T16_3MODT16 Ch.3 Mode Register
0x5484 T16_3CTLT16 Ch.3 Control Register
0x5486 T16_3TRT16 Ch.3 Reload Data Register
0x5488 T16_3TCT16 Ch.3 Counter Data Register
0x548a T16_3INTFT16 Ch.3 Interrupt Flag Register
0x548c T16_3INTET16 Ch.3 Interrupt Enable Register
12-bit A/D converter (ADC12A) 0x54a2 ADC12_0CTLADC12A Ch.0 Control Register
0x54a4 ADC12_0TRG
ADC12A Ch.0 Trigger/Analog Input Select Register
0x54a6 ADC12_0CFG ADC12A Ch.0 Configuration Register
0x54a8 ADC12_0INTF ADC12A Ch.0 Interrupt Flag Register
0x54aa ADC12_0INTE ADC12A Ch.0 Interrupt Enable Register
0x54ac ADC12_0AD0D ADC12A Ch.0 Result Register 0
0x54ae ADC12_0AD1D ADC12A Ch.0 Result Register 1
0x54b0 ADC12_0AD2D ADC12A Ch.0 Result Register 2
0x54b2 ADC12_0AD3D ADC12A Ch.0 Result Register 3
0x54b4 ADC12_0AD4D ADC12A Ch.0 Result Register 4
0x54b6 ADC12_0AD5D ADC12A Ch.0 Result Register 5
0x54b8 ADC12_0AD6D ADC12A Ch.0 Result Register 6
0x54ba ADC12_0AD7D ADC12A Ch.0 Result Register 7
*1 Cannot be used in the S1C17M20/M23 (24-pin package).
*2 Cannot be used in the S1C17M20/M23 (32-pin package).
*3 Cannot be used in the S1C17M21/M24.
The system-protect function protects control registers and bits from writings. They cannot be rewritten unless write
protection is removed by writing 0x0096 to the MSCPROT.PROT[15:0] bits. This function is provided to prevent
deadlock that may occur when a system-related register is altered by a runaway CPU. See “Control Registers” in
each peripheral circuit to identify the registers and bits with write protection.
Note: Once write protection is removed using the MSCPROT.PROT[15:0] bits, write enabled status is
maintained until write protection is applied again. After the registers/bits required have been altered, apply write protection.
4.6 Control Registers
MISC System Protect Register
Register nameBitBit nameInitialResetR/WRemarks
MSCPROT15–0 PROT[15:0]0x0000H0R/W–
Bits 15–0 PROT[15:0]
These bits protect the control registers related to the system against writings.
0x0096 (R/W): Disable system protection
Other than 0x0096 (R/W): Enable system protection
While the system protection is enabled, any data will not be written to the affected control bits (bits
with “WP” or “R/WP” appearing in the R/W column).
MISC IRAM Size Register
Register nameBitBit nameInitialResetR/WRemarks
MSCIRAMSZ15–9 –0x00–R–
8(reserved)0H0R/WP Always set to 0.
7–3 –0x04–R–
2–0 IRAMSZ[2:0]0x2H0R/WP
Bits 15–3 Reserved
Bits 2–0 IRAMSZ[2:0]
These bits set the internal RAM size that can be used.
Table 4.6.1 Internal RAM Size Selections
MSCIRAMSZ.IRAMSZ[2:0] bitsInternal RAM size
0x7–0x3Reserved
0x22KB
0x11KB
0x0512B
FLASHC Flash Read Cycle Register
Register nameBitBit nameInitialResetR/WRemarks
FLASHCWAIT15–9 –0x00–R–
8(reserved)0H0R/WP Always set to 0.
7–2 –0x00–R
1–0 RDWAIT[1:0]0x1H0R/WP
Bits 15–2 Reserved
–
Bits 1–0 RDWAIT[1:0]
These bits set the number of bus access cycles for reading from the Flash memory.
• Honors interrupt requests from the peripheral circuits and outputs the interrupt request, interrupt level and vector
number signals to the CPU.
• The interrupt level of each interrupt source is selectable from among eight levels.
• Priorities of the simultaneously generated interrupts are established from the interrupt level.
• Handles the simultaneously generated interrupts with the same interrupt level as smaller vector number has higher priority.
Figure 5.1.1 shows the configuration of the ITC.
Debug interrupt
Peripheral circuit
Interrupt request
Peripheral circuit
Internal data bus
Interrupt request
Watchdog timer
• • •
CPU core
HALT/SLEEP
cancelation signal
Interrupt request
Interrupt level
Vector number
NMI
ITC
ILVx[2:0]
Interrupt
control
circuit
Figure 5.1.1 ITC Configuration
• • •
ILVy[2:0]
5.2 Vector Table
The vector table contains the vectors to the interrupt handler routines (handler routine start address) that will be
read by the CPU to execute the handler when an interrupt occurs.
Table 5.2.1 shows the vector table.
Table 5.2.1 Vector Table
TTBR initial value = 0x8000
Vector number/
Software interrupt
number
0 (0x00)TTBR + 0x00 Reset• Low input to the #RESET pin
• Analog input signal m A/D conversion result over-
write error
*1
5.2.1 Vector Table Base Address (TTBR)
The MSCTTBRL and MSCTTBRH registers are provided to set the base (start) address of the vector table in which
interrupt vectors are programmed. “TTBR” described in Table 5.2.1 means the value set to these registers. After an
initial reset, the MSCTTBRL and MSCTTBRH registers are set to address 0x8000. Therefore, even when the vector table location is changed, it is necessary that at least the reset vector be written to the above address. Bits 7 to 0
in the MSCTTBRL register are fixed at 0, so the vector table always begins from a 256-byte boundary address.
5.3 Initialization
The following shows an example of the initial setting procedure related to interrupts:
1. Execute the di instruction to set the CPU into interrupt disabled state.
2. If the vector table start address is different from the default address, set it to the MSCTTBRL and MSCTTBRH
registers after removing system protection by writing 0x0096 to the MSCPROT.PROT[15:0] bits. Then, write a
value other than 0x0096 to the MSCPROT.PROT[15:0] bits to set system protection.
3. Set the interrupt enable bit of the peripheral circuit to 0 (interrupt disabled).
4. Set the interrupt level for the peripheral circuit using the ITCLVx.ILVx[2:0] bits in the ITC.
5. Configure the peripheral circuit and start its operation.
6. Clear the interrupt factor flag of the peripheral circuit.
7. Set the interrupt enable bit of the peripheral circuit to 1 (interrupt enabled).
8. Execute the ei instruction to set the CPU into interrupt enabled state.
5.4 Maskable Interrupt Control and Operations
5.4.1 Peripheral Circuit Interrupt Control
The peripheral circuit that generates interrupts includes an interrupt enable bit and an interrupt flag for each interrupt cause.
Interrupt flag: The flag is set to 1 when the interrupt cause occurs. The clear condition depends on the periph-
eral circuit.
Interrupt enable bit: By setting this bit to 1 (interrupt enabled), an interrupt request will be sent to the ITC when the
interrupt flag is set to 1. When this bit is set to 0 (interrupt disabled), no interrupt request will
be sent to the ITC even if the interrupt flag is set to 1. An interrupt request is also sent to the
ITC if the status is changed to interrupt enabled when the interrupt flag is 1.
For specific information on causes of interrupts, interrupt flags, and interrupt enable bits, refer to the respective peripheral circuit descriptions.
Note: To prevent occurrence of unnecessary interrupts, the corresponding interrupt flag should be
cleared before setting the interrupt enable bit to 1 (interrupt enabled) and before terminating the
interrupt handler routine.
On receiving an interrupt signal from a peripheral circuit, the ITC sends an interrupt request, the interrupt level,
and the vector number to the CPU. Vector numbers are determined by the ITC internal hardware for each interrupt
cause, as shown in Table 5.2.1. The interrupt level is a value to configure the priority, and it can be set to between 0
(low) and 7 (high) using the ITCLVx.ILVx[2:0] bits provided for each interrupt source. The default ITC settings are
level 0 for all maskable interrupts. Interrupt requests are not accepted by the CPU if the level is 0.
The ITC outputs the interrupt request with the highest priority to the CPU in accordance with the following conditions if interrupt requests are input to the ITC simultaneously from two or more peripheral circuits.
• The interrupt with the highest interrupt level takes precedence.
• If multiple interrupt requests are input with the same interrupt level, the interrupt with the lowest vector number
takes precedence.
The other interrupts occurring at the same time are held until all interrupts with higher priority levels have been accepted by the CPU.
If an interrupt cause with higher priority occurs while the ITC is outputting an interrupt request signal to the CPU
(before being accepted by the CPU), the ITC alters the vector number and interrupt level signals to the setting information on the more recent interrupt. The previously occurring interrupt is held. The held interrupt is canceled
and no interrupt is generated if the interrupt flag in the peripheral circuit is cleared via software.
Note: Before changing the interrupt level, make sure that no interrupt of which the level is changed can
be generated (the interrupt enable bit of the peripheral circuit is set to 0 or the peripheral circuit
is deactivated).
5.4.3 Conditions to Accept Interrupt Requests by the CPU
The CPU accepts an interrupt request sent from the ITC when all of the following conditions are met:
• The IE (Interrupt Enable) bit of the PSR has been set to 1.
• The interrupt request that has occurred has a higher interrupt level than the value set in the IL[2:0] (Interrupt
Level) bits of the PSR.
• No other interrupt request having higher priority, such as NMI, has occurred.
5.5 NMI
The watchdog timer embedded in this IC can generate a non-maskable interrupt (NMI). This interrupt takes precedence over other interrupts and is unconditionally accepted by the CPU.
For detailed information on generating NMI, refer to the “Watchdog Timer” chapter.
5.6 Software Interrupts
The CPU provides the “int imm5” and “intl imm5, imm3” instructions allowing the software to generate any interrupts. The operand imm5 specifies a vector number (0–31) in the vector table. In addition to this, the intl instruction
has the operand imm3 to specify the interrupt level (0–7) to be set to the IL[2:0] bits in the PSR. The software interrupt cannot be disabled (non-maskable interrupt). The processor performs the same interrupt processing operation
as that of the hardware interrupt.
The CPU samples interrupt requests for each cycle. On accepting an interrupt request, the CPU switches to interrupt processing immediately after execution of the current instruction has been completed.
Interrupt processing involves the following steps:
1. The PSR and current program counter (PC) values are saved to the stack.
2. The PSR IE bit is cleared to 0 (disabling subsequent maskable interrupts).
3. The PSR IL[2:0] bits are set to the received interrupt level. (The NMI does not affect the IL bits.)
4. The vector for the interrupt occurred is loaded to the PC to execute the interrupt handler routine.
When an interrupt is accepted, Step 2 prevents subsequent maskable interrupts. Setting the IE bit to 1 in the interrupt handler routine allows handling of multiple interrupts. In this case, since the IL[2:0] bits are changed by Step 3,
only an interrupt with a higher level than that of the currently processed interrupt will be accepted.
Ending interrupt handler routines using the reti instruction returns the PSR to the state before the interrupt occurred.
The program resumes processing following the instruction being executed at the time the interrupt occurred.
Note: When HALT or SLEEP mode is canceled, the CPU jumps to the interrupt handler routine after
executing one instruction. To execute the interrupt handler routine immediately after HALT or
SLEEP mode is canceled, place the nop instruction at just behind the halt/slp instruction.
5.8 Control Registers
MISC Vector Table Address Low Register
Register nameBitBit nameInitialResetR/WRemarks
MSCTTBRL15–8 TTBR[15:8]0x80H0R/WP –
7–0 TTBR[7:0]0x00H0R
Bits 15–0 TTBR[15:0]
These bits set the vector table base address (16 low-order bits).
MISC Vector Table Address High Register
Register nameBitBit nameInitialResetR/WRemarks
MSCTTBRH15–8 –0x00–R–
7–0 TTBR[23:16]0x00H0R/WP
Bits 15–8 Reserved
Bits 7–0 TTBR[23:16]
These bits set the vector table base address (eight high-order bits).
ITC Interrupt Level Setup Register x
Register nameBitBit nameInitialResetR/WRemarks
ITCLVx15–11 –0x00–R–
10–8 I LVy
7–3 –0x00–R
2–0 I LVy
Bits 15–11 Reserved
Bits 7–3 Reserved
Bits 10–8 ILVy
Bits 2–0 ILVy
1[2:0] (y1 = 2x +1)
0[2:0] (y0 = 2x)
These bits set the interrupt level of each interrupt.
Peripheral I/O function 0 I/O control
Peripheral I/O function 1 I/O control
Peripheral I/O function 2 I/O control
Peripheral I/O function 3 I/O control
General-purpose
I/O control
GPIO function
I/O cell
control signal
Output signal
Input signal
PxOUTy
PxyMUX[1:0]
GPIO/
peripheral I/O
function
switching
circuit
PxOENy
PxIENy
PxPDPUy
PxRENy
PxINy
KRSTCFG[1:0]
CLKSRC[1:0]
CLKDIV[3:0]
PxSELy
Clock
generator
Interrupt
controller
System reset
controller
DBRUN
Px
y
CLK_PPORT
I/O cell
Internal data bus
Exist only in the ports that supports the interrupt function.
Chattering
filter
Interrupt
control circuit
Key-entry
reset control
circuit
PxCHATENy
PxEDGEy
PxIFy
PxIEy
PxINT
Key-entry
reset signal
Over voltage tolerant fail-safe type I/O cell
Analog control signal
Standard I/O cell
6.2 I/O Cell Structure and Functions
Figure 6.2.1 shows the I/O cell Configuration.
Pull-up/down
Control signal
Input signal
Input control signal
Output signal
Output control signal
Analog signal
Refer to “Pin Descriptions” in the “Overview” chapter for the cell type, either the over voltage tolerant fail-safe
type I/O cell or the standard I/O cell, included in each port.
The input functions are all configured with the Schmitt interface level. When a port is set to input disable status
(PxIOEN.PxIENy bit = 0), unnecessary current is not consumed if the Pxy pin is placed into floating status.
6.2.2 Over Voltage Tolerant Fail-Safe Type I/O Cell
The over voltage tolerant fail-safe type I/O cell allows interfacing without passing unnecessary current even if a
voltage exceeding V
biased without supplying V
DD is applied to the port. Also unnecessary current is not consumed when the port is externally
DD. However, be sure to avoid applying a voltage exceeding the recommended maxi-
mum operating power supply voltage to the port.
6.2.3 Pull-Up/Pull-Down
The GPIO port has a pull-up/pull-down function. Either pull-up or pull-down may be selected for each port individually. This function may also be disabled for the port that does not require pulling up/down.
When the port level is switched from low to high through the pull-up resistor included in the I/O cell or from high
to low through the pull-down resistor, a delay will occur in the waveform rising/falling edge depending on the time
constant by the pull-up/pull-down resistance and the pin load capacitance. The rising/falling time is commonly determined by the following equation:
PR: Rising time (port level = low → high) [second]
t
PF: Falling time (port level = high → low) [second]
V
T+: High level Schmitt input threshold voltage [V]
V
T-: Low level Schmitt input threshold voltage [V]
R
INU/RIND: Pull-up/pull-down resistance [W]
C
IN: Pin capacitance [F]
C
BOARD: Parasitic capacitance on the board [F]
6.2.4 CMOS Output and High Impedance State
The I/O cells except for analog output can output signals in the VDD and VSS levels. Also the GPIO ports may be
put into high-impedance (Hi-Z) state.
6.3 Clock Settings
6.3.1 PPORT Operating Clock
When using the chattering filter for entering external signals to PPORT, the PPORT operating clock CLK_PPORT
must be supplied to PPORT from the clock generator.
The CLK_PPORT supply should be controlled as in the procedure shown below.
1. Enable the clock source in the clock generator if it is stopped (refer to “Clock Generator” in the “Power Supply,
Reset, and Clocks” chapter).
2. Write 0x0096 to the MSCPROT.PROT[15:0] bits. (Remove system protection)
3. Set the following PCLK register bits:
- PCLK.CLKSRC[1:0] bits (Clock source selection)
- PCLK.CLKDIV[3:0] bits (Clock division ratio selection = Clock frequency setting)
4. Write a value other than 0x0096 to the MSCPROT.PROT[15:0] bits. (Set system protection)
Settings in Step 3 determine the input sampling time of the chattering filter.
When using the
configured so that it will keep suppling by writing 0 to the
source.
If the
CLGOSC.xxxxSLPC bit for the CLK_PPORT clock source is 1, the CLK_PPORT clock source is deactivated during SLEEP mode and it disables the
bit setting (chattering filter enabled/disabled).
chattering filter function during SLEEP mode, the PPORT operating clock CLK_PPORT must be
CLGOSC.xxxxSLPC bit for the CLK_PPORT clock
chattering filter function regardless of the PxCHATEN.PxCHATENy
6.3.3 Clock Supply in DEBUG Mode
The CLK_PPORT supply during DEBUG mode should be controlled using the PCLK.DBRUN bit.
The CLK_PPORT supply to PPORT is suspended when the CPU enters DEBUG mode if the PCLK.DBRUN bit
= 0. After the CPU returns to normal mode, the CLK_PPORT supply resumes. The PPORT chattering filter stops
operating when the CLK_PPORT supply is suspended. If the chattering filter is enabled in PPORT, the input port
function is also deactivated. However, the control registers can be altered. If the PCLK.DBRUN bit = 1, the CLK_
PPORT supply is not suspended and the chattering filter will keep operating in DEBUG mode.
6.4 Operations
6.4.1 Initialization
After a reset, the ports except for the debugging function are configured as shown below.
• Port input: Disabled
• Port output: Disabled
• Pull-up: Off
• Pull-down: Off
• Port pins: High impedance state
• Port function: Configured to GPIO
This status continues until the ports are configured via software. The debugging function ports are configured for
debug signal input/output.
Initial settings when using a port for a peripheral I/O function
When using the Pxy port for a peripheral I/O function, perform the following software initial settings:
1. Set the following PxIOEN register bits:
- Set the PxIOEN.PxIENy bit to 0. (Disable input)
- Set the PxIOEN.PxOENy bit to 0. (Disable output)
2. Set the PxMODSEL.PxSELy bit to 0. (Disable peripheral I/O function)
3. Initialize the peripheral circuit that uses the pin.
4. Set the PxFNCSEL.PxyMUX[1:0] bits. (Select peripheral I/O function)
5. Set the PxMODSEL.PxSELy bit to 1. (Enable peripheral I/O function)
For the list of the peripheral I/O functions that can be assigned to each port of this IC, refer to “Control Register
and Port Function Configuration of this IC.” For the specific information on the peripheral I/O functions, refer
to the respective peripheral circuit chapter.
Initial settings when using a port as a general-purpose output port
(only for the ports with GPIO function)
When using the Pxy port pin as a general-purpose output pin, perform the following software initial settings:
1. Set the PxIOEN.PxOENy bit to 1. (Enable output)
2. Set the PxMODSEL.PxSELy bit to 0. (Enable GPIO function)
Initial settings when using a port as a general-purpose input port
(only for the ports with GPIO function)
When using the Pxy port pin as a general-purpose input pin, perform the following software initial settings:
1. Write 0 to the PxINTCTL.PxIEy bit. * (Disable interrupt)
2. When using the chattering filter, configure the PPORT operating clock (see “PPORT Operating Clock”) and
set the PxCHATEN.PxCHATENy bit to 1. *
When the chattering filter is not used, set the PxCHATEN.PxCHATENy bit to 0 (supply of the PPORT op-
erating clock is not required).
3. Configure the following PxRCTL register bits when pulling up/down the port using the internal pull-up or
down resistor:
- PxRCTL.PxPDPUy bit (Select pull-up or pull-down resistor)
- Set the PxRCTL.PxRENy bit to 1. (Enable pull-up/down)
Set the PxRCTL.PxRENy bit to 0 if the internal pull-up/down resistors are not used.
4. Set the PxMODSEL.PxSELy bit to 0. (Enable GPIO function)
5. Configure the following bits when using the port input interrupt: *
- Write 1 to the PxINTF.PxIFy bit. (Clear interrupt flag)
- PxINTCTL.PxEDGEy bit (Select interrupt edge (input rising edge/falling edge))
- Set the PxINTCTL.PxIEy bit to 1. (Enable interrupt)
6. Set the following PxIOEN register bits:
- Set the PxIOEN.PxOENy bit to 0. (Disable output)
- Set the PxIOEN.PxIENy bit to 1. (Enable input)
* Steps 1 and 5 are required for the ports with an interrupt function. Step 2 is required for the ports with a chat-
tering filter function.
Table 6.4.1.1 lists the port status according to the combination of data input/output control and pull-up/down
control.
Table 6.4.1.1 GPIO Port Control List
PxIOEN.
PxIENy bit
000×DisabledOff (Hi-Z) *1
0010DisabledPulled down
0011DisabledPulled up
100×EnabledDisabledOff (Hi-Z) *2
1010EnabledDisabledPulled down
1011EnabledDisabledPulled up
010×DisabledEnabledOff
0110DisabledEnabledOff
0111DisabledEnabledOff
1110EnabledEnabledOff
1111EnabledEnabledOff
*1: Initial status. Current does not flow if the pin is placed into floating status.
*2: Use of the pull-up or pull-down function is recommended, as undesired current will flow if the port input is set to floating status.
PxIOEN.
PxOENy bit
PxRCTL.
PxRENy bit
PxRCTL.
PxPDPUy bit
InputOutput
Pull-up/pull-down
condition
Note: If the PxMODSEL.PxSELy bit for the port without a GPIO function is set to 0, the port goes into
initial status (refer to “Initial Settings”). The GPIO control bits are configured to a read-only bit always read out as 0.
6.4.2 Port Input/Output Control
Peripheral I/O function control
The port for which a peripheral I/O function is selected is controlled by the peripheral circuit. For more infor-
mation, refer to the respective peripheral circuit chapter.
Write data (1 = high output, 0 = low output) to be output from the Pxy pin to the PxD AT. P xOUTy bit.
Reading input data from a GPIO port
The data (1 = high input, 0 = low input) input from the Pxy pin can be read out from the PxD AT. P xINy bit.
Chattering filter function
Some ports have a chattering filter function and it can be controlled in each port. This function is enabled by
setting the PxCHATEN.PxCHATENy bit to 1. The input sampling time to remove chattering is determined by
the CLK_PPORT frequency configured using the PCLK register in common to all ports. The chattering filter
removes pulses with a shorter width than the input sampling time.
2 to 3
Input sampling time = ———————————— [second] (Eq.6.2)
CLK_PPORT frequency [Hz]
Make sure the Pxy port interrupt is disabled before altering the PCLK register and PxCHATEN.PxCHATENy
bit settings. A Pxy port interrupt may erroneously occur if these settings are altered in an interrupt enabled status. Furthermore, enable the interrupt after a lapse of four or more CLK_PPORT cycles from enabling the chattering filter function.
If the clock generator is configured so that it will supply CLK_PPORT to PPORT in SLEEP mode, the chatter-
ing filter of the port will function even in SLEEP mode. If CLK_PPORT is configured to stop in SLEEP mode,
PPORT inactivates the chattering filter during SLEEP mode to input pin status transitions directly to itself.
Key-entry reset function
This function issues a reset request when low-level pulses are input to all the specified ports simultaneously.
Make the following settings when using this function:
1. Configure the ports to be used for key-entry reset as general-purpose input ports (refer to “Initial settings
when using a port as a general-purpose input port (only for the ports with GPIO function)”).
2. Configure the input pin combination for key-entry reset using the PCLK.KRSTCFG[1:0] bits.
Note: When enabling the key-entry reset function, be sure to configure the port pins to be used for it
as general-purpose input pins before setting the PCLK.KRSTCFG[1:0] bits.
PPORT issues a reset request immediately after all the input pins specified by the PCLK.KRSTCFG[1:0] are
set to a low level if the chattering filter function is disabled (initial status). To issue a reset request only when
low-level signals longer than the time configured are input, enable the chattering filter function for all the ports
used for key-entry reset.
The pins configured for key-entry reset can also be used as general-purpose input pins.
6.5 Interrupts
When the GPIO function is selected for the port with an interrupt function, the port input interrupt function can be
used.
PPORT provides interrupt enable bits (PxINTCTL.PxIEy bit) corresponding to each interrupt flag. An inter-
rupt request is sent to the interrupt controller only when the interrupt flag, of which interrupt has been enabled
by the interrupt enable bit, is set. For more information on interrupt control, refer to the “Interrupt Controller”
chapter.
Interrupt check in port group unit
When interrupts are enabled in two or more port groups, check the PINTFGRP.PxINT bit in the interrupt han-
dler first. It helps minimize the handler codes for finding the port that has generated an interrupt. If this bit is
set to 1, an interrupt has occurred in the port group. Next, check the PxINTF.PxIFy bit set to 1 in the port group
to determine the port that has generated an interrupt. Clearing the PxINTF.PxIFy bit also clears the PINTFGRP.
PxINT bit. If the port is set to interrupt disabled status by the PxINTCTL.PxIEy bit, the PINTFGRP.PxINT bit
will not be set even if the PxINTF.PxIFy bit is set to 1.
6.6 Control Registers
This section describes the same control registers of all port groups as a single register. For the register and bit configurations in each port group and their initial values, refer to “Control Register and Port Function Configuration of
this IC.”
Px Port Data Register
Register nameBitBit nameInitialResetR/WRemarks
PxDAT15–8 PxOUT[7:0]0x00H0R/W–
7–0 PxIN[7:0]0x00H0R
*1: This register is effective when the GPIO function is selected.
*2: The bit configuration differs depending on the port group.
*3: The initial value may be changed by the port.
Bits 15–8 PxOUT[7:0]
These bits are used to set data to be output from the GPIO port pins.
1 (R/W): Output high level from the port pin
0 (R/W): Output low level from the port pin
When output is enabled (PxIOEN.PxOENy bit = 1), the port pin outputs the data set here. Although
data can be written when output is disabled (PxIOEN.PxOENy bit = 0), it does not affect the pin status.
These bits do not affect the outputs when the port is used as a peripheral I/O function.
Bits 7–0 PxIN[7:0]
The GPIO port pin status can be read out from these bits.
1 (R): Port pin = High level
0 (R): Port pin = Low level
The port pin status can be read out when input is enabled (PxIOEN.PxIENy bit = 1). When input is
disabled (PxIOEN.PxIENy bit = 0), these bits are always read as 0.
When the port is used for a peripheral I/O function, the input value cannot be read out from these bits.
Px Port Enable Register
Register nameBitBit nameInitialResetR/WRemarks
PxIOEN15–8 PxIEN[7:0]0x00H0R/W–
7–0 PxOEN[7:0]0x00H0R/W
*1: This register is effective when the GPIO function is selected.
*2: The bit configuration differs depending on the port group.
Bits 15–8 PxIEN[7:0]
These bits enable/disable the GPIO port input.
1 (R/W): Enable (The port pin status is input.)
0 (R/W): Disable (Input data is fixed at 0.)
When both data output and data input are enabled, the pin output status controlled by this IC can be
read.
These bits do not affect the input control when the port is used as a peripheral I/O function.
Bits 7–0 PxOEN[7:0]
These bits enable/disable the GPIO port output.
1 (R/W): Enable (Data is output from the port pin.)
0 (R/W): Disable (The port is placed into Hi-Z.)
These bits do not affect the output control when the port is used as a peripheral I/O function.
Px Port Pull-up/down Control Register
Register nameBitBit nameInitialResetR/WRemarks
PxRCTL15–8 PxPDPU[7:0]0x00H0R/W–
7–0 PxREN[7:0]0x00H0R/W
*1: This register is effective when the GPIO function is selected.
*2: The bit configuration differs depending on the port group.
Bits 15–8 PxPDPU[7:0]
These bits select either the pull-up resistor or the pull-down resistor when using a resistor built into
the port.
1 (R/W): Pull-up resistor
0 (R/W): Pull-down resistor
The selected pull-up/down resistor is enabled when the PxRCTL.PxRENy bit = 1.
Bits 7–0 PxREN[7:0]
These bits enable/disable the port pull-up/down control.
1 (R/W): Enable (The built-in pull-up/down resistor is used.)
0 (R/W): Disable (No pull-up/down control is performed.)
Enabling this function pulls up or down the port when output is disabled (PxIOEN.PxOENy bit = 0).
When output is enabled (PxIOEN.PxOENy bit = 1), the PxRCTL.PxRENy bit setting is ineffective re-
gardless of how the PxIOEN.PxIENy bit is set and the port is not pulled up/down.
These bits do not affect the pull-up/down control when the port is used as a peripheral I/O function.
Px Port Interrupt Flag Register
Register nameBitBit nameInitialResetR/WRemarks
PxINTF15–8 –0x00–R–
7–0 PxIF[7:0]0x00H0R/WCleared by writing 1.
*1: This register is effective when the GPIO function is selected.
*2: The bit configuration differs depending on the port group.
Bits 15–8 Reserved
Bits 7–0 PxIF[7:0]
These bits indicate the port input interrupt cause occurrence status.
1 (R): Cause of interrupt occurred
0 (R): No cause of interrupt occurred
1 (W): Clear flag
0 (W): Ineffective
Px Port Interrupt Control Register
Register nameBitBit nameInitialResetR/WRemarks
PxINTCTL15–8 PxEDGE[7:0]0x00H0R/W–
7–0 PxIE[7:0]0x00H0R/W
*1: This register is effective when the GPIO function is selected.
*2: The bit configuration differs depending on the port group.
These bits select the input signal edge to generate a port input interrupt.
1 (R/W): An interrupt will occur at a falling edge.
0 (R/W): An interrupt will occur at a rising edge.
Bits 7–0 PxIE[7:0]
These bits enable port input interrupts.
1 (R/W): Enable interrupts
0 (R/W): Disable interrupts
Note: To prevent generating unnecessary interrupts, the corresponding interrupt flag should be cleared
before enabling interrupts.
Px Port Chattering Filter Enable Register
Register nameBitBit nameInitialResetR/WRemarks
PxCHATEN15–8 –0x00–R–
7–0 PxCHATEN[7:0]0x00H0R/W
*1: The bit configuration differs depending on the port group.
Bits 15–8 Reserved
Bits 7–0 PxCHATEN[7:0]
These bits enable/disable the chattering filter function.
1 (R/W): Enable (The chattering filter is used.)
0 (R/W): Disable (The chattering filter is bypassed.)
Px Port Mode Select Register
Register nameBitBit nameInitialResetR/WRemarks
PxMODSEL15–8 –0x00–R–
7–0 PxSEL[7:0]0x00H0R/W
*1: The bit configuration differs depending on the port group.
*2: The initial value may be changed by the port.
Bits 15–8 Reserved
Bits 7–0 PxSEL[7:0]
These bits select whether each port is used for the GPIO function or a peripheral I/O function.
1 (R/W): Use peripheral I/O function
0 (R/W): Use GPIO function
This bit sets whether the PPORT operating clock is supplied in DEBUG mode or not.
1 (R/WP): Clock supplied in DEBUG mode
0 (R/WP): No clock supplied in DEBUG mode
Bits 7–4 CLKDIV[3:0]
These bits select the division ratio of the PPORT operating clock (chattering filter clock).
Bits 3–2 KRSTCFG[1:0]
These bits configure the key-entry reset function.
Table 6.6.2 Key-Entry Reset Function Settings
PCLK.KRSTCFG[1:0] bitskey-entry reset
0x3Reset when P0[3:0] inputs = all low
0x2Reset when P0[2:0] inputs = all low
0x1Reset when P0[1:0] inputs = all low
0x0Disable
Bits 1–0 CLKSRC[1:0]
These bits select the clock source of PPORT (chattering filter).
The PPORT operating clock should be configured by selecting the clock source using the PCLK.
CLKSRC[1:0] bits and the clock division ratio using the PCLK.CLKDIV[3:0] bits as shown in Table
6.6.3. These settings determine the input sampling time of the chattering filter.
*1: Only the bits corresponding to the port groups that support interrupts are provided.
Bits 15–13 Reserved
6 I/O PORTS (PPORT)
Bits 12–0 PxINT
These bits indicate that Px port group includes a port that has generated an interrupt.
1 (R): A port generated an interrupt
0 (R): No port generated an interrupt
The PINTFGRP.PxINT bit is cleared when the interrupt flag for the port that has generated an interrupt
The Pd0–Pd2 ports are configured as a debugging function port at initialization. The Pd port group supports the
GPIO functions. The GPIO function of the Pd2 port supports output only, therefore, the pull-up/down function cannot be used.
UPMUX is a multiplexer that allows software to assign the desired peripheral I/O function to an I/O port. The main
features are outlined below.
• Allows programmable assignment of the synchronous serial interface, I
eral I/O functions to the P0, P1, P2, and P3 port groups.
• The peripheral I/O function assigned via
UPMUX is enabled by setting the PxFNCSEL.PxyMUX[1:0] bits to 0x1.
Note: ‘x’, which is used in the port names Pxy, register names, and bit names, refers to a port group (x
= 0, 1, 2, 3) and ‘y’ refers to a port number (y = 0, 1, 2, ··· , 7).
Figure 7.1.1 shows the configuration of UPMUX.
UPMUX
PxyPPFNC[2:0]
PxyPERICH[1:0]
PxyPERISEL[2:0]
Input data
selector
2
C,
UART, and 16-bit PWM timer
Peripheral circuit
periph-
Output data
selector
Data, I/O control
Function 1 selection
Figure 7.1.1 UPMUX Configuration
I/O port
Pxy
7.2 Peripheral Circuit I/O Function Assignment
An I/O function of a peripheral circuit supported may be assigned to peripheral I/O function 1 of an I/O port listed
above. The following shows the procedure to assign a peripheral I/O function and enable it in the I/O port:
1. Configure the PxIOEN register of the I/O port.
- Set the PxIOEN.PxIENy bit to 0. (Disable input)
- Set the PxIOEN.PxOENy bit to 0. (Disable output)
2. Set the PxMODSEL.PxSELy bit of the I/O port to 0. (Disable peripheral I/O function)
3. Set the following PxUPMUXn register bits (n = 0 to 3).
*1: ‘x’ in the register name refers to a port group number and ‘n’ refers to a register number (0–3).
*2: ‘x’ in the bit name refers to a port group number, ‘y’ refers to an even port number (0, 2, 4, 6), and ‘z’ refers to an
odd port number (z = y + 1).
Bits 15–13 PxzPPFNC[2:0]
Bits 7–5 PxyPPFNC[2:0]
These bits specify the peripheral I/O function to be assigned to the port. (See Table 7.3.1.)
Bits 12–11 PxzPERICH[1:0]
Bits 4–3 PxyPERICH[1:0]
These bits specify a peripheral circuit channel number. (See Table 7.3.1.)
WDT2 restarts the system if a problem occurs, such as when the program cannot be executed normally.
The features of WDT2 are listed below.
• Includes a 10-bit up counter to count NMI/reset generation cycle.
• A counter clock source and clock division ratio are selectable.
• Can generate a reset or NMI in a cycle given via software.
• Can generate a reset at the next NMI generation cycle after an NMI is generated.
Figure 8.1.1 shows the configuration of WDT2.
Clock generator
Internal data bus
MOD[1:0]
WDTRUN[3:0]
WDTCNTRST
CLK_WDT2
CLKSRC[1:0]
CLKDIV[1:0]CMP[9:0]
DBRUN
Mode setting circuit
10-bit counter
Figure 8.1.1 WDT2 Configuration
Comparator
NMI
STATNMI
Reset
8.2 Clock Settings
8.2.1 WDT2 Operating Clock
When using WDT2, the WDT2 operating clock CLK_WDT2 must be supplied to WDT2 from the clock generator.
The CLK_WDT2 supply should be controlled as in the procedure shown below.
1. Write 0x0096 to the MSCPROT.PROT[15:0] bits. (Remove system protection)
2. Enable the clock source in the clock generator if it is stopped (refer to “Clock Generator” in the “Power Supply,
Reset, and Clocks” chapter).
3. Set the following WDTCLK register bits:
WDTCLK.CLKSRC[1:0] bits (Clock source selection)
WDTCLK.CLKDIV[1:0] bits (Clock division ratio selection = Clock frequency setting)
4. Write a value other than 0x0096 to the MSCPROT.PROT[15:0] bits. (Set system protection)
8.2.2 Clock Supply in DEBUG Mode
The CLK_WDT2 supply during DEBUG mode should be controlled using the WDTCLK.DBRUN bit.
The CLK_WDT2 supply to WDT2 is suspended when the CPU enters DEBUG mode if the WDTCLK.DBRUN
bit = 0. After the CPU returns to normal mode, the CLK_WDT2 supply resumes. Although WDT2 stops operating
when the CLK_WDT2 supply is suspended, the register retains the status before DEBUG mode was entered.
If the WDTCLK.DBRUN bit = 1, the CLK_WDT2 supply is not suspended and WDT2 will keep operating in DEBUG mode.
operates in HALT mode. HALT mode is therefore cleared by an NMI or reset if it continues for more than the
NMI/reset generation cycle and the CPU executes the interrupt handler. To disable
by writing 0xa to the
WDTCTL.WDTRUN[3:0] bits
before executing the halt instruction. Reset
WDT2
in HALT mode, stop
WDT2
WDT2
before re-
suming operations after HALT mode is cleared.
During SLEEP mode
WDT2 operates in SLEEP mode if the selected clock source is running. SLEEP mode is cleared by an NMI or reset if
it continues for more than the NMI/reset generation cycle and the CPU executes the interrupt handler. Therefore, stop
WDT2
by setting the
If the clock source stops in SLEEP mode, WDT2 stops. To prevent generation of an unnecessary NMI or reset after
This bit sets whether the WDT2 operating clock is supplied in DEBUG mode or not.
1 (R/WP): Clock supplied in DEBUG mode
0 (R/WP): No clock supplied in DEBUG mode
Bits 7–6 Reserved
Bits 5–4 CLKDIV[1:0]
These bits select the division ratio of the WDT2 operating clock (counter clock). The clock frequency
should be set to around 256 Hz.
Bits 3–2 Reserved
Bits 1–0 CLKSRC[1:0]
These bits select the clock source of WDT2.
Table 8.4.1 Clock Source and Division Ratio Settings
0x3Reserved–
0x2RESET after NMI mode If the WDTCTL.STATNMI bit is not cleared to 0 after an NMI
0x1NMI modeWDT2 issues an NMI when a counter compare match occurs.
0x0RESET modeWDT2 issues a reset when a counter compare match occurs.
Bit 8 STATNMI
This bit indicates that a counter compare match and NMI have occurred.
1 (R): NMI (counter compare match) occurred
0 (R): NMI not occurred
Operating modeDescription
has occurred due to a counter compare match, WDT2 issues
a reset when the next compare match occurs.
When the NMI generation function of WDT2 is used, read this bit in the NMI handler routine to con-
firm that WDT2 was the source of the NMI.
The WDTCTL.STATNMI bit set to 1 is cleared to 0 by writing 1 to the WDTCTL.WDTCNTRST bit.
Bits 7–5 Reserved
Bit 4 WDTCNTRST
This bit resets the 10-bit counter and the WDTCTL.STATNMI bit.
1 (WP): Reset
0 (WP): Ignored
0 (R): Always 0 when being read
Bits 3–0 WDTRUN[3:0]
These bits control WDT2 to run and stop.
0xa (WP): Stop
Values other than 0xa (WP): Run
0xa (R): Idle
0x0 (R): Running
Always 0x0 is read if a value other than 0xa is written.
Since an NMI or reset may be generated immediately after running depending on the counter value,
WDT2 should also be reset concurrently when running WDT2.
RTCA is a real-time clock with a perpetual calendar function. The main features of RTCA are outlined below.
• Includes a BCD real-time clock counter to implement a time-of-day clock (second, minute, and hour) and calendar (day, day of the week, month, and year with leap year supported).
• Provides a hold function for reading correct counter values by suspending the real-time clock counter operation.
• 24-hour or 12-hour mode is selectable.
• Capable of controlling the starting and stopping of the time-of-day clock.
• Provides a 30-second correction function to adjust time using a time signal.
• Includes a 1 Hz counter to count 128 to 1 Hz.
• Includes a BCD stopwatch counter with 1/100-second counting supported.
• Provides a theoretical regulation function to correct clock error due to frequency tolerance with no external parts
required.
Figure 9.1.1 shows the configuration of RTCA.
Clock generator
fOSC1
OSC1
oscillator
Interrupt controller
1/128
Internal data bus
RTCTRM[6:0]
RTCTRMBSY
RTCHLD
RTCRST
RTCRUN
RTCBSY
SWRST
SWRUN
SW1IE
SW10IE
SW100IE
ALARMIE
1DAYIE
1HURIE
1MINIE
1SECIE
1_2SECIE
1_4SECIE
1_8SECIE
1_32SECIE
RTC
count
control
circuit
Stopwatch
count
control
circuit
Interrupt
control
circuit
RTC
RTC
RTC
128HZ
64HZ
128
64
Hz
Hz
BCD
100[3:0]
1/100
s
Stopwatch counter
SW1IF
SW10IF
SW100IF
ALARMIF
1DAYIF
1HURIF
1MINIF
1SECIF
1_2SECIF
1_4SECIF
1_8SECIF
1_32SECIF
Stopwatch counter interrupt
1 Hz counter interrupt
Alarm interrupt
Real-time clock counter interrupt
32HZ
BCD
10[3:0]
1/10
s
32
Hz
RTC
16HZ
1 Hz counter
16
Hz
RTC
8HZ
8
Hz
RTCAPA
RTCHHA[1:0]
/RTCHLA[3:0]
RTCMIHA[2:0]
/RTCMILA[3:0]
RTCSHA[2:0]
/RTCSLA[3:0]
RTC
4HZ
RTC
RTC
2HZ
1HZ
4
2
Hz
1
Hz
RTC24H
RTCADJ
Comparator
Hz
1-second
signal
Real-time
clock
counter
Day of
week
Year
Month
Day
A.M./
P.M.
Hour
Minute
Second
RTCWK[2:0]
RTCYH[3:0]
/RTCYL[3:0]
RTCMOH
/RTCMOL[3:0]
RTCDH[1:0]
/RTCDL[3:0]
RTCHH[1:0]
/RTCHL[3:0]
RTCMIH[2:0]
/RTCMIL[3:0]
RTCSH[2:0]
/RTCSL[3:0]
RTCAP
R
Figure 9.1.1 RTCA Configuration
9.2 Output Pin and External Connection
9.2.1 Output Pin
Table 9.2.1.1 shows the RTCA pin.
Table 9.2.1.1 RTCA Pin
Pin nameI/O*Initial status*Function
RTC1SOO (L)1-second signal monitor output pin
* Indicates the status when the pin is configured for RTCA.
If the port is shared with the RTCA output function and other functions, the RTCA function must be assigned to the
port. For more information, refer to the “I/O Ports” chapter.
RTCA uses CLK_RTCA, which is generated by the clock generator from OSC1 as the clock source, as its operating clock. RTCA is operable when OSC1 is enabled.
To continue the RTCA operation during SLEEP mode with OSC1 being activated, the CLGOSC.OSC1SLPC bit
must be set to 0.
9.3.2 Theoretical Regulation Function
The time-of-day clock loses accuracy if the OSC1 frequency fOSC1 has a frequency tolerance from 32.768 kHz. To
correct this error without changing any external part, RTCA provides a theoretical regulation function. Follow the
procedure below to perform theoretical regulation.
1. Measure the frequency tolerance “m [ppm]” of f
2. Determine the theoretical regulation execution cycle time “n seconds.”
3. Determine the value to be written to the RTCCTL.RTCTRM[6:0] bits from the results in Steps 1 and 2.
4. Write the value determined in Step 3 to the RTCCTL.RTCTRM[6:0] bits periodically in n-second cycles using
an RTCA alarm or second interrupt.
5. Monitor the RTC1S signal to check that every n-second cycle has no error included.
The correction value for theoretical regulation can be specified within the range from -64 to +63 and it should be
written to the RTCCTL.RTCTRM[6:0] bits as a two’s-complement number. Use Eq. 9.1 to calculate the correction
value.
m
RTCTRM[6:0] = —— × 256 × n
10
6
(However, RTCTRM[6:0] is an integer after rounding off to -64 to +63.) (Eq. 9.1)
Where
n: Theoretical regulation execution cycle time [second] (time interval to write the correct value to the RTCCTL.
RTCTRM[6:0] bits periodically via software)
m: OSC1 frequency tolerance [ppm]
Figure 9.3.2.1 shows the RTC1S signal waveform.
OSC1.
32,768/fOSC1 [s]
RTC1S
TCCTL.RTCTRMBSY
Writing to the RTCCTL.RTCTRM[6:0] bits
T = correction time set in the RTCCTL.RTCTRM[6:0] bits
Figure 9.3.2.1 RTC1S Signal Waveform
32,768/fOSC1± ∆T [s]
completion interrupt
Table 9.3.2.1 lists the frequency tolerance correction rates when the theoretical regulation execution cycle time n is
4,096 seconds as an example.
Table 9.3.2.1 Correction Rates when Theoretical Regulation Execution Cycle Time n = 4,096 Seconds
Notes: • The theoretical regulation affects only the real-time clock counter and 1 Hz counter. It does
not affect the stopwatch counter.
• After a value is written to the RTCCTL.RTCTRM[6:0] bits, the theoretical regulation correction
takes effect on the 1 Hz counter value at the same timing as when the 1 Hz counter changes
to 0x7f. Also an interrupt occurs depending on the counter value at this time.
9.4 Operations
9.4.1 RTCA Control
Follow the sequences shown below to set time to RTCA, to read the current time and to set alarm.
Time setting
1. Set RTCA to 12H or 24H mode using the RTCCTL.RTC24H bit.
2. Write 1 to the RTCCTL.RTCRUN bit to enable for the real-time clock counter to start counting up.
3. Check to see if the RTCCTL.RTCBSY bit = 0 that indicates the counter is ready to rewrite. If the RTCCTL.
RTCBSY bit = 1, wait until it is set to 0.
4. Write the current date and time in BCD code to the control bits listed below.
RTCSEC.RTCSH[2:0]/RTCSL[3:0] bits (second)
RTCHUR.RTCMIH[2:0]/RTCMIL[3:0] bits (minute)
RTCHUR.RTCHH[1:0]/RTCHL[3:0] bits (hour)
RTCHUR.RTCAP bit (AM/PM) (effective when RTCCTL.RTC24H bit = 0)
RTCMON.RTCDH[1:0]/RTCDL[3:0] bits (day)
RTCMON.RTCMOH/RTCMOL[3:0] bits (month)
RTCYAR.RTCYH[3:0]/RTCYL[3:0] bits (year)
RTCYAR.RTCWK[2:0] bits (day of the week)
5 Write 1 to the RTCCTL.RTCADJ bit (execute 30-second correction) using a time signal to adjust the time.
(For more information on the 30-second correction, refer to “Real-Time Clock Counter Operations.”)
6. Write 1 to the real-time clock counter interrupt flags in the RTCINTF register to clear them.
7. Write 1 to the interrupt enable bits in the RTCINTE register to enable real-time clock counter interrupts.
Time read
1. Check to see if the RTCCTL.RTCBSY bit = 0. If the RTCCTL.RTCBSY bit = 1, wait until it is set to 0.
2. Write 1 to the RTCCTL.RTCHLD bit to suspend count-up operation of the real-time clock counter.
3. Read the date and time from the control bits listed in “Time setting, Step 4” above.
4. Write 0 to the RTCCTL.RTCHLD bit to resume count-up operation of the real-time clock counter. If a
second count-up timing has occurred in the count hold state, the hardware corrects the second counter for
+1 second (for more information on the +1 second correction, refer to “Real-Time Clock Counter Operations”).
Alarm setting
1. Write 0 to the RTCINTE.ALARMIE bit to 0 to disable alarm interrupts.
2. Write the alarm time in BCD code to the control bits listed below (a time within 24 hours from the current
time can be specified).
RTCALM1.RTCSHA[2:0]/RTCSLA[3:0] bits (second)
RTCALM2.RTCMIHA[2:0]/RTCMILA[3:0] bits (minute)
RTCALM2.RTCHHA[1:0]/RTCHLA[3:0] bits (hour)
RTCALM2.RTCAPA bit (AM/PM) (effective when RTCCTL.RTC24H bit = 0)
3. Write 1 to the RTCINTF.ALARMIF bit to clear the alarm interrupt flag.
4. Write 1 to the RTCINTE.ALARMIE bit to enable alarm interrupts.
When the real-time clock counter reaches the alarm time set in Step 2, an alarm interrupt occurs.
The real-time clock counter consists of second, minute, hour, AM/PM, day, month, year, and day of the week counters and it performs counting up using the RTC1S signal. It has the following functions as well.
Recognizing leap years
The leap year recognizing algorithm used in RTCA is effective only for Christian Era years. Years within 0 to
99 that can be divided by four without a remainder are recognized as leap years. If the year counter = 0x00,
RTCA assumes it as a common year. If a leap year is recognized, the count range of the day counter changes
when the month counter is set to February.
Corrective operation when a value out of the effective range is set
When a value out of the effective range is set to the year, day of the week, or hour (in 24H mode) counter, the
counter will be cleared to 0 at the next count-up timing. When a such value is set to the month, day, or hour (in
12H mode) counter, the counter will be set to 1 at the next count-up timing.
30-second correction
This function is provided to set the time-of-day clock by the time signal. Writing 1 to the RTCCTL.RTCADJ
bit adds 1 to the minute counter if the second counter represents 30 to 59 seconds, or clears the second counter
with the minute counter left unchanged if the second counter represents 0 to 29 seconds.
+1 second correction
If a second count-up timing occurred while the RTCCTL.RTCHLD bit = 1 (count hold state), the real-time
clock counter counts up by +1 second (performs +1 second correction) after the counting has resumed by writing 0 to the RTCCTL.RTCHLD bit.
Note: If two or more second count-up timings occurred while the RTCCTL.RTCHLD bit = 1, the coun-
ter is always corrected for +1 second only.
9.4.3 Stopwatch Control
Follow the sequences shown below to start counting of the stopwatch and to read the counter.
Count start
1. Write 1 to the RTCSWCTL.SWRST bit to reset the stopwatch counter.
2. Write 1 to the stopwatch interrupt flags in the RTCINTF register to clear them.
3. Write 1 to the interrupt enable bits in the RTCINTE register to enable stopwatch interrupts.
4. Write 1 to the RTCSWCTL.SWRUN bit to start stopwatch count up operation.
Counter read
1. Read the count value from the RTCSWCTL.BCD10[3:0] and BCD100[3:0] bits.
2. Read again.
i. If the two read values are the same, assume that the count values are read correctly.
ii.
If different values are read, perform reading once more and compare the read value with the previous one.
9.4.4 Stopwatch Count-up Pattern
The stopwatch consists of 1/100-second and 1/10-second counters and these counters perform counting up in increments of approximate 1/100 and 1/10 seconds with the count-up patterns shown in Figure 9.4.4.1.