• MC9S08JS16 (Data Sheet)
Contains pin assignments and diagrams, all electrical
specifications, and mechanical drawing outlines.
Find the most current versions of all documents at:
http://www.freescale.com
MC9S08JS16 Features
8-Bit HCS08 Central Processor Unit (CPU)
•48 MHz HCS08 CPU (central processor
unit)
•24 MHz internal bus frequency
•HC08 instruction set with added BGND
instruction
•Support for up to 32 interrupt/reset sources
Memory Options
•Up to 16 KB of on-chip in-circuit
programmable flash memory with block
protection and security options
•Up to 512 bytes of on-chip RAM
•256 bytes of USB RAM
Clock Source Options
•Clock source options include crystal,
resonator, external clock
•MCG (multi-purpose clock generator) —
PLL and FLL; internal reference clock with
trim adjustment
System Protection
•Optional computer operating properly
(COP) reset with option to run from
independent 1 kHz internal clock source or
the bus clock
•Low-voltage detection
•Illegal opcode detection with reset
•Illegal address detection with reset
Power-Saving Modes
•Wait plus two stops
USB Bootload
•Mass erase entire flash array
•Partial erase flash array — erase all flash
blocks except for the first 1 KB of flash
transceiver; supports endpoint 0 and up to 6
additional endpoints
•SPI — One 8- or 16-bit selectable serial
peripheral interface module with a receive
data buffer hardware match function
•SCI — One serial communication interface
module with optional 13-bit break. Full
duplex non-return to zero (NRZ); LIN
master extended break generation; LIN
slave extended break detection; wakeup on
active edge
•MTIM — One 8-bit modulo counter with
8-bit prescaler and overflow interrupt
•TPM — One 2-channel 16-bit
timer/pulse-width modulator (TPM)
module: selectable input capture, output
compare, and edge-aligned PWM capability
on each channel. Timer module may be
configured for buffered, centered PWM
(CPWM) on all channels
•KBI — 8-pin keyboard interrupt module
•RTC — Real-time counter with binary- or
decimal-based prescaler
•CRC — Hardware CRC generator circuit
using 16-bit shift register; CRC16-CCITT
compliancy with x16+x12+x5+1 polynomial
Input/Output
•Software selectable pullups on ports when
used as inputs
•Software selectable slew rate control on
ports when used as outputs
•Software selectable drive strength on ports
when used as outputs
•Master reset pin and power-on reset (POR)
•Internal pullup on RESET, IRQ, and
BKGD/MS pins to reduce customer system
cost
Package Options
•Program flash
Peripherals
•USB — USB 2.0 full-speed (12 Mbps) with
dedicated on-chip 3.3 V regulator and
•24-pin quad flat no-lead (QFN)
•20-pin small outline IC package (SOIC)
MC9S08JS16 MCU Series Reference Manual
Covers:MC9S08JS16
MC9S08JS8
MC9S08JS16L
MC9S08JS8L
MC9S08JS16RM
Rev. 4
4/2009
Revision History
To provide the most up-to-date information, the revision of our documents on the World Wide Web will
be the most current. Your printed copy may be an earlier revision. To verify you have the latest information
available, refer to:
http://freescale.com
The following revision history table summarizes changes contained in this document.
Revision
Number
18/27/2008Initial public release.
212/17/2008Changed the content of register at address 0xFFAE and 0xFFAF in Ta bl e 4 - 4 and added the
33/6/2009Updated Figure 4-4 and Figure 4-5.
44/24/2009Added MC9S08JS16L and MC9S08JS8L information.
Revision
Date
Description of Changes
description of factory trim value before this table.
Deleted duplicated information in KBI Features section.
Changed the default of PTASE/PTBSE registers after reset to 0.
This product incorporates SuperFlash® technology licensed from SST.
6.2Port Data and Data Direction ..........................................................................................................79
6.3Pin Control ......................................................................................................................................80
14.2 Features .........................................................................................................................................215
14.3 TPMV3 Differences from Previous Versions ................................................................................217
14.3.1 Migrating from TPMV1 ..................................................................................................219
14.3.2 Features ...........................................................................................................................220
14.3.3 Modes of Operation ........................................................................................................220
17.4.1 BDC Registers and Control Bits .....................................................................................297
17.4.2 System Background Debug Force Reset Register (SBDFR) ..........................................299
17.4.3 DBG Registers and Control Bits .....................................................................................300
MC9S08JS16 MCU Series Reference Manual, Rev. 4
16Freescale Semiconductor
Chapter 1
Device Overview
1.1Introduction
MC9S08JS16 series MCUs are members of the low-cost, high-performance HCS08 family of 8-bit
microcontroller units (MCUs). All MCUs in the family use the enhanced HCS08 core and are available
with a variety of modules, memory sizes, memory types, and package types.
NOTE
The only difference between MC9S08JS16/MC9S08JS8 and
MC9S08JS16L/MC9S08JS8L is that MC9S08JS16 and MC9S08JS8
support USB bootloader function with voltage above 3.9 V while
MC9S08JS16L and MC9S08JS8L support USB bootloader function at
3.3 V.
Disable internal USB voltage regulator and apply 3.3 V to the V
USB33
pin
when using MC9S08JS16L and MC9S08JS8L for the USB bootloader
function.
Table 1-1 summarizes the peripheral availability per package type for the devices available in the
MC9S08JS16 series.
Table 1-1. MC9S08JS16 Series Features by MCU and Package
FeatureMC9S08JS8/MC9S08JS8LMC9S08JS16/MC9S08JS16L
Package24-pin QFN20-pin SOIC24-pin QFN20-pin SOIC
Flash size (bytes)8,19216,384
RAM size (bytes)512512
USB RAM (bytes)256256
IRQyesyes
KBI88
SCIyesyes
SPIyesyes
MTIMyesyes
TPM channels22
USByesyes
CRCyesyes
I/O pins14 (2 output only)14 (2 output only)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor17
Chapter 1 Device Overview
V
SS
V
DD
PORT B
8-BIT KEYBOARD
INTERRUPT MODULE (KBI)
USER FLASH (IN BYTES)
USER RAM (IN BYTES)
ON-CHIP ICE AND
DEBUG MODULE (DBG)
HCS08 CORE
CPU
NOTES:
1. Port pins are software configurable with pullup device if input port.
2. Pin contains software configurable pullup/pulldown device if IRQ is enabled (IRQPE = 1).
Pulldown is enabled if rising edge detect is selected (IRQEDG = 1).
3. IRQ does not have a clamp diode to V
DD
. IRQ must not be driven above VDD.
4. RESET
contains integrated pullup device if PTB1 enabled as reset pin function (RSTPE = 1).
5. Pin contains integrated pullup device.
6. When pin functions as KBI (KBIPEn = 1) and associated pin is configured to enable the pullup
device, KBEDGn can be used to reconfigure the pullup as a pulldown device.
PTA2/KBIP2/MOSI
PORT A
HCS08 SYSTEM CONTROL
RESETS AND INTERRUPTS
MODES OF OPERATION
POWER MANAGEMENT
VOLTAGE
REGULATOR
COPIRQLVD
LOW-POWER OSCILLATOR
MULTI-PURPOSE CLOCK
GENERATOR (MCG)
RESET
2-CHANNEL TIMER/PWM
MODULE (TPM)
PTA3/KBIP3/SPSCK
BKGD/MS
IRQ
KBIPx
TCLK
TPMCH0
TPMCH1
EXTAL
XTAL
USB
USB ENDPOINT
MODULE
RAM
FULL SPEED
USB
TRANSCEIVER
USBDP
USBDN
PTA6/KBIP6/RxD
PTA7/KBIP7/TxD
REAL-TIME COUNTER
(RTC)
PTA4/KBIP4/SS
PTA5/KBIP5/TPMCH1
8
SYSTEM
USB 3.3 V VOLTAGE REGULATOR
V
USB33
512
MC9S08JS16 = 16,384
V
SSOSC
PTA0/KBIP0/TPMCH0
PTA1/KBIP1/MISO
PTB3/BLMS
PTB2/BKGD/MS
PTB0/IRQ/TCLK
PTB1/RESET
PTB5/EXTAL
PTB4/XTAL
SERIAL PERIPHERAL
INTERFACE MODULE (SPI)
SPSCK
SS
MISO
MOSI
8-/16-BIT
8-BIT MODULO TIMER
MODULE (MTIM)
INTERFACE MODULE (SCI)
SERIAL COMMUNICATIONS
RxD
TxD
BDC
Bootloader ROM (IN BYTES)
4096
16-BIT Cyclic Redundancy
MODULE (CRC)
Check Generator
MC9S08JS8L = 8,192
MC9S08JS16L = 16,384
MC9S08JS8 = 8,192
1.2MCU Block Diagram
The block diagram in Figure 1-1 shows the structure of the MC9S08JS16 series MCU.
Figure 1-1. MC9S08JS16 Series Block Diagram
18Freescale Semiconductor
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 1 Device Overview
TPM
BDC
CPU
RAMFLASH
2
MCG
MCGOUT
÷2
BUSCLK
MCGLCLK
MCGERCLK
COP
1
The fixed frequency clock (FFCLK) is internally synchronized to the bus clock and must not exceed one half of the
bus clock frequency.
2
Flash and EEPROM have frequency requirements for program and erase operation. See MC9S08JS16 Series
Data Sheet for details.
XOSC
EXTALXTAL
FFCLK
1
MCGFFCLK
RTC
1 kHz
LPO
TCLK
MCGIRCLK
÷2
USB
USB RAM
SCI
ROM
MTIM
SPI
CRC
Table 1-2 lists the functional versions of the on-chip modules.
Table 1-2. Versions of On-Chip Modules
ModuleVersion
Central Processing Unit(CPU)2
Keyboard Interrupt(KBI)2
Multi-Purpose Clock Generator(MCG)1
Real-Time Counter(RTC)1
Serial Communications Interface(SCI)4
Serial Peripheral Interface(SPI16)1
Modulo Timer (MTIM)1
Timer Pulse-Width Modulator(TPM)3
Universal Serial Bus(USB)1
Cyclic Redundancy Check Generator(CRC)2
Debug Module(DBG)2
1.3System Clock Distribution
TCLK — External input clock source for TPM and MTIM and is referenced as TPMCLK in Chapter 14,
“Timer/Pulse-Width Modulator (S08TPMV3).”
Figure 1-2. System Clock Distribution Diagram
The MCG supplies the following clock sources:
Freescale Semiconductor19
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 1 Device Overview
•MCGOUT — This clock source is used as the CPU, USB RAM and USB module clock, and is
divided by two to generate the peripheral bus clock (BUSCLK). Control bits in the MCG control
registers determine which of the three clock sources is connected:
— Internal reference clock
— External reference clock
— Frequency-locked loop (FLL) or phase-locked loop (PLL) output
See Chapter 9, “Multi-Purpose Clock Generator (S08MCGV1),” for details on configuring the
MCGOUT clock.
•MCGLCLK — This clock source is derived from the digitally controlled oscillator (DCO) of the
MCG. Development tools can select this internal self-clocked source to speed up BDC
communications in systems where the bus clock is slow.
•MCGIRCLK — This is the internal reference clock and can be selected as the real-time counter
(RTC) clock source. Chapter 9, “Multi-Purpose Clock Generator (S08MCGV1),” explains the
MCGIRCLK in more detail. See Chapter 11, “Real-Time Counter (S08RTCV1),” for more
information regarding the use of MCGIRCLK.
•MCGERCLK — This is the external reference clock and can be selected as the clock source of
RTC module. Section 9.4.6, “External Reference Clock,” explains the MCGERCLK in more
detail. See Chapter 11, “Real-Time Counter (S08RTCV1),” for more information regarding the use
of MCGERCLK with this module.
•MCGFFCLK — This clock source is divided by two to generate FFCLK after being synchronized
to the BUSCLK. It can be selected as clock source for the TPM or MTIM modules. The frequency
of the MCGFFCLK is determined by the settings of the MCG. See Section 9.4.7, “Fixed Frequency
Clock,” for details.
•LPO clock — This clock is generated from an internal low power oscillator that is completely
independent of the MCG module. The LPO clock can be selected as the clock source to the RTC
or COP modules. See Chapter 11, “Real-Time Counter (S08RTCV1),” and Section 5.4, “Computer
Operating Properly (COP) Watchdog,” for details on using the LPO clock with these modules.
•TCLK — TCLK is the optional external clock source for the TPM or MTIM modules. The TCLK
must be limited to 1/4th the frequency of the BUSCLK for synchronization. See Chapter 14,
“Timer/Pulse-Width Modulator (S08TPMV3),” for more details.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
20Freescale Semiconductor
Chapter 2
USBDN
PTB3/BLMS
1
2
3
4
5
PTA0/KBIP0/TPMCH0
81011
7
17
23
PTB2/BKGD/MS
13
14
15
16
22212019
PTB5/EXTAL
V
SSOSC
PTA5/KBIP5/TPMCH1
V
USB33
V
DD
PTA4/KBIP4/SS
PTA2/KBIP2/MOSI
PTA1/KBIP1/MISO
PTA7/KBIP7/TxD
PTB4/XTAL
PTA3/KBIP3/SPSCK
PTB1/RESET
PTB0/IRQ/TCLK
USBDP
V
SS
PTA6/KBIP6/RxD
24-Pin QFN
12
NC
6
NC
V
SS
NC
18
24
NC
9
Pins and Connections
2.1Introduction
This chapter describes signals that connect to package pins. It includes a pinout diagram, a table of signal
properties, and detailed discussion of signals.
2.2Device Pin Assignment
Freescale Semiconductor21
Figure 2-1. MC9S08JS16 Series in 24-pin QFN Package
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 2 Pins and Connections
1
2
3
4
5
6
7
8
9
10
20
19
18
17
16
15
14
13
12
11
PTA3/KBIP3/SPSCK
PTA4/KBIP4/SS
USBDP
USBDN
V
USB33
PTA5/KBIP5/TPMCH1
V
DD
V
SS
V
SSOSC
PTB0/IRQ/TCLK
PTB1/RESET
PTA0/KBIP0/TPMCH0
PTA1/KBIP1/MISO
PTA2/KBIP2/MOSI
PTA7/KBIP7/TxD
PTA6/KBIP6/RxD
PTB5/EXTAL
PTB4/XTAL
PTB2/BKGD/MS
PTB3/BLMS
Figure 2-2. MC9S08JS16 Series in 20-Pin SOIC Package
2.3Recommended System Connections
Figure 2-3 shows pin connections that are common to almost all MC9S08JS16 series application systems.
22Freescale Semiconductor
MC9S08JS16 MCU Series Reference Manual, Rev. 4
V
DD
V
SS
RESET
OPTIONAL
MANUAL
RESET
V
DD
1
BACKGROUND HEADER
C
BY
0.1 μF
C
BLK
10 μF
+
5 V
+
SYSTEM
POWER
I/O AND
PERIPHERAL
INTERFACE TO
SYSTEM
APPLICATION
V
DD
PORT
A
PORT
B
IRQ
ASYNCHRONOUS
INTERRUPT
INPUT
NOTES:
1. External crystal circuity is not required if using the MCG internal clock. For USB operation, an external crystal is required.
2. XTAL and EXTAL use the same pins as PTB4 and PTB5, respectively.
3. RC filters on RESET
and IRQ are recommended for EMC-sensitive applications.
4. R
PUDP
is shown for full-speed USB only. The diagram shows a configuration where the on-chip regulator and R
PUDP
are enabled. The voltage regulator output is
used for R
PUDP. RPUDP
can optionally be disabled if using an external pullup resistor on USBDP.
5. V
BUS
is a 5.0 V supply from upstream port that can be used for USB operation.
6. USBDP and USBDN are powered by the 3.3 V regulator.
7. For USB operation, an external crystal with a value of 2 MHz or 4 MHz is recommended.
8. BLMS
pin has loading limitation, do not connect any cap with this pin.
9. If there is an external pullup resistor on PTB2/PTB3, PTB2/PTB3 must be configured as anoutput pin. Otherwise there will be current consumption on the pin (about
0.5 mA for a 10 kΩ resistor). The load on PTB2/PTB3 must be smaller than 50 pF.
10. When using internal V
USB33
as supply, there needs to be an external cap.
MC9S08JS16
V
DD
4.7 kΩ
–
0
.1 μF
V
DD
4.7 kΩ–10 kΩ
0.1 μF
1
0 kΩ
2
43
USBDN
V
USB33
USBDP
V
Bus
USB SERIES-B CONNECTOR
V
USB33
3.3 V Reference
R
PUDP
BKGD/MS
XTAL
EXTAL
C2
C1
X1
R
F
R
S
NOTE 1
V
SSOSC
PTB3/BLMS
PTB2/BKGD/MS
PTB0/IRQ/TCLK
PTB1/RESET
PTB5/EXTAL
PTB4/XTAL
PTA2/KBIP2/MOSI
PTA3/KBIP3/SPSCK
PTA6/KBIP6/RxD
PTA7/KBIP7/TxD
PTA4/KBIP4/SS
PTA5/KBIP5/TPMCH1
PTA0/KBIP0/TPMCH0
PTA1/KBIP1/MISO
BLMS
OPTIONAL
MANUAL
BLMS
NOTE 8, 9
C
4
0.47 μF
C
3
4.7 μF
+
NOTE 10
33 Ω ± 1%
33 Ω ± 1%
Chapter 2 Pins and Connections
Freescale Semiconductor23
Figure 2-3. Basic System Connections
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 2 Pins and Connections
2.3.1Power (VDD, VSS, V
SSOSC
, V
USB33
)
VDD and VSS are the primary power supply pins for the MCU. This voltage source supplies power to all
I/O buffer circuitry and to an internal voltage regulator. The internal voltage regulator provides regulated
lower-voltage source to the CPU and other internal circuitry of the MCU.
Typically, application systems have two separate capacitors across the power pins. In this case, there must
be a bulk electrolytic capacitor, such as a 10 μF tantalum capacitor, to provide bulk charge storage for the
overall system and a 0.1 μF ceramic bypass capacitor located as near to the paired VDD and V
pins as practical to suppress high-frequency noise. The MC9S08JS16 has a V
pin. This pin must be
SSOSC
SS
power
connected to the system ground plane or to the primary VSS pin through a low-impedance connection.
V
Controller (S08USBV1),” for a complete description of the V
is connected to the internal USB 3.3 V regulator. See Chapter 15, “Universal Serial Bus Device
USB33
power pin.
USB33
2.3.2Oscillator (XTAL, EXTAL)
Immediately after reset, the MCU uses an internally generated clock provided by the multi-purpose clock
generator (MCG) module. For more information on the MCG, see Chapter 9, “Multi-Purpose Clock
Generator (S08MCGV1).”
The oscillator (XOSC) in this MCU is a Pierce oscillator that can accommodate a crystal or ceramic
resonator. Rather than a crystal or ceramic resonator, an external oscillator can be connected to the EXTAL
input pin.
RS (when used) and RF must be low-inductance resistors such as carbon composition resistors.
Wire-wound resistors, and some metal film resistors, have too much inductance. C1 and C2 normally are
high-quality ceramic capacitors that are specifically designed for high-frequency applications.
RF is used to provide a bias path to keep the EXTAL input in its linear range during crystal startup; its value
is not generally critical. Typical systems use 1 MΩ to 10 MΩ. Higher values are sensitive to humidity and
lower values reduce gain and (in extreme cases) could prevent startup.
C1 and C2 are typically in the 5 pF to 25 pF range and are chosen to match the requirements of a specific
crystal or resonator. Be sure to take into account printed circuit board (PCB) capacitance and MCU pin
capacitance when selecting C1 and C2. The crystal manufacturer typically specifies a load capacitance that
is the series combination of C1 and C2 (which are usually the same size). As a first-order approximation,
use 10 pF as an estimate of combined pin and PCB capacitance for each oscillator pin (EXTAL and
XTAL).
2.3.3RESET Pin
After a power-on reset (POR), the PTB1/RESET pin defaults to a general-purpose input port pin, PTB1.
Setting RSTPE in SOPT1 configures the pin to be the RESET pin containing an internal pullup device.
After configured as RESET
enabled can be used to reset the MCU from an external source when the pin is driven low.
, the pin remains RESET until the next LVD or POR. The RESET pin when
MC9S08JS16 MCU Series Reference Manual, Rev. 4
24Freescale Semiconductor
Chapter 2 Pins and Connections
Internal power-on reset and low-voltage reset circuitry typically make external reset circuitry unnecessary.
This pin is normally connected to the standard 6-pin background debug connector so a development
system can directly reset the MCU system. If desired, a manual external reset can be added by supplying
a simple switch to ground (pull reset pin low to force a reset).
When any non-POR reset is initiated (whether from an external source or from an internal source), the
RESET pin is driven low for approximately 66 bus cycles and released. The reset circuity decodes the
cause of reset and records it by setting a corresponding bit in the system control reset status register (SRS).
NOTE
The voltage on the internally pulled up RESET pin when measured is below
VDD. The internal gates connected to this pin are pulled to VDD. If the
RESET pin is required to drive to a V
level, an external pullup must be
DD
used.
NOTE
In EMC-sensitive applications, an external RC filter is recommended on the
RESET pin, if enabled (Figure 2-3).
2.3.4Background/Mode Select (BKGD/MS)
During a power-on-reset (POR) or background debug force reset (see Section 5.7.3, “System Background
Debug Force Reset Register (SBDFR),” for details), the PTB2/BKGD/MS pin functions as a mode select
pin. Immediately after reset rises the pin functions as the background pin and can be used for background
debug communication. When enabled as the BKGD/MS pin (BKGDPE = 1), an internal pullup device is
automatically enabled.
The background debug communication function is enabled when BKGDPE in SOPT1 is set. BKGDPE is
set following any reset of the MCU and must be cleared to use the PTB2/BKGD/MS pin’s alternative pin
functions.
If nothing is connected to this pin, the MCU will enter normal operating mode at the rising edge of reset.
If a debug system is connected to the 6-pin standard background debug header, it can hold BKGD/MS low
during the rising edge of reset which forces the MCU to active background mode.
The BKGD pin is used primarily for background debug controller (BDC) communications using a custom
protocol that uses 16 clock cycles of the target MCU’s BDC clock per bit time. The target MCU’s BDC
clock could be as fast as the bus clock rate, so there must never be any significant capacitance connected
to the BKGD/MS pin that could interfere with background serial communications.
Although the BKGD pin is a pseudo open-drain pin, the background debug communication protocol
provides brief, actively driven, high speedup pulses to ensure fast rise times. Small capacitances from
cables and the absolute value of the internal pullup device play almost no role in determining rise and fall
times on the BKGD pin.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor25
Chapter 2 Pins and Connections
NOTE
Before the IRQ or RESET function is enabled, be sure to enable the GPIO
pullup in that function’s pin and wait about 2 μs. Otherwise the IRQ or
RESET configuration may fail.
2.3.5Bootloader Mode Select (BLMS)
During a power-on-reset (POR), the CPU detects the state of the PTB3/BLMS pin that functions as a mode
select pin. When the logic is low and BKGD/MS is not pulled low, the CPU enters the bootloader mode.
During a power-on-reset (POR), an internal pullup device is automatically enabled in PTB3/BLMS pin.
Immediately after reset rises the pin functions as a general-purpose output only pin and an internal pullup
device is automatically disabled.
2.3.6USB Data Pins (USBDP, USBDN)
The USBDP (D+) and USBDN (D–) pins are the analog input/output lines for full-speed data
communication in the USB physical layer (PHY) module. An optional internal pullup resistor for the
USBDP pin, R
, is available.
PUDP
2.3.7General-Purpose I/O and Peripheral Ports
The MC9S08JS16 series of MCUs supports up to 14 general-purpose I/O pins, including two output-only
pins, which are shared with on-chip peripheral functions (timers, serial I/O, keyboard interrupts, etc.).
When a port pin is configured as a general-purpose output or a peripheral uses the port pin as an output,
software can select one of two drive strengths and enable or disable slew rate control. When a port pin is
configured as a general-purpose input or a peripheral uses the port pin as an input, software can enable a
pullup device.
For information about controlling these pins as general-purpose I/O pins, see Chapter 6, “Parallel
Input/Output.” For information about how and when on-chip peripheral systems use these pins, see the
appropriate module chapter.
Immediately after reset, all pins except the output-only pin (PTB2/BKGD/MS, PTB3/BLMS) are
configured as high-impedance general-purpose inputs with internal pullup devices disabled.
Table 2-1. Pin Availability by Package Pin-Count
Pin Number
(Package)
24 (QFN) 20 (SOIC)Port PinAlt 1Alt 2
14PTB0IRQTCLK
<-- Lowest Priority --> Highest
25PTB1RESET
36PTB2BKGDMS
47PTB3BLMS
MC9S08JS16 MCU Series Reference Manual, Rev. 4
26Freescale Semiconductor
Chapter 2 Pins and Connections
Table 2-1. Pin Availability by Package Pin-Count (continued)
Pin Number
(Package)
24 (QFN) 20 (SOIC)Port PinAlt 1Alt 2
58PTA0KBIP0TPMCH0
6—NC
79PTA1KBIP1MISO
810PTA2KBIP2MOSI
911PTA3KBIP3SPSCK
1012PTA4KBIP4SS
1113V
12—NC
1314V
1415USBDN
1516USBDP
1617V
1718PTA5KBIP5TPMCH1
18—NC
<-- Lowest Priority --> Highest
DD
SS
USB33
1919PTA6KBIP6RxD
2020PTA7KBIP7TxD
211PTB4XTAL
222PTB5EXTAL
233V
24—NC
SSOSC
NOTE
When an alternative function is first enabled, it is possible to get a spurious
edge to the module. User software must clear any associated flags before
interrupts are enabled. Table 2-1 illustrates the priority if multiple modules
are enabled. The highest priority module will have control over the pin.
Selecting a higher priority pin function with a lower priority function
already enabled can cause spurious edges to the lower priority module. All
modules that share a pin must be disabled before another module is enabled.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor27
Chapter 2 Pins and Connections
MC9S08JS16 MCU Series Reference Manual, Rev. 4
28Freescale Semiconductor
Chapter 3
Modes of Operation
3.1Introduction
The operating modes of the MC9S08JS16 series are described in this section. Entry into each mode, exit
from each mode, and functionality while in each mode are described.
3.2Features
•Active background mode for code development
•Wait mode:
— CPU halts operation to conserve power
— System clocks keep running
— Full voltage regulation is maintained
•Stop modes: CPU and bus clocks stopped
— Stop2: Partial power down of internal circuits; RAM and USB RAM contents retained
— Stop3: All internal circuits powered for fast recovery; RAM, USB RAM, and register contents
are retained
3.3Run Mode
Run is the normal operating mode for the MC9S08JS16 series. This mode is selected upon the MCU
exiting reset if the BKGD/MS pin is high. In this mode, the CPU executes code from internal memory with
execution beginning at the address fetched from memory at 0xFFFE:0xFFFF after reset.
3.4Active Background Mode
The active background mode functions are managed through the background debug controller (BDC) in
the HCS08 core. The BDC, together with the on-chip in-circuit emulator (ICE) debug module (DBG),
provides the means for analyzing MCU operation during software development.
Active background mode is entered in any of the following ways:
•When the BKGD/MS pin is low during POR or immediately after issuing a background debug
force reset (see Section 5.7.3, “System Background Debug Force Reset Register (SBDFR)”)
•When a BACKGROUND command is received through the BKGD pin
•When a BGND instruction is executed
•When encountering a BDC breakpoint
•When encountering a DBG breakpoint
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor29
Chapter 3 Modes of Operation
After entering active background mode, the CPU is held in a suspended state waiting for serial background
commands rather than executing instructions from the user application program.
Background commands are of two types:
•Non-intrusive commands, defined as commands that can be issued while the user program is
running. Non-intrusive commands can be issued through the BKGD pin while the MCU is in run
mode; non-intrusive commands can also be executed when the MCU is in the active background
mode. Non-intrusive commands include:
— Memory access commands
— Memory-access-with-status commands
— BDC register access commands
— The BACKGROUND command
•Active background commands, which can only be executed while the MCU is in active background
mode. Active background commands include commands to:
— Read or write CPU registers
— Trace one user program instruction at a time
— Leave active background mode to return to the user application program (GO)
The active background mode is used to program a bootloader or user application program into the flash
program memory before the MCU is operated in run mode for the first time. When the MC9S08JS16 series
devices are shipped from the Freescale factory, the flash program memory is erased by default unless
specifically noted, so there is no program that could be executed in run mode until the flash memory is
initially programmed. The active background mode can also be used to erase and reprogram the flash
memory after it has been previously programmed.
For additional information about the active background mode, refer to Chapter 17, “Development
Support.”
3.5Wait Mode
Wait mode is entered by executing a WAIT instruction. Upon execution of the WAIT instruction, the CPU
enters a low-power state in which it is not clocked. The I bit in the condition code register (CCR) is cleared
when the CPU enters wait mode, enabling interrupts. When an interrupt request occurs, the CPU exits wait
mode and resumes processing, beginning with the stacking operations leading to the interrupt service
routine.
While the MCU is in wait mode, there are some restrictions on which background debug commands can
be used. Only the BACKGROUND command and memory-access-with-status commands are available
while the MCU is in wait mode. The memory-access-with-status commands do not allow memory access,
but they report an error indicating that the MCU is in stop or wait mode. The BACKGROUND command
can be used to wake the MCU from wait mode and enter active background mode.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
30Freescale Semiconductor
Chapter 3 Modes of Operation
3.6Stop Modes
One of two stop modes is entered upon execution of a STOP instruction when STOPE in SOPT1 is set. In
any stop mode, the bus and CPU clocks are halted. The MCG module can be configured to leave the
reference clocks running. See Chapter 9, “Multi-Purpose Clock Generator (S08MCGV1),” for more
information.
Some HCS08 devices that are designed for low-voltage operation (1.8 to 3.6 V) also include stop1 mode.
The MC9S08JS16 series of MCUs do not include stop1 mode.
Table 3-1 shows all of the control bits that affect stop mode selection and the mode selected under various
conditions. The selected mode is entered following the execution of a STOP instruction.
Table 3-1. Stop Mode Selection
STOPEENBDM
0xxxStop modes disabled; illegal opcode reset if STOP
11xxStop3 with BDM enabled
10Both bits must be 1xStop3 with voltage regulator active
10Either bit a 00Stop3
10Either bit a 01Stop2
1
ENBDM is located in the BDCSCR which is only accessible through BDC commands, see Section 14.4.1.1,
“BDC Status and Control Register (BDCSCR).”
2
When in stop3 mode with BDM enabled, The S
enabled.
1
LVD ELVD S EPP D CSt o p M o de
instruction executed
will be near R
IDD
levels because internal clocks are
IDD
2
3.6.1Stop3 Mode
Stop3 mode is entered by executing a STOP instruction under the conditions shown in Tabl e 3- 1. The
states of all of the internal registers and logic, RAM contents, and I/O pin states are maintained.
Stop3 can be exited by asserting RESET, or by an interrupt from one of the following sources: the real-time
clock (RTC) interrupt, the USB resume interrupt, LVD, IRQ, KBI, or the SCI.
If stop3 is exited by the RESET pin, then the MCU is reset and operation will resume after taking the reset
vector. Exit by one of the internal interrupt sources results in the MCU taking the appropriate interrupt
vector.
3.6.1.1LVD Enabled in Stop Mode
The LVD system is capable of generating an interrupt or a reset when the supply voltage drops below the
LVD voltage. If the LVD is enabled in stop (LVDE and LVDSE bits in SPMSC1 both set) at the time the
CPU executes a STOP instruction, then the voltage regulator remains active during stop mode. If the user
attempts to enter stop2 with the LVD enabled for stop, the MCU will enter stop3 instead.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor31
Chapter 3 Modes of Operation
For the XOSC to operate with an external reference when RANGE in MCGC2 is set, the LVD must be left
enabled when entering stop3.
NOTE
To get low USB suspend current, before entering USB suspend mode, we
must set ERCLKEN and EREFSTEN in MCGC2, but leave LVD disabled
in stop3.
3.6.1.2Active BDM Enabled in Stop Mode
Entry into the active background mode from run mode is enabled if ENBDM in BDCSCR is set. This
register is described in Chapter 17, “Development Support.” If ENBDM is set when the CPU executes a
STOP instruction, the system clocks to the background debug logic remain active when the MCU enters
stop mode. Because of this, background debug communication remains possible. In addition, the voltage
regulator does not enter its low-power standby state but maintains full internal regulation. If the user
attempts to enter stop2 with ENBDM set, the MCU will enter stop3 instead.
Most background commands are not available in stop mode. The memory-access-with-status commands
do not allow memory access, but they report an error indicating that the MCU is in stop or wait mode. The
BACKGROUND command can be used to wake the MCU from stop and enter active background mode
if the ENBDM bit is set. After entering background debug mode, all background commands are available.
3.6.2Stop2 Mode
Stop2 mode is entered by executing a STOP instruction under the conditions as shown in Table 3- 1. Most
of the internal circuitry of the MCU is powered off in stop2, with the exception of the RAM. Upon entering
stop2, all I/O pin control signals are latched so that the pins retain their states during stop2.
Exit from stop2 is performed by asserting either wakeup pin: RESET or IRQ. When an application utilizes
the stop2 state, RESET or IRQ pin must be pre-configured as an input prior to entering stop2. There is a
direct analog connection from RESET or IRQ pad to the power management controller wakeup pin — if
configured as a GPIO output, it could prevent operation of stop2.
In addition, the RTC interrupt can wake the MCU from stop2, if enabled.
Upon wakeup from stop2 mode, the MCU starts up as from a power-on reset (POR):
•All module control and status registers are reset
•The LVD reset function is enabled and the MCU remains in the reset state if V
trip point (low trip point selected due to POR)
•The CPU takes the reset vector
In addition to the above, upon waking from stop2, the PPDF bit in SPMSC2 is set. This flag is used to
direct user code to go to a stop2 recovery routine. PPDF remains set and the I/O pin states remain latched
until a 1 is written to PPDACK in SPMSC2.
is below the LVD
DD
To maintain I/O states for pins that are configured as general-purpose I/O before entering stop2, the user
must restore the contents of the I/O port registers, which have been saved in RAM, to the port registers
MC9S08JS16 MCU Series Reference Manual, Rev. 4
32Freescale Semiconductor
Chapter 3 Modes of Operation
before writing to the PPDACK bit. If the port registers are not restored from RAM before writing to
PPDACK, then the pins will switch to their reset states when PPDACK is written.
For pins that are configured as peripheral I/O, the user must reconfigure the peripheral module that
interfaces to the pin before writing to the PPDACK bit. If the peripheral module is not enabled before
writing to PPDACK, the pins will be controlled by their associated port control registers when the I/O
latches are opened.
3.6.3On-Chip Peripheral Modules in Stop Modes
When the MCU enters any stop mode, system clocks to the internal peripheral modules are stopped. Even
in the exception case (ENBDM = 1), where clocks to the background debug logic continue to operate,
clocks to the peripheral systems are halted to reduce power consumption. Refer to Section 3.6.2, “Stop2
Mode,” and Section 3.6.1, “Stop3 Mode,” for specific information on system behavior in stop modes.
Table 3-2. Stop Mode Behavior
Mode
Peripheral
CPUOffStandby
RAMStandbyStandby
FlashOffStandby
Parallel Port RegistersOffStandby
MCGOffOptionally On
RTCOptionally on
SCIOffStandby
SPIOffStandby
MTIMOffStandby
TPMOffStandby
System Voltage RegulatorOffStandby
XOSCOffOptionally On
I/O PinsStates HeldStates Held
USB (SIE and PHY)OffOptionally On
USB 3.3 V RegulatorOffStandby
USB RAMStandbyStandby
CRCOffStandby
1
IREFSTEN set in MCGC1, else in standby.
2
RTCPS[3:0] in RTCSC does not equal 0 before entering stop, else off.
3
EREFSTEN set in MCGC2, else in standby. For high frequency range (RANGE in
MCGC2 set), the LVD must also be enabled in stop3.
4
USBEN in CTL is set and USBPHYEN in USBCTL0 is set, else off.
Stop2Stop3
2
Optionally on
1
2
3
4
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor33
Chapter 3 Modes of Operation
MC9S08JS16 MCU Series Reference Manual, Rev. 4
34Freescale Semiconductor
Chapter 4
Memory
4.1MC9S08JS16 Series Memory Map
Figure 4-1 shows the memory map for the MC9S08JS16 series. On-chip memory in the MC9S08JS16
series of MCUs consists of RAM, flash program memory for nonvolatile data storage, plus I/O and
control/status registers. The registers are divided into three groups:
•Direct-page registers (0x0000 through 0x007F)
•High-page registers (0x1800 through 0x185F)
•Nonvolatile registers (0xFFB0 through 0xFFBF)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor35
Chapter 4 Memory
DIRECT-PAGE REGISTERS
RAM
HIGH-PAGE REGISTERS
512 BYTES
0x0000
0x007F
0x0080
0x027F
0x1800
0x17FF
0x185F
0xFFFF
0x0280
MC9S08JS16
MC9S08JS16L
FLASH
16,384 BYTES
0x1860
UNIMPLEMENTED
0xC000
0xBFFF
UNIMPLEMENTED
USB Buffer RAM
0x195F
0x1960
(256 BYTES)
0x3160
0x315F
Bootloader ROM
(4096 BYTES)
0x2160
0x215F
UNIMPLEMENTED
(2048 BYTES)
MC9S08JS8
MC9S08JS8L
FLASH
8,192 BYTES
0xE000
RESERVED
8,192 BYTES
0xDFFF
DIRECT-PAGE REGISTERS
RAM
HIGH-PAGE REGISTERS
512 BYTES
0x0000
0x007F
0x0080
0x027F
0x1800
0x17FF
0x185F
0xFFFF
0x0280
0x1860
UNIMPLEMENTED
0xC000
0xBFFF
UNIMPLEMENTED
USB Buffer RAM
0x195F
0x1960
(256 BYTES)
0x3160
0x315F
Bootloader ROM
(4096 BYTES)
0x2160
0x215F
UNIMPLEMENTED
(2048 BYTES)
4.1.1Reset and Interrupt Vector Assignments
Table 4-1 shows address assignments for reset and interrupt vectors. The vector names shown in this table
are the labels used in the Freescale-provided equate file for the MC9S08JS16 series. For more details about
resets, interrupts, interrupt priority, and local interrupt mask controls, refer to Chapter 5, “Resets,
Interrupts, and System Configuration.”
Figure 4-1. MC9S08JS16 Series Memory Map
36Freescale Semiconductor
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Table 4-1. Reset and Interrupt Vectors
Chapter 4 Memory
Address
(High/Low)
0xFFC0:0xFFC1
to
0xFFC2:FFC3
0xFFC4:FFC5RTCVrtc
0xFFC6:FFC7Unused vector space—
0xFFC8:FFC9Unused vector space—
0xFFCA:FFCBMTIMVmtim
0xFFCC:FFCDKBIVkeyboard
0xFFCE:FFCF
to
0xFFD2:FFD3
0xFFD4:FFD5SCI TransmitVscitx
0xFFD6:FFD7SCI ReceiveVscirx
0xFFD8:FFD9SCI ErrorVscierr
0xFFDA:FFDB
to
0xFFE6:FFE7
Vector Vector Name
Unused vector space
Unused vector space—
Reserved—
1
—
0xFFE8:FFE9TPM OverflowVtpmovf
0xFFEA:FFEBTPM Channel 1Vtpmch1
0xFFEC:FFEDTPM Channel 0Vtpmch0
0xFFEE:FFEFUnused vector space—
0xFFF0:FFF1USB StatusVusb
0xFFF2:FFF3Unused vector space—
0xFFF4:FFF5SPIVspi
0xFFF6:FFF7MCG Loss of LockVlol
0xFFF8:FFF9Low Voltage DetectVlvd
0xFFFA:FFFBIRQVirq
0xFFFC:FFFDSWIVswi
0xFFFE:FFFFResetVreset
1
Unused vector space is available for use as general flash memory. However, other
devices in the S08 family of MCUs may use these locations as interrupt vectors.
Therefore, care must be taken when using these locations if the code will be
ported to other MCUs.
4.2Register Addresses and Bit Assignments
The registers in the MC9S08JS16 series are divided into these three groups:
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor37
Chapter 4 Memory
•Direct-page registers are located in the first 128 locations in the memory map, so they are
accessible with efficient direct addressing mode instructions.
•High-page registers are used much less often, so they are located above 0x1800 in the memory
map. This leaves more room in the direct-page for more frequently used registers and variables.
•The nonvolatile register area consists of a block of 16 locations in flash memory at
0xFFB0–0xFFBF.
Nonvolatile register locations include:
— Three values that are loaded into working registers at reset
— An 8-byte backdoor comparison key that optionally allows a user to gain controlled access to
secure memory
Because the nonvolatile register locations are flash memory, they must be erased and programmed
like other flash memory locations.
Direct-page registers can be accessed with efficient direct addressing mode instructions. Bit manipulation
instructions can be used to access any bit in any direct-page register. Tab le 4-2 is a summary of all
user-accessible direct-page registers and control bits.
The direct-page registers in Table 4-2 can use the more efficient direct addressing mode that requires only
the lower byte of the address. Because of this, the lower byte of the address in column one is shown in bold
text. In Table 4-3 and Ta ble 4-4 the whole address in column one is shown in bold. In Tab l e 4- 2, Table 4-3,
and Tabl e 4-4, the register names in column two are shown in bold to set them apart from the bit names to
the right. Cells that are not associated with named bits are shaded. A shaded cell with a 0 indicates this
unused bit always reads as a 0. Shaded cells with dashes indicate unused or reserved bit locations that could
read as 1s or 0s.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
38Freescale Semiconductor
Table 4-2. Direct-Page Register Summary (Sheet 1 of 3)
Table 4-2. Direct-Page Register Summary (Sheet 3 of 3)
Chapter 4 Memory
Address
0x0070EPCTL3000EPCTLDISEPRXENEPTXENEPSTALLEPHSHK
0x0071EPCTL4
0x0072EPCTL5
0x0073EPCTL6
0x0074–
0x007F
Register
Name
Reserved
Bit 7654321Bit 0
000EPCTLDISEPRXENEPTXENEPSTALLEPHSHK
000EPCTLDISEPRXENEPTXENEPSTALLEPHSHK
000EPCTLDISEPRXENEPTXENEPSTALLEPHSHK
————————
High-page registers, as shown in Table 4-3, are accessed much less often than other I/O and control
registers so they have been located outside the direct addressable memory space, starting at 0x1800.
NOTE
The MCG factory trim values will automatically be loaded into the 0x180C
and 0x180D registers after any reset.
Table 4-3. High-Page Register Summary (Sheet 1 of 2)
AddressRegister NameBit 7654321Bit 0
0x1800SRSPORPINCOPILOPILADLOCLVD—
0x1801 SBDFR
0x1802SOPT1COPTSTOPE10BLMSSBKGDPERSTPE
0x1803SOPT2COPCLKSCOPW
0x1804Reserved
0x1805Reserved————————
0x1806SDIDH
0x1807SDIDLID7ID6ID5ID4ID3ID2ID1ID0
0x1808Reserved
0x1809SPMSC1LV W FLV WA CKLVW IELV DR ELVD S ELV DE
0x180ASPMSC2
0x180BReserved————————
0x180CReserved for
storage of FTRIM
0x180DReserved for
storage of
MCGTRIM
0x180EFPROTD
0x180FSIGNATURESIGNATURE semaphore
0x1810DBGCAHBit 1514131211109Bit 8
0x1811DBGCALBit 7654321Bit 0
0x1812DBGCBHBit 1514131211109Bit 8
0x1813DBGCBLBit 7654321Bit 0
0x1814DBGFHBit 1514131211109Bit 8
0x1815DBGFLBit 7654321Bit 0
0x1816DBGCDBGENARMTAGBRKENRWARWAENRWBRWBEN
0x1817DBGTTRGSELBEGIN
0x1818DBGSAFBFARMF
0000000BDFR
000SPIFE00
————————
————ID11ID10ID9ID8
————————
00
00LVDVLVWVPPDFPPDACK0PPDC
0000000FTRIM
TRIM
———————Bit 0
00TRG3TRG2TRG1TRG0
0CNT3CNT2CNT1CNT0
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor41
Chapter 4 Memory
Table 4-3. High-Page Register Summary (Sheet 2 of 2)
Nonvolatile flash registers, as shown in Table 4-4, are located in the flash memory. These registers include
an 8-byte backdoor key that optionally can be used to gain access to secure memory resources. During
reset events, the contents of NVPROT and NVOPT in the nonvolatile register area of the flash memory
are transferred into corresponding FPROT and FOPT working registers in the high-page registers to
control security and block protection options.
The factory MCG trim value is stored in the flash information row (IFR1) and will be loaded into the
MCGTRM and MCGSC registers after any reset. The internal reference trim values stored in flash, TRIM
and FTRIM, can be programmed by third party programmers and must be copied into the corresponding
MCG registers by user code to override the factory trim.
NOTE
When the MCU is in active BDM, the trim value in the IFR will not be
loaded, the MCGTRM register will reset to 0x80 and the FTRIM bit in the
MCGSC register will be reset to 0.
1. IFR — Nonvolatile information memory that can be only accessed during production test. During production test, system
initialization, configuration and test information is stored in the IFR. This information cannot be read or modified in normal user
or background debug modes.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
42Freescale Semiconductor
Chapter 4 Memory
Table 4-4. Nonvolatile Register Summary
AddressRegister NameBit 7654321Bit 0
0xFFAEReserved for storage
of FTRIM
0xFFAFReserved for storage
of MCGTRIM
0xFFB0–
0xFFB7
0xFFB8Flash Block Checksum High Byte
0xFFB9Flash Block Checksum Low Byte
0xFFBAChecksum Bypass
0xFFBBReserved for user’s
0xFFBCReserved for user’s
0xFFBDNVPROTFPS7FPS6FPS5FPS4FPS3FPS2FPS1FPDIS
0xFFBEFlash Partial Erase semaphore
0xFFBFNVOPTKEYENFNORED
NVBACKKEY
storage of data
storage of data
0000000FTRIM
TRIM
8-Byte Comparison Key
User Data
User Data
0000SEC01SEC00
Provided the key enable (KEYEN) bit is 1, the 8-byte comparison key can be used to temporarily
disengage memory security. This key mechanism can be accessed only through user code running in
secure memory. (A security key cannot be entered directly through background debug commands.)This
security key can be disabled completely by programming the KEYEN bit to 0. If the security key is
disabled, the only way to disengage security is by mass erasing the flash if needed (normally through the
background debug interface) and verifying that flash is blank. To avoid returning to secure mode after the
next reset, program the security bits (SEC01:SEC00) to the unsecured state (1:0).
0xFFBB and 0xFFBC are used to store user data, such as the user’s MCG trimmed value.
4.3RAM (System RAM)
The MC9S08JS16 series devices include static RAM. The locations in RAM below 0x0100 can be
accessed using the more efficient direct addressing mode, and any single bit in this area can be accessed
with the bit manipulation instructions (BCLR, BSET, BRCLR, and BRSET). Locating the most frequently
accessed program variables in this area of RAM is preferred.
The RAM retains data when the MCU is in low-power wait, stop2, or stop3 mode. At power-on, the
contents of RAM are uninitialized. RAM data is unaffected by any reset provided that the supply voltage
does not drop below the minimum value for RAM retention.
For compatibility with older M68HC05 MCUs, the HCS08 resets the stack pointer to 0x00FF. In the
MC9S08JS16 series, re-initialize the stack pointer to the top of the RAM so the direct-page RAM can be
used for frequently accessed RAM variables and bit-addressable program variables. Include the following
2-instruction sequence in your reset initialization routine (where RamLast is equated to the highest address
of the RAM in the Freescale-provided equate file).
LDHX #RamLast+1 ;point one past RAM
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor43
Chapter 4 Memory
TXS ;SP<-(H:X-1)
When security is enabled, the RAM is considered a secure memory resource and is not accessible through
BDM or through code executing from non-secure memory. See Section 4.7, “Security,” for a detailed
description of the security feature.
4.4USB RAM
USB RAM is discussed in detail in Chapter 15, “Universal Serial Bus Device Controller (S08USBV1).”
4.5Bootloader ROM
The Bootloader ROM holds code that is used to erase and program flash memory. The Bootloader ROM
provides quick and reliable flash erase and program procedures from a USB host such as a personal
computer (PC).
Freescale provides a PC GUI (Graphic User Interface) that can communicate with bootloader in ROM via
USB interface (PC as a host USB device).
Working with the PC GUI, the user can:
•Mass erase entire flash array
•Partial erase flash array— erase all flash blocks except for the first 1 KB of flash
•Program flash
•Reset MCU
NOTE
If bootloader function is used, the MCU supply voltage must be above 4 V.
The internal USB 3.3 V voltage regulator will be enabled when entering
bootloader mode.
NOTE
USB bootloader requires an external oscillator which must be at 2 MHz,
4 MHz, 6 MHz, 8 MHz, 12 MHz, or 16 MHz. Bootloader code can identify
the external oscillator automatically. If the bootloader is not used, there are
no such restrictions.
NOTE
The USB descriptors for bootloader are fixed: VID is 0x15A2, PID is
0x0038. The user’s application can use its own descriptors.
4.5.1External Signal Description
The BLMS pin of bootloader ROM decides whether the MCU will enter bootloader mode directly during
power-on reset. This pin is only examined during Power-On Reset (POR).
The signal properties of bootrom are shown in Table 4-5 .
MC9S08JS16 MCU Series Reference Manual, Rev. 4
44Freescale Semiconductor
Chapter 4 Memory
Table 4-5. Signal Properties
SignalFunctionI/O
BLMSBootloader mode selection I
4.5.2Modes of Operation
After any reset, the MCU jumps to bootloader ROM address, where several qualification factors are
examined to determine whether to jump to the bootloader code or to the user code. The bootloader ROM
can be accessed in bootloader mode or user mode. This section describes the valid operations and
protection mechanism in these two modes.
The following four items will be examined after each reset of the MCU.
•BLMS pin
•SIGNATURE semaphore byte
•Flash block CRC checksum
•CRC BYPASS byte
4.5.2.1Bootloader Mode
Bootloader mode can be entered in the following 4 conditions:
1. When BLMS pin is low and BKGD/MS is not pulled low during power-on-reset (POR), the
bootloader mode is entered directly with no other qualifications.
2. When BLMS pin and BKGD/MS are high during power-on-reset (POR), a CHECKSUM BYPASS
flash location is examined. If it is not equal to 0x00 or 0xFF, then the bootloader mode is entered.
3. When BLMS pin and BKGD/MS are high during power-on-reset (POR), a CHECKSUM BYPASS
flash location is examined. If it is equal to 0xFF, a flash CRC is calculated for the flash array and
compared with a FLASHCRC 16-bit word. If the result does not match, then the bootloader mode
is entered.
4. After a reset (other than a power-on reset), the SIGNATURE semaphore byte is examined. If it is
equal to 0xC3, then the bootloader mode is entered.
4.5.2.2User mode
User mode can be entered in the following 3 conditions:
1. When BLMS pin and BKGD/MS are high during power-on-reset (POR), and the CHECKSUM
BYPASS byte is equal to 0x00, the user mode is entered.
2. When BLMS pin and BKGD/MS are high during power-on-reset (POR), and the CHECKSUM
BYPASS byte is equal to 0xFF, a flash CRC is calculated for the flash array and compared with a
FLASHCRC 16-bit word. If the result matches, the user mode is entered.
3. When a reset occurs (other than a power-on reset), if the SIGNATURE semaphore is not equal to
0xC3, the user mode is entered.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor45
Chapter 4 Memory
Flash Block
0xXXXX
0xFFFF
0xFF00
0xFEFF
Flash Block
Vectors
Flash Block Checksum
0xFFB9
0xFFB8
0xFFB7
Other Registers
and
0xXXXX + 0x400
0xXXXX + 0x3FF
(1,024 bytes)
Flash Block
Checksum Bypass
0xFFBA
0xFFBB
(Some bytes in the last flash page are skipped)
Flash block Checksum Range
0xXXXX + 0x400
0xFFFF
Flash Block
0xFFBD
0xFFBE
0xFFBF
Flash Partial Erase semaphore
4.5.2.3Active Background Mode and Bootloader Mode Arbitrage
During POR, if both BKGD/MS and BLMS pins are low, active background mode is entered.
4.5.2.4Disable Flash Protection
The protected flash section can be disabled by back-to-back writes of 0x55 and 0xAA to the address of
FPROTD (flash protection defeat register), then setting bit FPDIS = 1 in FPROT.
4.5.3Flash Memory Map
The general flash memory map of bootloader is shown in Figure 4-2.
•Flash block checksum stores in 0xFFB8 (checksum high byte) and 0xFFB9 (checksum low byte)
•Checksum bypass information stores in 0xFFBA
•Flash partial erase semaphore stores in 0xFFBE
46Freescale Semiconductor
Figure 4-2. General Flash Memory Map
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 4 Memory
The value of the checksum bypass is programed by the user. This value is checked by bootloader software
only after power-on reset. The checksum bypass value in this byte indicates if the flash block checksum
will be calculated or not, and if the flash sector whose address is behind the first 1 KB of flash is used as
EEPROM. When the value is other than 0x00 and 0xFF, the calculation of flash block checksum is
bypassed and the code jumps to bootloader entry. When the value is 0xFF, the flash block checksum will
be calculated after power-on reset. When the value is 0x00, the calculation of flash block checksum is
bypassed, the MCU jumps to user code entry and the flash sectors whose addresses are behind the first
1 KB of flash will be used as EEPROM.
The value of this byte is 0xFF when chip is shipped from Freescale.
NOTE
The first 1 KB segment of flash array is not in the CRC checksum
calculation so that users can deploy this area as user EEPROM. If users need
to use other flash locations out of the first 1 KB segment, they need to
re-calculate the CRC and re-program the CRC checksum to ensure reliable
entry after a POR.
4.5.4Bootloader Operation
This section describes the bootloader mechanism and bootloader flow chart.
The bootloader software is located in bootloader ROM. User can perform flash erasing and programming
when:
•Bootloader mode is entered
•Flash block checksum that has been calculated and flash block checksum do not match after
power-on reset
•SIGNATURE value in register matches
4.5.4.1Flash Block Checksum
Upon power-on reset (POR), if BLMSS = 0 and the value of checksum bypass is 0xFF, the bootloader will
calculate the flash checksum. The checksum is calculated from the end of first 1 KB of the flash to 0xFFFF
(some bytes in last flash page are skipped). The first 1 KB of flash is not included in the checksum to allow
users to use it as pseudo EEPROM in this area. The calculated checksum are verified with a checksum
written to the two bytes of the flash (FLASHCRC). If the checksum matches, the previous bootloader
operation was successful and the MCU jumps to the user code entry and starts to execute user code. If the
checksum does not match, it jumps to bootloader entry to wait for commands.
Flash block checksum calculation uses 16-bit CRC.
JS16 flash block checksum range is 0xC400–0xFFAD and 0xFFC0–0xFFFF, JS8 flash block checksum
range is 0xE400–0xFFAD and 0xFFC0–0xFFFF.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor47
Chapter 4 Memory
4.5.4.2SIGNATURE Semaphore Register
Upon regular reset, the bootloader verifies SIGNATURE semaphore register. If SIGNATURE = 0xC3, the
MCU jumps to bootloader entry to wait for commands. If not, it jumps to the user code entry and starts to
execute user code.
Users are required to provide a mechanism in their application code to set the SIGNATURE to 0xC3 and
initiate a reset if they want to re-enter bootloader mode after a successful user code has been programmed.
Alternatively, BKGD mode can be entered and SIGNATURE can be updated using BDM commands and
reset initiated with BKGD pin high.
4.5.4.3Flash Partial Erase Semaphore
The value of flash partial erase is programmed by the user. Only when flash partial erase is programmed
to 0x00, can the partial erase flash array command be supported by bootloader.
The value of this byte is 0xFF when the device is shipped from Freescale.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
48Freescale Semiconductor
4.5.4.4Flow Chart
Start
YES
YES
Power-on reset?
Jump to bootrom
BLMSS=1?
YES
YES
Bootloader Mode entered
NO
Regular reset
SIGNATURE
=0xC3?
NO
Flash checksum
match?
NO
NO
Jump to user code entry,
User code executed.
YES
Jump to bootloader entry
CMD=Mass erase?
NO
NO
Initial bus frequency to
24 MHz,
Initial USB
Waiting for CMD
CMD=Program Flash?
CMD=Reset?
Put Pass/Fail on stack
YES
Put Pass/Fail on stack
YES
NO
Chang SIGNATURE=0xC3
Chang SIGNATURE=0xC3
Clear SIGNATURE
Checksum bypass
=0xFF?
YES
NO
Calculate Flash
block checksum
Checksum bypass
=0x00?
NO
Jump to user code entry,
User code executed.
YES
CMD=Partial erase?
NO
YES
Put Pass/Fail on stack
Note:
Only when FlASH PARTIAL ERASE=0x00,
this command is valid.
Chapter 4 Memory
Figure 4-3. Bootloader Flow Chart
Freescale Semiconductor49
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 4 Memory
4.6Flash Memory
The flash memory is primarily for program storage. In-circuit programming allows the operating program
to be loaded into the flash memory after final assembly of the application product. It is possible to program
the entire array through the single-wire background debug interface. Because no special voltages are
needed for flash erase and programming operations, in-application programming is also possible through
other software-controlled communication paths. For a more detailed discussion of in-circuit and
in-application programming, refer to the HCS08 Family Reference Manual, Volume I, Freescale
Semiconductor document order number HCS08RMv1.
•Command interface for fast program and erase operation
•Up to 100,000 program/erase cycles at typical voltage and temperature
•Flexible block protection
•Security feature for flash and RAM
•Auto power-down for low-frequency read accesses
4.6.2Program and Erase Time
Before any program or erase command can be accepted, the flash clock divider register (FCDIV) must be
written to set the internal clock for the flash module to a frequency (f
(see Section 4.8.1, “Flash Clock Divider Register (FCDIV)”). This register can be written only once, so
normally this write is done during reset initialization. FCDIV cannot be written if the access error flag,
FACCERR in FSTAT, is set. The user must ensure that FACCERR is not set before writing to the FCDIV
register. One period of the resulting clock (1/f
) is used by the command processor to time program
FCLK
and erase pulses. An integer number of these timing pulses is used by the command processor to complete
a program or erase command.
Table 4-6 shows program and erase time. The bus clock frequency and FCDIV determine the frequency of
FCLK (f
cycles of FCLK and as an absolute time for the case where t
). The time for one cycle of FCLK is t
FCLK
FCLK
=1/f
FCLK
FCLK
=5μs. Program and erase time shown
include overhead for the command state machine and enabling and disabling of program and erase
voltages.
) between 150 kHz and 200 kHz
FCLK
. The times are shown as a number of
MC9S08JS16 MCU Series Reference Manual, Rev. 4
50Freescale Semiconductor
Chapter 4 Memory
Table 4-6. Program and Erase Time
ParameterCycles of FCLKTime if FCLK = 200 kHz
Byte program 945 μs
Byte program (burst) 420 μs
Page erase 400020 ms
Mass erase 20,000100 ms
1
Excluding start/end overhead
1
4.6.3Program and Erase Command Execution
The steps for executing any of the commands are listed below. The FCDIV register must be initialized and
any error flag must be cleared before beginning command execution. The command execution steps are:
1. Write a data value to an address in the flash array. The address and data information from this write
is latched into the flash interface. This write is a required first step in any command sequence. For
erase and blank check commands, the value of the data is not important. For page erase commands,
the address may be any address in the 512-byte page of flash to be erased. For mass erase and blank
check commands, the address can be any address in the flash memory. Whole pages of 512 bytes
are the smallest block of flash that can be erased.
NOTE
Do not program any byte in the flash more than once after a successful erase
operation. Reprogramming bits to a byte which is already programmed is
not allowed without first erasing the page in which the byte resides or mass
erasing the entire flash memory. Programming without first erasing may
disturb data stored in the flash.
2. Write the command code for the desired command to FCMD. The five valid commands are blank
check (0x05), byte program (0x20), burst program (0x25), page erase (0x40), and mass erase
(0x41). The command code is latched into the command buffer.
3. Write a 1 to the FCBEF bit in FSTAT to clear FCBEF and launch the command (including its
address and data information).
A partial command sequence can be aborted manually by writing a 0 to FCBEF any time after the write to
the memory array and before writing the 1 that clears FCBEF and launches the complete command.
Aborting a command in this way sets the FACCERR access error flag which must be cleared before
starting a new command.
A strictly monitored procedure must be obeyed or the command will not be accepted. This minimizes the
possibility of any unintended change to the flash memory contents. The command complete flag (FCCF)
indicates when a command is complete. The command sequence must be completed by clearing FCBEF
to launch the command. Figure 4-4 is a flowchart for executing all of the commands except for burst
programming. The FCDIV register must be initialized before using any flash commands.This must be
done only once following a reset.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor51
Chapter 4 Memory
START
WRITE COMMAND TO FCMD
NO
YES
FPVIOL OR
WRITE 1 TO FCBEF
TO LAUNCH COMMAND
AND CLEAR FCBEF
(2)
1
0
FCCF?
(3)
ERROR EXIT
DONE
(2)
Wait at least four bus cycles
before checking FCBEF or FCCF.
0
FACCERR OR FPVIOL?
CLEAR ERRORS
FACCERR?
WRITE TO FCDIV
(1)
(1)
Required only once
after reset.
PROGRAM AND
ERASE FLOW
WRITE TO FLASH TO BUFFER
ADDRESS AND DATA
0
FCBEF?
(3)
During this time, avoid actions
that woudl result in an
FACCERR error.
Such as executing a
STOP instruction or writing
to the flash.
Reads of the flash during
program or erase are
ignored and invalid data
is returned.
1
Figure 4-4. Flash Program and Erase Flowchart
4.6.4Burst Program Execution
The burst program command is used to program sequential bytes of data in less time than would be
required using the standard program command. This is possible because the high voltage to the flash array
does not need to be disabled between program operations. Ordinarily, when a program or erase command
is issued, an internal charge pump associated with the flash memory must be enabled to supply high
voltage to the array. Upon completion of the command, the charge pump is turned off. When a burst
program command is issued, the charge pump is enabled and then remains enabled after completion of the
burst program operation if these two conditions are met:
•The next burst program command has been queued before the current program operation is
52Freescale Semiconductor
completed.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 4 Memory
1
0
FCBEF?
START
WRITE TO Flash
TO BUFFER ADDRESS AND DATA
WRITE COMMAND TO FCMD
NO
YES
FPVIOL OR
WRITE 1 TO FCBEF
TO LAUNCH COMMAND
AND CLEAR FCBEF
(2)
NO
YES
NEW BURST COMMAND?
1
0
FCCF?
(3)
ERROR EXIT
DONE
(2)
Wait at least four bus cycles
before checking FCBEF or FCCF.
FACCERR?
WRITE TO FCDIV
(1)
(1)
Required only once
after reset.
BURST PROGRAM
FLOW
(3)
During this time, avoid actions
that woudl result in an
FACCERR error.
Such as executing a
STOP instruction or writing
to the flash.
Reads of the flash during
program or erase are
ignored and invalid data
is returned.
0
FACCERR OR FPVIOL?
CLEAR ERRORS
•The next sequential address selects a byte on the same physical row as the current byte being
programmed. A row of flash memory consists of 64 bytes. A byte within a row is selected by
addresses A5 through A0. A new row begins when addresses A5 through A0 are all zero.
The first byte of a series of sequential bytes being programmed in burst mode will take the same amount
of time to program as a byte programmed in standard mode. Subsequent bytes will program in the burst
program time provided that the conditions above are met. If the next sequential address is the beginning
of a new row, the program time for that byte will be the standard time instead of the burst time. This is
because the high voltage to the array must be disabled and then enabled again. If a new burst command
has not been queued before the current command completes, then the charge pump will be disabled and
high voltage will be removed from the array.
Figure 4-5. Flash Burst Program Flowchart
Freescale Semiconductor53
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 4 Memory
4.6.5Access Errors
An access error occurs whenever the command execution protocol is violated.
Any of the following specific actions will cause the access error flag (FACCERR) in FSTAT to be set.
FACCERR must be cleared by writing a 1 to FACCERR in FSTAT before any command can be processed.
•Writing to a flash address before the internal flash clock frequency has been set by writing to the
FCDIV register
•Writing to a flash address while FCBEF is not set (A new command cannot be started until the
command buffer is empty.)
•Writing a second time to a flash address before launching the previous command (There is only
one write to flash for every command.)
•Writing a second time to FCMD before launching the previous command (There is only one write
to FCMD for every command.)
•Writing to any flash control register other than FCMD after writing to a flash address
•Writing any command code other than the five allowed codes (0x05, 0x20, 0x25, 0x40, and 0x41)
to FCMD
•Accessing (read or write) any flash control register other than the write to FSTAT (to clear FCBEF
and launch the command) after writing the command to FCMD
•The MCU enters stop mode while a program or erase command is in progress (The command is
aborted.)
•Writing the byte program, burst program, or page erase command code (0x20, 0x25, or 0x40) with
a background debug command while the MCU is secured (The background debug controller can
only do blank check and mass erase commands when the MCU is secure.)
•Writing 0 to FCBEF to cancel a partial command
4.6.6Flash Block Protection
The block protection feature prevents the protected region of flash from program or erase changes. Block
protection is controlled through the flash protection register (FPROT). When enabled, block protection
begins at any 512 byte boundary below the last address of flash, 0xFFFF. (See Section 4.8.4, “Flash
Protection Register (FPROT and NVPROT).”)
After exit from reset, FPROT is loaded with the contents of the NVPROT location that is in the nonvolatile
register block of the flash memory. FPROT cannot be changed directly from application software so a
runaway program cannot alter the block protection settings. Because NVPROT is within the last 512 bytes
of flash memory, if any amount of memory is protected, NVPROT is itself protected and cannot be altered
(intentionally or unintentionally) by the application software. FPROT can be written through background
debug commands which allows a way to erase and reprogram a protected flash memory.
The block protection mechanism is illustrated below. The FPS bits are used as the upper bits of the last
address of unprotected memory. This address is formed by concatenating FPS7:FPS1 with logic 1 bit as
shown. For example, to protect the last 1536 bytes of memory (addresses 0xFA00 through 0xFFFF), the
FPS bits must be set to 1111 100, which results in the value 0xF9FF as the last address of unprotected
memory. In addition to programming the FPS bits to the appropriate value, FPDIS (bit 0 of NVPROT)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
54Freescale Semiconductor
Chapter 4 Memory
FPS7 FPS6 FPS5 FPS4FPS3 FPS2 FPS1
A15A14A13A12A11A10A9A81A7 A6 A5 A4 A3 A2 A1 A0
11111111
must be programmed to logic 0 to enable block protection. Therefore the value 0xF8 must be programmed
into NVPROT to protect addresses 0xFA00 through 0xFFFF.
Figure 4-6. Block Protection Mechanism
One use for block protection is to block-protect an area of flash memory for a bootloader program. This
bootloader program then can be used to erase the rest of the flash memory and reprogram it. Because the
bootloader is protected, it remains intact even if MCU power is lost in the middle of an erase and
reprogram operation.
4.6.7Flash Block Protection Disabled
Protected flash section can be disabled by back to back write 0x55 and 0xAA to the address of FPROTD
(flash protection defeat register) first, then setting bit FPDIS = 1 in FPROT.
4.6.8Vector Redirection
Whenever any block protection is enabled, the reset and interrupt vectors will be protected. Vector
redirection allows users to modify interrupt vector information without unprotecting bootloader and reset
vector space. Vector redirection is enabled by programming the FNORED bit in the NVOPT register
located at address 0xFFBF to zero. For redirection to occur, at least some portion but not all of the flash
memory must be block protected by programming the NVPROT register located at address 0xFFBD. All
of the interrupt vectors (memory locations 0xFFC0–0xFFFD) are redirected, though the reset vector
(0xFFFE:FFFF) is not.
For example, if 512 bytes of flash are protected, the protected address region is from 0xFE00 through
0xFFFF. The interrupt vectors (0xFFC0–0xFFFD) are redirected to the locations 0xFDC0–0xFDFD. Now,
if a TPM1 overflow interrupt is taken for instance, the values in the locations 0xFDE0:FDE1 are used for
the vector instead of the values in the locations 0xFFE0:FFE1. This allows the user to reprogram the
unprotected portion of the flash with new program code including new interrupt vector values while
leaving the protected area, which includes the default vector locations, unchanged.
4.7Security
The MC9S08JS16 series include circuitry to prevent unauthorized access to the contents of flash and RAM
memory. When security is engaged, flash and RAM are considered secure resources. Direct-page registers,
high-page registers, and the background debug controller are considered unsecured resources. Programs
executing within secure memory have normal access to any MCU memory locations and resources.
Attempts to access a secure memory location with a program executing from an unsecured memory space
or through the background debug interface are blocked (writes are ignored and reads return all 0s).
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor55
Chapter 4 Memory
Security is engaged or disengaged based on the state of two nonvolatile register bits (SEC01:SEC00) in
the FOPT register. During reset, the contents of the nonvolatile location NVOPT are copied from flash
memory into the working FOPT register in high-page register space. A user engages security by
programming the NVOPT location which can be done at the same time the flash memory is programmed.
The 1:0 state disengages security and the other three combinations engage security. Notice the erased state
(1:1) makes the MCU secure. During development, whenever the flash is erased, program the SEC00 bit
to 0 in NVOPT immediately so SEC01:SEC00 = 1:0. This allows the MCU to remain unsecured after a
subsequent reset.
The on-chip debug module cannot be enabled while the MCU is secure. The separate background debug
controller can still be used for background memory access commands of unsecured resources.
A user can choose to allow or disallow a security unlocking mechanism through an 8-byte backdoor
security key. If the nonvolatile KEYEN bit in NVOPT/FOPT is 0, the backdoor key is disabled and there
is no way to disengage security without completely erasing all flash locations. If KEYEN is 1, a secure
user program can temporarily disengage security by:
1. Writing 1 to KEYACC in the FCNFG register. This makes the flash module interpret writes to the
backdoor comparison key locations (NVBACKKEY through NVBACKKEY+7) as values to be
compared against the key rather than as the first step in a flash program or erase command.
2. Writing the user-entered key values to the NVBACKKEY through NVBACKKEY+7 locations.
These writes must be done in order starting with the value for NVBACKKEY and ending with
NVBACKKEY+7. STHX must not be used for these writes because these writes cannot be done
on adjacent bus cycles. User software normally gets the key codes from outside the MCU system
through a communication interface such as a serial I/O.
3. Writing 0 to KEYACC in the FCNFG register. If the 8-byte key just written matches the key stored
in the flash locations, SEC01:SEC00 are automatically changed to 1:0 and security will be
disengaged until the next reset.
The security key can be written only from secure memory (RAM or flash), so it cannot be entered through
background commands without the cooperation of a secure user program.
The backdoor comparison key (NVBACKKEY through NVBACKKEY+7) is located in flash memory
locations of the nonvolatile register space, so users can program these locations exactly as they program
any other flash memory location. The nonvolatile registers are in the same 512-byte block of flash as the
reset and interrupt vectors, so block protecting that space also block-protects the backdoor comparison
key. Block-protect cannot be changed from user application programs, so if the vector space is
block-protected, the backdoor security key mechanism cannot permanently change the block-protect,
security settings, or the backdoor key.
Security can always be disengaged through the background debug interface by taking these steps:
1. Disable any block protections by writing FPROT. In MC9S08JS16 series, FPROT can be changed
when FPROTD is set.
2. Mass erase flash if necessary.
3. Blank check flash. Provided flash is completely erased, security is disengaged until the next reset.
To avoid returning to secure mode after the next reset, program NVOPT so SEC01:SEC00 = 1:0.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
56Freescale Semiconductor
Chapter 4 Memory
4.8Flash Registers and Control Bits
The flash module has nine 8-bit registers in the high-page register space, twolocations (NVOPT,
NVPROT) in the nonvolatile register space in flash memory which are copied into corresponding
high-page control registers at reset. There is also an 8-byte comparison key in flash memory. Refer to
Table 4-3 and Tabl e 4-4 for the absolute address assignments for all flash registers. This section refers to
registers and control bits only by their names. A Freescale-provided equate or header file normally is used
to translate these names into the appropriate absolute addresses.
4.8.1Flash Clock Divider Register (FCDIV)
Bit 7 of this register is a read-only status flag. Bits 6 through 0 may be read at any time but can be written
only one time. Before any erase or programming operations are possible, write to this register to set the
frequency of the clock for the nonvolatile memory system within acceptable limits.
76543210
RDIVLD
W
Reset00000000
PRDIV8DIV5DIV4DIV3DIV2DIV1DIV0
= Unimplemented or Reserved
Figure 4-7. Flash Clock Divider Register (FCDIV)
Table 4-7. FCDIV Register Field Descriptions
FieldDescription
7
DIVLD
6
PRDIV8
5:0
DIV[5:0]
Divisor Loaded Status Flag — When set, this read-only status flag indicates that the FCDIV register has been
written since reset. Reset clears this bit and the first write to this register causes this bit to become set regardless
of the data written.
0 FCDIV has not been written since reset; erase and program operations disabled for flash memory.
1 FCDIV has been written since reset; erase and program operations enabled for flash memory.
Prescale (Divide) Flash Clock by 8
0 Clock input to the flash clock divider is the bus rate clock.
1 Clock input to the flash clock divider is the bus rate clock divided by 8.
Divisor for Flash Clock Divider — The flash clock divider divides the bus rate clock (or the bus rate clock
divided by 8 if PRDIV8 = 1) by the value in the 6-bit DIV5:DIV0 field plus one. The resulting frequency of the
internal flash clock must fall within the range of 200 kHz to 150 kHz for proper flash operations. Program/Erase
timing pulses are one cycle of this internal flash clock which corresponds to a range of 5 μs to 6.7 μs. The
automated programming logic uses an integer number of these pulses to complete an erase or program
operation. See Equation 4-1, Equation 4-2, and Ta bl e 4 - 7 .
if PRDIV8 = 0 — f
FCLK
= f
÷ ([DIV5:DIV0] + 1)Eqn. 4-1
Bus
if PRDIV8 = 1 — f
FCLK
= f
÷ (8 × ([DIV5:DIV0] + 1))Eqn. 4-2
Bus
Table 4-8 shows the appropriate values for PRDIV8 and DIV5:DIV0 for selected bus frequencies.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor57
Chapter 4 Memory
Table 4-8. Flash Clock Divider Settings
f
Bus
24 MHz114200 kHz5 μs
20 MHz112192.3 kHz5.2 μs
10 MHz049200 kHz5 μs
8 MHz039200 kHz5 μs
4 MHz019200 kHz5 μs
2 MHz09200 kHz5 μs
1 MHz04200 kHz5 μs
200 kHz00200 kHz5 μs
150 kHz00150 kHz6.7 μs
PRDIV8
(Binary)
DIV5:DIV0
(Decimal)
f
FCLK
Program/Erase Timing Pulse
(5 μs Min, 6.7 μs Max)
4.8.2Flash Options Register (FOPT and NVOPT)
During reset, the contents of the nonvolatile location NVOPT are copied from flash into FOPT. Bits 5
through 2 are not used and always read 0. This register may be read at any time, but writes have no meaning
or effect. To change the value in this register, erase and reprogram the NVOPT location in flash memory
as usual and then issue a new MCU reset.
76543210
RKEYENFNORED0000SEC01SEC00
W
ResetThis register is loaded from nonvolatile location NVOPT during reset.
= Unimplemented or Reserved
Figure 4-8. Flash Options Register (FOPT)
Table 4-9. FOPT Register Field Descriptions
FieldDescription
7
KEYEN
6
FNORED
1:0
SEC0[1:0]
Backdoor Key Mechanism Enable — When this bit is 0, the backdoor key mechanism cannot be used to
disengage security. The backdoor key mechanism is accessible only from user (secured) firmware. BDM
commands cannot be used to write key comparison values that would unlock the backdoor key. For more detailed
information about the backdoor key mechanism, refer to Section 4.7, “Security.”
0 No backdoor key access allowed.
1 If user firmware writes an 8-byte value that matches the nonvolatile backdoor key (NVBACKKEY through
NVBACKKEY+7 in that order), security is temporarily disengaged until the next MCU reset.
Vector Redirection Disable — When this bit is 1, then vector redirection is disabled.
0 Vector redirection enabled.
1 Vector redirection disabled.
Security State Code — This 2-bit field determines the security state of the MCU as shown in Ta b le 4 - 1 0. When
the MCU is secure, the contents of RAM and flash memory cannot be accessed by instructions from any
unsecured source including the background debug interface. For more detailed information about security, refer
to Section 4.7, “Security.”
MC9S08JS16 MCU Series Reference Manual, Rev. 4
58Freescale Semiconductor
Chapter 4 Memory
Table 4-10. Security States
SEC01:SEC00Description
0:0secure
0:1secure
1:0unsecured
1:1secure
SEC01:SEC00 changes to 1:0 after successful backdoor key entry or a successful blank check of flash
memory.
4.8.3Flash Configuration Register (FCNFG)
Bits 7 through 5 may be read or written at any time. Bits 4 through 0 always read 0 and cannot be written.
76543210
R00
KEYACC
W
Reset00000000
00000
= Unimplemented or Reserved
Figure 4-9. Flash Configuration Register (FCNFG)
Table 4-11. FCNFG Register Field Descriptions
FieldDescription
5
KEYACC
Enable Writing of Access Key — This bit enables writing of the backdoor comparison key. For more detailed
information about the backdoor key mechanism, refer to Section 4.7, “Security.”
0 Writes to 0xFFB0–0xFFB7 are interpreted as the start of a flash programming or erase command.
1 Writes to NVBACKKEY (0xFFB0–0xFFB7) are interpreted as comparison key writes.
4.8.4Flash Protection Register (FPROT and NVPROT)
During reset, the contents of the nonvolatile location NVPROT is copied from flash memory into FPROT.
This register may be read at any time, but user program writes have no meaning or effect. Background
debug commands can write to FPROT.
76543210
RFPS7FPS6FPS5FPS4FPS3FPS2FPS1FPDIS
W
ResetThis register is loaded from nonvolatile location NVPROT during reset.
1
Background commands can be used to change the contents of these bits in FPRO.
(1)(1)(1)(1)(1)(1)(1)(1)
Figure 4-10. Flash Protection Register (FPROT)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor59
Chapter 4 Memory
Table 4-12. FPROT Register Field Descriptions
FieldDescription
7:1
FPS[7:1]
0
FPDIS
Flash Protect Select Bits — When FPDIS = 0, this 7-bit field determines the ending address of unprotected
flash locations at the high address end of the flash. Protected flash locations cannot be erased or programmed.
Flash Protection Disable
0 Flash block specified by FPS[7:1] is block protected (program and erase are not allowed).
1 No flash block is protected.
4.8.5Flash Status Register (FSTAT)
Bits 3, 1, and 0 always read 0 and writes have no meaning or effect. The remaining five bits are status bits
that can be read at any time. Writes to these bits have special meanings that are discussed in the bit
descriptions.
76543210
R
FCBEF
W
Reset11000000
FCCF
FPVIOLFACCERR
= Unimplemented or Reserved
Figure 4-11. Flash Status Register (FSTAT)
Table 4-13. FSTAT Register Field Descriptions
0FBLANK00
FieldDescription
7
FCBEF
6
FCCF
5
FPVIOL
Flash Command Buffer Empty Flag — The FCBEF bit is used to launch commands. It also indicates that the
command buffer is empty so that a new command sequence can be executed when performing burst
programming. The FCBEF bit is cleared by writing a 1 to it or when a burst program command is transferred to
the array for programming. Only burst program commands can be buffered.
0 Command buffer is full (not ready for additional commands).
1 A new burst program command may be written to the command buffer.
Flash Command Complete Flag — FCCF is set automatically when the command buffer is empty and no
command is being processed. FCCF is cleared automatically when a new command is started (by writing 1 to
FCBEF to register a command). Writing to FCCF has no meaning or effect.
0 Command in progress
1 All commands complete
Protection Violation Flag — FPVIOL is set automatically when a command is written that attempts to erase or
program a location in a protected block (the erroneous command is ignored). FPVIOL is cleared by writing a 1 to
FPVIOL.
0 No protection violation.
1 An attempt is made to erase or program a protected location.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
60Freescale Semiconductor
Table 4-13. FSTAT Register Field Descriptions (continued)
FieldDescription
Chapter 4 Memory
4
FACCERR
2
FBLANK
Access Error Flag — FACCERR is set automatically when the proper command sequence is not obeyed exactly
(the erroneous command is ignored), if a program or erase operation is attempted before the FCDIV register has
been initialized, or if the MCU enters stop while a command was in progress. For a more detailed discussion of
the exact actions that are considered access errors, see Section 4.6.5, “Access Errors.” FACCERR is cleared by
writing a 1 to FACCERR. Writing a 0 to FACCERR has no meaning or effect.
0 No access error.
1 An access error has occurred.
Flash Verified as All Blank (erased) Flag — FBLANK is set automatically at the conclusion of a blank check
command if the entire flash array was verified to be erased. FBLANK is cleared by clearing FCBEF to write a new
valid command. Writing to FBLANK has no meaning or effect.
0 After a blank check command is completed and FCCF = 1, FBLANK = 0 indicates the flash array is not
completely erased.
1 After a blank check command is completed and FCCF = 1, FBLANK = 1 indicates the flash array is completely
erased (all 0xFF).
4.8.6Flash Command Register (FCMD)
Only five command codes are recognized in normal user modes as shown in Table 4-15. Refer to
Section 4.6.3, “Program and Erase Command Execution” for a detailed discussion of flash programming
and erase operations.
76543210
R00000000
WFCMD7FCMD6FCMD5FCMD4FCMD3FCMD2FCMD1FCMD0
Reset00000000
Figure 4-12. Flash Command Register (FCMD)
Table 4-14. FCMD Register Field Descriptions
FieldDescription
FCMD[7:0]Flash Command Bits — See Ta b l e 4 - 1 5
Table 4-15. Flash Commands
CommandFCMDEquate File Label
Blank check0x05mBlank
Byte program0x20mByteProg
Byte program — burst mode0x25mBurstProg
Page erase (512 bytes/page)0x40mPageErase
Mass erase (all flash)0x41mMassErase
All other command codes are illegal and generate an access error.
It is not necessary to perform a blank check command after a mass erase operation. Blank check is required
only as part of the security unlocking mechanism.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor61
Chapter 4 Memory
MC9S08JS16 MCU Series Reference Manual, Rev. 4
62Freescale Semiconductor
Chapter 5
Resets, Interrupts, and System Configuration
5.1Introduction
This chapter discusses basic reset and interrupt mechanisms and the various sources of reset and interrupts
in the MC9S08JS16 series. Some interrupt sources from peripheral modules are discussed in greater detail
in other chapters of this reference manual. This chapter gathers basic information about all reset and
interrupt sources in one place for easy reference. A few reset and interrupt sources, including the computer
operating properly (COP) watchdog, are not part of on-chip peripheral systems with their own sections but
are part of the system control logic.
5.2Features
Reset and interrupt features include:
•Multiple sources of reset for flexible system configuration and reliable operation
•Reset status register (SRS) to indicate source of most recent reset
•Separate interrupt vectors for each module (reduces polling overhead) (see Tab le 5-1)
5.3MCU Reset
Resetting the MCU provides a way to start processing from a known set of initial conditions. During reset,
most control and status registers are forced to initial values and the program counter is loaded from the
reset vector (0xFFFE:0xFFFF). On-chip peripheral modules are disabled and I/O pins are initially
configured as general-purpose high-impedance inputs with pullup devices disabled. The I bit in the
condition code register (CCR) is set to block maskable interrupts so the user program has a chance to
initialize the stack pointer (SP) and system control settings. SP is forced to 0x00FF at reset.
The MC9S08JS16 series have following sources for reset:
•Power-on reset (POR)
•Low-voltage detect (LVD)
•Computer operating properly (COP) timer
•Illegal opcode detect (ILOP)
•Illegal address detect (ILAD)
•Background debug forced reset
•External reset pin (RESET)
•Clock generator loss of lock and loss of clock reset (LOC)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor63
Chapter 5 Resets, Interrupts, and System Configuration
Each of these sources, with the exception of the background debug forced reset, has an associated bit in
the system reset status (SRS) register.
5.4Computer Operating Properly (COP) Watchdog
The COP watchdog is used to force a system reset when the application software fails to execute as
expected. To prevent a system reset from the COP timer (when it is enabled), application software must
reset the COP counter periodically. If the application program gets lost and fails to reset the COP counter
before it times out, a system reset is generated to force the system back to a known starting point.
After any reset, the COP watchdog is enabled (see Section 5.7.4, “System Options Register 1 (SOPT1),”
for additional information). If the COP watchdog is not used in an application, it can be disabled by
clearing COPT bits in SOPT1.
The COP counter is reset by writing 0x55 and 0xAA (in this order) to the address of SRS during the
selected timeout period. Writes do not affect the data in the read-only SRS. As soon as the write sequence
is done, the COP timeout period is restarted. If the program fails to do this during the time-out period, the
MCU will reset. Also, if any value other than 0x55 or 0xAA is written to SRS, the MCU is immediately
reset.
The COPCLKS bit in SOPT2 (see Section 5.7.5, “System Options Register 2 (SOPT2),” for additional
information) selects the clock source used for the COP timer. The clock source options are either the bus
clock or an internal 1 kHz clock source. With each clock source, there are three associated time-outs
controlled by the COPT bits in SOPT1. Table 5-6 summaries the control functions of the COPCLKS and
COPT bits. The COP watchdog defaults to operation from the 1 kHz clock source and the longest time-out
10
(2
cycles).
When the bus clock source is selected, windowed COP operation is available by setting COPW in the
SOPT2 register. In this mode, writes to the SRS register to clear the COP timer must occur in the last 25%
of the selected timeout period. A premature write immediately resets the MCU. When the 1 kHz clock
source is selected, windowed COP operation is not available.
The COP counter is initialized by the first writes to the SOPT1 and SOPT2 registers and after any system
reset. Subsequent writes to SOPT1 and SOPT2 have no effect on COP operation. Even if the application
will use the reset default settings of COPT, COPCLKS, and COPW bits, the user must write to the
write-once SOPT1 and SOPT2 registers during reset initialization to lock in the settings. This will prevent
accidental changes if the application program gets lost}.
The write to SRS that services (clears) the COP counter must not be placed in an interrupt service routine
(ISR) because the ISR could continue to be executed periodically even if the main application program
fails.
If the bus clock source is selected, the COP counter does not increment while the MCU is in background
debug mode or while the system is in stop mode. The COP counter resumes when the MCU exits
background debug mode or stop mode.
If the 1 kHz clock source is selected, the COP counter is re-initialized to zero upon entry to background
debug mode or stop mode and begins from zero upon exit from background debug mode or stop mode.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
64Freescale Semiconductor
Chapter 5 Resets, Interrupts, and System Configuration
5.5Interrupts
Interrupts provide a way to save the current CPU status and registers, execute an interrupt service routine
(ISR), and then restore the CPU status so processing resumes where it left off before the interrupt. Other
than the software interrupt (SWI), which is a program instruction, interrupts are caused by hardware events
such as an edge on the IRQ pin or a timer-overflow event. The debug module can also generate an SWI
under certain circumstances.
If an event occurs in an enabled interrupt source, an associated read-only status flag becomes set. The CPU
will not respond until and unless the local interrupt enable is a logic 1 to enable the interrupt. The I bit in
the CCR is 0 to allow interrupts. The global interrupt mask (I bit) in the CCR is initially set after reset,
which masks (prevents) all maskable interrupt sources. The user program initializes the stack pointer and
performs other system setup before clearing the I bit to allow the CPU to respond to interrupts.
When the CPU receives a qualified interrupt request, it completes the current instruction before responding
to the interrupt. The interrupt sequence obeys the same cycle-by-cycle sequence as the SWI instruction
and consists of:
•Saving the CPU registers on the stack
•Setting the I bit in the CCR to mask further interrupts
•Fetching the interrupt vector for the highest-priority interrupt that is currently pending
•Filling the instruction queue with the first three bytes of program information starting from the
address fetched from the interrupt vector locations
While the CPU is responding to the interrupt, the I bit is automatically set to avoid the possibility of
another interrupt interrupting the ISR itself (this is called nesting of interrupts). Normally, the I bit is
restored to 0 when the CCR is restored from the value stacked on entry to the ISR. In rare cases, the I bit
may be cleared inside an ISR (after clearing the status flag that generates the interrupt) so that other
interrupts can be serviced without waiting for the first service routine to finish. This practice is not
recommended for anyone other than the most experienced programmers because it can lead to subtle
program errors that are difficult to debug.
The interrupt service routine ends with a return-from-interrupt (RTI) instruction which restores the CCR,
A, X, and PC registers to their pre-interrupt values by reading the previously saved information off the
stack.
NOTE
For compatibility with the M68HC08, the H register is not automatically
saved and restored. It is good programming practice to push H onto the stack
at the start of the interrupt service routine (ISR) and restore it immediately
before the RTI that is used to return from the ISR.
When two or more interrupts are pending when the I bit is cleared, the highest priority source is serviced
first (see Table 5-1 ).
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor65
Chapter 5 Resets, Interrupts, and System Configuration
CONDITION CODE REGISTER
ACCUMULATOR
INDEX REGISTER (LOW BYTE X)
PROGRAM COUNTER HIGH
* High byte (H) of index register is not automatically stacked.
*
PROGRAM COUNTER LOW
70
UNSTACKING
ORDER
STACKING
ORDER
5
4
3
2
1
1
2
3
4
5
TOWARD LOWER ADDRESSES
TOWARD HIGHER ADDRESSES
SP BEFORE
SP AFTER
INTERRUPT STACKING
THE INTERRUPT
5.5.1Interrupt Stack Frame
Figure 5-1 shows the contents and organization of a stack frame. Before the interrupt, the stack pointer
(SP) points at the next available byte location on the stack. The current values of CPU registers are stored
on the stack starting with the low-order byte of the program counter (PCL) and ending with the CCR. After
stacking, the SP points at the next available location on the stack which is the address that is one less than
the address where the CCR was saved. The PC value that is stacked is the address of the instruction in the
main program that would have executed next if the interrupt had not occurred.
Figure 5-1. Interrupt Stack Frame
When an RTI instruction is executed, these values are recovered from the stack in reverse order. As part
of the RTI sequence, the CPU fills the instruction pipeline by reading three bytes of program information,
starting from the PC address recovered from the stack.
The status flag causing the interrupt must be acknowledged (cleared) before returning from the ISR.
Typically, the flag must be cleared at the beginning of the ISR so that if another interrupt is generated by
this same source, it will be registered so it can be serviced after completion of the current ISR.
5.5.2External Interrupt Request (IRQ) Pin
External interrupts are managed by the IRQSC status and control register. When the IRQ function is
enabled, synchronous logic monitors the pin for edge-only or edge-and-level events. When the MCU is in
stop mode and system clocks are shut down, a separate asynchronous path is used so the IRQ (if enabled)
can wake the MCU.
5.5.2.1Pin Configuration Options
The IRQ pin enable (IRQPE) control bit in IRQSC must be 1 in order for the IRQ pin to act as the interrupt
request (IRQ) input. As an IRQ input, the user can choose the polarity of edges or levels detected
(IRQEDG), whether the pin detects edges-only or edges and levels (IRQMOD), and whether an event
causes an interrupt or only sets the IRQF flag which can be polled by software.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
66Freescale Semiconductor
Chapter 5 Resets, Interrupts, and System Configuration
The IRQ pin, when enabled, defaults to use an internal pull device (IRQPDD = 0), the device is a pullup
or pulldown depending on the polarity chosen. If the user desires to use an external pullup or pulldown,
the IRQPDD can be written to a 1 to turn off the internal device.
BIH and BIL instructions may be used to detect the level on the IRQ pin when the pin is configured to act
as the IRQ input.
NOTE
This pin does not contain a clamp diode to VDD and must not be driven
above VDD.
The voltage measured on the internally pulled up IRQ pin may be as low as
VDD – 0.7 V. The internal gates connected to this pin are pulled to VDD. If
the IRQ pin is required to drive to a V
level an external pullup must be
DD
used
NOTE
When enabling the IRQ pin for use, the IRQF will be set, and should be
cleared prior to enabling the interrupt. When configuring the pin for falling
edge and level sensitivity in a 5V system, it is necessary to wait at least 6
cycles between clearing the flag and enabling the interrupt.
5.5.2.2Edge and Level Sensitivity
The IRQMOD control bit re-configure the detection logic so it detects edge events and pin levels. In this
edge detection mode, the IRQF status flag becomes set when an edge is detected (when the IRQ pin
changes from the deasserted to the asserted level), but the flag is continuously set (and cannot be cleared)
as long as the IRQ pin remains at the asserted level.
5.5.3Interrupt Vectors, Sources, and Local Masks
Table 5-1 provides a summary of all interrupt sources. Higher-priority sources are located toward the
bottom of the table. The high-order byte of the address for the interrupt service routine is located at the
first address in the vector address column, and the low-order byte of the address for the interrupt service
routine is located at the next higher address.
When an interrupt condition occurs, an associated flag bit becomes set. If the associated local interrupt
enable is 1, an interrupt request is sent to the CPU. Within the CPU, if the global interrupt mask (I bit in
the CCR) is 0, the CPU will finish the current instruction, stack the PCL, PCH, X, A, and CCR CPU
registers, set the I bit, and then fetch the interrupt vector for the highest priority pending interrupt.
Processing then continues in the interrupt service routine.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor67
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-1. Vector Summary (from Lowest to Highest Priority)
Vector
Number
31 to 30
290xFFC4:FFC5Vrtc
28 to 27
Address
(High/Low)
0xFFC0:FFC1
0xFFC2:FFC3
0xFFC6:FFC7
0xFFC8:FFC9
Vector NameModuleSourceEnableDescription
Unused vector space (available for user program)
System
control
RTIFRTIERTC real-time interrupt
1
Unused vector space (available for user program)
260xFFCA:FFCBVmtimMTIMTOFTOIEMTIM overflow
250xFFCC:FFCDVkeyboardKBIKBFKBIEKeyboard pins
0xFFCE:FFCF
24 to 22
to
Unused vector space (available for user program)
0xFFD2:FFD3
210xFFD4:FFD5VscitxSCI
200xFFD6:FFD7VscirxSCI
190xFFD8:FFD9VscierrSCI
TDRE
TC
IDLE
RDRF
OR
NF
FE
PF
T I E
TCIE
I L I E
R IE
O R I E
N F I E
F E I E
PFIE
SCI transmit
SCI receive
SCI error
0xFFDA:FFDB
18 to 12
to
Unused vector space (available for user program)
0xFFE6:FFE7
110xFFE8:FFE9VtpmovfTPMTOFTOIETPM overflow
100xFFEA:FFEBVtpmch1TPMCH1FCH1IETPM channel 1
90xFFEC:FFEDVtpmch0TPMCH0FCH0IETPM channel 0
80xFFEE:FFEFUnused vector space (available for user program)
70xFFF0:FFF1VusbUSB
STALLF
RESUMEF
SLEEPF
TOKDNEF
SOFTOKF
ERRORF
USBRSTF
STALL
RESUME
SLEEP
TOKDNE
SOFTOK
ERROR
USBRST
USB Status
60xFFF2:FFF3Unused vector space (available for user program)
50xFFF4:FFF5VspiSPI
SPRF
MODF
SPTEF
SPMF
S P I E
S P IE
S P TI E
SPMIE
SPI
40xFFF6:FFF7VlolMCGLOLSLOLIEMCG loss of lock
30xFFF8:FFF9Vlvd
System
control
LVDFLVDIELow-voltage detect
MC9S08JS16 MCU Series Reference Manual, Rev. 4
68Freescale Semiconductor
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-1. Vector Summary (from Lowest to Highest Priority) (continued)
Unused vector space is available for use as general flash memory. However, other devices in the S08 family of MCUs
may use this location as interrupt vectors. Therefore, care must be taken when using this location if the code will be
ported to other MCUs.
Address
(High/Low)
Vector NameModuleSourceEnableDescription
System
control
COP
LV D
RESET
Illegal opcode
Illegal address
pin
LOC
POR
BDFR
C O P E
L V D R E
—
ILOP
ILAD
C M E
POR
Watchdog timer
Low-voltage detect
Ext er na l p in
Illegal opcode
Illegal address
Loss of clock
Power-on-r eset
BDM-forced reset
5.6Low-Voltage Detect (LVD) System
The MC9S08JS16 series include a system to protect against low-voltage conditions to protect memory
contents and control MCU system states during supply voltage variations. The system is composed of a
power-on reset (POR) circuit and a LVD circuit with trip voltages for warning and detection. The LVD
circuit is enabled when LVDE in SPMSC1 is set to 1. The LVD is disabled upon entering any of the stop
modes unless LVDSE is set in SPMSC1. If LVDSE and LVDE are both set, then the MCU cannot enter
stop2 (it will enter stop3 instead), and the current consumption in stop3 with the LVD enabled will be
higher.
5.6.1Power-On Reset Operation
When power is initially applied to the MCU, or when the supply voltage drops below the power-on reset
re-arm voltage level, V
, the POR circuit will cause a reset condition. As the supply voltage rises, the
POR
LVD circuit will hold the MCU in reset until the supply has risen above the low voltage detection low
threshold, V
. Both the POR bit and the LVD bit in SRS are set following a POR.
LV DL
5.6.2Low-Voltage Detection (LVD) Reset Operation
The LVD can be configured to generate a reset upon detection of a low voltage condition by setting
LVDRE to 1. The low voltage detection threshold is determined by the LVDV bit. After an LVD reset has
occurred, the LVD system will hold the MCU in reset until the supply voltage has risen above the low
voltage detection threshold. The LVD bit in the SRS register is set following either an LVD reset or POR.
The LVD system has a low voltage warning flag to indicate to the user that the supply voltage is
approaching the low voltage condition. When a low voltage warning condition is detected and is
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor69
Chapter 5 Resets, Interrupts, and System Configuration
configured for interrupt operation (LVWIE set to 1), LVWF in SPMSC1 will be set and an LVW interrupt
request will occur.
5.7Reset, Interrupt, and System Control Registers and Control Bits
One 8-bit register in the direct-page register space and eight 8-bit registers in the high-page register space
are related to reset and interrupt systems.
Refer to the direct-page register summary in Chapter 4, “Memory,” of this data sheet for the absolute
address assignments for all registers. This section refers to registers and control bits only by their names.
A Freescale-provided equate or header file is used to translate these names into the appropriate absolute
addresses.
Some control bits in the SOPT1 and SPMSC2registers are related to modes of operation. Although brief
descriptions of these bits are provided here, the related functions are discussed in greater detail in
Chapter 3, “Modes of Operation.”
5.7.1Interrupt Pin Request Status and Control Register (IRQSC)
This direct-page register includes status and control bits, which are used to configure the IRQ function,
report status, and acknowledge IRQ events.
76543210
R0
WIRQACK
Reset00000000
FieldDescription
6
IRQPDD
5
IRQEDG
4
IRQPE
Interrupt Request (IRQ) Pull Device Disable — This read/write control bit is used to disable the internal pullup
device when the IRQ pin is enabled (IRQPE = 1) allowing for an external device to be used.
0 IRQ pull device enabled if IRQPE = 1.
1 IRQ pull device disabled if IRQPE = 1.
Interrupt Request (IRQ) Edge Select — This read/write control bit is used to select the polarity of edges or
levels on the IRQ pin that cause IRQF to be set. The IRQMOD control bit determines whether the IRQ pin is
sensitive to both edges and levels or only edges. When the IRQ pin is enabled as the IRQ input and is configured
to detect rising edges, the optional pullup resistor is re-configured as an optional pulldown resistor.
0 IRQ is falling edge or falling edge/low-level sensitive.
1 IRQ is rising edge or rising edge/high-level sensitive.
IRQ Pin Enable — This read/write control bit enables the IRQ pin function. When this bit is set the IRQ pin can
be used as an interrupt request.
0 IRQ pin function is disabled.
1 IRQ pin function is enabled.
IRQPDDIRQEDGIRQPE
= Unimplemented or Reserved
Figure 5-2. Interrupt Request Status and Control Register (IRQSC)
Table 5-2. IRQSC Register Field Descriptions
IRQF0
IRQIEIRQMOD
MC9S08JS16 MCU Series Reference Manual, Rev. 4
70Freescale Semiconductor
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-2. IRQSC Register Field Descriptions (continued)
FieldDescription
3
IRQF
2
IRQACK
1
IRQIE
0
IRQMOD
IRQ Flag — This read-only status bit indicates when an interrupt request event has occurred.
0 No IRQ request.
1 IRQ event detected.
IRQ Acknowledge — This write-only bit is used to acknowledge interrupt request events (write 1 to clear IRQF).
Writing 0 has no meaning or effect. Reads always return 0. If edge-and-level detection is selected (IRQMOD = 1),
IRQF cannot be cleared while the IRQ pin remains at its asserted level.
IRQ Interrupt Enable — This read/write control bit determines whether IRQ events generate an interrupt
request.
0 Interrupt request when IRQF set is disabled (use polling).
1 Interrupt requested whenever IRQF = 1.
IRQ Detection Mode — This read/write control bit selects either edge-only detection or edge-and-level
detection. See Section 5.5.2.2, “Edge and Level Sensitivity,” for more details.
0 IRQ event on falling/rising edges only.
1 IRQ event on falling/rising edges and low/high levels.
5.7.2System Reset Status Register (SRS)
This register includes seven read-only status flags to indicate the source of the most recent reset. When a
debug host forces reset by writing 1 to BDFR in the SBDFR register, none of the status bits in SRS will
be set. Writing any value to this register address causes a COP reset when the COP is enabled except for
the values 0x55 and 0xAA. Writing a 0x55—0xAA sequence to this address clears the COP watchdog timer
without affecting the contents of this register. The reset state of these bits depends on what caused the
MCU to reset.
76543210
RPORPINCOPILOPILADLOCLVD—
WWriting any value to SRS address clears COP watchdog timer.
POR10000010
LVR:
Any other
U0000010
0
(1)(1)(1)
0
(1)
00
reset:
U = Unaffected by reset
1
Any of these reset sources that are active at the time of reset will cause the corresponding bit(s) to be set; bits corresponding
to sources that are not active at the time of reset will be cleared.
Figure 5-3. System Reset Status (SRS)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor71
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-3. SRS Register Field Descriptions
FieldDescription
7
POR
6
PIN
5
COP
4
ILOP
3
ILAD
2
LOC
Power-On Reset — Reset was caused by the power-on detection logic. Because the internal supply voltage was
ramping up at the time, the low-voltage reset (LVR) status bit is also set to indicate that the reset occurred while
the internal supply was below the LVR threshold.
0 Reset not caused by POR.
1 POR caused reset.
External Reset Pin — Reset was caused by an active-low level on the external reset pin.
0 Reset not caused by external reset pin.
1 Reset came from external reset pin.
Computer Operating Properly (COP) Watchdog — Reset was caused by the COP watchdog timer timing out.
This reset source may be blocked by COPE = 0.
0 Reset not caused by COP timeout.
1 Reset caused by COP timeout.
Illegal Opcode — Reset was caused by an attempt to execute an unimplemented or illegal opcode. The STOP
instruction is considered illegal if stop is disabled by STOPE = 0 in the SOPT register. The BGND instruction is
considered illegal if active background mode is disabled by ENBDM = 0 in the BDCSC register.
0 Reset not caused by an illegal opcode.
1 Reset caused by an illegal opcode.
Illegal Address — Reset was caused by an attempt to access either data or an instruction at an unimplemented
memory address.
0 Reset not caused by an illegal address
1 Reset caused by an illegal address
Loss-of-Clock Reset — Reset was caused by a loss of external clock.
0 Reset not caused by a loss of external clock.
1 Reset caused by a loss of external clock.
1
LV D
Low Voltage Detect — If the LVD is enable with the LVDRE or LVDSE bit is set, and the supply drops below the
LVD trip voltage, an LVD reset will occur. This bit is also set by POR.
0 Reset not caused by LVD trip or POR.
1 Reset caused by LVD trip or POR.
5.7.3System Background Debug Force Reset Register (SBDFR)
This register contains a single write-only control bit. A serial background command such as
WRITE_BYTE must be used to write to SBDFR. Attempts to write this register from a user program are
ignored. Reads always return 0x00.
76543210
R00000000
WBDFR
Reset00000000
= Unimplemented or Reserved
1
BDFR is writable only through serial background debug commands, not from user programs.
Figure 5-4. System Background Debug Force Reset Register (SBDFR)
1
MC9S08JS16 MCU Series Reference Manual, Rev. 4
72Freescale Semiconductor
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-4. SBDFR Register Field Descriptions
FieldDescription
0
BDFR
Background Debug Force Reset — A serial background command such as WRITE_BYTE may be used to
allow an external debug host to force a target system reset. Writing logic 1 to this bit forces an MCU reset. This
bit cannot be written from a user program.
5.7.4System Options Register 1 (SOPT1)
This register may be read at any time. Bits 4 and 3 are unimplemented and always read 0. This is a
write-once register so only the first write after reset is honored. Any subsequent attempt to write to SOPT
(intentionally or unintentionally) is ignored to avoid accidental changes to these sensitive settings. SOPT
must be written during the user’s reset initialization program to set the desired controls even if the desired
settings are the same as the reset settings.
R
W
Reset:1101001u
POR:110100 or 1
LVR:1101001u
1
u = unaffected
2
Depends on PTB3/BLMS pin state.
COPTSTOPE
Figure 5-5. System Options Register (SOPT1)
10BLMSS
(2)
BKGDPERSTPE
10
(1)
Table 5-5. SOPT1 Register Field Descriptions
FieldDescription
7:6
COPT[1:0]
5
STOPE
2
BLMSS
COP Watchdog Timeout — These write-once bits select the timeout period of the COP. COPT along with
COPCLKS in SOPT2 defines the COP timeout period. See Ta b le 5 -6 .
Stop Mode Enable — This write-once bit defaults to 0 after reset, which disables stop mode. If stop mode is
disabled and a user program attempts to execute a STOP instruction, an illegal opcode reset is forced.
0 Stop mode disabled.
1 Stop mode enabled.
Pin State— This read only bit indicates PTB3/BLMS pin state during power-on reset (POR).
BLMS
0BLMS pin is high during POR.
1BLMS pin is low and MS pin is high during POR.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor73
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-5. SOPT1 Register Field Descriptions (continued)
FieldDescription
1
BKGDPE
Background Debug Mode Pin Enable — This write-once bit when set enables the PTB2/BKGD/MS pin to
function as BKGD/MS. When clear, the pin functions as one of its output-only alternative functions. This pin
defaults to the BKGD/MS function following any MCU reset.
0 PTB2/BKGD/MS pin functions as PTB2.
1 PTB2/BKGD/MS pin functions as BKGD/MS.
0
RSTPE
Pin Enable — This write-once bit when set enables the PTB1/RESET pin to function as RESET. When
RESET
clear, the pin functions as one of its alternative functions. This pin defaults to a general-purpose input port
function following a POR reset. When configured as RESET
, the pin will be unaffected by LVR or other internal
resets. When RSTPE is set, an internal pullup device is enabled on RESET.
0 PTB1/RESET pin functions as PTB1.
1 PTB1/RESET
pin functions as RESET.
Table 5-6. COP Configuration Options
Control Bits
Clock Source
COPCLKSCOPT[1:0]
COP Window
(COPW = 1)
N/A0:0N/AN/ACOP is disabled
00:1
01:0
01:1
10:1
11:0
11:1
1
Windowed COP operation requires the user to clear the COP timer in the last 25% of the selected timeout period. This column
1 kHzN/A
1 kHzN/A
1 kHzN/A
Bus6144 cycles
Bus49,152 cycles
Bus196,608 cycles
displays the minimum number of clock counts required before the COP timer can be reset when in windowed COP mode
(COPW = 1).
2
Values shown in milliseconds based on t
= 1 ms. See t
LPO
in the MC9S08JS16 Data Sheet for the tolerance of this value.
LPO
1
Opens
COP Overflow Count
5
2
cycles (32 ms2)
8
2
cycles (256 ms
10
2
cycles (1.024 s2)
13
2
cycles
16
2
cycles
18
2
cycles
2
5.7.5System Options Register 2 (SOPT2)
76543210
R
COPCLKS
1
COPW
1
W
Reset00000100
= Unimplemented or Reserved
1
This bit can be written only one time after reset. Additional writes are ignored.
Figure 5-6. System Options Register 2 (SOPT2)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
74Freescale Semiconductor
000
SPIFE
00
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-7. SOPT2 Register Field Descriptions
FieldDescription
7
COPCLKS
6
COPW
2
SPIFE
COP Watchdog Clock Select — This write-once bit selects the clock source of the COP watchdog.
0 Internal 1 kHz clock is source to COP.
1 Bus clock is source to COP.
COP Window — This write-once bit selects the COP operation mode. When set, the 0x55–0xAA write sequence
to the SRS register must occur in the last 25% of the selected period. Any write to the SRS register during the
first 75% of the selected period will reset the MCU.
0 Normal COP operation.
1 Window COP operation.
SPI1 Ports Input Filter Enable
0 Disable input filter on SPI port pins to allow for higher maximum SPI baud rate.
1 Enable input filter on SPI port pins to eliminate noise and restrict maximum SPI baud rate.
Protected flash section can be disabled by write 0x55 and 0xAA back to back to the address of FPROTD first,
0
then set bit FPDIS = 1 in FPROT register. This bit set to 1only after write 0x55 and 0xAA back to back successfully
that means FPDIS can be set to 1. Any write operation, will clear this bit except 0x55–AA write squence.
0 The bit FPDIS in FPROT can not be set to 1.
1 The bit FPDIS in FPROT can be set to 1.
5.7.7SIGNATURE Register (SIGNATURE)
76543210
R
W
POR00000000
= Unimplemented or Reserved
Figure 5-8. SIGNATURE Register (SIGNATURE)
SIGNATURE semaphore
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor75
Chapter 5 Resets, Interrupts, and System Configuration
Table 5-9. SIGNATURE Register Field Descriptions
FieldDescription
The SIGNATURE semaphore is used as the semaphore to jump to bootloader mode or not after regular reset.
7:0
This byte only can be cleared by power-on reset (POR), content retains after regular reset.
This read-only register is included so host development systems can identify the HCS08 derivative and
revision number. This allows the development software to recognize where specific memory blocks,
registers, and control bits are located in a target MCU.
76543210
RID11ID10ID9ID8
W
Reset———— 0 0 0 0
= Unimplemented or Reserved
Figure 5-9. System Device Identification Register — High (SDIDH)
Table 5-10. SDIDH Register Field Descriptions
FieldDescription
7:4
Reserved
3:0
ID[11:8]
RID7ID6ID5ID4ID3ID2ID1ID0
W
Reset00100100
Bits 7:4 are reserved. Reading these bits will result in an indeterminate value; writes have no effect.
Part Identification Number — Each derivative in the HCS08 Family has a unique identification number. The
MC9S08JS16 series are hard coded to the value 0x024. See also ID bits in Ta b l e 5 - 11 .
76543210
= Unimplemented or Reserved
Figure 5-10. System Device Identification Register — Low (SDIDL)
Table 5-11. SDIDL Register Field Descriptions
FieldDescription
7:0
ID[7:0]
Part Identification Number — Each derivative in the HCS08 Family has a unique identification number. The
MC9S08JS16 series are hard coded to the value 0x024. See also ID bits in Ta b l e 5 - 10 .
MC9S08JS16 MCU Series Reference Manual, Rev. 4
76Freescale Semiconductor
Chapter 5 Resets, Interrupts, and System Configuration
5.7.9System Power Management Status and Control 1 Register
(SPMSC1)
This high-page register contains status and control bits to support the low-voltage detect function. This
register must be written during the user’s reset initialization program to set the desired controls even if the
desired settings are the same as the reset settings.
RLVWF
WLV WA C K
Reset:00011100
1
LVWF will be set in the case when V
2
This bit can be written only one time after reset. Additional writes are ignored.
1
0
= Unimplemented or Reserved
Supply
LV WI ELV D RE
transitions below the trip point or after reset and V
2
LV DS ELVD E
2
is already below V
Supply
00
.
LV W
Figure 5-11. System Power Management Status and Control 1 Register (SPMSC1)
Table 5-12. SPMSC1 Register Field Descriptions
FieldDescription
7
LV WF
6
LV WAC K
5
LV WI E
Low-Voltage Warning Flag — The LVWF bit indicates the low-voltage warning status.
0 low-voltage warning is not present.
1 low-voltage warning is present or was present.
Low-Voltage Warning Acknowledge — If LVWF = 1, a low-voltage condition has occurred. To acknowledge this
low-voltage warning, write 1 to LVWACK, which will automatically clear LVWF to 0 if the low-voltage warning is
no longer present.
Low-Voltage Warning Interrupt Enable — This bit enables hardware interrupt requests for LVWF.
0 Hardware interrupt disabled (use polling).
1 Request a hardware interrupt when LVWF = 1
4
LVDRE
3
LV DS E
2
LV DE
Freescale Semiconductor77
Low-Voltage Detect Reset Enable — This write-once bit enables LVD events to generate a hardware reset
(provided LVDE = 1).
0 LVD events do not generate hardware resets.
1 Force an MCU reset when an enabled low-voltage detect event occurs.
Low-Voltage Detect Stop Enable — Provided LVDE = 1, this read/write bit determines whether the low-voltage
detect function operates when the MCU is in stop mode.
0 Low-voltage detect disabled during stop mode.
1 Low-voltage detect enabled during stop mode.
Low-Voltage Detect Enable — This write-once bit enables low-voltage detect logic and qualifies the operation
of other bits in this register.
0 LVD logic disabled.
1 LVD logic enabled.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 5 Resets, Interrupts, and System Configuration
5.7.10System Power Management Status and Control 2 Register
(SPMSC2)
This register is used to report the status of the low voltage warning function, and to configure the stop
mode behavior of the MCU.
76543 210
R00
PPDF00PPDC
LV DVLV WV
WPPDACK
Power-on Reset:00000 000
LVD Reset:00uu0000
Any other Reset:00uu0000
= Unimplemented or Reservedu = Unaffected by reset
1
This bit can be written only one time after reset. Additional writes are ignored.
Figure 5-12. System Power Management Status and Control 2 Register (SPMSC2)
Table 5-13. SPMSC2 Register Field Descriptions
FieldDescription
1
5
LV DV
4
LV WV
3
PPDF
2
PPDACK
0
PPDC
Low-Voltage Detect Voltage Select — This bit selects the low voltage detect (LVD) trip point setting.It also
selects the warning voltage range. See Ta b le 5 - 1 4.
Low-Voltage Warning Voltage Select — This bit selects the low voltage warning (LVW) trip point voltage. See
Ta bl e 5 - 1 4 .
Partial Power Down Flag — This read-only status bit indicates that the MCU has recovered from stop2 mode.
0 MCU has not recovered from stop2 mode.
1 MCU recovered from stop2 mode.
Partial Power Down Acknowledge — Writing a 1 to PPDACK clears the PPDF bit
Partial Power Down Control — This write-once bit controls whether stop2 or stop3 mode is selected.
See MC9S08JS16 Series Data Sheet for minimum and maximum values.
LV W0
LV W1
LV W2
LV W3
= 2.74 V
= 2.92 V
= 4.3 V
= 4.6 V
V
V
LV D0
LV D1
= 2.56 V
= 4.0 V
MC9S08JS16 MCU Series Reference Manual, Rev. 4
78Freescale Semiconductor
Chapter 6
Parallel Input/Output
6.1Introduction
This chapter explains software controls related to parallel input/output (I/O). The MC9S08JS16 has two
I/O ports which include a total of 14 general-purpose I/O pins. See Chapter 2, “Pins and Connections,” for
more information about the logic and hardware aspects of these pins.
Many of the I/O pins are shared with on-chip peripheral functions, as shown in Tab le 2-1. The peripheral
modules have priority over the I/Os, so when a peripheral is enabled, the I/O functions are disabled.
After reset, the shared peripheral functions are disabled so that the pins are controlled by the parallel I/O.
All of the parallel I/O pins are configured as inputs (PTxDDn = 0). The pin control functions for each pin
are configured as follows: slew rate control enabled (PTxSEn = 1), low drive strength selected (PTxDSn
= 0), and internal pullups disabled (PTxPEn = 0).
NOTE
To avoid extra current drain from floating input pins, the user’s reset
initialization routine in the application program must either enable on-chip
pullup devices or change the direction of unconnected pins to outputs so the
pins do not float.
NOTE
When PTB0 is configured as output pin, it’s open-drain output.
6.2Port Data and Data Direction
Reading and writing of parallel I/O is done through the port data registers. The direction, input or output,
is controlled through the port data direction registers. The parallel I/O port function for an individual pin
is illustrated in the block diagram below.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor79
Chapter 6 Parallel Input/Output
QD
QD
1
0
Por t Read
PTxDDn
PTxDn
Output Enable
Output Data
Input Data
Synchronizer
Data
BUSCLK
Figure 6-1. Parallel I/O Block Diagram
The data direction control bits determine whether the pin output driver is enabled. Each port pin has a data
direction register bit. When PTxDDn = 0, the corresponding pin is an input and reads of PTxD return the
pin value. When PTxDDn = 1, the corresponding pin is an output and reads of PTxD return the last value
written to the port data register. When a peripheral module or system function is in control of a port pin,
the data direction register bit still controls what is returned for reads of the port data register, even though
the peripheral system has overriding control of the actual pin direction.
When a shared analog function is enabled for a pin, all digital pin functions are disabled. A read of the port
data register returns a value of 0 for any bit which has shared analog functions enabled. In general,
whenever a pin is shared with both an alternate digital function and an analog function, the analog function
has priority such that if both the digital and analog functions are enabled, the analog function controls the
pin.
Write to the port data register before changing the direction of a port pin to output. This ensures that the
pin will not be driven momentarily with an old data value that happened to be in the port data register.
6.3Pin Control
The pin control registers are located in the high-page register block of the memory. These registers are used
to control pullups, slew rate, and drive strength for the I/O pins. The pin control registers operate
independently of the parallel I/O registers.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
80Freescale Semiconductor
Chapter 6 Parallel Input/Output
6.3.1Internal Pullup Enable
An internal pullup device can be enabled for each port pin by setting the corresponding bit in one of the
pullup enable registers (PTxPEn). The pullup device is disabled if the pin is configured as an output by the
parallel I/O control logic or any shared peripheral function regardless of the state of the corresponding
pullup enable register bit. The pullup device is also disabled if the pin is controlled by an analog function.
6.3.2Output Slew Rate Control Enable
Slew rate control can be enabled for each port pin by setting the corresponding bit in one of the slew rate
control registers (PTxSEn). When enabled, slew control limits the rate at which an output can transition in
order to reduce EMC emissions. Slew rate control has no effect on pins which are configured as inputs.
6.3.3Output Drive Strength Select
An output pin can be selected to have high output drive strength by setting the corresponding bit in one of
the drive strength select registers (PTxDSn). When high drive is selected, the pin is capable of sourcing
and sinking greater current. Even though every I/O pin can be selected as high drive, the user must ensure
that the total current source and sink limits for the chip are not exceeded. Drive strength selection is
intended to affect the DC behavior of I/O pins. However, the AC behavior is also affected. High drive
allows a pin to drive a greater load with the same switching speed as a low drive enabled pin into a smaller
load. Because of this, the EMC emissions may be affected by enabling pins as high drive.
6.4Pin Behavior in Stop Modes
Depending on the stop mode, I/O functions differently as the result of executing a STOP instruction. An
explanation of I/O behavior for the various stop modes follows:
•Stop2 mode is a partial power-down mode, whereby I/O latches are maintained in their state as
before the STOP instruction was executed. CPU register status and the state of I/O registers must
be saved in RAM before the STOP instruction is executed to place the MCU in stop2 mode. Upon
recovery from stop2 mode, before accessing any I/O, the user must examine the state of the PPDF
bit in the SPMSC2 register. If the PPDF bit is 0, I/O must be initialized as if a power-on reset had
occurred. If the PPDF bit is 1, I/O register states must be restored from the values saved in RAM
before the STOP instruction was executed. Peripherals may require initialization or restoration to
their pre-stop condition. The user must then write a 1 to the PPDACK bit in the SPMSC2 register.
Access to I/O is now permitted again in the user’s application program.
•In stop3 mode, all I/O is maintained because internal logic circuitry stays powered up. Upon
recovery, normal I/O function is available to the user.
6.5Parallel I/O and Pin Control Registers
This section provides information about the registers associated with the parallel I/O ports and pin control
functions. These parallel I/O registers are located in page zero of the memory map and the pin control
registers are located in the high-page register section of memory.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor81
Chapter 6 Parallel Input/Output
Refer to tables in Chapter 4, “Memory,” for the absolute address assignments of all parallel I/O and pin
control registers. This section refers to registers and control bits only by their names. A Freescale-provided
equate or header file normally is used to translate these names into the appropriate absolute addresses.
6.5.1Port A I/O Registers (PTAD and PTADD)
Port A parallel I/O function is controlled by the registers listed below.
76543210
R
PTAD7PTAD6PTAD5PTAD4PTAD3PTAD2PTAD1PTAD0
W
Reset00000000
Figure 6-2. Port A Data Register (PTAD)
Table 6-1. PTAD Register Field Descriptions
FieldDescription
7:0
PTAD[7:0]
R
W
Reset00000000
Port A Data Register Bits — For port A pins that are inputs, reads return the logic level on the pin. For port A
pins that are configured as outputs, reads return the last value written to this register.
Writes are latched into all bits of this register. For port A pins that are configured as outputs, the logic level is
driven out the corresponding MCU pin.
Reset forces PTAD to all 0s, but these 0s are not driven out the corresponding pins because reset also configures
all port pins as high-impedance inputs with pullups disabled.
76543210
PTADD7PTADD6PTADD5PTADD4PTADD3PTADD2PTADD1PTADD0
Figure 6-3. Data Direction for Port A Register (PTADD)
Table 6-2. PTADD Register Field Descriptions
FieldDescription
7:0
PTADD[7:0]
Data Direction for Port A Bits — These read/write bits control the direction of port A pins and what is read for
PTAD reads.
0 Input (output driver disabled) and reads return the pin value.
1 Output driver enabled for port A bit n and PTAD reads return the contents of PTADn.
6.5.2Port A Pin Control Registers (PTAPE, PTASE, PTADS)
In addition to the I/O control, port A pins are controlled by the registers listed below.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
82Freescale Semiconductor
Chapter 6 Parallel Input/Output
76543210
R
PTAPE7PTAPE6PTAPE5PTAPE4PTAPE3PTAPE2PTAPE1PTAPE0
W
Reset00000000
Figure 6-4. Internal Pullup Enable for Port A (PTAPE)
Table 6-3. PTAPE Register Field Descriptions
FieldDescription
[7:0]
PTAPE[7:0]
Internal Pullup Enable for Port A Bits — Each of these control bits determines if the internal pullup device is
enabled for the associated PTA pin. For port A pins that are configured as outputs, these bits have no effect and
the internal pullup devices are disabled.
0 Internal pullup device disabled for port A bit n.
1 Internal pullup device enabled for port A bit n.
76543210
R
PTASE7PTASE6PTASE5PTASE4PTASE3PTASE2PTASE1PTASE0
W
Reset00000000
Figure 6-5. Output Slew Rate Control Enable for Port A (PTASE)
Table 6-4. PTASE Register Field Descriptions
FieldDescription
7:0
PTASE[7:0]
Output Slew Rate Control Enable for Port A Bits — Each of these control bits determine whether output slew
rate control is enabled for the associated PTA pin. For port A pins that are configured as inputs, these bits have
no effect.
0 Output slew rate control disabled for port A bit n.
1 Output slew rate control enabled for port A bit n.
76543210
R
PTADS7PTADS6PTADS5PTADS4PTADS3PTADS2PTADS1PTADS0
W
Reset00000000
Figure 6-6. Output Drive Strength Selection for Port A (PTADS)
Table 6-5. PTADS Register Field Descriptions
FieldDescription
7:0
PTADS[7:0]
Freescale Semiconductor83
Output Drive Strength Selection for Port A Bits — Each of these control bits selects between low and high
output drive for the associated PTA pin.
0 Low output drive enabled for port A bit n.
1 High output drive enabled for port A bit n.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 6 Parallel Input/Output
6.5.3Port B I/O Registers (PTBD and PTBDD)
Port B parallel I/O function is controlled by the registers listed below.
76543210
R00
W
Reset00000000
= Unimplemented or Reserved
FieldDescription
PTBD5PTBD4PTBD3PTBD2PTBD1PTBD0
Figure 6-7. Port B Data Register (PTBD)
Table 6-6. PTBD Register Field Descriptions
5:0
PTBD[5:0]
R00
W
Reset00000000
Port B Data Register Bits — For port B pins that are inputs, reads return the logic level on the pin. For port B
pins that are configured as outputs, reads return the last value written to this register.
Writes are latched into all bits of this register. For port B pins that are configured as outputs, the logic level is
driven out the corresponding MCU pin.
Reset forces PTBD to all 0s, but these 0s are not driven out the corresponding pins because reset also configures
all port pins as high-impedance inputs with pullups disabled.
76543210
PTBDD5PTBDD4RRPTBDD1PTBDD0
= Unimplemented or Reserved
Figure 6-8. Data Direction for Port B (PTBDD)
Table 6-7. PTBDD Register Field Descriptions
FieldDescription
5:4, 1:0
PTBDD[5:4,
1:0]
Data Direction for Port B Bits — These read/write bits control the direction of port B pins and what is read for
PTBD reads.
0 Input (output driver disabled) and reads return the pin value.
1 Output driver enabled for port B bit n and PTBD reads return the contents of PTBDn.
6.5.4Port B Pin Control Registers (PTBPE, PTBSE, PTBDS)
In addition to the I/O control, port B pins are controlled by the registers listed below.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
84Freescale Semiconductor
Chapter 6 Parallel Input/Output
76543210
R00
PTBPE5PTBPE4RRPTBPE1PTBPE0
W
Reset00000000
= Unimplemented or Reserved
Figure 6-9. Internal Pullup Enable for Port B (PTBPE)
Table 6-8. PTBPE Register Field Descriptions
FieldDescription
5:4, 1:0
PTBPE[5:4,
1:0]
Internal Pullup Enable for Port B Bits — Each of these control bits determines if the internal pullup device is
enabled for the associated PTB pin. For port B pins that are configured as outputs, these bits have no effect and
the internal pullup devices are disabled.
0 Internal pullup device disabled for port B bit n.
1 Internal pullup device enabled for port B bit n.
76543210
R00
0
PTBSE5PTBSE4PTBSE3PTBSE2PTBSE1
W
Reset00000000
= Unimplemented or Reserved
Figure 6-10. Output Slew Rate Control Enable (PTBSE)
Table 6-9. PTBSE Register Field Descriptions
FieldDescription
5:0
PTBSE[5:1]
Output Slew Rate Control Enable for Port B Bits— Each of these control bits determine whether output slew
rate control is enabled for the associated PTB pin. For port B pins that are configured as inputs, these bits have
no effect.
0 Output slew rate control disabled for port B bit n.
1 Output slew rate control enabled for port B bit n.
76543210
R00
0
PTBDS5PTBDS4PTBDS3PTBDS2PTBDS1
W
Reset00000000
= Unimplemented or Reserved
Figure 6-11. Output Drive Strength Selection for Port B (PTBDS)
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor85
Chapter 6 Parallel Input/Output
Table 6-10. PTBDS Register Field Descriptions
FieldDescription
5:0
PTBDS[5:1]
Output Drive Strength Selection for Port B Bits — Each of these control bits selects between low and high
output drive for the associated PTB pin.
0 Low output drive enabled for port B bit n.
1 High output drive enabled for port B bit n.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
86Freescale Semiconductor
Chapter 7
Central Processor Unit (S08CPUV2)
7.1Introduction
This section provides summary information about the registers, addressing modes, and instruction set of
the CPU of the HCS08 Family. For a more detailed discussion, refer to the HCS08 Family Reference Manual, volume 1, Freescale Semiconductor document order number HCS08RMV1/D.
The HCS08 CPU is fully source- and object-code-compatible with the M68HC08 CPU. Several
instructions and enhanced addressing modes were added to improve C compiler efficiency and to support
a new background debug system which replaces the monitor mode of earlier M68HC08 microcontrollers
(MCU).
7.1.1Features
Features of the HCS08 CPU include:
•Object code fully upward-compatible with M68HC05 and M68HC08 Families
•All registers and memory are mapped to a single 64-Kbyte address space
•16-bit index register (H:X) with powerful indexed addressing modes
•8-bit accumulator (A)
•Many instructions treat X as a second general-purpose 8-bit register
•Seven addressing modes:
— Inherent — Operands in internal registers
— Relative — 8-bit signed offset to branch destination
— Immediate — Operand in next object code byte(s)
— Direct — Operand in memory at 0x0000–0x00FF
— Extended — Operand anywhere in 64-Kbyte address space
— Indexed relative to H:X — Five submodes including auto increment
— Indexed relative to SP — Improves C efficiency dramatically
•Memory-to-memory data move instructions with four address mode combinations
•Overflow, half-carry, negative, zero, and carry condition codes support conditional branching on
the results of signed, unsigned, and binary-coded decimal (BCD) operations
•Efficient bit manipulation instructions
•Fast 8-bit by 8-bit multiply and 16-bit by 8-bit divide instructions
•STOP and WAIT instructions to invoke low-power operating modes
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor87
Chapter 7 Central Processor Unit (S08CPUV2)
SP
PC
CONDITION CODE REGISTER
CARRY
ZERO
NEGATIVE
INTERRUPT MASK
HALF-CARRY (FROM BIT 3)
TWO’S COMPLEMENT OVERFLOW
HX
0
0
0
7
15
15
70
ACCUMULATOR
A
INDEX REGISTER (LOW)INDEX REGISTER (HIGH)
STACK POINTER
87
PROGRAM COUNTER
16-BIT INDEX REGISTER H:X
CCR
CV11H INZ
7.2Programmer’s Model and CPU Registers
Figure 7-1 shows the five CPU registers. CPU registers are not part of the memory map.
7.2.1Accumulator (A)
The A accumulator is a general-purpose 8-bit register. One operand input to the arithmetic logic unit
(ALU) is connected to the accumulator and the ALU results are often stored into the A accumulator after
arithmetic and logical operations. The accumulator can be loaded from memory using various addressing
modes to specify the address where the loaded data comes from, or the contents of A can be stored to
memory using various addressing modes to specify the address where data from A will be stored.
Reset has no effect on the contents of the A accumulator.
7.2.2Index Register (H:X)
This 16-bit register is actually two separate 8-bit registers (H and X), which often work together as a 16-bit
address pointer where H holds the upper byte of an address and X holds the lower byte of the address. All
indexed addressing mode instructions use the full 16-bit value in H:X as an index reference pointer;
however, for compatibility with the earlier M68HC05 Family, some instructions operate only on the
low-order 8-bit half (X).
Many instructions treat X as a second general-purpose 8-bit register that can be used to hold 8-bit data
values. X can be cleared, incremented, decremented, complemented, negated, shifted, or rotated. Transfer
instructions allow data to be transferred from A or transferred to A where arithmetic and logical operations
can then be performed.
For compatibility with the earlier M68HC05 Family, H is forced to 0x00 during reset. Reset has no effect
on the contents of X.
Figure 7-1. CPU Registers
MC9S08JS16 MCU Series Reference Manual, Rev. 4
88Freescale Semiconductor
Chapter 7 Central Processor Unit (S08CPUV2)
7.2.3Stack Pointer (SP)
This 16-bit address pointer register points at the next available location on the automatic last-in-first-out
(LIFO) stack. The stack may be located anywhere in the 64-Kbyte address space that has RAM and can
be any size up to the amount of available RAM. The stack is used to automatically save the return address
for subroutine calls, the return address and CPU registers during interrupts, and for local variables. The
AIS (add immediate to stack pointer) instruction adds an 8-bit signed immediate value to SP. This is most
often used to allocate or deallocate space for local variables on the stack.
SP is forced to 0x00FF at reset for compatibility with the earlier M68HC05 Family. HCS08 programs
normally change the value in SP to the address of the last location (highest address) in on-chip RAM
during reset initialization to free up direct-page RAM (from the end of the on-chip registers to 0x00FF).
The RSP (reset stack pointer) instruction was included for compatibility with the M68HC05 Family and
is seldom used in new HCS08 programs because it only affects the low-order half of the stack pointer.
7.2.4Program Counter (PC)
The program counter is a 16-bit register that contains the address of the next instruction or operand to be
fetched.
During normal program execution, the program counter automatically increments to the next sequential
memory location every time an instruction or operand is fetched. Jump, branch, interrupt, and return
operations load the program counter with an address other than that of the next sequential location. This
is called a change-of-flow.
During reset, the program counter is loaded with the reset vector that is located at 0xFFFE and 0xFFFF.
The vector stored there is the address of the first instruction that will be executed after exiting the reset
state.
7.2.5Condition Code Register (CCR)
The 8-bit condition code register contains the interrupt mask (I) and five flags that indicate the results of
the instruction just executed. Bits 6 and 5 are set permanently to 1. The following paragraphs describe the
functions of the condition code bits in general terms. For a more detailed explanation of how each
instruction sets the CCR bits, refer to the HCS08 Family Reference Manual, volume 1, Freescale
Semiconductor document order number HCS08RMv1.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor89
Chapter 7 Central Processor Unit (S08CPUV2)
CONDITION CODE REGISTER
CARRY
ZERO
NEGATIVE
INTERRUPT MASK
HALF-CARRY (FROM BIT 3)
TWO’S COMPLEMENT OVERFLOW
70
CCR
CV11H INZ
Figure 7-2. Condition Code Register
Table 7-1. CCR Register Field Descriptions
FieldDescription
7
V
Two’s Complement Overflow Flag — The CPU sets the overflow flag when a two’s complement overflow occurs.
The signed branch instructions BGT, BGE, BLE, and BLT use the overflow flag.
0 No overflow
1Overflow
4
H
Half-Carry Flag — The CPU sets the half-carry flag when a carry occurs between accumulator bits 3 and 4 during
an add-without-carry (ADD) or add-with-carry (ADC) operation. The half-carry flag is required for binary-coded
decimal (BCD) arithmetic operations. The DAA instruction uses the states of the H and C condition code bits to
automatically add a correction value to the result from a previous ADD or ADC on BCD operands to correct the
result to a valid BCD value.
0 No carry between bits 3 and 4
1 Carry between bits 3 and 4
3
Interrupt Mask Bit — When the interrupt mask is set, all maskable CPU interrupts are disabled. CPU interrupts
I
are enabled when the interrupt mask is cleared. When a CPU interrupt occurs, the interrupt mask is set
automatically after the CPU registers are saved on the stack, but before the first instruction of the interrupt service
routine is executed.
Interrupts are not recognized at the instruction boundary after any instruction that clears I (CLI or TAP). This
ensures that the next instruction after a CLI or TAP will always be executed without the possibility of an intervening
interrupt, provided I was set.
0 Interrupts enabled
1 Interrupts disabled
2
N
Negative Flag — The CPU sets the negative flag when an arithmetic operation, logic operation, or data
manipulation produces a negative result, setting bit 7 of the result. Simply loading or storing an 8-bit or 16-bit value
causes N to be set if the most significant bit of the loaded or stored value was 1.
0 Non-negative result
1 Negative result
1
Z
0
C
90Freescale Semiconductor
Zero Flag — The CPU sets the zero flag when an arithmetic operation, logic operation, or data manipulation
produces a result of 0x00 or 0x0000. Simply loading or storing an 8-bit or 16-bit value causes Z to be set if the
loaded or stored value was all 0s.
0 Non-zero result
1Zero result
Carry/Borrow Flag — The CPU sets the carry/borrow flag when an addition operation produces a carry out of bit
7 of the accumulator or when a subtraction operation requires a borrow. Some instructions — such as bit test and
branch, shift, and rotate — also clear or set the carry/borrow flag.
0 No carry out of bit 7
1 Carry out of bit 7
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Chapter 7 Central Processor Unit (S08CPUV2)
7.3Addressing Modes
Addressing modes define the way the CPU accesses operands and data. In the HCS08, all memory, status
and control registers, and input/output (I/O) ports share a single 64-Kbyte linear address space so a 16-bit
binary address can uniquely identify any memory location. This arrangement means that the same
instructions that access variables in RAM can also be used to access I/O and control registers or nonvolatile
program space.
Some instructions use more than one addressing mode. For instance, move instructions use one addressing
mode to specify the source operand and a second addressing mode to specify the destination address.
Instructions such as BRCLR, BRSET, CBEQ, and DBNZ use one addressing mode to specify the location
of an operand for a test and then use relative addressing mode to specify the branch destination address
when the tested condition is true. For BRCLR, BRSET, CBEQ, and DBNZ, the addressing mode listed in
the instruction set tables is the addressing mode needed to access the operand to be tested, and relative
addressing mode is implied for the branch destination.
7.3.1Inherent Addressing Mode (INH)
In this addressing mode, operands needed to complete the instruction (if any) are located within CPU
registers so the CPU does not need to access memory to get any operands.
7.3.2Relative Addressing Mode (REL)
Relative addressing mode is used to specify the destination location for branch instructions. A signed 8-bit
offset value is located in the memory location immediately following the opcode. During execution, if the
branch condition is true, the signed offset is sign-extended to a 16-bit value and is added to the current
contents of the program counter, which causes program execution to continue at the branch destination
address.
7.3.3Immediate Addressing Mode (IMM)
In immediate addressing mode, the operand needed to complete the instruction is included in the object
code immediately following the instruction opcode in memory. In the case of a 16-bit immediate operand,
the high-order byte is located in the next memory location after the opcode, and the low-order byte is
located in the next memory location after that.
7.3.4Direct Addressing Mode (DIR)
In direct addressing mode, the instruction includes the low-order eight bits of an address in the direct page
(0x0000–0x00FF). During execution a 16-bit address is formed by concatenating an implied 0x00 for the
high-order half of the address and the direct address from the instruction to get the 16-bit address where
the desired operand is located. This is faster and more memory efficient than specifying a complete 16-bit
address for the operand.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor91
Chapter 7 Central Processor Unit (S08CPUV2)
7.3.5Extended Addressing Mode (EXT)
In extended addressing mode, the full 16-bit address of the operand is located in the next two bytes of
program memory after the opcode (high byte first).
7.3.6Indexed Addressing Mode
Indexed addressing mode has seven variations including five that use the 16-bit H:X index register pair
and two that use the stack pointer as the base reference.
7.3.6.1Indexed, No Offset (IX)
This variation of indexed addressing uses the 16-bit value in the H:X index register pair as the address of
the operand needed to complete the instruction.
7.3.6.2Indexed, No Offset with Post Increment (IX+)
This variation of indexed addressing uses the 16-bit value in the H:X index register pair as the address of
the operand needed to complete the instruction. The index register pair is then incremented
(H:X = H:X + 0x0001) after the operand has been fetched. This addressing mode is only used for MOV
and CBEQ instructions.
7.3.6.3Indexed, 8-Bit Offset (IX1)
This variation of indexed addressing uses the 16-bit value in the H:X index register pair plus an unsigned
8-bit offset included in the instruction as the address of the operand needed to complete the instruction.
7.3.6.4Indexed, 8-Bit Offset with Post Increment (IX1+)
This variation of indexed addressing uses the 16-bit value in the H:X index register pair plus an unsigned
8-bit offset included in the instruction as the address of the operand needed to complete the instruction.
The index register pair is then incremented (H:X = H:X + 0x0001) after the operand has been fetched. This
addressing mode is used only for the CBEQ instruction.
7.3.6.5Indexed, 16-Bit Offset (IX2)
This variation of indexed addressing uses the 16-bit value in the H:X index register pair plus a 16-bit offset
included in the instruction as the address of the operand needed to complete the instruction.
7.3.6.6SP-Relative, 8-Bit Offset (SP1)
This variation of indexed addressing uses the 16-bit value in the stack pointer (SP) plus an unsigned 8-bit
offset included in the instruction as the address of the operand needed to complete the instruction.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
92Freescale Semiconductor
Chapter 7 Central Processor Unit (S08CPUV2)
7.3.6.7SP-Relative, 16-Bit Offset (SP2)
This variation of indexed addressing uses the 16-bit value in the stack pointer (SP) plus a 16-bit offset
included in the instruction as the address of the operand needed to complete the instruction.
7.4Special Operations
The CPU performs a few special operations that are similar to instructions but do not have opcodes like
other CPU instructions. In addition, a few instructions such as STOP and WAIT directly affect other MCU
circuitry. This section provides additional information about these operations.
7.4.1Reset Sequence
Reset can be caused by a power-on-reset (POR) event, internal conditions such as the COP (computer
operating properly) watchdog, or by assertion of an external active-low reset pin. When a reset event
occurs, the CPU immediately stops whatever it is doing (the MCU does not wait for an instruction
boundary before responding to a reset event). For a more detailed discussion about how the MCU
recognizes resets and determines the source, refer to the Resets, Interrupts, and System Configuration
chapter.
The reset event is considered concluded when the sequence to determine whether the reset came from an
internal source is done and when the reset pin is no longer asserted. At the conclusion of a reset event, the
CPU performs a 6-cycle sequence to fetch the reset vector from 0xFFFE and 0xFFFF and to fill the
instruction queue in preparation for execution of the first program instruction.
7.4.2Interrupt Sequence
When an interrupt is requested, the CPU completes the current instruction before responding to the
interrupt. At this point, the program counter is pointing at the start of the next instruction, which is where
the CPU should return after servicing the interrupt. The CPU responds to an interrupt by performing the
same sequence of operations as for a software interrupt (SWI) instruction, except the address used for the
vector fetch is determined by the highest priority interrupt that is pending when the interrupt sequence
started.
The CPU sequence for an interrupt is:
1. Store the contents of PCL, PCH, X, A, and CCR on the stack, in that order.
2. Set the I bit in the CCR.
3. Fetch the high-order half of the interrupt vector.
4. Fetch the low-order half of the interrupt vector.
5. Delay for one free bus cycle.
6. Fetch three bytes of program information starting at the address indicated by the interrupt vector
to fill the instruction queue in preparation for execution of the first instruction in the interrupt
service routine.
After the CCR contents are pushed onto the stack, the I bit in the CCR is set to prevent other interrupts
while in the interrupt service routine. Although it is possible to clear the I bit with an instruction in the
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor93
Chapter 7 Central Processor Unit (S08CPUV2)
interrupt service routine, this would allow nesting of interrupts (which is not recommended because it
leads to programs that are difficult to debug and maintain).
For compatibility with the earlier M68HC05 MCUs, the high-order half of the H:X index register pair (H)
is not saved on the stack as part of the interrupt sequence. The user must use a PSHH instruction at the
beginning of the service routine to save H and then use a PULH instruction just before the RTI that ends
the interrupt service routine. It is not necessary to save H if you are certain that the interrupt service routine
does not use any instructions or auto-increment addressing modes that might change the value of H.
The software interrupt (SWI) instruction is like a hardware interrupt except that it is not masked by the
global I bit in the CCR and it is associated with an instruction opcode within the program so it is not
asynchronous to program execution.
7.4.3Wait Mode Operation
The WAIT instruction enables interrupts by clearing the I bit in the CCR. It then halts the clocks to the
CPU to reduce overall power consumption while the CPU is waiting for the interrupt or reset event that
will wake the CPU from wait mode. When an interrupt or reset event occurs, the CPU clocks will resume
and the interrupt or reset event will be processed normally.
If a serial BACKGROUND command is issued to the MCU through the background debug interface while
the CPU is in wait mode, CPU clocks will resume and the CPU will enter active background mode where
other serial background commands can be processed. This ensures that a host development system can still
gain access to a target MCU even if it is in wait mode.
7.4.4Stop Mode Operation
Usually, all system clocks, including the crystal oscillator (when used), are halted during stop mode to
minimize power consumption. In such systems, external circuitry is needed to control the time spent in
stop mode and to issue a signal to wake the target MCU when it is time to resume processing. Unlike the
earlier M68HC05 and M68HC08 MCUs, the HCS08 can be configured to keep a minimum set of clocks
running in stop mode. This optionally allows an internal periodic signal to wake the target MCU from stop
mode.
When a host debug system is connected to the background debug pin (BKGD) and the ENBDM control
bit has been set by a serial command through the background interface (or because the MCU was reset into
active background mode), the oscillator is forced to remain active when the MCU enters stop mode. In this
case, if a serial BACKGROUND command is issued to the MCU through the background debug interface
while the CPU is in stop mode, CPU clocks will resume and the CPU will enter active background mode
where other serial background commands can be processed. This ensures that a host development system
can still gain access to a target MCU even if it is in stop mode.
Recovery from stop mode depends on the particular HCS08 and whether the oscillator was stopped in stop
mode. Refer to the Modes of Operation chapter for more details.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
94Freescale Semiconductor
Chapter 7 Central Processor Unit (S08CPUV2)
7.4.5BGND Instruction
The BGND instruction is new to the HCS08 compared to the M68HC08. BGND would not be used in
normal user programs because it forces the CPU to stop processing user instructions and enter the active
background mode. The only way to resume execution of the user program is through reset or by a host
debug system issuing a GO, TRACE1, or TAGGO serial command through the background debug
interface.
Software-based breakpoints can be set by replacing an opcode at the desired breakpoint address with the
BGND opcode. When the program reaches this breakpoint address, the CPU is forced to active
background mode rather than continuing the user program.
MC9S08JS16 MCU Series Reference Manual, Rev. 4
Freescale Semiconductor95
Chapter 7 Central Processor Unit (S08CPUV2)
C
b0
b7
0
b0
b7
C
7.5HCS08 Instruction Set Summary
Table 7-2 provides a summary of the HCS08 instruction set in all possible addressing modes. The table
shows operand construction, execution time in internal bus clock cycles, and cycle-by-cycle details for
each addressing mode variation of each instruction.