• Up to 40 MHz CPU at 5.5 V to 2.7 V across temperature
range of –40 °C to 85 °C and –40 °C to 105 °C
• HCS08 instruction set with added BGND instruction
• Support for up to 32 interrupt/reset sources
On-Chip Memory
• 32 KB or 18 KB dual array flash; read/program/erase
over full operating voltage and temperature
• 1984 byte random access memory (RAM)
• Security circuitry to prevent unauthorized access to
RAM and flash contents
Power-Saving Modes
• Two low-power stop modes (stop2 and stop3)
• Reduced-power wait mode
• Peripheral clock gating register can disable clocks to
unused modules, thereby reducing currents
• Low power on-chip crystal oscillator (XOSC) that can be
used in low-power modes to provide accurate clock
source to real time counter and LCD controller
• 100 μs typical wakeup time from stop3 mode
Clock Source Options
• Oscillator (XOSC) — Loop-control Pierce oscillator;
crystal or ceramic resonator range of 31.25 kHz to
38.4 kHz or 1 MHz to 16 MHz
• Internal Clock Source (ICS) — Internal clock source
module containing a frequency-locked-loop (FLL)
controlled by internal or external reference; precision
trimming of internal reference allows 0.2% resolution
and 2% deviation over temperature and voltage; supports
bus frequencies from 1 MHz to 20 MHz
System Protection
• On-chip in-circuit emulator (ICE) debug module
containing three comparators and nine trigger modes;
eight deep FIFO for storing change-of-flow addresses
and event-only data; debug module supports both tag and
force breakpoints
Peripherals
• LCD — Up to 4 x 41 or 8 x 37 LCD driver with internal
charge pump
• ADC — Up to 16-channel, 12-bit resolution; 2.5 μs
conversion time; automatic compare function;
temperature sensor; internal bandgap reference channel;
runs in stop3 and can wake up the system; fully
functional from 5.5 V to 2.7 V
• SCI — Full duplex non-return to zero (NRZ); LIN
master extended break generation; LIN slave extended
break detection; wakeup on active edge
• SPI— Full-duplex or single-wire bidirectional;
double-buffered transmit and receive; master or slave
mode; MSB-first or LSB-first shifting
• IIC — With up to 100 kbps with maximum bus loading;
multi-master operation; programmable slave address;
interrupt driven byte-by-byte data transfer; supports
broadcast mode and 10-bit addressing
• TPMx — One 6 channel and one 2 channel; selectable
input capture, output compare, or buffered edge or
center-aligned PWM on each channel
• MTIM — 8-bit counter with match register; four clock
sources with prescaler dividers; can be used for periodic
wakeup
• RTC — 8-bit modulus counter with binary or decimal
based prescaler; three clock sources including one
external source; can be used for time base, calendar, or
task scheduling functions
• KBI — One keyboard control module capable of
supporting 8x8 keyboard matrix
• IRQ — External pin for wakeup from low-power modes
• COP reset with option to run from dedicated 1 kHz
internal clock or bus clock
• Low-voltage warning with interrupt
• Low-voltage detection with reset
• Illegal opcode detection with reset
• Illegal address detection with reset
• Flash and RAM protection
Development Support
• Single-wire background debug interface
• Breakpoint capability to allow single breakpoint setting
during in-circuit debugging (plus two more breakpoints
in on-chip debug module)
Input/Output
• 39, 53, or 69 GPIOs
• 8 KBI and 1 IRQ interrupt with selectable polarity
• Hysteresis and configurable pullup device on all input
pins; configurable slew rate and drive strength on all
output pins
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://www.freescale.com
The following revision history table summarizes changes contained in this document.
• Changed ‘LCDCPEN” to “LCDPEN” and “LCDFWF” to “LCDWF.”
•In Chapter 12, “Inter-Integrated Circuit (S08IICV2),” a note is added in the
introduction mentioning that MC9S08LG32 series of MCUs include only one
IIC module.
The MC9S08LG32 and MC9S08LG16 are the members of the low-cost, low-power, and
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 memory sizes and package types.
The MC9S08LG32 series MCUs are targeted to serve automotive, consumer and industrial markets.
Please check the ordering part numbers for different qualification tier products in Ordering Information section of MC9S08LG32 Data Sheet.
1.1Devices in the MC9S08LG32 Series
Table 1-1 summarizes the feature set available in the MC9S08LG32 series of MCUs.
Table 1-1. MC9S08LG32 series Features by MCU and Package
FeatureMC9S08LG32MC9S08LG16
Flash size (bytes)32,76818,432
RAM size (bytes)1984
Pin quantity8064486448
ADC16 ch12 ch9 ch12 ch9 ch
LCD8 x 37
4 x 41
ICE + DBGyes
ICSyes
IICyes
IRQyes
KBI8 pin
GPIOs695339 5339
RTCyes
MTIMyes
SCI1yes
SCI2yes
SPIyes
TPM1 channels2
TPM2 channels6
XOSCyes
8 x 29
4 x 33
8 x 21
4 x 25
8 x 29
4 x 33
8 x 21
4 x 25
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor21
Page 22
Chapter 1 Device Overview
8-BIT KEYBOARD
INTERRUPT (
KBI
)
IIC MODULE (
IIC
)
SERIAL PERIPHERAL
INTERFACE (
SPI
)
USER FLASH B
USER RAM
ON-CHIP ICE (
ICE
) and
DEBUG MODULE (
DBG
)
(LG32 = 16K BYTES)
HCS08 CORE
CPU
BKGD
INT
BKP
2-CHANNEL TIMER/PWM
(
TPM1
)
HCS08 SYSTEM CONTROL
RESETS AND INTERRUPTS
MODES OF OPERATION
POWER MANAGEMENT
IRQLVD
LOW-POWER OSCILLATOR
INTERNAL CLOCK
Source (
ICS
)
SERIAL COMMUNICATIONS
6-CHANNEL TIMER/PWM
(
TPM2
)
V
LL1
(LCD)
V
LL2
V
LL3
V
CAP1
V
CAP2
LCD[44:0]
V
SS
V
DD
VO LTAGE
REGULATOR
USER FLASH A
(LG16 = 2K BYTES)
LCD28/ADC5/TPMCLK
/PTA7
LCD27/ADC4/TPM2CH1/KBI7/
PTA6
LCD25/ADC2/RX2/KBI5/
PTA4
INTERFACE (
SCI1
)
TxD1
RxD1
SS
SPSCK
SCL
SDA
MOSI
MISO
V
SSA/VREFL
V
DDA/VREFH
XTAL
EXTAL
IRQ
KBI[7:0]
PORT A
RESET
LIQUID CRYSTAL
DISPLAY DRIVER
ANALOG-TO-DIGITAL
CONVERTER (
ADC
)
12-BIT
AD[15:0]
TPM2CH[5:0]
TPMCLK
TPMCLK
LCD24/ADC1/TX2/KBI4/
PTA3
LCD23/ADC0/SDA/
PTA2
LCD22/SCL/
PTA1
LCD21/
PTA0
(LG32 = 16K BYTES)
(LG16 = 16K BYTES)
LCD26/ADC3/TPM2CH0/KBI6/
PTA5
BKGD/MS
TPM1CH[1:0]
COP
Real Time Counter
(
RTC
)
TMRCLK
SERIAL COMMUNICATIONS
INTERFACE (
SCI2
)
TxD2
RxD2
PORT C
EXTAL/
PTF7
XTAL/
PTF6
TPM2CH4/KBI1/MISO
/
PTF4
PORT F
TPM2CH5/KBI0/SS/
PTF3
ADC14/IRQ/TPM1CH1/SPSCK/
PTF2
ADC13/TPM1CH0/RX1/
PTF1
ADC12/TPM2CH2/KBI3/TX1/
PTF0
TPM2CH3/KBI2/MOSI/
PTF5
SPSCK/SDA/TPM2CH1/
PTI4
PORT I
MOSI/TPM2CH2/
PTI3
MISO/TPM2CH3/
PTI2
TX2/TMRCLK/
PTI1
RX2
/PTI0
SS/SCL/TPM2CH0/
PTI5
PORT D
PORT E
LCD[40:37]
/PTB[7:4]
LCD[32:29]
/PTB[3:0]
LCD[7:0]
/PTD[7:0]
PORT B
LCD[15:8]/
PTE[7:0]
LCD[44:41]/
PTG[7:4]
LCD[36:33]
/PTG[3:0]
PORT G
ADC11/TPM1CH0/KBI3/TX1/
PTH5
ADC10/TPM1CH1/KBI2/RX1/
PTH4
ADC[9:6]/KBI[7:4]/
PTH[3:0]
TPM2CH4/KBI1/
PTH7
ADC15/KBI0/TPM2CH5/
PTH6
PORT H
V
SS2
V
LL3_2
Available only on 80-pin package
Available only on 64-pin and 80-pin package
*/
Default function out of reset
/*
BKGD/MS
/PTC5
RESET
/PTC6
Modulo Timer
(
MTIM
)
1984 BYTES
LCD[20:16]/
PTC[4:0]
1.2MCU Block Diagram
The block diagram in Figure 1-1 shows the structure of the MC9S08LG32 series MCU.
22Freescale Semiconductor
Figure 1-1. MC9S08LG32 Series Block Diagram
MC9S08LG32 MCU Series, Rev. 5
Page 23
Table 1-2 provides the functional version of the on-chip modules.
Table 1-2. Module Versions
ModuleVersion
Analog-to-Digital Converter(ADC12)1
Central Processor Unit(CPU)5
Inter-Integrated Circuit(IIC)2
Internal Clock Source(ICS)3
Keyboard Interrupt(KBI)2
Liquid Crystal Display Module(LCD)1
Low Power Oscillator(XOSC)1
Modulo Timer(MTIM)1
On-Chip In-Circuit Debug/Emulator(DBG)3
Real Time Counter(RTC)1
Serial Communications Interface(SCI)4
Serial Peripheral Interface(SPI)4
Timer Pulse Width Modulator(TPM)3
Chapter 1 Device Overview
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor23
Page 24
Chapter 1 Device Overview
1.3System Clock Distribution
Figure 1-2 shows a simplified clock connection diagram of the ICS. Some modules in the MCU have
selectable clock inputs as shown. The clock inputs to the modules indicate the clock(s) that are used to
drive the module function. All memory-mapped registers associated with the modules are clocked with
BUSCLK. The ICS supplies the following clock sources:
•ICSOUT — This clock source is used as the CPU clock and is divided by 2 to generate the
peripheral bus clock, BUSCLK. Control bits in the ICS control registers determine which of the
three clock sources is connected:
— Internal reference clock
— External reference clock
— Frequency-locked loop (FLL) output
For more information on configuring the ICSOUT clock, see Chapter 11, “Internal Clock Source
(S08ICSV3).”
•ICSLCLK — This clock source is derived from the digitally controlled oscillator (DCO) of the ICS
when the ICS is configured to run off the internal or external reference clock. The development
tools can select this internal self-clocked source (~ 8 MHz) to speed up the BDC communications
in systems where the bus clock is slow.
•ICSERCLK — This is an external reference clock and can be selected as the alternate clock for
ADC. The “Optional External Reference Clock” section in Chapter 11, “Internal Clock Source
(S08ICSV3),” explains the ICSERCLK in more detail. For more information regarding the use of
ICSERCLK with this module, see Chapter 10, “Analog-to-Digital Converter (S08ADC12V1).”
•ICSIRCLK — This is an internal reference clock and can be selected as the RTC clock source, or
as ALTCLK source for the LCD. Chapter 11, “Internal Clock Source (S08ICSV3)” explains the
ICSIRCLK in more detail. For more information regarding use of ICSIRCLK with these modules,
see Chapter 15, “Real-Time Counter (S08RTCV1),” and Chapter 9, “LCD Module
(S08LCDLPV1).”
•ICSFFCLK — This fixed frequency clock (FFCLK) is generated after it is synchronized with the
bus clock. The frequency of the ICSFFCLK is determined by the settings of the ICS. For more
information, see the “Fixed Frequency Clock” section in Chapter 11, “Internal Clock Source
(S08ICSV3).” It can be selected as a clock source for the MTIM and TPM modules. For
information regarding use of ICSFFCLK with these modules, see Chapter 16, “Timer/Pulse-Width
Modulator (S08TPMV3),” and Chapter 17, “Modulo Timer (S08MTIMV1).”
•LPOCLK — This clock is generated from an internal low power oscillator (LPO) that is
completely independent of the ICS module. The LPOCLK can be selected as the clock source to
the COP and RTC module. See Section 5.4, “Computer Operating Properly (COP) Watchdog,” and
Chapter 15, “Real-Time Counter (S08RTCV1),” for details on using the LPOCLK with these
modules.
•OSCOUT — This is the output of the XOSC module and can be selected as the LCD and RTC
clock source. This clock source can be used for LCD and RTC in stop2 mode. For more information
regarding use of OSCOUT with these modules, see Chapter 15, “Real-Time Counter
(S08RTCV1),” and Chapter 9, “LCD Module (S08LCDLPV1).”
MC9S08LG32 MCU Series, Rev. 5
24Freescale Semiconductor
Page 25
Chapter 1 Device Overview
TPM1TPM2
SCI1SCI2
BDC
CPU
ADC
FLASH
ICS
ICSOUT
÷2
BUSCLK
ICSLCLK
ICSIRCLK
COP
* The fixed frequency clock (FFCLK) is internally
synchronized to the bus clock and must not
exceed one half of the bus clock frequency.
Flash has frequency
requirements for program
and erase operation. See the
electricals appendix for
details.
ADC has min and max
frequency requirements.
See the ADC chapter and
electricals appendix for
details.
XOSC
EXTALXTAL
FFCLK*
ICSFFCLK
1 kHz
LPO
ICSERCLK
÷2
IIC
DBG
SYNC*
LPOCLK
OSCOUT
LCD
TPMCLK
MTIM
TMRCLK
SPI
KBI
RTC
•TPMCLK — The TPMCLK is an optional external clock source for the TPM modules. The
TPMCLK must be limited to 1/4th of the frequency of the bus clock for synchronization. For more
information, see the “External TPM Clock Sources” section in Chapter 16, “Timer/Pulse-Width
Modulator (S08TPMV3).”
•TMRCLK — The TMRCLK is an optional external clock source for the MTIM module. For more
information, see Chapter 17, “Modulo Timer (S08MTIMV1).”
NOTE
ICSERCLK is a gated version of OSCOUT. ICSERCLK is not available in
STOP modes while OSCOUT is available if ERCLKEN and EREFSTEN
are set.
Figure 1-2. System Clock Distribution Diagram
Freescale Semiconductor25
MC9S08LG32 MCU Series, Rev. 5
Page 26
Chapter 1 Device Overview
MC9S08LG32 MCU Series, Rev. 5
26Freescale Semiconductor
Page 27
Chapter 2
Pins and Connections
2.1Introduction
This section describes signals that connect to the package pins. It includes pinout diagrams, recommended
system connections, and detailed discussions of signals.
2.2Device Pin Assignment
This section shows the pin assignments for MC9S08LG32 series. The priority of functions on a pin is in
ascending order from left to right and bottom to top. Another view of pinouts and function priority is given
in Table 2-1.
Figure 2-4 shows pin connections that are common to MC9S08LG32 series application systems.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor31
Page 32
Chapter 2 Pins and Connections
BKGD/MS
RESET
OPTIONAL
MANUAL
RESET
V
DD
BACKGROUND HEADER
C
2
C
1
X1
R
F
R
S
SYSTEM
POWER
MC9S08LG32
V
DDA/VREFH
V
SSA/VREFL
C
BYAD
0.1
μ
F
V
DD
V
SS
C
BY
0.1
μ
F
C
BLK
10
μ
F
+
5 V
+
XTAL
EXTAL
NOTES:
1
RESET pin can only be used to reset into user mode, you can not enter BDM using RESET pin. To enter BDM, hold MS low
during POR or write a 1 to BDFR in SBDFR with MS low after issuing BDM command.
2
RC filter on RESET pin recommended for noisy environments.
3
When PTC6 is configured as RESET, pin becomes bi-directional with output being open-drain drive containing an internal
pullup device.
4
When PTC5 is configured as BKGD, pin becomes bi-directional.
5
LCD mode shown is for Charge pump enabled, other configurations are necessary for different LCD modes.
(NOTE 3)
(NOTE 4)
LCD Glass
V
LL1
V
LL2
V
CAP2
0.1
μ
F
0.1
μ
F
0.1
μ
F
V
CAP1
0.1μF
V
LL3
LCD[44:0]
LCD
Module
LCD28/ADC5/TPMCLK/
PTA7
LCD25/ADC2/RX2/KBI5/
PTA4
PORT A
LCD24/ADC1/TX2/KBI4/
PTA3
LCD23/ADC0/SDA/
PTA2
LCD22/SCL/
PTA1
LCD21/
PTA0
PORT C
EXTAL/
PTF7
XTAL/
PTF6
TPM2CH4/KBI1/MISO
/
PTF4
PORT F
TPM2CH5/KBI0/
SS/
PTF3
ADC14/IRQ/TPM1CH1/SPSCK/
PTF2
ADC13/TPM1CH0/RX1/
PTF1
ADC12/TPM2CH2/KBI3/TX1/
PTF0
TPM2CH3/KBI2/MOSI/
PTF5
SPSCK/SDA/TPM2CH1/
PTI4
PORT I
MOSI/TPM2CH2/
PTI3
MISO/TPM2CH3/
PTI2
TX2/TMRCLK/
PTI1
RX2/
PTI0
SS
/SCL/TPM2CH0/
PTI5
PORT D
PORT E
LCD[40:37]/
PTB[7:4]
LCD[32:29]/
PTB[3:0]
LCD[20:16]/
PTC[4:0]
LCD[7:0]/
PTD[7:0]
PORT B
LCD[15:8]/
PTE[7:0]
LCD[44:41]/
PTG[7:4]
LCD[36:33]/
PTG[3:0]
PORT G
ADC11/TPM1CH0/KBI3/TX1/
PTH5
ADC10/TPM1CH1/KBI2/RX1/
PTH4
ADC[9:6]/KBI[7:4]/
PTH[3:0]
TPM2CH4/KBI1/
PTH7
ADC15/KBI0/TPM2CH5/
PTH6
PORT H
BKGD/MS
/PTC5
RESET_B
/PTC6
LCD27/ADC4/TPM2CH1/KBI7/
PTA6
LCD26/ADC3/TPM2CH0/KBI6/
PTA5
Available only on 80-pin package
Available only on 64-pin and 80-pin package
*/Default function out of reset/*
Figure 2-4. Basic System Connections
32Freescale Semiconductor
MC9S08LG32 MCU Series, Rev. 5
Page 33
Chapter 2 Pins and Connections
2.3.1Power
VDD and VSS are 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 a regulated
lower-voltage source for the CPU and other internal circuitry of the MCU.
The LCD/GPIO can be powered differently. For additional information, see Chapter 6, “Parallel
Input/Output Control.”
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 MCU power pins as practical
to suppress high-frequency noise.
V
and V
DDA
ADC modules.
are the analog power supply pins for the MCU. This voltage source supplies power to the
SSA
V
for the ADC module. For this MCU, V
REFH
and V
pins are the voltage reference high and the voltage reference low inputs, respectively,
REFL
shares the V
DDA
REFH
pin and V
shares the V
SSA
REFL
pin.
2.3.2Oscillator
Immediately after reset, the MCU uses an internally generated clock provided by the internal clock source
(ICS) module. The ICS can be configured to run off the on-chip oscillator (ICSERCLK). The output of the
oscillator (OSCOUT) is used to run the RTC and LCD bypassing the ICS. The oscillator can be configured
to run in stop2 or stop3 modes. For more information, see Section 1.3, “System Clock Distribution,” and
Chapter 11, “Internal Clock Source (S08ICSV3).”
The oscillator (XOSC) in this MCU is a Pierce oscillator that can accommodate a crystal or ceramic
resonator. An external clock source can optionally be connected to the EXTAL input pin.
Refer to Figure 2-4 for the following discussion. 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 must be high-quality ceramic capacitors that are specifically designed for
high-frequency applications.
provides a bias path to keep the EXTAL input in its linear range during crystal startup; its value is not
R
F
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 consider the printed circuit board (PCB) capacitance and the MCU pin
capacitance when selecting C1 and C2. The crystal manufacturer typically specifies a load capacitance,
which is the series combination of C
and C2 (which are usually of the same size). As a first-order
1
approximation, use 10 pF as an estimate of combined pin and PCB capacitance for each oscillator pin
(EXTAL and XTAL).
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor33
Page 34
Chapter 2 Pins and Connections
2.3.3RESET
After a power-on reset (POR), the PTC6/RESET pin defaults to RESET. Clearing RSTPE in SOPT1
configures the pin to be an output-only pin with an open-drain drive and an internal pullup device. RSTPE
is a write-once bit; so once written, it becomes read-only until the next reset. This bit is sticky and is reset
only at POR or LVD; it retains its value across other resets. When enabled, the RESET
reset the MCU from an external source when the pin is driven low.
Internal POR 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. A manual external reset can be added by supplying a simple switch to
ground (pull reset pin low to force a reset).
Whenever any non-POR reset is initiated (whether from an external signal or from an internal system), the
enabled RESET
pin is driven low for about 34 bus cycles. The reset circuitry decodes the cause of reset
and records it by setting a corresponding bit in the system reset status register (SRS).
NOTE
This pin does not contain a clamp diode to VDD and must not be driven
above VDD.
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
DD
be used.
pin can be used to
In EMC-sensitive applications, an external RC filter is recommended on the
RESET pin, if enabled.
2.3.4Background / Mode Select (BKGD/MS)
During POR or background debug force reset (for more information, see Section 5.8.3, “System
Background Debug Force Reset Register (SBDFR)”), the PTC5/BKGD/MS pin functions as a mode select
pin. Immediately after any reset, the pin functions as the background pin and can be used for background
debug communication. When BKGD/MS function is enabled with BKGDPE = 1, an internal pullup device
automatically becomes active. Clearing BKGDPE in SOPT1 configures the pin to be an output-only pin.
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 PTC5/BKGD/MS pin’s alternative pin
functions.
After any reset, if nothing is connected to this pin, the MCU enters normal operating mode. If a debug
system is connected to the 6-pin standard background debug header, it can hold BKGD/MS low. It can do
this during a POR or after issuing a background debug force reset. This forces the MCU to active
background mode.
The BKGD/MS pin is used primarily with BDC communications, and features a custom protocol that uses
16 clock cycles of the target MCU’s BDC clock per bit time. The target MCU’s BDC clock can run as fast
MC9S08LG32 MCU Series, Rev. 5
34Freescale Semiconductor
Page 35
Chapter 2 Pins and Connections
as the bus clock, so no significant capacitance must be connected to the BKGD/MS pin that could interfere
with background serial communications.
Although the BKGD/MS 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 a minimal role in determining rise and fall
times on the BKGD/MS pin.
NOTE
Ensure this pin is not low when the part is coming out of POR or BDFR
reset. Exit from stop2 causes POR, therefore POR includes the exit from
stop2. Because the pin defaults to BKGD/MS function out of reset, a low
value on this pin while coming out of POR or BDFR causes the part to boot
into BDM mode. If this pin is not being used at all, it must be tied high. A
pullup is recommended when using this pin as GPIO.
2.3.5IRQ
The PTF2/IRQ pin can be used as a wakeup source for the MCU. For stop2 wakeup, this pin has an analog
path which is enabled based on the input buffer enable for this pin, irrespective of whether or not this pin
is configured as IRQ.
NOTE
Care needs to be taken that if this pin is configured as input, it is not low
during stop2 mode, otherwise the part exits stop2 mode irrespective of
whether this pin is configured as IRQ or not. This pin can be disabled as a
wakeup source if it is configured as an output.
2.3.6LCD Pins
2.3.6.1LCD Power Pins
The V
64-pin and 80-pin packages the V
LCD pins, see Chapter 9, “LCD Module (S08LCDLPV1).”
2.3.6.2LCD Driver Pins
The MC9S08LG32 series of MCUs provide 45 LCD driver pins for the 80-pin packages, 37 pins for the
64-pin packages, and 29 pins for the 48-pin packages. Each LCD pin has pin enable control, so you can
choose to use any LCD pin as either LCD driver or GPIO. If the LCD module is disabled, the LCD driver
pins become high-impedance and the LCD/GPIO pins are configured as GPIO. The LCD pins are
open-drain after resets except for stop2 wakeup. For more information about LCD driver pins, see
Chapter 9, “LCD Module (S08LCDLPV1).”
LL1
, V
LL2
, V
LL3
, V
cap1
, and V
LL3_2
pins are dedicated to providing power to the LCD module. On
cap2
pin must be tied to V
on board. For more information about
LL3
Pins that have shared function with the LCD have special behavior based on the state of the VSUPPLY
bits in the LCDSUPPLY register. These pins can operate as full complementary drive or open drain drive
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor35
Page 36
Chapter 2 Pins and Connections
depending on the VSUPPLY bits. When V
is connected to VDD externally, VSUPPLY = 11,
LL3
FCDEN = 1, and RVEN = 0, the pins operate as full complementary drive. For all other VSUPPLY modes,
the LCD/GPIO operates as open drain.
NOTE
For GPIO muxed with LCD pins, full complimentary or open drain drive is
controlled by the LCD controller. When LCD pins are configured as open
drain GPIOs, then the internal pullup is not disabled in output mode and is
controlled by the GPIO pull control register. This can cause some leakage
from the pads if a pullup is enabled and a zero is being driven.
2.3.7General-Purpose I/O (GPIO) and Peripheral Ports
The MC9S08LG32 series of MCUs support up to 69 GPIO pins including 2 output-only pins that are
shared with on-chip peripheral functions (timers, serial I/O, LCD, ADC, etc.). The GPIO output-only pins
(PTC5/BKGD/MS and PTC6/RESET) are bi-directional when configured as BKGD and RESET,
respectively.
GPIO that is muxed with LCD pins can be configured to reference VDD or V
“LCD Driver Pins,” for more details.
When a port pin is configured as a general-purpose output or a peripheral uses the port pin as an output,
the software can select one of the two drive strengths and can enable or disable the slew rate control. When
a port pin is configured as a general-purpose input or a peripheral uses the port pin as an input, the software
can enable a pullup device.
. See Section 2.3.6.2,
LL3
When an on-chip peripheral system is controlling a pin, the data direction control bits still determine what
is read from port data registers even though the peripheral module controls the pin direction by controlling
an enable for the pin’s output buffer. For information about controlling these pins as general-purpose I/O
pins, see Chapter 6, “Parallel Input/Output Control.”
NOTE
•To avoid extra current drain from floating input pins, the reset
initialization routine in the application program must either enable
on-chip pullup devices or change the direction of unused or non-bonded
pins to outputs so they do not float.
•When using RESET
pin as bi-directional reset and LCD pins as
open-drain GPIO, the internal pullups are not disabled when these pins
are used in output mode. This can cause some current leakage through
the pads if zero is driven. This is also true for stop2 mode.
Table 2-1. Pin Availability by Package Pin-Count
Packages<-- Lowest Priority --> Highest
806448Port PinAlt 1Alt 2Alt 3Alt 4
111PTD7LCD7———
222PTD6LCD6———
MC9S08LG32 MCU Series, Rev. 5
36Freescale Semiconductor
Page 37
Chapter 2 Pins and Connections
Table 2-1. Pin Availability by Package Pin-Count (continued)
Packages<-- Lowest Priority --> Highest
806448Port PinAlt 1Alt 2Alt 3Alt 4
333PTD5LCD5———
444PTD4LCD4———
555PTD3LCD3———
666PTD2LCD2———
77—PTB3 LCD32———
88—PTB2 LCD31———
9—— PTB7 LCD40———
10——PTB6LCD39———
11——PTB5LCD38———
12——PTB4LCD37———
139—PTB1LCD30———
1410—PTB0LCD29———
15117PTD1LCD1———
16128PTD0LCD0———
17139V
181410V
191511V
201612V
211713V
CAP1
CAP2
LL1
LL2
LL3
221814PTF5MOSIKBI2TPM2CH3—
231915PTF4MISOKBI1TPM2CH4—
2420—PTI5TPM2CH0SCLSS
2521—PTI4TPM2CH1SDASPSCK—
26——PTI3TPM2CH2MOSI——
27——PTI2TPM2CH3MISO——
28——PTI1TMRCLKTX2——
29——PTI0RX2———
3022—PTH7KBI1TPM2CH4——
312316V
322417V
SS
DD
332518PTF7EXTAL———
342619PTF6XTAL———
352720V
362821V
DDA
SSA
3729—PTH6TPM2CH5KBI0ADC15—
383022PTF2SPSCKTPM1CH1IRQADC14
393123PTF1RX1TPM1CH0ADC13—
403224PTF0TX1KBI3TPM2CH2ADC12
—— — —
—— — —
—— — —
—— — —
—— — —
—
—— — —
—— — —
V
V
REFH
REFL
———
———
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor37
Page 38
Chapter 2 Pins and Connections
Table 2-1. Pin Availability by Package Pin-Count (continued)
Packages<-- Lowest Priority --> Highest
806448Port PinAlt 1Alt 2Alt 3Alt 4
413325PTF3SS
KBI0TPM2CH5—
4234—PTH5TX1KBI3TPM1CH0ADC11
4335—PTH4RX1KBI2TPM1CH1ADC10
44——PTH3KBI7ADC9——
45——PTH2KBI6ADC8——
46——PTH1KBI5ADC7——
47——PTH0KBI4ADC6——
483626PTC6RESET
———
493727PTC5BKGD/MS———
503828PTA7TPMCLKADC5LCD28—
513929PTA6KBI7TPM2CH1ADC4LCD27
524030PTA5KBI6TPM2CH0ADC3LCD26
534131PTA4KBI5RX2ADC2LCD25
544232PTA3KBI4TX2ADC1LCD24
554333PTA2SDAADC0LCD23—
564434PTA1SCLLCD22——
5745—PTG3LCD36———
5846—PTG2LCD35———
594735PTA0LCD21———
604836PTC4LCD20———
614937PTC3LCD19———
625038PTC2LCD18———
635139PTC1LCD17———
645240PTC0LCD16———
655341PTE7LCD15———
665442PTE6LCD14———
6755—V
6856—V
SS2
LL3_2
—— — —
—— — —
69——PTG7LCD44———
70——PTG6LCD43———
71——PTG5LCD42———
72——PTG4LCD41———
7357—PTG1LCD34———
7458—PTG0LCD33———
755943PTE5LCD13———
766044PTE4LCD12———
776145PTE3LCD11———
786246PTE2LCD10———
MC9S08LG32 MCU Series, Rev. 5
38Freescale Semiconductor
Page 39
Chapter 2 Pins and Connections
Table 2-1. Pin Availability by Package Pin-Count (continued)
Packages<-- Lowest Priority --> Highest
806448Port PinAlt 1Alt 2Alt 3Alt 4
796347PTE1LCD9———
806448PTE0LCD8———
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor39
Page 40
Chapter 2 Pins and Connections
MC9S08LG32 MCU Series, Rev. 5
40Freescale Semiconductor
Page 41
Chapter 3
Modes of Operation
3.1Introduction
This chapter describes the operating modes of the MC9S08LG32 series. It also describes entry, exit, and
the functionality of each mode.
3.2Features
•Active background mode for code development.
•Run mode — CPU clocks can be run at full speed and the internal supply is fully regulated.
•Wait mode — CPU shuts down to conserve power; system clocks are running and full regulation
is maintained.
•Stop modes — System clocks are stopped and voltage regulator is in standby.
— Stop3 — All internal circuits are powered for fast recovery.
— Stop2 — Partial power down of internal circuits, RAM content is retained, and the I/O states
are held.
3.3Run Mode
This is the normal operating mode for the MC9S08LG32 series. 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 BDC in the HCS08 core. The BDC and
the on-chip debug module (DBG), provide the means for analyzing MCU operation during software
development.
Active background mode is entered by any of six methods:
•When the BKGD/MS pin is low during POR
•When the BKGD/MS pin is low immediately after issuing a background debug force reset (for
more information, see Section 5.8.3, “System Background Debug Force Reset Register (SBDFR)”)
•When a BACKGROUND command is received through the BKGD/MS pin
•When a BGND instruction is executed
•When encountering a BDC breakpoint
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor41
Page 42
Chapter 3 Modes of Operation
•When encountering a DBG breakpoint
NOTE
The MCU needs to be unsecure for the last four methods.
After entering active background mode, the CPU is held in a suspended state while it waits for serial
background commands instead of executing instructions from the user application program.
The background commands are of two types:
•Non-intrusive commands — These commands are 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 active
background mode. Non-intrusive commands include:
•Active background commands— These commands 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)
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 MC9S08LG32
series is shipped from the Freescale Semiconductor factory, the flash program memory is erased by default,
unless specifically noted. As a result, no program can be executed in run mode until the flash memory is
initially programmed. 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 the Chapter 18, “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 CCR is cleared when the CPU enters wait
mode, enabling interrupts. When an interrupt request occurs, the CPU exits the wait mode and resumes
processing beginning with the stacking operations that lead 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
when 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 either in stop or wait mode. The BACKGROUND
command can be used to wake the MCU from the wait mode and enter active background mode.
MC9S08LG32 MCU Series, Rev. 5
42Freescale Semiconductor
Page 43
Chapter 3 Modes of Operation
The clocks to the peripherals are controlled by SCGC registers in this mode. For lowest possible current
in WAIT mode, all peripherals which are not required must be clock gated before entering in this mode.
3.6Stop Modes
One of the two stop modes (stop2 or stop3) is entered upon execution of a STOP instruction when the
STOPE bit in the system option 1 register (SOPT1) is set. In both the stop modes, the bus and the CPU
clocks are halted.
•In stop3, the voltage regulator is in standby and ICS module can be configured to leave the
reference clocks running.
•In stop2, the voltage regulator is in partial powerdown.
See Chapter 11, “Internal Clock Source (S08ICSV3),” for more information.
If the STOPE bit is not set when the CPU executes a STOP instruction, the MCU does not enter either of
the stop modes and an illegal opcode reset is forced. Stop modes are selected by setting the appropriate
bits in the System Power Management Status and Control Registers, SPMSC1 and SPMSC2.
Table 3-1 shows all control bits that affect the stop mode selection and the modes selected under various
conditions. The selected mode is entered following the execution of a STOP instruction.
Table 3-1. Stop Mode Selection
RegisterSOPT1BDCSCRSPMSC1SPMSC2
Bit nameSTOPEENBDM
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 (with Voltage regulator in Standby)
10Either bit a 01Stop2
1
ENBDM is located in the BDCSCR that is only accessible through BDC commands, see Chapter 18, “Development
Support.”
2
When in stop3 mode with BDM enabled, the S
1
LV DELV D SEP PD C
is near the R
IDD
instruction executed
levels because internal clocks are enabled.
IDD
Stop Mode
2
3.6.1Stop2 Mode
To enter stop2, execute a STOP instruction under the conditions as shown in Tab le 3-1 . Most of an internal
circuitry of the MCU is powered off in stop2 mode with an exception of the RAM, the low power
oscillator, RTC and the LCD module. Upon entering stop2 mode, all I/O pin control signals are latched so
that the pins retain their states during stop2. The LCD driver pins continue to drive the signals necessary
to display the LCD data.
To exit from stop2 mode, assert the wakeup pins (PTC6/RESET
or PTF2/IRQ) or through RTC interrupt
or POR.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor43
Page 44
Chapter 3 Modes of Operation
NOTE
When PTC6/RESET or PTF2/IRQ is used as an active low wakeup source
it must be configured as an input prior to executing a STOP instruction.
PTC6/RESET and PTF2/IRQ can be disabled as a wakeup if it is configured
as output port. For lowest power consumption in stop2, these pins must not
be left open if configured as input (enable the internal pullup or tie an
external pullup device).
Upon wakeup from stop2 mode, the MCU starts up as from a POR with the following sequence:
•All module control and status registers are reset, except for SPMSC1-SPMSC2, RTCSC,
RTCCNT, RTCMOD, LCDPENx, LCDBPENx, and LCDWFRx.
•The LVD reset function is enabled and the MCU remains in the reset state if V
is below the LVD
DD
trip point.
•The CPU takes the reset vector
In addition to the above, upon waking up from stop2 mode, 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.
If using the low-power oscillator during stop2 mode, you reconfigure the ICSC2 register that contains
oscillator control bits before PPDACK is written.
To maintain I/O states for pins that were configured as GPIO before entering stop2, you restore the
contents of the I/O port registers to the port registers before writing to the PPDACK bit. If the port registers
are not restored from RAM before writing to PPDACK, then the pins are switched to their reset states when
PPDACK is written.
For pins that were configured as peripheral I/O, you 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 are controlled by their associated port control registers when the I/O latches are opened.
If enabled, LCD functionality continues in stop2 mode and upon stop2 recovery the LCD control registers
(LCDC0, LCDC1, LCDSUPPLY, LCDRVC, LCDBCTL, and LCDS) must be re-initialized before writing
the PPDACK.
3.6.2Stop3 Mode
To enter stop3 mode, execute a STOP instruction under the conditions shown in Tabl e 3-1 . The states of
all the internal registers and logic, RAM contents, and I/O pin states are maintained.
Stop3 mode can be exited by asserting RESET, or by an interrupt from one of the following sources: LVW,
RTC, ADC, IRQ, SCI1, SCI2, LCD, or KBI.
If stop3 is exited by means of the RESET
reset vector. Using an internal interrupt sources to exit, results in the MCU taking an appropriate interrupt
vector.
pin, the MCU is reset and operation resumes after taking the
MC9S08LG32 MCU Series, Rev. 5
44Freescale Semiconductor
Page 45
Chapter 3 Modes of Operation
3.6.3Active BDM Enabled in Stop Mode
Entry into active background mode from run mode is enabled if the ENBDM bit in BDCSCR is set. This
register is described in Chapter 18, “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
the 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 you
attempt to enter the stop2 mode with ENBDM set, the MCU enters the stop3 mode instead.
Most background commands are not available in the stop mode. The memory-access-with-status
commands do not allow memory access, but they report an error indicating that the MCU is in either stop
or wait mode. The BACKGROUND command can be used to wake the MCU from the stop mode and enter
the active background mode if the ENBDM bit is set. After entering the background debug mode, all
background commands are available.
3.6.4LVD Enabled in Stop Mode
The LVD system can generate a reset or an interrupt when the supply voltage drops below the LVD or
LVW threshold respectively. If the LVD is enabled in stop (LVDE and LVDSE bits in SPMSC1 both set),
the voltage regulator remains active during stop mode. If you attempt to enter the stop2 mode with LVD
enabled for stop, the MCU enters the stop3 mode instead.
3.7Mode Selection
Several control signals are used to determine the current operating mode of the device. Table 3-2 shows
the conditions for each of the device’s operating modes.
Table 3-2. Power Mode Selections
Mode of Operation
RUN mode0xxxOn. ICS in any mode.offon
WAIT mode—(Assumes
WAIT instruction executed.)
Stop3—(Assumes STOPE
bit is set and STOP
instruction executed.) Note
that stop3 is used in place of
stop2 if the BDM or LVD is
enabled.
BDCSCR
BDM
ENBDM
1on
0xxxCPU clock is off;
1on
00x0ICS in STOP. OSCOUT
010 0off
011xoffon—stop
1xxxICSLCLK still active.on
SPMSC1
PMC
1
LV DE LVD SEP PD C
SPMSC2
PMC
CPU & Periph CLKs
peripheral clocks on. ICS
state is same as RUN
mode.
optionally on.
2
Affects on
Sub-System
BDM
Clock
offon
offstandby
Volt ag e
Regulator
currents
increased.
are
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor45
Page 46
Chapter 3 Modes of Operation
ModeRegulator State
RunFull on
WaitFull on
Stop3Standby
Stop2Partial powerdown
Run
Stop3
Stop2
Wait
3
1
2
Table 3-2. Power Mode Selections (continued)
Mode of Operation
Stop2—(Assumes STOPE
bit is set and STOP
instruction executed.) If BDM
BDCSCR
BDM
ENBDM
00x1OSCOUT optionally on.
SPMSC1
SPMSC2
PMC
1
LV DE LVD SEP PD C
10
PMC
CPU & Periph CLKs
2,3
Affects on
Sub-System
BDM
Clock
offpartial
or LVD is enabled, stop3 is
invoked rather than stop2.
1
ENBDM is located in the BDC status and control register (BDCSCR) which is write-accessible only through BDC
commands.
2
Configured within the ICS module based on the settings of IREFSTEN, EREFSTEN, IRCLKEN and ERCLKEN.
3
In stop2, the CPU, flash, ICS and all peripheral modules are powered down except for the RTC and LCD.
Volt ag e
Regulator
powerdown
Figure 3-1. Allowable Power Mode Transitions for the MC9S08LG32 Series
Figure 3-1 illustrates mode state transitions allowed between the legal states shown in Tab le 3- 1.
Table 3-3 defines triggers for the various state transitions shown in Figure 3-1.
Table 3 - 3 . Tr i gg ers fo r Tr a n si ti o ns Shown in Figure 3-1.
Transition #FromToTrigger
1RunWaitWAIT instruction
WaitRunInterrupt or reset
2RunStop3Pre-configure settings shown in Ta b le 3 - 1 , issue
46Freescale Semiconductor
STOP instruction
Stop3RunInterrupt or reset
MC9S08LG32 MCU Series, Rev. 5
Page 47
Chapter 3 Modes of Operation
Table 3-3. Triggers for Transitions Shown in Figure 3-1. (continued)
Transition #FromToTrigger
3RunStop2Pre-configure settings shown in Ta b le 3 - 1 , issue
STOP instruction
Stop2Runassert zero on wakup pins (PTC6/RESET or
PTF2/IRQ)
1
An analog connection from these pins to the on-chip regulator wakes up the regulator, which initiates a power-on-reset
1
or RTC interrupt or POR
sequence.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor47
Page 48
Chapter 3 Modes of Operation
3.7.1On-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.1, “Stop2
Mode,” and Section 3.6.2, “Stop3 Mode,” for specific information on system behavior in stop modes.
Table 3-4. Stop and Low Power Mode Behavior
Peripheral
Mode
Stop2Stop3
CPUOffStandby
RAMStandbyStandby
FLASHOffStandby
Port I/O RegistersOffStandby
ADCOffOptionally On
BDMOff
2
Optionally On
COPOffOff
ICSOffOptionally On
IICOffStandby
IRQWake UpOptionally On
KBIOffOptionally On
LV D/ LV WO ff
4
Optionally On
LCDOptionally OnOptionally On
MTIMOffOptionally On
SCIxOffStandby
SPIOffStandby
RTCOptionally OnOptionally On
TPMxOffStandby
Voltage RegulatorPartial PowerdownOptionally On
XOSCOptionally On
6
Optionally On
I/O PinsStates HeldPeripheral Control
1
Requires the asynchronous ADC clock. For stop3, LVD must be enabled to
run in stop if converting the bandgap channel.
2
If ENBDM is set when entering stop2, the MCU will actually enter stop3.
3
IRCLKEN and IREFSTEN set in ICSC1, else in standby.
4
If LVDSE is set when entering stop2, the MCU will actually enter stop3.
5
Requires the LVD to be enabled, else in standby. See Section 3.6.4, “LVD
Enabled in Stop Mode”.
6
ERCLKEN and EREFSTEN set in ICSC2, else in standby.
1
3
5
6
MC9S08LG32 MCU Series, Rev. 5
48Freescale Semiconductor
Page 49
Chapter 4
Memory
4.1Introduction
This chapter describes the on-chip memory in the MC9S08LG32 series of MCUs. It details the memory
map, vector and bit assignments, registers and control bits, and other RAM and flash features.
4.2MC9S08LG32 Series Memory Map
As shown in Figure 4-1, on-chip memory in the MC9S08LG32 series of MCUs consists of RAM, flash
memory for nonvolatile data storage, and I/O and control/status registers. The registers are divided into
four groups:
•Direct-page registers (0x0000 through 0x005F)
•LCD data registers (0x0820 through 0x085C)
•High-page registers (0x1800 through 0x187A)
•Nonvolatile registers (0xFFB0 through 0xFFBF)
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor49
Page 50
Chapter 4 Memory
MC9S08LG32
DIRECT PAGE REGISTERS
RAM
HIGH PAGE REGISTERS
1984 BYTES
0x1800
0x17FF
0xFFFF
16,384 BYTES
UNIMPLEMENTED
0x7FFF
0x8000
0x005F
0x0060
0x187A
0x187B
0x081F
0x0820
MC9S08LG16
0xFFFF
2048 BYTES
16,384 BYTES
FLASH A
FLASH A
0xC000
0xB7FF
FLASHB
Flash B
LCD Registers
0x085C
0x0860
UNIMPLEMENTED
4000 BYTES
DIRECT PAGE REGISTERS
RAM
HIGH PAGE REGISTERS
1984 BYTES
0x1800
0x17FF
UNIMPLEMENTED
0x005F
0x0060
0x187A
0x187B
0x081F
0x0820
LCD Registers
0x085C
0x0860
4000 BYTES
0xC000
0x0000
0x0000
UNIMPLEMENTED
16,384 BYTES
Note:
0x085C-0x085F is reserved. Unlike un-implemented spaces, access to these locations would not cause illegal address
reset.
0xB800
Figure 4-1. MC9S08LG32 Series Memory Maps
4.3Reset and Interrupt Vector Assignments
Table 4-1 shows the address assignments for reset and interrupt vectors. The vector names shown in this
table are labels used in the Freescale Semiconductor equate file for the MC9S08LG32 series.
Address
(High/Low)
0xFF80:FF81
0xFFC8:FFC9
Table 4-1. Reset and Interrupt Vectors (Sheet 1 of 2)
VectorVector Name
Unused Vector Space
(available for user program)
50Freescale Semiconductor
MC9S08LG32 MCU Series, Rev. 5
Page 51
Table 4-1. Reset and Interrupt Vectors (Sheet 2 of 2) (continued)
Chapter 4 Memory
Address
(High/Low)
VectorVector Name
0xFFCA:0xFFCBRTCVrtc
0xFFCC:0xFFCDModulo TimerVmtim
0xFFCE:0xFFCFTPM2 OverflowVtpm2ovf
0xFFD0:0xFFD1TPM2 Channel 5Vtpm2ch5
0xFFD2:0xFFD3TPM2 Channel 4Vtpm2ch4
0xFFD4:0xFFD5TPM2 Channel 3Vtpm2ch3
0xFFD6:0xFFD7TPM2 Channel 2Vtpm2ch2
0xFFD8:0xFFD9TPM2 Channel 1Vtpm2ch1
0xFFDA:0xFFDBTPM2 Channel 0Vtpm2ch0
0xFFDC:0xFFDDADC ConversionVadc
0xFFDE:0xFFDFKBI InterruptVkeyboard
0xFFE0:0xFFE1IICViic
0xFFE2:0xFFE3SCI2 TransmitVsci2tx
0xFFE4:0xFFE5SCI2 ReceiveVsci2rx
0xFFE6:0xFFE7SCI2 ErrorVsci2err
0xFFE8:0xFFE9SPIVspi
0xFFEA:0xFFEBLCD Frame Vlcd
0xFFEC:0xFFEDSCI1 TransmitVsci1tx
0xFFEE:0xFFEFSCI1 ReceiveVsci1rx
0xFFF0:0xFFF1SCI1 ErrorVsci1err
0xFFF2:0xFFF3TPM1 OverflowVtpm1ovf
0xFFF4:0xFFF5TPM1 Channel 1Vtpm1ch1
0xFFF6:0xFFF7TPM1 Channel 0Vtpm1ch0
0xFFF8:0xFFF9Low Voltage WarningVlvw
0xFFFA:0xFFFBIRQVirq
0xFFFC:0xFFFDSWIVswi
0xFFFE:0xFFFFResetVreset
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor51
Page 52
Chapter 4 Memory
4.4Register Addresses and Bit Assignments
The register groups in the MC9S08LG32 series consist of the following locations in the memory map:
•Direct-page registers are located at the first 96 locations. Access these locations with efficient
direct addressing mode instructions.
•LCD Registers, LCDPENx, LCDBPENx, LCDWFx are located at the end of the RAM module.
•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 registers for more frequently used registers and
RAM.
•The nonvolatile register area consists of a block of 16 locations in flash memory at
0xFFB0–0xFFBF. Nonvolatile register locations include:
— NVPROT and NVOPT are loaded into working registers at reset
— An 8-byte backdoor comparison key that optionally allows 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. Table 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, which 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-4 and Tab le 4-5, the whole address in column one is shown in bold. In Tabl e 4-2,
Table 4-4, and Tab le 4- 5, 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. When writing to these bits, write a 0 unless otherwise specified.
MC9S08LG32 MCU Series, Rev. 5
52Freescale Semiconductor
Page 53
Table 4-2. Direct-Page Register Summary (Sheet 1 of 3)
High-page registers, shown in Table 4-4 , 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.
MC9S08LG32 MCU Series, Rev. 5
56Freescale Semiconductor
Page 57
Chapter 4 Memory
Table 4-4. High-Page Register Summary (Sheet 1 of 3)
Several reserved flash memory locations, shown in Tab le 4-5, are used for storing values used by several
registers. These registers include an 8-byte backdoor key, NVBACKKEY, which can be used to gain
access to secure memory resources. During reset events, the contents of NVPROT and NVOPT in the
reserved flash memory are transferred into corresponding FPROT and FOPT registers in the high-page
registers area to control security and block protection options.
Locations 0xFFAE and 0xFFAF are reserved for ICS FTRIM and ICS TRIM values respectively. These
locations are left blank at the factory. Third party tools can program these locations with the trim values.
User can copy these values to corresponding ICS registers to get ICS trimmed clock frequency
Table 4-5. Reserved Flash Memory Addresses
AddressRegister NameBit 7654321Bit 0
0xFFB0 –
0xFFB7
0xFFB8 –
0xFFBC
0xFFBDNVPROT
0xFFBE
0xFFBFNVOPT
NVBACKKEY
Reserved
Reserved
8-Byte Comparison Key
—
—
————————
KEYENFNORED0000SEC
—
—
—
—
—
—
FPSFPDIS
—
—
—
—
—
—
—
—
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
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor59
Page 60
Chapter 4 Memory
debug interface) and verifying that flash is blank. To avoid returning to secure mode after the next reset,
program the security bits (SEC) to the unsecured state (1:0).
4.5RAM
The MC9S08LG32 series includes 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.
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 (V
For compatibility with M68HC05 MCUs, the HCS08 resets the stack pointer to 0x00FF. In the
MC9S08LG32 series, it is usually best to reinitialize 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 Semiconductor-provided equate file).
LDHX #RamLast+1 ;point one past RAM
TXS ;SP<-(H:X-1)
RAM
).
When security is enabled, the RAM is considered a secure memory resource and is not accessible through
background debug mode (BDM) or through code executing from non-secure memory. See Section 4.7,
“Security,” for a detailed description of the security feature.
4.6Flash
The flash memory is intended 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/D.
Because the MC9S08LG32 series contains two flash arrays, program and erase operations can be
conducted on one array while executing code from the other. The security and protection features treat the
two arrays as a single memory entity. Programming and erasing of each flash array is conducted through
the same command interface detailed in the following sections.
It is not possible to page erase or program both arrays at the same time. The mass erase command erases
both arrays, and the blank check command checks both arrays.
MC9S08LG32 MCU Series, Rev. 5
60Freescale Semiconductor
Page 61
Chapter 4 Memory
4.6.1Features
Features of the flash memory include:
•Flash size
— MC9S08LG32: 32,768 bytes (16,384 bytes in Flash A, 16,384 bytes in Flash B)
— MC9S08LG16: 18,432 bytes (2,048 bytes in Flash A, 16,384 in Flash B)
•Single power supply program and erase
•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 Times
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 performed during reset initialization. FCDIV cannot be written if the access error
flag, FACCERR in FSTAT, is set. Ensure that FACCERR is not set before writing to the FCDIV register.
The command processor uses one period of the resulting clock (1/f
FCLK
An integer number of these timing pulses is used by the command processor to complete a program or
erase command.
) between 150 kHz and 200 kHz
FCLK
) to time program and erase pulses.
Table 4-6 shows program and erase times. The bus clock frequency and FCDIV determine the frequency
of FCLK (f
of 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
. The times are shown as a number
FCLK
=5μs. Program and erase times
shown include overhead for the command state machine and enabling and disabling of program and erase
voltages.
Table 4-6. Program and Erase Times
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
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor61
Page 62
Chapter 4 Memory
4.6.3Program and Erase Command Execution
The FCDIV register must be initialized and any error flag is 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 may be erased.
NOTE
Do not program any byte in the flash more than once after a successful erase
operation. Reprogramming bits to a byte that 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 changes 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-2 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.
4. Wait until the FCCF bit in FSTAT is set. As soon as FCCF= 1, the operation has completed
successfully.
MC9S08LG32 MCU Series, Rev. 5
62Freescale Semiconductor
Page 63
Chapter 4 Memory
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)
1
0
FCCF?
ERROR EXIT
DONE
(2)
Wait at least four bus cycles
0
FACCERR?
CLEAR ERROR
FACCERR?
WRITE TO FCDIV
(1)
(1)
Required only once after reset.
1
before checking FCBEF or FCCF.
FLASH PROGRAM AND
ERASE FLOW
Figure 4-2. 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 has
completed.
•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.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor63
Page 64
Chapter 4 Memory
1
0
FCBEF?
START
WRITE TO FLASH
TO BUFFER ADDRESS AND DATA
WRITE COMMAND (0x25) TO FCMD
NO
YES
FPVIO OR
WRITE 1 TO FCBEF
TO LAUNCH COMMAND
AND CLEAR FCBEF
(2)
NO
YES
NEW BURST COMMAND?
1
0
FCCF?
ERROR EXIT
DONE
(2)
Wait at least four bus cycles before
1
0
FACCERR?
CLEAR ERROR
FACCERR?
(1)
Required only once after reset.
WRITE TO FCDIV
(1)
checking FCBEF or FCCF.
FLASH BURST
PROGRAM FLOW
The first byte of a series of sequential bytes being programmed in burst mode takes the same amount of
time to program as a byte programmed in standard mode. The subsequent bytes program in the burst
program time provided that the conditions above are met. In the case where the next sequential address is
the beginning of a new row, the program time for that byte is 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 is disabled
and the high voltage removed from the array.
Figure 4-3. Flash Burst Program Flowchart
MC9S08LG32 MCU Series, Rev. 5
64Freescale Semiconductor
Page 65
Chapter 4 Memory
4.6.5Access Errors
An access error occurs whenever the command execution protocol is violated.
Any of the following actions causes the access error flag (FACCERR) in FSTAT to be set. Before any
command can be processed, FACERR must be cleared. To clear FACCERR, write a 1 to FACCERR in
FSTAT.
•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 start 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 to FCMD other than the five allowed codes (0x05, 0x20, 0x25, 0x40,
or 0x41)
•Writing 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, which is in the
nonvolatile register block of the flash memory. FPROT cannot be changed directly from application
software to prevent runaway programs from altering the block protection settings. Because NVPROT is
within the last 512 bytes of flash, 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 protected flash memory to be erased and
reprogrammed.
The block protection mechanism is illustrated in Figure 4-4. 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 bits
as shown. For example, to protect the last 1536 bytes of memory (addresses 0xFA00 through 0xFFFF), the
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor65
Page 66
Chapter 4 Memory
FPS7 FPS6 FPS5 FPS4 FPS3 FPS2 FPS1
A15A14A13A12A11A10A9A81A7 A6 A5 A4 A3 A2 A1 A0
11111111
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)
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-4. Block Protection Mechanism
One use of 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.7Vector Redirection
Whenever any block protection is enabled, the reset and interrupt vectors are 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. For
instance, if an SPI interrupt is taken, the values in the locations 0xFDE8:FDE9 are used for the vector
instead of the values in the locations 0xFFE8:FFE9. This allows you 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 MC9S08LG32 series includes 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).
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 into
the working FOPT register in high-page register space. To engage security, program the NVOPT location.
MC9S08LG32 MCU Series, Rev. 5
66Freescale Semiconductor
Page 67
Chapter 4 Memory
You can do this 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, you must immediately program the SEC00 bit to 0 in NVOPT
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.
You 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 would get 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 that was just written matches the
key stored in the flash locations, SEC01:SEC00 are automatically changed to 1:0 and security
disengages until the next reset.
The security key can be written only from secure memory (either 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 in the nonvolatile register space so users can program these locations exactly as they would
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 protects 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. FPROT can be written only with background
debug commands, not from application software.
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.
4.8Flash Registers and Control Bits
The flash module has six 8-bit registers in the high-page register space. Two locations (NVOPT,
NVPROT) in the nonvolatile register space in flash memory are copied into corresponding high-page
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor67
Page 68
Chapter 4 Memory
control registers (FOPT, FPROT) at reset. There is also an 8-byte comparison key in flash memory. Refer
to Table 4-4 and Ta ble 4-5 for the absolute address assignments for all flash registers. This section refers
to registers and control bits only by their names. A Freescale Semiconductor-provided equate or header
file is normally 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 flag. DIV Bits 6: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.Table 4-8 shows the appropriate
values for PRDIV8 and DIV for selected bus frequencies.
76543210
RDIVLD
W
Reset00000000
PRDIV8DIV
= Unimplemented or Reserved
Figure 4-5. Flash Clock Divider Register (FCDIV)
Table 4-7. FCDIV Register Field Descriptions
FieldDescription
7
DIVLD
6
PRDIV8
5:0
DIV
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.
1 FCDIV has been written since reset; erase and program operations enabled for flash.
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 DIV 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 and Equation 4-2.
if PRDIV8 = 0 — f
if PRDIV8 = 1 — f
FCLK
FCLK
= f
= f
÷ (DIV + 1)Eqn. 4-1
Bus
÷ (8 × (DIV + 1))Eqn. 4-2
Bus
Table 4-8 shows the appropriate values for PRDIV8 and DIV for selected bus frequencies.
During reset, the contents of the nonvolatile location NVOPT are copied from flash into FOPT. 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-6. 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 the 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 - 10 . 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. SEC01:SEC00 changes to 1:0 after successful
backdoor key entry or a successful blank check of flash.
For more detailed information about security, refer to Section 4.7, “Security.”
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor69
Page 70
Chapter 4 Memory
Table 4-10. Security States
SEC01:SEC00Description
0:0secure
0:1secure
1:0unsecured
1:1secure
1
SEC01:SEC00 changes to 1:0 after successful backdoor
key entry or a successful blank check of flash.
1
4.8.3Flash Configuration Register (FCNFG)
76543210
R00
KEYACC
W
Reset00000000
= Unimplemented or Reserved
Figure 4-7. Flash Configuration Register (FCNFG)
00000
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 flash are interpreted as the start of a flash programming or erase command.
1 Writes to NVBACKKEY (0xFFB0–0xFFB7) are interpreted as comparison key writes while writes to rest of the
flash are ignored.
4.8.4Flash Protection Register (FPROT and NVPROT)
During reset, the contents of the nonvolatile location NVPROT is copied from flash into FPROT. FPROT
can be read at any time. With FPDIS set, all bits are writable, but with FPDIS clear the FPS bits are writable
as long as the size of the protected region is being increased. Any FPROT write that attempts to decrease
the size of the protected region is ignored.
76543210
R
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 FPROT.
FPS
(1)
FPDIS
(1)
Figure 4-8. Flash Protection Register (FPROT)
MC9S08LG32 MCU Series, Rev. 5
70Freescale Semiconductor
Page 71
Table 4-12. FPROT Register Field Descriptions
FieldDescription
Chapter 4 Memory
7:1
FPS
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 FPS7:FPS1 is block protected (program and erase not allowed).
1 No flash block is protected.
4.8.5Flash Status Register (FSTAT)
76543210
R
FCBEF
W
Reset11000000
FieldDescription
7
FCBEF
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 can be written to the command buffer.
FCCF
FPVIOLFACCERR
= Unimplemented or Reserved
Figure 4-9. Flash Status Register (FSTAT)
Table 4-13. FSTAT Register Field Descriptions
0FBLANK00
6
FCCF
5
FPVIOL
Freescale Semiconductor71
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 was made to erase or program a protected location.
MC9S08LG32 MCU Series, Rev. 5
Page 72
Chapter 4 Memory
Table 4-13. FSTAT Register Field Descriptions (continued)
FieldDescription
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-14. Refer to Section
4.6.3, “Program and Erase Command Execution,” for a detailed discussion of flash programming and erase
operations.
76543210
R00000000
WFCMD
Reset00000000
Figure 4-10. Flash Command Register (FCMD)
Table 4-14. 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. Only blank check is
required as part of the security unlocking mechanism.
MC9S08LG32 MCU Series, Rev. 5
72Freescale Semiconductor
Page 73
Chapter 5
Resets, Interrupts, and General System Control
5.1Introduction
This section discusses basic reset and interrupt mechanisms and the various sources of reset and interrupt
in the MC9S08LG32 series. Some interrupt sources from peripheral modules are discussed in greater
detail in other sections of this document. This section gathers basic information about all reset and interrupt
sources in one place for easy reference.
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 vector for all modules (reduces polling overhead) (see Table 5-2)
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 MC9S08LG32 series has the following sources for reset:
•Power-on reset (POR)
•External pin reset (PIN)
•Computer operating properly (COP) timer
•Illegal opcode detect (ILOP)
•Illegal address detect (ILAD)
•Low-voltage detect (LVD)
•Background debug forced reset
Each of these sources, with the exception of the background debug forced reset, has an associated bit in
the system reset status register (SRS). The background debug forced reset causes all the bits in the SRS
register to clear, and can be detected by all zeros in SRS.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor73
Page 74
Chapter 5 Resets, Interrupts, and General System Control
5.4Computer Operating Properly (COP) Watchdog
The COP watchdog is intended 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 COPE becomes set in SOPT1 enabling the COP watchdog (see Section 5.8.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 COPE. The COP counter is reset by writing any value to the
address of SRS. This write does not affect the data in the read-only SRS. Instead, the act of writing to this
address is decoded and sends a reset signal to the COP counter.
The COPCLKS bit in SOPT2 (see Section 5.8.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 is an associated short and long
time-out controlled by COPT in SOPT1. Ta ble 5-1 summaries the control functions of the COPCLKS and
COPT bits. The COP watchdog defaults to operation from the 1 kHz clock source and the associated long
time-out (28 cycles).
Table 5-1. COP Configuration Options
Control Bits
Clock SourceCOP Overflow Count
COPCLKSCOPT
00~1 kHz2
01~1 kHz2
10Bus 2
11Bus 2
1
Values are shown in this column based on t
tolerance of this value.
=1ms. See t
LPO
5
cycles (32 ms)
8
cycles (256 ms)
13
cycles
18
cycles
in the data sheet for the
LPO
1
1
Even if your application uses the reset default settings of COPE, COPCLKS, and COPT; you must write
to the write-once SOPT1 and SOPT2 registers, during reset initialization, to lock in the settings. That way,
the settings cannot be changed accidentally if the application program gets lost. The initial writes to SOPT1
and SOPT2 reset the COP counter.
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.
In background debug mode, the COP counter does not increment.
When the bus clock source is selected, the COP counter does not increment while the system is in stop
mode. The COP counter resumes as soon as the MCU exits stop mode.
MC9S08LG32 MCU Series, Rev. 5
74Freescale Semiconductor
Page 75
Chapter 5 Resets, Interrupts, and General System Control
When the 1 kHz clock source is selected, the COP counter is re-initialized to zero upon entry to stop mode.
The COP counter begins from zero after the MCU exits stop mode.
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 can resume 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 is set. The CPU does
not respond unless the local interrupt enable is a 1 (enabled) and 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 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
can be cleared inside an ISR (after clearing the status flag that generated 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 from the
stack.
NOTE
For compatibility with M68HC08 devices, 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.
If more than one interrupt is pending when the I bit is cleared, the highest priority source is serviced first
(see Table 5-2).
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor75
Page 76
Chapter 5 Resets, Interrupts, and General System Control
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. This address 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 corresponding to the interrupt source must be acknowledged (cleared) before returning
from the ISR. Typically, the flag is cleared at the beginning of the ISR so that if another interrupt is
generated by this same source it is 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 IRQ status and control register (IRQSC). 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 pin 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, you 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 (IRQIE).
76Freescale Semiconductor
MC9S08LG32 MCU Series, Rev. 5
Page 77
Chapter 5 Resets, Interrupts, and General System Control
The IRQ pin, when enabled, defaults to use an internal pull device (IRQPDD = 0), configured as 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.
5.5.2.2Edge and Level Sensitivity
The IRQMOD control bit reconfigures the detection logic so it detects edge events and pin levels. In the
edge and level 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.2.3IRQ Initialization
When IRQ is first enabled it is possible to get a false IRQ interrupt flag. To prevent a false interrupt request
during IRQ initialization, you must do the following:
1. Mask IRQ interrupt by clearing IRQIE in IRQSC.
2. Select the IRQ mode by writing to the IRQEDG, IRQMOD and IRQPDD bits in IRQSC.
3. Enable the IRQ pin by setting the IRQPE bit in IRQSC.
4. Write to IRQACK in IRQSC to clear any false interrupts.
5. Set IRQIE in IRQSC to enable interrupts.
5.5.3Interrupt Vectors, Sources, and Local Masks
Table 5-2 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 finishes 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.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor77
Page 78
Chapter 5 Resets, Interrupts, and General System Control
control
20xFFFA/0xFFFBVirqIRQIRQFIRQIEIRQ pin
10xFFFC/0xFFFDVswiCoreSWI Instruction—Software interrupt
00xFFFE/0xFFFFVresetSystem
control
COP
LV D
RESET
pin
Illegal opcode
Illegal address
COPE
LV DR E
RSTPE
—
—
Watchdog timer
Low-voltage detect
External pin
Illegal opcode
Illegal address
POR
MC9S08LG32 MCU Series, Rev. 5
78Freescale Semiconductor
Page 79
Chapter 5 Resets, Interrupts, and General System Control
5.6Low-Voltage Detect (LVD) System
The MC9S08LG32 series includes a system to protect against low voltage conditions to protect memory
contents and control MCU system states during supply voltage variations. The system is comprised of a
power-on reset (POR) circuit and a LVD circuit. The LVD circuit is enabled when LVDE in SPMSC1. The
LVD is disabled upon entering either of the stop modes unless LVDSE is set in SPMSC1. If LVDSE and
LVDE are both set, then the MCU enters stop3 instead of stop2, and the current consumption in stop3 with
the LVD enabled is greater.
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
rearm voltage level, V
circuit holds 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. After an LVD reset has occurred, the LVD system holds 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 POR circuit causes a reset condition. As the supply voltage rises, the LVD
The LVD system has a low voltage warning flag (LVWF) to indicate to you that the supply voltage is
approaching, but remains above, the LVD voltage. The LVW has an interrupt associated with it, enabled
by setting the LVWIE bit in the SPMSC1 register. If enabled, an LVW interrupt request occurs when the
LVWF is set. LVWF is cleared by writing a 1 to the LVWACK bit in SPMSC1 provided the LVW condition
no longer exists.
5.7Peripheral Clock Gating
The MC9S08LG32 series includes a clock gating system to manage the bus clock sources to the individual
peripherals. Using this system, you can enable or disable the bus clock to each of the peripherals at the
clock source, eliminating unnecessary clocks to peripherals which are not in use and thereby reducing the
overall run and wait mode currents.
Out of reset, all peripheral clocks are disabled. For lowest possible run or wait currents, user software must
disable the clock source to any peripheral not in use. The actual clock is enabled or disabled immediately
following the write to the Clock Gating Control registers (SCGC1 and SCGC2). Any peripheral with a
gated clock cannot be used unless its clock is enabled. Writing to the registers of a peripheral with a
disabled clock has no effect.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor79
Page 80
Chapter 5 Resets, Interrupts, and General System Control
NOTE
User software must disable the peripheral before disabling the clocks to the
peripheral. When clocks are re-enabled to a peripheral, the peripheral
registers need to be re-initialized by user software.
In stop modes, the bus clock is disabled for all gated peripherals, regardless of the settings in SCGC1 and
SCGC2.
5.8Reset, Interrupt, and System Control Registers and Control Bits
One 8-bit register in the direct page register space and fourteen 8-bit registers in the high-page register
space are related to reset and interrupt systems.
Refer to Table 4-2 and Table 4-4 in Chapter 4, “Memory,” 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.8.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
Interrupt Request (IRQ) Pull Device Disable — This read/write control bit is used to disable the internal
pullup/pulldown 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 IRQEDG = 1 and the internal pull device is enabled, the
pullup device is reconfigured as an optional pulldown device.
0 IRQ is falling edge or falling edge/low-level sensitive.
1 IRQ is rising edge or rising edge/high-level sensitive.
IRQPDDIRQEDGIRQPE
= Unimplemented or Reserved
Figure 5-2. Interrupt Request Status and Control Register (IRQSC)
Table 5-3. IRQSC Register Field Descriptions
IRQF0
IRQIEIRQMOD
MC9S08LG32 MCU Series, Rev. 5
80Freescale Semiconductor
Page 81
Chapter 5 Resets, Interrupts, and General System Control
Table 5-3. IRQSC Register Field Descriptions (continued)
FieldDescription
4
IRQPE
3
IRQF
2
IRQACK
1
IRQIE
0
IRQMOD
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.
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. The IRQEDG control bit determines the polarity of edges and levels that are detected as interrupt
request events. See Section 5.5.2.2, “Edge and Level Sensitivity,” for more details.
0 IRQ event on falling edges or rising edges only.
1 IRQ event on falling edges and low levels or on rising edges and high levels.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor81
Page 82
Chapter 5 Resets, Interrupts, and General System Control
5.8.2System Reset Status Register (SRS)
This high-page register includes 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 is
set. Writing any value to this register 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
RPORPINCOPILOPILAD0LVD0
WWriting any value to SRS address clears COP watchdog timer.
POR:
LV D:
Any other
reset:
1
u = unaffected
2
Any of these reset sources that are active at the time of reset entry causes the corresponding bit(s) to be set; bits corresponding
to sources that are not active at the time of reset entry are cleared.
10000010
(1)
u
0Note
0000010
(2)
Note
(2)
Note
(2)
Note
(2)
000
Figure 5-3. System Reset Status (SRS)
Table 5-4. SRS Register Field Descriptions
FieldDescription
7
POR
6
PIN
5
COP
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 (LVD) status bit is also set to indicate that the reset occurred while
the internal supply was below the LVD 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 can be blocked by COPE = 0.
0 Reset not caused by COP timeout.
1 Reset caused by COP timeout.
4
ILOP
82Freescale Semiconductor
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.
MC9S08LG32 MCU Series, Rev. 5
Page 83
Chapter 5 Resets, Interrupts, and General System Control
Table 5-4. SRS Register Field Descriptions (continued)
FieldDescription
3
ILAD
1
LV D
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
Low Voltage Detect — If the LVDRE bit is set and the supply drops below the LVD trip voltage, an LVD reset
occurs. 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.8.3System Background Debug Force Reset Register (SBDFR)
This high-page 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
Reset:00000000
= Unimplemented or Reserved
Figure 5-4. System Background Debug Force Reset Register (SBDFR)
1
BDFR is writable only through serial background debug commands, not from user programs.
1
Table 5-5. SBDFR Register Field Descriptions
FieldDescription
0
BDFR
Background Debug Force Reset — A serial background command such as WRITE_BYTE can be used to allow
an external debug host to force a target system reset. Writing 1 to this bit forces an MCU reset. This bit cannot
be written from a user program.To enter user mode, PTC5/BKGD/MS must be high immediately after issuing
WRITE_BYTE command. To enter BDM, PTC5/BKGD/MS must be low immediately after issuing WRITE_BYTE
command. See the data sheet for more information.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor83
Page 84
Chapter 5 Resets, Interrupts, and General System Control
5.8.4System Options Register 1 (SOPT1)
This high-page register is a write-once register, so only the first write after reset is honored. It can be read
at any time. Any subsequent attempt to write to SOPT1 (intentionally or unintentionally) is ignored to
avoid accidental changes to these sensitive settings. SOPT1 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.
76543210
R
COPECOPTSTOPE
W
Reset:1100001u
000
BKGDPERSTPE
(1)
POR and
LV R:
11000011
= Unimplemented or Reserved
Figure 5-5. System Options Register 1 (SOPT1)
1
u = unaffected
Table 5-6. SOPT1 Register Field Descriptions
FieldDescription
7
COPE
6
COPT
5
STOPE
1
BKGDPE
COP Watchdog Enable — This write-once bit selects whether the COP watchdog is enabled.
0 COP watchdog timer disabled.
1 COP watchdog timer enabled (force reset on timeout).
COP Watchdog Timeout — This write-once bit selects the timeout period of the COP. COPT along with
COPCLKS in SOPT2 defines the COP timeout period.
0 Short timeout period selected.
1 Long timeout period selected.
Stop Mode Enable — This write-once bit is used to enable 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.
Background Debug Mode Pin Enable — This write-once bit when set enables the PTC5/BKGD/MS pin to
function as BKGD/MS. When clear, the pin functions as output only GPIO. This pin defaults to the BKGD/MS
function following any MCU reset.
0 PTC5/BKGD/MS pin functions as PTC5.
1 PTC5/BKGD/MS pin functions as BKGD/MS.
0
RSTPE
84Freescale Semiconductor
RESET
clear, the pin functions as open drain output only GPIO. This pin defaults to its RESET
POR or LVD. When RSTPE is set, an internal pullup device is enabled on RESET
0 PTC6/RESET
1 PTC6/RESET
Pin Enable — This write-once bit when set enables the PTC6/RESET pin to function as RESET. When
function following an MCU
.
pin functions as PTC6.
pin functions as RESET.
MC9S08LG32 MCU Series, Rev. 5
Page 85
Chapter 5 Resets, Interrupts, and General System Control
5.8.5System Options Register 2 (SOPT2)
This high-page register contains bits to configure MCU specific features on the MC9S08LG32 series
devices.
76543210
R
COPCLKS
W
Reset:00000001
1
This bit can be written only one time after reset. Additional writes are ignored.
FieldDescription
1
000000
SPIFE
= Unimplemented or Reserved
Figure 5-6. System Options Register 2 (SOPT2)
Table 5-7. SOPT2 Register Field Descriptions
7
COPCLKS
0
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.
SPI Filter Enable— This bit selects the IFE control of the SPI pins.
0IFE disabled
1 IFE enabled
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor85
Page 86
Chapter 5 Resets, Interrupts, and General System Control
These high-page read-only registers are included so host development systems can identify the HCS08
derivative. 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-7. System Device Identification Register — High (SDIDH)
Table 5-8. SDIDH Register Field Descriptions
FieldDescription
7:4
Reserved
3:0
ID[11:8]
76543210
RID7ID6ID5ID4ID3ID2ID1ID0
W
Reset:00101010
Bits 7:4 are reserved. Reading these bits result in an indeterminate value; writes have no effect.
Part Identification Number — Each derivative in the HCS08 Family has a unique identification number. The
MC9S08LG32 is hard coded to the value 0x02A. See also ID bits in Ta bl e 5 -9 .
= Unimplemented or Reserved
Figure 5-8. System Device Identification Register — Low (SDIDL)
Table 5-9. 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
MC9S08LG32 is hard coded to the value 0x02A. See also ID bits in Ta bl e 5 -8 .
MC9S08LG32 MCU Series, Rev. 5
86Freescale Semiconductor
Page 87
Chapter 5 Resets, Interrupts, and General System Control
5.8.7System Power Management Status and Control 1 Register
(SPMSC1)
This high-page register contains status and control bits to support the low voltage detect function, and to
enable the bandgap voltage reference for use by the ADC module. To configure the low voltage detect trip
voltage, see Table for the LVDV bit description in SPMSC2.
76543210
RLVWF
WLVWACK
RESET:00011100
POR and LVD:00011100
1
0
LVWIELVDRE
= Unimplemented or Reserved
2
LVDSELVDE
2
Figure 5-9. System Power Management Status and Control 1 Register (SPMSC1)
1
LVWF is set in the case when V
2
Write-once only after any system reset
3
Bit 1 is a reserved bit that must always be written to 0.
transitions below the trip point or after reset and V
Supply
Supply
3
0
is already below V
BGBE
LV W
.
Table 5-10. SPMSC1 Register Field Descriptions
FieldDescription
7
LVWF
6
LV WAC K
5
LV WI E
4
VDRE
3
LV DS E
Low-Voltage Warning Flag - The LVWF bit indicates the Low-Voltage Warning status.
0 Low voltage warning not present.
1 Low voltage warning is present or was present.
Low-Voltage Warning Acknowledge
The LVWACK bit indicates the Low-Voltage Warning Acknowledge status. Writing a logic 1 to LVWACK clears
LVWF to a logic 0 if a low voltage warning is not 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.
Low-Voltage Detect Reset Enable
This write-once bit enables LVD events to generate a hardware reset(provided LVDE=1). This bit has no effect if
the LVDE bit is a logic 0.
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. This bit has no effect if the LVDE bit is a logic 0.
0 Low-Voltage detect disabled during stop mode.
1 Low-Voltage detect enabled during stop mode.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor87
Page 88
Chapter 5 Resets, Interrupts, and General System Control
Table 5-10. SPMSC1 Register Field Descriptions (continued)
FieldDescription
2
LV DE
0
BGBE
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.
Bandgap Buffer Enable
This bit enables an internal buffer for the bandgap voltage reference for use by the ADC module on one of its
internal channels.
0 Bandgap buffer disabled.
1 Bandgap buffer enabled.
5.8.8System 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.
76543210
R00
WPPDACK
POR:00000000
LVD:00UU0000
LVDV
1
LV WV
PPDF00
PPDC
2
Any other Re-
set:
00UU0000
= Unimplemented or ReservedU = Unaffected by MCU Reset
Figure 5-10. System Power Management Status and Control 2 Register (SPMSC2)
1 This bit can be written only one time after power-on reset. Additional writes are ignored.
2 This bit can be written only one time after reset. Additional writes are ignore.
Table 5-11. SPMSC2 Register Field Descriptions
FieldDescription
5
LV DV
5
LV WV
3
PPDF
Low-Voltage Detect Voltage Select
This write-once bit selects the low voltage detect(LVD) trip point setting. It also selects warning voltage
range.See Table 5-12 for definition of these voltages.
Low-Voltage Warning Voltage Select
The bit selects the low voltage warning(LVW) trip point voltage. See Table 5-12 for definition of these voltages.
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.
MC9S08LG32 MCU Series, Rev. 5
88Freescale Semiconductor
Page 89
Chapter 5 Resets, Interrupts, and General System Control
Table 5-11. SPMSC2 Register Field Descriptions (continued)
FieldDescription
2
PPDACK
0
PPDC
Partial Power Down Acknowledge
Writing a logic 1 to PPDACK clears the PPDF bit.
Partial Power Down Control
This write-once bit controls whether stop2 or stop3 mode is selected.
0 Stop3 mode enabled.
1 Stop2, partial power down mode enabled.
Table 5-12. LVD and LVW Trip Points
NumCharacteristicSymbolMinMaxUnit
1High LVD trip point (V
2High LVD trip point (V
3Low LVD trip point (V
4Low LVD trip point (V
5High LVW trip point (V
6High LVW trip point (V
7Low LVW trip point (V
8Low LVW trip point (V
9High LVW trip point (V
10High LVW trip point (V
11Low LVW trip point (V
12Low LVW trip point (V
1
All values measured with respect to V
2
All values with factory trim
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
SUPPLY
falling, LVDV = 1)
1
V
LV DX H
rising, LVDV = 1)4.004.20V
falling, LVDV = 0)V
LV DX L
rising, LVDV = 0)2.542.70V
falling, {LVDV,LVWV} = 00) V
LV WX L L
rising, {LVDV,LVWV} = 00) 2.722.88V
falling, {LVDV,LVWV} = 01)V
LV WX L H
rising, {LVDV,LVWV} = 01)2.903.06V
falling, {LVDV,LVWV} = 10) V
LV WX H L
rising, {LVDV,LVWV} = 10) 4.304.50V
falling, {LVDV,LVWV} = 11)V
LV WX H H
rising, {LVDV,LVWV} = 11)4.604.80V
SUPPLY
2
3.90
4.10V
2.482.64V
2.662.82V
2.843.00V
4.204.40V
4.504.70V
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor89
Page 90
Chapter 5 Resets, Interrupts, and General System Control
5.8.9System Clock Gating Control 1Register (SCGC1)
This high-page register contains control bits to enable or disable the bus clock to the TPMx, ADC, IIC,
MTIM, RTC, and SCIx modules. Gating off the clocks to unused peripherals is used to reduce the MCU’s
run and wait currents. See Section 5.7, “Peripheral Clock Gating,” for more information.
NOTE
User software must disable the peripheral before disabling the clocks to the
peripheral. When clocks are re-enabled to a peripheral, the peripheral
registers need to be re-initialized by user software.
76543210
R
W
Reset:00000000
RTCTPM2TPM1ADCMTIMIICSCI2SCI1
Figure 5-11. System Clock Gating Control 1Register (SCGC1)
Table 5-13. SCGC1 Register Field Descriptions
FieldDescription
7
RTC
6
TPM2
5
TPM1
4
ADC
3
MTIM
2
IIC
1
SCI2
RTC Clock Gate Control — This bit controls the clock gate to the RTC module.
0 Bus clock to the RTC module is disabled.
1 Bus clock to the RTC module is enabled.
TPM2 Clock Gate Control — This bit controls the clock gate to the TPM2 module.
0 Bus clock to the TPM2 module is disabled.
1 Bus clock to the TPM2 module is enabled.
TPM1 Clock Gate Control — This bit controls the clock gate to the TPM1 module.
0 Bus clock to the TPM1 module is disabled.
1 Bus clock to the TPM1 module is enabled.
ADC Clock Gate Control — This bit controls the clock gate to the ADC module.
0 Bus clock to the ADC module is disabled.
1 Bus clock to the ADC module is enabled.
MTIM Clock Gate Control — This bit controls the clock gate to the MTIM module.
0 Bus clock to the MTIM module is disabled.
1 Bus clock to the MTIM module is enabled.
IIC Clock Gate Control — This bit controls the clock gate to the IIC module.
0 Bus clock to the IIC module is disabled.
1 Bus clock to the IIC module is enabled.
SCI2 Clock Gate Control — This bit controls the clock gate to the SCI2 module.
0 Bus clock to the SCI2 module is disabled.
1 Bus clock to the SCI2 module is enabled.
0
SCI1
90Freescale Semiconductor
SCI1 Clock Gate Control — This bit controls the clock gate to the SCI1 module.
0 Bus clock to the SCI1 module is disabled.
1 Bus clock to the SCI1 module is enabled.
MC9S08LG32 MCU Series, Rev. 5
Page 91
Chapter 5 Resets, Interrupts, and General System Control
5.8.10System Clock Gating Control 2 Register (SCGC2)
This high-page register contains control bits to enable or disable the bus clock to the IRQ, KBI, LCD, and
SPI modules. Gating off the clocks to unused peripherals is used to reduce the MCU’s run and wait
currents. See Section 5.7, “Peripheral Clock Gating,” for more information.
NOTE
User software must disable the peripheral before disabling the clocks to the
peripheral. When clocks are re-enabled to a peripheral, the peripheral
registers need to be re-initialized by user software.
76543210
R
DBGFLSIRQKBI
W——
Reset:01000000
= Unimplemented or Reserved
Figure 5-12. System Clock Gating Control 2 Register (SCGC2)
00
LCDSPI
Table 5-14. SCGC2 Register Field Descriptions
FieldDescription
7
DBG
6
FLS
5
IRQ
4
KBI
1
LCD
0
SPI
DBG Register Clock Gate Control — This bit controls the bus clock gate to the DBG module.
0 Bus clock to the DBG module is disabled.
1 Bus clock to the DBG module is enabled.
Flash Clock Gate Control — This bit controls the bus clock gate to the Flash module.
0 Bus clock to the Flash module is disabled.
1 Bus clock to the Flash module is enabled.
IRQ Clock Gate Control — This bit controls the bus clock gate to the IRQ module.
0 Bus clock to the IRQ module is disabled.
1 Bus clock to the IRQ module is enabled.
KBI Clock Gate Control — This bit controls the clock gate to the KBI module.
0 Bus clock to the KBI module is disabled.
1 Bus clock to the KBI module is enabled.
LCD Clock Gate Control — This bit controls the bus clock gate to the LCD module. Only the bus clock is gated,
the OSCOUT, TODCLK and LPOCLK are still available to the LCD.
0 Bus clock to the LCD module is disabled.
1 Bus clock to the LCD module is enabled.
SPI Clock Gate Control — This bit controls the clock gate to the SPI module.
0 Bus clock to the SPI module is disabled.
1 Bus clock to the SPI module is enabled.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor91
Page 92
Chapter 5 Resets, Interrupts, and General System Control
5.8.11Pin Position Control Register (PINPS1)
This high-page register contains the control bits that determine which of the two possible pins is used as
the source for the indicated KBIx pin function. The default source is the pin available on the 48-pin
package.
76543210
R
W
Reset:00000000
FieldDescription
KBI7KBI6KBI5KBI4KBI3KBI2KBI1KBI0
Figure 5-13. Pin Position Control Register (PINPS1)
Table 5-15. PINPS1 Register Field Descriptions
8
KBI7
7
KBI6
6
KBI5
5
KBI4
4
KBI3
3
KBI2
2
KBI1
1
KBI0
KBI7 Pin Position — This bit controls the pin position of KBI7.
0 KBI7 sourced from PTA6
1 KBI7 sourced from PTH3
KBI6 Pin Position — This bit controls the pin position of KBI6.
0 KBI6 sourced from PTA5
1 KBI6 sourced from PTH2
KBI5 Pin Position — This bit controls the pin position of KBI5.
0 KBI5 sourced from PTA4
1 KBI5 sourced from PTH1
KBI4 Pin Position — This bit controls the pin position of KBI4.
0 KBI4 sourced from PTA3
1 KBI4 sourced from PTH0
KBI3 Pin Position — This bit controls the pin position of KBI3.
0 KBI3 sourced from PTF0
1 KBI3 sourced from PTH5
KBI2 Pin Position — This bit controls the pin position of KBI2.
0 KBI2 sourced from PTF5
1 KBI2 sourced from PTH4
KBI1 Pin Position — This bit controls the pin position of KBI1.
0 KBI1 sourced from PTF4
1 KBI1 sourced from PTH7
KBI0 Pin Position — This bit controls the pin position of KBI0.
0 KBI0 sourced from PTF3
1 KBI0 sourced from PTH6
MC9S08LG32 MCU Series, Rev. 5
92Freescale Semiconductor
Page 93
Chapter 5 Resets, Interrupts, and General System Control
5.8.12Pin Position Control Register (PINPS2)
This high-page register contains the control bits that determine which of the two potential pins is used as
the source for the TPMx pin function. The default source is the pin available on the 48-pin package.
Figure 5-14. Pin Position Control Register (PINPS2)
Table 5-16. PINPS2 Register Field Descriptions
FieldDescription
7
TPM2[5]
6
TPM2[4]
5
TPM2[3]
4
TPM2[2]
3
TPM2[1]
2
TPM2[0]
1
TPM1[1]
0
TPM1[0]
TPM2[5] Pin Position — This bit controls the pin position of TPM2[5].
0 TPM2[5] sourced from PTF3
1 TPM2[5] sourced from PTH6
TPM2[4] Pin Position — This bit controls the pin position of TPM2[4].
0 TPM2[4] sourced from PTF4
1 TPM2[4] sourced from PTH7
TPM2[3] Pin Position — This bit controls the pin position of TPM2[3].
0 TPM2[3] sourced from PTF5
1 TPM2[3] sourced from PTI2
TPM2[2] Pin Position — This bit controls the pin position of TPM2[2].
0 TPM2[2] sourced from PTF0
1 TPM2[2] sourced from PTI3
TPM2[1] Pin Position — This bit controls the pin position of TPM2[1].
0 TPM2[1] sourced from PTA6
1 TPM2[1] sourced from PTI4
TPM2[0] Pin Position — This bit controls the pin position of TPM2[0].
0 TPM2[0] sourced from PTA5
1 TPM2[0] sourced from PTI5
TPM1[1] Pin Position — This bit controls the pin position of TPM1[1].
0 TPM1[1] sourced from PTF2
1 TPM1[1] sourced from PTH4
TPM1[0] Pin Position — This bit controls the pin position of TPM1[0].
0 TPM1[0] sourced from PTF1
1 TPM1[0] sourced from PTH5
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor93
Page 94
Chapter 5 Resets, Interrupts, and General System Control
5.8.13Pin Position Control Register (PINPS3)
This high-page register contains control bits that determine which of the two potential pins is used as the
source for the function. The default source is the pin available on the 48-pin package.
76543210
R
W
Reset:00000000
FieldDescription
TX2RX2SCLSDAMISOMOSISCKSS
Figure 5-15. Pin Position Control Register (PINPS3)
Table 5-17. PINPS3 Register Field Descriptions
7
TX2
6
RX2
5
SCL
4
SDA
3
MISO
2
MOSI
1
SCK
0
SS
TX2 Pin Position — This bit controls the pin position of TX2.
0 TX2 sourced from PTA3.
1 TX2 sourced from PTI1.
RX2 Pin Position — This bit controls the pin position of RX2.
0 RX2 sourced from PTA4.
1 RX2 sourced from PTI0.
SCL Pin Position — This bit controls the pin position of SCL.
0 SCL sourced from PTA1.
1 SCL sourced from PTI5.
SDA Pin Position — This bit controls the pin position of SDA.
0 SDA sourced from PTA2.
1 SDA sourced from PTI4.
MISO Pin Position — This bit controls the pin position of MISO.
0 MISO sourced from PTF4.
1 MISO sourced from PTI2.
MOSI Pin Position — This bit controls the pin position of MOSI.
0 MOSI sourced from PTF5.
1 MOSI sourced from PTI3.
SCK Pin Position — This bit controls the pin position of SCK.
0 SCK sourced from PTF2.
1 SCK sourced from PTI4.
SS Pin Position — This bit controls the pin position of SS.
0 SS sourced from PTF3.
1 SS sourced from PTI5.
MC9S08LG32 MCU Series, Rev. 5
94Freescale Semiconductor
Page 95
Chapter 5 Resets, Interrupts, and General System Control
5.8.14Pin Position Control Register (PINPS4)
This high-page register contains control bits that determine which of the two potential pins is used as the
source for the function. The default source is the pin available on 48-pin package.
76543210
R
W
Reset:00000000
FieldDescription
000000TX1RX1
Figure 5-16. Pin Position Control Register (PINPS4)
Table 5-18. PINPS4 Register Field Descriptions
1
TX1
0
RX1
TX1 Pin Position — This bit controls the pin position of TX1.
0 TX1 sourced from PTF0.
1 TX1 sourced from PTH5.
RX1 Pin Position — This bit controls the pin position of RX1.
0 RX1 sourced from PTF1.
1 RX1 sourced from PTH4.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor95
Page 96
Chapter 5 Resets, Interrupts, and General System Control
MC9S08LG32 MCU Series, Rev. 5
96Freescale Semiconductor
Page 97
Chapter 6
Parallel Input/Output Control
6.1Introduction
This section explains software controls related to parallel input/output (I/O) and pin control. The
MC9S08LG32 has nine parallel I/O ports (PTA-PTI) which include a total of 69 I/O pins, including two
output-only pins. See Chapter 2, “Pins and Connections,” for more information about pin assignments and
external hardware considerations of these pins.
Many of these pins are shared with on-chip peripherals such as timer systems, communication systems, or
keyboard interrupts, as shown in Table 2-1. The peripheral modules have priority over the general-purpose
I/O functions so that when a peripheral is enabled, the I/O functions associated with the shared pins may
be disabled.
After reset, the shared peripheral functions are disabled and the 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
All general-purpose I/O pins are not available on all packages. To avoid
extra current drain from floating input pins, your 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.
6.2Pins Shared with LCD
Pins that have shared function with the LCD have special behavior based on the state of the VSUPPLY
bits in the LCDSUPPLY register. These pins (PTA, PTB, PTC[4:0], PTD, PTE and PTG) can operate as
full complementary drive or open drain drive depending on the VSUPPLY bits. When V
to VDD externally, VSUPPLY = 11, FCDEN = 1, and RVEN = 0; the pins operate as full complementary
drive. For all other VSUPPLY modes, the GPIO shared with LCD operates as open drain.
is connected
LL3
6.3Port Data and Data Direction
Reading and writing of parallel I/Os are performed through the port data registers (PTxDn). The direction,
either input or output, is controlled through the port data direction registers (PTxDDn). The parallel I/O
port function for an individual pin is illustrated in the block diagram shown in Figure 6-1.
The data direction control bit (PTxDDn) determines whether the output buffer or the input buffer for the
associated pin is enabled. When a shared digital function is enabled for a pin, the output buffer is controlled
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor97
Page 98
Chapter 6 Parallel Input/Output Control
QD
QD
1
0
Port Read
PTxDDn
PTx Dn
Output Enable
Output Data
Input Data
Synchronizer
Data
BUSCLK
Input Enable
by the shared function. However, the data direction register bit continues to control the source for reads of
the port data register.
When a shared analog function is enabled for a pin, both the input and output buffers are disabled. A value
of 0 is read for any port data bit where the bit is an input (PTxDDn = 0) and the input buffer is disabled. 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.
It is good programming practice to write to the port data register before changing the direction of a port
pin so it becomes an output. This ensures that the pin is not driven momentarily with an old data value that
happen to be in the port data register.
Figure 6-1. Parallel I/O Block Diagram
6.4Pullup, Slew Rate, and Drive Strength
Associated with the parallel I/O ports is a set of registers located in the high-page register space that
operates independently of the parallel I/O registers. These registers are used to control pullups, slew rate,
and drive strength for the pins and can be used in conjunction with the peripheral functions on these pins.
6.4.1Port Internal Pullup Enable
For all GPIOs, set the corresponding bit in the pullup enable register (PTxPEn) to enable an internal pullup
resistor for each port pin. Typically, GPIO internal pullups are disabled when in output mode. However,
for GPIO that are muxed with LCD pins, the internal pullup is not disabled when in open drain, output
mode. Similarly the internal pullup for GPIO muxed with open drain RESET pin is not disabled in the
output mode.
98Freescale Semiconductor
MC9S08LG32 MCU Series, Rev. 5
Page 99
Chapter 6 Parallel Input/Output Control
The pullup device is disabled if the pin is controlled by an analog function regardless of the state of the
corresponding pullup enable register bit.
6.4.2Port Slew Rate Enable
Slew rate control can be enabled for each port pin by setting the corresponding bit in the slew rate control
register (PTxSEn). When enabled, slew control limits the rate at which an output can transition to reduce
EMC emissions. Slew rate control has no effect on pins that are configured as inputs.
6.4.3Port Drive Strength Select
An output pin can be configured for high-output drive strength by setting the corresponding bit in the drive
strength select register (PTxDSn). When high drive is selected, a pin is capable of sourcing and sinking
greater current. Even though every I/O pin can be selected as high drive, you must ensure that the total
current source and sink limits for the MCU 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.5Open Drain Operation
For most cases, port pins that share functions with the LCD operate as open drain outputs. As an open drain
output, the output high of the pin is dependent upon the pullup resistor. The pullup resistor can be an
internal resistor enabled by the PTxPEx bit or an external resistor.
•The value of the internal resistor can be in the range of 17.5 to 52.5 kΩ
•The value of an external resistor must be carefully selected to ensure it supports the output loads
that are being driven.
6.6Pin Behavior in Stop Modes
Pin behavior following execution of a STOP instruction depends on the stop mode that is entered. An
explanation of pin behavior for the various stop modes follows:
•Stop2 mode is a partial power-down mode, whereby I/O latches are maintained in their pre-STOP
instruction state. 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, you 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. You must then write a 1 to the PPDACK bit in the SPMSC2 register. Access to I/O is
again permitted in the user application program.
•If the LCD module is configured to operate in Stop modes, the drive mode of the GPIO shared with
LCD is retained upon stop recovery.
MC9S08LG32 MCU Series, Rev. 5
Freescale Semiconductor99
Page 100
Chapter 6 Parallel Input/Output Control
•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.7Parallel I/O and Pin Control Registers
This section provides information about the registers associated with the parallel I/O ports. The data and
data direction registers are located in page zero of the memory map. The pullup, slew rate, and drive
strength control registers are located in the high-page section of the memory map.
Refer to tables in Chapter 4, “Memory,” for the absolute address assignments for all parallel I/O and their
pin control registers. This section refers to registers and control bits only by their names. A Freescale
Semiconductor-provided equate or header file is normally to translate these names into the appropriate
absolute addresses.
6.7.1Port A Registers
Port A is controlled by the registers listed below. All the pins of port A are shared with LCD. These pins
have special behavior as explained in Section 6.2.
MC9S08LG32 MCU Series, Rev. 5
100Freescale Semiconductor
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.