MKE04P24M48SF0RM
MKE04P24M48SF0RM
MKE04P24M48SF0RM
Chapter 1
About This Document
1.1 Overview.........................................................................................................................................................................35
1.1.1 Purpose.............................................................................................................................................................35
1.1.2 Audience..........................................................................................................................................................35
1.2 Conventions....................................................................................................................................................................35
Chapter 2
Introduction
2.1 Overview.........................................................................................................................................................................37
2.2.4 Clocks...............................................................................................................................................................40
Chapter 3
Chip Configuration
3.1 Introduction.....................................................................................................................................................................45
3.3.1.5 Caches..........................................................................................................................................53
3.8 Analog.............................................................................................................................................................................72
3.9 Timers.............................................................................................................................................................................77
Chapter 4
Memory Map
4.1 Introduction.....................................................................................................................................................................91
Chapter 5
Clock Distribution
5.1 Introduction.....................................................................................................................................................................105
Chapter 6
Reset and Boot
6.1 Introduction.....................................................................................................................................................................115
6.2 Reset................................................................................................................................................................................115
6.3 Boot.................................................................................................................................................................................119
Chapter 7
Power Management
7.1 Introduction.....................................................................................................................................................................121
Chapter 8
Security
8.1 Introduction.....................................................................................................................................................................125
Chapter 9
Debug
9.1 Introduction.....................................................................................................................................................................127
Chapter 10
Signal Multiplexing and Signal Descriptions
10.1 Introduction.....................................................................................................................................................................133
10.2 Pinout..............................................................................................................................................................................133
10.3.4 Analog..............................................................................................................................................................137
Chapter 11
Port Control (PORT)
11.1 Introduction.....................................................................................................................................................................141
Chapter 12
System Integration Module (SIM)
12.1 Introduction.....................................................................................................................................................................155
12.1.1 Features............................................................................................................................................................155
Chapter 13
Power Management Controller (PMC)
13.1 Introduction.....................................................................................................................................................................171
Chapter 14
Miscellaneous Control Module (MCM)
14.1 Introduction.....................................................................................................................................................................177
14.1.1 Features............................................................................................................................................................177
Chapter 15
Peripheral Bridge (AIPS-Lite)
15.1 Introduction.....................................................................................................................................................................183
15.1.1 Features............................................................................................................................................................183
Chapter 16
Watchdog Timer (WDOG)
16.1 Introduction.....................................................................................................................................................................185
16.1.1 Features............................................................................................................................................................185
Chapter 17
Bit Manipulation Engine (BME)
17.1 Introduction.....................................................................................................................................................................201
17.1.1 Overview..........................................................................................................................................................202
17.1.2 Features............................................................................................................................................................203
Chapter 18
Flash Memory Module (FTMRE)
18.1 Introduction.....................................................................................................................................................................221
18.2 Feature.............................................................................................................................................................................221
18.3.6 Protection.........................................................................................................................................................228
18.3.7 Security............................................................................................................................................................232
Chapter 19
Flash Memory Controller (FMC)
19.1 Introduction.....................................................................................................................................................................257
19.1.1 Overview..........................................................................................................................................................257
19.1.2 Features............................................................................................................................................................257
Chapter 20
Internal Clock Source (ICS)
20.1 Introduction.....................................................................................................................................................................261
20.1.1 Features............................................................................................................................................................261
20.4.1.7 Stop..............................................................................................................................................271
Chapter 21
Oscillator (OSC)
21.1 Introduction.....................................................................................................................................................................277
21.1.1 Overview..........................................................................................................................................................277
21.6.1.1 Off................................................................................................................................................283
21.6.3 Counter.............................................................................................................................................................286
Chapter 22
Cyclic Redundancy Check (CRC)
22.1 Introduction.....................................................................................................................................................................287
22.1.1 Features............................................................................................................................................................287
Chapter 23
Interrupt (IRQ)
23.1 Introduction.....................................................................................................................................................................297
23.2 Features...........................................................................................................................................................................297
Chapter 24
Analog-to-digital converter (ADC)
24.1 Introduction.....................................................................................................................................................................301
24.1.1 Features............................................................................................................................................................301
Chapter 25
Analog comparator (ACMP)
25.1 Introduction.....................................................................................................................................................................335
25.1.1 Features............................................................................................................................................................335
25.6 Resets..............................................................................................................................................................................342
25.7 Interrupts.........................................................................................................................................................................342
Chapter 26
FlexTimer Module (FTM)
26.1 Introduction.....................................................................................................................................................................343
26.1.2 Features............................................................................................................................................................344
26.4.2 Prescaler...........................................................................................................................................................393
26.4.3 Counter.............................................................................................................................................................393
26.4.3.1 Up counting..................................................................................................................................393
26.4.12 Inverting...........................................................................................................................................................432
26.4.18 Initialization.....................................................................................................................................................444
Chapter 27
Pulse Width Timer (PWT)
27.1 Introduction.....................................................................................................................................................................465
27.1.1 Features............................................................................................................................................................465
27.5 Reset................................................................................................................................................................................475
27.5.1 General.............................................................................................................................................................475
27.6 Interrupts.........................................................................................................................................................................475
Chapter 28
Periodic Interrupt Timer (PIT)
28.1 Introduction.....................................................................................................................................................................479
28.1.2 Features............................................................................................................................................................480
28.4.1.1 Timers..........................................................................................................................................485
28.4.2 Interrupts..........................................................................................................................................................486
Chapter 29
Real-Time Counter (RTC)
29.1 Introduction.....................................................................................................................................................................491
29.2 Features...........................................................................................................................................................................491
Chapter 30
Serial Peripheral Interface (SPI)
30.1 Introduction.....................................................................................................................................................................499
30.1.1 Features............................................................................................................................................................499
30.4.1 General.............................................................................................................................................................511
30.4.6.1 SS Output.....................................................................................................................................518
30.4.9 Reset.................................................................................................................................................................522
30.4.10 Interrupts..........................................................................................................................................................523
30.4.10.1 MODF..........................................................................................................................................523
30.4.10.2 SPRF............................................................................................................................................523
30.4.10.3 SPTEF..........................................................................................................................................524
30.4.10.4 SPMF...........................................................................................................................................524
Chapter 31
Inter-Integrated Circuit (I2C)
31.1 Introduction.....................................................................................................................................................................529
31.1.1 Features............................................................................................................................................................529
31.4.1.8 Handshaking.................................................................................................................................547
31.4.4.1 Timeouts.......................................................................................................................................551
31.4.5 Resets...............................................................................................................................................................554
31.4.6 Interrupts..........................................................................................................................................................554
Chapter 32
Universal Asynchronous Receiver/Transmitter (UART)
32.1 Introduction.....................................................................................................................................................................561
32.1.1 Features............................................................................................................................................................561
Chapter 33
General-Purpose Input/Output (GPIO)
33.1 Introduction.....................................................................................................................................................................587
33.1.1 Features............................................................................................................................................................587
33.4.3 IOPORT...........................................................................................................................................................599
Chapter 34
Keyboard Interrupts (KBI)
34.1 Introduction.....................................................................................................................................................................601
34.1.1 Features............................................................................................................................................................601
1.1 Overview
1.1.1 Purpose
This document describes the features, architecture, and programming model of the
Freescale KE04 microcontroller.
1.1.2 Audience
This document is primarily for system architects and software application developers
who are using or considering using the KE04 microcontroller in a system.
1.2 Conventions
2.1 Overview
This chapter provides an overview of the Kinetis KE04 product family of ARM®
Cortex®-M0+ MCUs. It also presents high-level descriptions of the modules available on
the devices covered by this document.
2.2.4 Clocks
The following clock modules are available on this device.
Table 2-5. Clock modules
Module Description
Internal Clock Source (ICS) ICS module containing an internal reference clock (ICSIRCLK) and a frequency-
locked-loop (FLL).
System oscillator (OSC) The system oscillator, in conjunction with an external crystal or resonator,
generates a reference clock for the MCU.
Low-Power Oscillator (LPO) The PMC module contains a 1 kHz low-power oscillator which acts as a standalone
low-frequency clock source in all modes.
3.1 Introduction
This chapter provides details on the individual modules of the microcontroller. It
includes:
• Module block diagrams showing immediate connections within the device
• Specific module-to-module interactions not necessarily discussed in the individual
module chapters
• Links for more information
RXDFE[1:0] FTMIC[1:0]
+
ACMP0
–
+
ACMP1
–
in0 PWT_IN0
in1 PWT_IN1
PWT in2
in3
ovf RTC
2
tif PITch0 1
ADC trg rxd
UART0 0 UART0_RX
tif PITch1 txd
0
UART0_TX
1
3
2
inittrg FTM0 ch0 1
ch1 1 0 FTM0_CH0
0 FTM0_CH1
0 inittrg fault0
FTM2_FLT1
ovf DELAY 1 matchtrg fault1
fault2 FTM2_FLT2
FTM2
fault3
Bus CLK 1 1
trigger0
2N trigger1 0
trigger2
ADHWT[2:0] BUSREF RXDCE ACTRG FTMSYNC TXDME
BUSOUT
CLKOE
TX
UART0 0 UART0_TX
FTM0_CH0 1
PORT LOGIC
TXDME
RX
UART0 UART0_RX
1
FTM0_CH1
FTM0_CH1
0
RXDCE
0 UART0_RX
RX ACMP0
UART0 1 ++
2 +
ACMP1
To UART0_RX
Capture Function
RXDFE From Internal or External
Reference Voltage
When ADC hardware trigger selects the output of FTM2 triggers, an 8-bit delay block
will be enabled. This logic delays any trigger from FTM2 with an 8-bit counter whose
value is specified by SIM_SOPT[DELAY]. The reference clock to this module is the bus
clock with selectable predivider specified by SIM_SOPT[BUSREF].
Debug Interrupts
For details on the ARM Cortex-M0+ processor core see the ARM website: arm.com.
3.3.1.5 Caches
This device does not have processor related cache memories, but the flash controller has
an internal 32-byte cache for flash access.
Interrupts
ARM Cortex-M0+
Module
PPB Nested Vectored
Module
core
Interrupt Controller
(NVIC)
Module
R 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
IRQ3 IRQ2 IRQ1 IRQ0
W
• The NVIC registers you would use to configure the interrupt are:
• NVICIPR2
• To determine the particular IRQ's field location within these particular registers:
• NVICIPR2 field starting location = 8 * (IRQ mod 4) + 6 = 22
Since the NVICIPR fields are 2-bit wide (4 priority levels), the NVICIPR2 field
range is bits 22–23.
Therefore, the field locations NVICIPR2[23:22] are used to configure the SPI0 interrupts.
Clock logic
Wake-up
requests
interrupt controller
Nested vectored
Asynchronous
(NVIC)
Module
Wake-up Interrupt
Controller (AWIC)
Module
Peripheral
bridge
Register
access
System integration
module (SIM)
Peripheral
bridge
Register access
Power Management
Controller (PMC)
Miscellaneous
core
Control Module
Transfers
(MCM)
GPIO
controller
Crossbar Switch
Flash
S0
controller
BME
ARM core
M0
unified bus
SRAML
S1
SRAMU
Peripheral
S2
Peripherals
bridge 0
Peripherals
Transfers Transfers
AIPS-Lite
peripheral bridge
Register
access
CRC
Peripheral
bridge
Register
access
System integration
module
WDOG
The watchdog counter has four clock source options selected by programming
WDOG_CS2[CLK]. The clock source options are the bus clock, internal 1 kHz clock,
external clock, or an internal 32 kHz clock source.
The refresh timeout time is defined by WDOG_TOVALH:L. In addition, if window
mode is used, software must not start the refresh sequence until after the time value set in
the WDOG_WINH:L registers.
An optional fixed prescaler for all clock sources allows for longer timeout periods. When
WDOG_CS2[PRES] is set, the clock source is prescaled by 256 before clocking the
watchdog counter.
The watchdog counter registers CNTH:L provide access to the value of the free-running
watchdog counter. The software can read the counter registers at any time but cannot
write directly to the watchdog counter. The refresh sequence resets the watchdog counter
to 0x0000. Write to the WDOG_CNTH:L registers of 0xC520 followed by 0xD928
within 16 bus clocks start the unlock sequence. On completing the unlock sequence, the
user must reconfigure the watchdog within 128 bus clocks; otherwise, the watchdog
forces a reset to the MCU.
By default, the watchdog is not functional in Debug mode, Wait mode, or Stop mode.
Setting WDOG_CS1[DBG], WDOG_CS1[WAIT] or WDOG_CS1[STOP] can activate
the watchdog in Debug, Wait or Stop modes.
Peripheral
bridge
Register
access
System integration
module (SIM)
oscillator
System
ICS
Peripheral
bridge
Register
access
Signal multiplexing
Module signals
ICS
System oscillator
Peripheral bus
controller 0
Register
access
Flash memory
controller
Transfers
Flash memory
The on-chip flash memory is implemented in a portion of the allocated Flash range to
form a contiguous block in the memory map beginning at address 0x0000_0000. See
Flash memory sizes for details of supported ranges.
Access to the flash memory ranges outside the amount of flash on the device causes the
bus cycle to be terminated with an error followed by the appropriate response in the
requesting bus master.
MCM
Crossbar switch
Flash memory
Transfers Transfers
Flash memory
controller
Transfers
crossbar SRAM upper
Cortex-M0+ SRAM
core switch controller
SRAM lower
SRAM_L
0x1FFF_FFFF
0x2000_0000
SRAM size * (3/4)
SRAM_U
0x2000_0000 + SRAM_size(3/4) - 1
3.8 Analog
Register
access
Signal multiplexing
Transfers Module signals
Other peripherals SAR ADC
The ADC supports both software and hardware triggers. The ADC hardware trigger,
ADHWT, is selectable from ACMP0, ACMP1, FTM0 init trigger, FTM2 init trigger,
FTM2 match trigger, RTC overflow, or PITCH0/1 overflow. The hardware trigger can be
configured to cause a hardware trigger in MCU Run, Wait, and Stop modes.
The hardware trigger sources details are listed in the Module-to-Module section.
ALTCLK is active while the MCU is in Wait mode provided the conditions described
above are met. This allows ALTCLK to be used as the conversion clock source for the
ADC while the MCU is in Wait mode.
ALTCLK cannot be used as the ADC conversion clock source while the MCU is in Stop
mode.
Register
access
Signal multiplexing
Module signals
Other peripherals ACMP
The ACMP modules support internal bandgap reference voltage. When using the
bandgap reference, the user must enable the PMC bandgap buffer first.
The ACMP modules can continue to operate in Wait and Stop mode if enabled, and can
wake the MCU when a compare event occurs.
3.9 Timers
Register
access
Signal multiplexing
Transfers Module signals
Other peripherals FlexTimer
This device contains up to two FTM modules of one 6-channel FTM with full functions
and one 2-channel FTM with basic TPM functions. Each FTM module can use
independent external clock input. The table below summarizes the configuration of FTM
modules.
Table 3-33. FTM modules features
Feature FTM0 FTM2
Number of channels 2 6
Initial counting value no yes
Periodic TOF no yes
Input capture mode yes yes
Channel input filter no channels 0, 1, 2 and 3
Output compare mode yes yes
Edge-Aligned PWM (EPWM) yes yes
Center-Aligned PWM (CPWM) yes yes
Combine mode no yes
Complementary mode no yes
PWM synchronization no yes
Inverting no yes
Software output control (SWOC) no yes
Deadtime insertion no yes
Output mask no yes
Fault control no yes
Number of fault inputs 0 4
Fault input filter no fault inputs 0, 1 ,2 and 3
Polarity control no yes
Initialization no yes
Channel match trigger no yes
Initialization trigger yes yes
Capture test mode no yes
DMA no no
Dual edge capture mode no yes
Quadrature decoder mode no no
Quadrature decoder input filter no no
Debug modes no yes
Intermediary load no yes
Global time base enable1 no yes
Registers available FTM_SC, FTM_CNT, FTM_SC, FTM_CNT, FTM_MOD, FTM_C0SC,
FTM_MOD, FTM_C0V, FTM_C1SC, and FTM_C1V,
FTM_C0SC, FTM_C0V, FTM_C2SC, FTM_C2V, FTM_C3SC, FTM_C3V,
FTM_C1SC, and FTM_C4SC, FTM_C4V, FTM_C5SC, FTM_C5V,
FTM_C1V, FTM_CNTIN, FTM_STATUS, FTM_MODE,
FTM_EXTTRIG FTM_SYNC, FTM_OUTINIT, FTM_OUTMASK,
1. The global time base (GTB) feature allows the synchronization of multiple FTM modules on a chip. It requires the GTB
function supported by all the related FTM modules. On this device, only one FTM module (FTM2) supports the GTB
function, so the GTB function is actually not usable.
Register
access
Periodic interrupt
timer
Register
access
Signal multiplexing
Module signals
Real-time clock
Register
access
Signal multiplexing
Transfers Pulse width timer Module signals
Other peripherals
(PWT)
The counter of PWT has two selectable clocks sources, which are sharing with FTM
modules, and support up to 48 MHz with internal timer clock. PWT module supports
programmable positive or negative pulse edges, and programmable interrupt generation
upon pulse width values or counter overflow.
Peripheral
bridge
Register
access
Module signals
Signal
SPI
multiplexing
Peripheral
bridge
Register
access
Signal multiplexing
Module signals
I2 C
Peripheral
bridge
Register
access
Signal multiplexing
Module signals
UART
Register
access
Signal multiplexing
ARM Cortex -M0+
GPIO controller
Register
access
Signal multiplexing
ARM Cortex -M0+
KBI
Register
access
Signal multiplexing
ARM Cortex -M0+
IRQ
4.1 Introduction
This device contains various memories and memory-mapped peripherals which are
located in a 4 GB memory space. This chapter describes the memory and peripheral
locations within that memory space.
1. The program flash always begins at 0x0000_0000 but the end of implemented flash varies depending on the amount of
flash implemented for a particular device. See Flash memory sizes for details.
2. This range varies depending on SRAM sizes. See SRAM Sizes for details.
3. Includes BME operations to GPIO at slot 15 (based at 0x4000_F000).
4. This device implements a system ROM table which is used to redirect to ARM Cortex M0+ (Flycatcher) ROM table in
CoreSight debug system. See System ROM memory map for details.
31 0 31 0
1 KByte
32 KByte
ARM recommends that a debugger follows the flow as shown in the following figure to
discover the components in the CoreSight debug infrastructure. In this case, a debugger
reads the peripheral and component ID registers for each CoreSight component in the
CoreSight system.
Base pointer
CoreSight ID
Pointers
+ Optional component
+
Following table shows the Freescale system ROM table memory map. It includes the
ROM entry, peripheral ID and component ID required by ARM CoreSight debug
infrastructure.
NOTE
This device contains only standard ARM M0+ core debug
components which defined in Flycatcher ROM table. No
custom-built debug components are included.
ROM memory map
Absolute
Width Section/
address Register name Access Reset value
(in bits) page
(hex)
F000_2000 Entry (ROM_ENTRY0) 32 R See section 4.5.1/95
F000_2004 End of Table Marker Register (ROM_TABLEMARK) 32 R 0000_0000h 4.5.2/96
F000_2FCC System Access Register (ROM_SYSACCESS) 32 R 0000_0001h 4.5.3/96
F000_2FD0 Peripheral ID Register (ROM_PERIPHID4) 32 R See section 4.5.4/97
F000_2FD4 Peripheral ID Register (ROM_PERIPHID5) 32 R See section 4.5.4/97
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R ENTRY
W
Reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R MARK
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R SYSACCESS
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
R PERIPHID
W
Reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
R COMPID
W
Reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
5.1 Introduction
This chapter presents the clock architecture for the device, the overview of the clocks and
includes a terminology section.
The Cortex M0+ resides within a synchronous core platform, where the processor and
bus masters, flash and peripherals clocks can be configured independently.
The ICS module will be used for main system clock generation. The ICS module controls
which clock sources (internal references, external crystals or external clock signals)
generate the source of the system clocks.
• System Oscillator (OSC) module: The system oscillator providing reference clock to
internal clock source (ICS), the real-time clock counter clock module (RTC), and
other MCU sub-systems
• Low-Power Oscillator (LPO) module: The on-chip low-power oscillator providing 1
kHz reference clock to RTC and Watchdog (WDOG)
Figure 5-1 shows how clocks from the ICS and OSC modules are distributed to the
microcontroller’s other function units. Some modules in the microcontroller have
selectable clock input.
The following registers of the system oscillator, ICS, and SIM modules control the
multiplexers, dividers, and clock gates shown in the figure:
Table 5-1. Registers controlling multiplexers, dividers, and clock gate
OSC ICS SIM
Multiplexers OSC_CR ICS_C1 SIM_SOPT
Dividers — ICS_C2 SIM_CLKDIV
Clock gates OSC_CR ICS_C1 SIM_SCGC
ICS SIM
ICSIRCLK
CG CG RTC / WDOG
ICSFFCLK
CG FTM
32 kHz IRC
FLL
RDIV
DIV2 CG Bus/Flash Clock
CLK_GEN
System oscillator
EXTAL OSCCLK OSCERCLK
CG RTC / WDOG / ADC
XTAL_CLK
OSC
XTAL logic OSCOS
PMC
LPOCLK
1kHz LPO RTC / WDOG
CG — Clock gate
Note: See subsequent sections for details on where these clocks are used.
1-kHz LPOCLK
LPO
EXTAL OSCCLK
OSC
XTAL
ICSIRCLK
TCLK1
TCLK2
ICSFFCLK
TIMER_CLK
32-kHz BUS_CLK
IRC
ACMP0
PIT CRC IIC SPI0 UART0
ACMP1
SYS_CLK
FLASH_CLK
NOTE
Clock divide and gating are not shown in clock distribution
diagram.
Table 5-4. ICS bus frequency availability with internal reference (continued)
Reference ICSOUTCLK
BDIV = 8 2.5 MHz ~ 3.125 MHz
BDIV = 16 1.25 MHz ~ 1.5625 MHz
BDIV = 32 625 kHz ~ 781.25 kHz
BDIV = 64 312.5 kHz ~ 390.625 kHz
BDIV = 128 156.25 kHz ~ 195.3125 kHz
1. Carefully configure SIM_CLKDIV and BDIV to avoid any clock frequency higher than 48 MHz.
The following table shows the frequency availability of this device when sourcing from
OSC clock. OSC external clock mode is not shown.
Table 5-5. OSC frequency availability
ICS configuration External reference RDIV
FBE 31.25 kHz ~ 39.0625 kHz ̶
4 MHz ~ 24 MHz ̶
FEE1 31.25 kHz ~ 39.0625 kHz RDIV = 1
62.5 kHz ~ 78.125 kHz RDIV = 2
125 kHz ~ 56.25 kHz RDIV = 4
250 kHz ~ 312.5 kHz RDIV = 8
500 kHz ~ 625 kHz RDIV = 16
1 MHz ~ 1.25 MHz RDIV = 32
2 MHz ~ 2.5 MHz RDIV = 64
4 MHz ~ 5 MHz RDIV = 128
1. In FEE mode, FLL output frequency = OSC/RDIV *1280. Select the OSC and RDIV carefully to keep the FLL output
frequency within the limits.
ICSIRCLK
TIMER_CLK
ICSFLLCLK DIV3
OSCERCLK
TCLK1
TCLK2
FTM0_SC[CLKS]
SIM_PINSEL[FTM0CLKPS]
FTM2 clock
SIM_PINSEL[FTM2CLKPS] FTM2_SC[CLKS]
PWT clock
SIM_PINSEL[PWTCLKPS]
PWT_R1[PCLKS]
6.1 Introduction
The following reset sources are supported in this MCU:
Table 6-1. Reset sources
Reset sources Description
POR reset • Power-on reset (POR)
System resets • External pin reset (PIN)
• Low-voltage detect (LVD)
• Watchdog (WDOG) timer
• ICS loss of clock (LOC) reset
• Stop mode acknowledge error (SACKERR)
• Software reset (SW)
• Lockup reset (LOCKUP)
• MDM DAP system reset
Each of the system reset sources has an associated bit in the System Reset Status and ID
Register (SIM_SRSID).
The MCU can exit and reset in functional mode where the CPU is executing code
(default) or the CPU is in a debug halted state. There are several boot options that can be
configured. See Boot for more details.
6.2 Reset
This section discusses basic reset mechanisms and sources. Some modules that cause
resets can be configured to cause interrupts instead. Consult the individual peripheral
chapters for more information.
The glitch width threshold can be adjusted easily by setting Port Filter Register
(PORT_IOFLT) between 1~4096 BUSCLKs (or 1~128 LPOCLKs). This configurable
glitch filter can replace an on-board external analog filter, and greatly improve the EMC
performance. Setting Port Filter Register (PORT_IOFLT) can configure the filter of the
whole port.
6.3 Boot
This section describes the boot sequence, including sources and options.
Some configuration information such as clock trim values stored in factory programmed
flash locations is auto-loaded.
1. VTOR: refer to Vector Table Offset Register in the ARMv6-M Architecture Reference Manual.
This device supports booting from internal flash with the reset vectors located at
addresses 0x0 (initial SP_main), 0x4 (initial PC), and RAM with relocating the exception
vector table to RAM.
7.1 Introduction
This chapter describes the various chip power modes and functionality of the individual
modules in these modes.
1. SRAM enable signal disables internal clock signal and masks the address and data inputs when held low, RAM clock at
chip can be active in Wait mode.
2. Supports wake-up on edge in Stop mode
3. Supports slave mode receive and wake-up in Stop mode
4. Supports address match wake-up in Stop mode
5. Supports pin interrupt wake-up in Stop mode
8.1 Introduction
This device implements security based on the mode selected from the flash module. The
following sections provide an overview of flash security and details of the effects of
security on non-flash modules.
9.1 Introduction
This device's debug is based on the ARM CoreSight architecture and is configured to
provide the maximum flexibility as allowed by the restrictions of the pinout and other
available resources.
It provides register and memory accessibility from the external debugger interface, basic
run/halt control plus 2 breakpoints and 2 watchpoints.
This device supports only one debug interface, Serial Wire Debug (SWD).
1. The pad library of this device does not support on-chip pull down; the SWD_CLK pin supports only pullup controlled by
PTAPE0, external pulldown resistor is required to fully support SWD protocol.
DPACC APACC
0x0C
Debug Port ID Register (IDCODE) 0x00
0x04
0x08
Debug Port
SW-DP
Control/Status (CTRL/STAT)
Generic
Debug Port
(DP)
Internal Bus
SELECT[31:24] (APSEL) selects the AP
SELECT[7:4] (APBANKSEL) selects the bank
A[3:2] from the APACC selects the register
within the bank
AHB-AP
0x00
0x3F
0x01
1 Flash Ready Indicates that flash memory has been initialized and debugger can be
configured even if system is continuing to be held in reset via the
debugger.
0 Flash is under initialization.
Table continues on the next page...
1 Debug Disable N Set to disable debug. Clear to allow debug operation. When set, it
overrides the C_DEBUGEN field within the DHCSR2 and forces to
disable Debug logic.
2 Debug Request N Set to force the core to halt.
If the core is in Stop or Wait mode, this field can be used to wake the
core and transition to a halted state.
3 System Reset Request Y Set to force a system reset. The system remains held in reset until
this field is cleared. When this bit is set, RESET pin does not reflect
the status of system reset and does not keep low.
4 Core Hold N Configuration field to control core operation at the end of system
reset sequencing.
0 Normal operation—release the core from reset along with the rest
of the system at the end of system reset sequencing.
Table continues on the next page...
10.1 Introduction
To optimize functionality in small packages, pins have several functions available via
signal multiplexing. This chapter illustrates which of this device's signals are multiplexed
on which external pin.
The Pin Selection Register (SIM_PINSEL) controls which signal is present on the
external pin. Refer to that register to find the detailed control operation of a specific
multiplexed pin.
10.2 Pinout
24 20 16 Pin Name Default ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 ALT6 ALT7
QFN SOIC TSSO
P
1 — — PTC5 DISABLED PTC5 KBI1_P1 FTM2_CH3 BUSOUT
2 — — PTC4 DISABLED PTC4 KBI1_P0 FTM2_CH2 PWT_IN0
3 3 3 VDD VDD VDD
3 3 3 VREFH VDDA/ VDDA VREFH
VREFH
4 4 4 VREFL VREFL VREFL
4 4 4 VSS VSS/ VSSA VSS
VSSA
5 5 5 PTB7 EXTAL PTB7 I2C0_SCL EXTAL
6 6 6 PTB6 XTAL PTB6 I2C0_SDA XTAL
7 7 7 PTB5 ACMP1_OUT PTB5 KBI1_P7 FTM2_CH5 SPI0_PCS ACMP1_OUT
8 8 8 PTB4 NMI_b PTB4 KBI1_P6 FTM2_CH4 SPI0_MISO ACMP1_IN2 NMI_b
9 9 — PTC3 ADC0_SE11 PTC3 KBI1_P5 FTM2_CH3 ADC0_SE11
10 10 — PTC2 ADC0_SE10 PTC2 KBI1_P4 FTM2_CH2 ADC0_SE10
11 11 — PTC1 ADC0_SE9 PTC1 KBI1_P3 FTM2_CH1 ADC0_SE9
12 12 — PTC0 ADC0_SE8 PTC0 KBI1_P2 FTM2_CH0 ADC0_SE8
13 13 9 PTB3 ADC0_SE7 PTB3 KBI0_P7 SPI0_MOSI FTM0_CH1 ADC0_SE7
14 14 10 PTB2 ADC0_SE6 PTB2 KBI0_P6 SPI0_SCK FTM0_CH0 ACMP0_IN0 ADC0_SE6
15 15 11 PTB1 ADC0_SE5 PTB1 KBI0_P5 UART0_TX SPI0_MISO TCLK2 ADC0_SE5
16 16 12 PTB0 ADC0_SE4 PTB0 KBI0_P4 UART0_RX SPI0_PCS PWT_IN1 ADC0_SE4
17 — — PTA7 ADC0_SE3 PTA7 FTM2_FLT2 SPI0_MOSI ACMP1_IN1 ADC0_SE3
18 — — PTA6 ADC0_SE2 PTA6 FTM2_FLT1 SPI0_SCK ACMP1_IN0 ADC0_SE2
19 17 13 PTA3 DISABLED PTA3 KBI0_P3 UART0_TX I2C0_SCL
20 18 14 PTA2 DISABLED PTA2 KBI0_P2 UART0_RX I2C0_SDA
21 19 15 PTA1 ADC0_SE1 PTA1 KBI0_P1 FTM0_CH1 ACMP0_IN1 ADC0_SE1
22 20 16 PTA0 SWD_CLK PTA0 KBI0_P0 FTM0_CH0 RTCO ACMP0_IN2 ADC0_SE0 SWD_CLK
23 1 1 PTA5 RESET_b PTA5 IRQ TCLK1 RESET_b
24 2 2 PTA4 SWD_DIO PTA4 ACMP0_OUT SWD_DIO
PTA4
PTA5
PTA0
PTA1
PTA2
PTA3
21
22
19
20
24
23
PTC5 1 18 PTA6
PTC4 2 17 PTA7
PTB7 5 14 PTB2
PTB6 6 13 PTB3
10
11
12
9
7
PTC1
PTC0
PTC3
PTB5
PTB4
PTC2
PTA5 1 20 PTA0
PTA4 2 19 PTA1
VDD /VREFH 3 18 PTA2
VSS /VREFL 4 17 PTA3
PTB7 5 16 PTB0
PTB6 6 15 PTB1
PTB5 7 14 PTB2
PTB4 8 13 PTB3
PTC3 9 12 PTC0
PTC2 10 11 PTC1
PTA5 1 16 PTA0
PTA4 2 15 PTA1
VDD /VREFH 3 14 PTA2
VSS /VREFL 4 13 PTA3
PTB7 5 12 PTB0
PTB6 6 11 PTB1
PTB5 7 10 PTB2
PTB4 8 9 PTB3
1. The pad library of this device does not support on-chip pull down; the SWD_CLK pin supports only pullup controlled by
PTAPE0, external pulldown resistor is required to fully support SWD protocol.
10.3.4 Analog
Table 10-4. ADC0 signal descriptions
Chip signal name Module signal Description I/O
name
ADC0_SEn AD11-AD0 Analog channel inputs I
VDD/VREFH VDDA/VREFH Analog power supply / voltage reference high I
VSS/VREFL VSSA/VREFL Analog power ground / voltage reference low I
1. The available GPIO pins depend on the specific package. See the signal multiplexing section for which exact GPIO signals
are available.
11.1 Introduction
This device has three sets of I/O ports, which include up to 22 general-purpose I/O pins.
Not all pins are available on all devices.
Many of the I/O pins are shared with on-chip peripheral functions. The peripheral
modules have priority over the I/O, so when a peripheral is enabled, the associated I/O
functions are disabled.
After reset, the shared peripheral functions are disabled so that the pins are controlled by
the parallel I/O except PTA4, PTA0, PTB4 and PTA5 that are default to SWD_DIO,
SWD_CLK, NMI and RESET function. All of the parallel I/O are configured as high-
impedance (Hi-Z). The pin control functions for each pin are configured as follows:
• input disabled (GPIOx_PIDR[PID] = 1),
• output disabled ( GPIOx_PDDR[PDD] = 0), and
• internal pullups disabled (PORT_PUE(L)[PTxPEn] = 0).
Additionally, the parallel I/O that support high drive capability are disabled (HDRVE =
0x00) after reset.
The following three figures show the structures of each I/O pin.
PORT_PUEL[PTxPEn]
GPIOx_PDDR[PDD]
GPIOx_PDOR[PDO]
GPIOx_PIDR[PID]
1 0 (except RESET/NMI)
CPU read GPIOx_PDIR[PDI]
0 Glitch filter
PORT_IOFLT
PORT_PUEL[PTxPEn]
GPIOx_PDDR[PDD]
GPIOx_PDOR[PDO]
GPIOx_PIDR[PID]
1 0 (except RESET/NMI)
CPU read GPIOx_PDIR[PDI]
0 Glitch filter
PORT_IOFLT
PORT_PUEL[PTxPEn]
GPIOx_PDDR[PDD]
GPIOx_PDOR[PDO]
GPIOx_PIDR[PID]
HDRVE
1 0 (except RESET/NMI)
CPU read GPIOx_PDIR[PDI]
0 Glitch filter
PORT_IOFLT
When a peripheral module or system function is in control of a port pin, the data direction
register bit still controls what is returned for reads of the port data register, even though
the peripheral system has overriding control of the actual pin direction.
When a shared analog function is enabled for a pin, all digital pin functions are disabled.
A read of the port data register returns a value of 0 for any bits that have shared analog
functions enabled. In general, whenever a pin is shared with both an alternate digital
function and an analog function, the analog function has priority such that if both of the
digital and analog functions are enabled, the analog function controls the pin.
A write of valid data to a port data register must occur before setting the output enable bit
of an associated port pin. This ensures that the pin will not be driven with an incorrect
data value.
Setting register PORT_IOFLT can configure the filters of the whole port or peripheral
inputs. For example, setting PORT_IOFLT[FLTA] will affect all PTAn pins.
Glitches that are shorter than the selected clock period will be filtered out; Glitches that
are more than twice the selected clock period will not be filtered out. It will pass to
internal circuitry.
Pass to
internal rate
100%
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R
W
FLTDIV3 FLTDIV2 FLTDIV1 FLTNMI FLTKBI1 FLTKBI0 FLTRST
Reset 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
FLTPWT FLTFTM0 FLTIIC FLTC FLTB FLTA
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
000 LPOCLK
001 LPOCLK/2
010 LPOCLK/4
011 LPOCLK/8
100 LPOCLK/16
101 LPOCLK/32
110 LPOCLK/64
111 LPOCLK/128
28–26 Filter Division Set 2
FLTDIV2
Table continues on the next page...
000 BUSCLK/32
001 BUSCLK/64
010 BUSCLK/128
011 BUSCLK/256
100 BUSCLK/512
101 BUSCLK/1024
110 BUSCLK/2048
111 BUSCLK/4096
25–24 Filter Division Set 1
FLTDIV1
Port Filter Division Set 1
00 BUSCLK/2
01 BUSCLK/4
10 BUSCLK/8
11 BUSCLK/16
23–22 Filter Selection for Input from NMI
FLTNMI
00 No filter.
01 Selects FLTDIV1, and will switch to FLTDIV3 in Stop mode automatically.
10 Selects FLTDIV2, and will switch to FLTDIV3 in Stop mode automatically.
11 FLTDIV3
21–20 Filter Selection for Input from KBI1
FLTKBI1
00 No filter
01 Selects FLTDIV1, and will switch to FLTDIV3 in Stop mode automatically.
10 Selects FLTDIV2, and will switch to FLTDIV3 in Stop mode automatically.
11 FLTDIV3
19–18 Filter selection for Input from KBI0
FLTKBI0
00 No filter.
01 Selects FLTDIV1, and will switch to FLTDIV3 in Stop mode automatically.
10 Selects FLTDIV2, and will switch to FLTDIV3 in Stop mode automatically.
11 FLTDIV3
17–16 Filter Selection for Input from RESET/IRQ
FLTRST
00 No filter.
01 Selects FLTDIV1, and will switch to FLTDIV3 in Stop mode automatically.
10 Selects FLTDIV2, and will switch to FLTDIV3 in Stop mode automatically.
11 FLTDIV3
15–14 Filter Selection For Input from PWT_IN1/PWT_IN0
FLTPWT
00 No filter
01 Select FLTDIV1
10 Select FLTDIV2
11 Select FLTDIV3
00 BUSCLK
01 FLTDIV1
10 FLTDIV2
11 FLTDIV3
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
PTCPE5
PTCPE4
PTCPE3
PTCPE2
PTCPE1
PTCPE0
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
PTBPE7
PTBPE6
PTBPE5
PTBPE4
PTBPE3
PTBPE2
PTBPE1
PTBPE0
PTAPE7
PTAPE6
PTAPE5
PTAPE4
PTAPE3
PTAPE2
PTAPE1
PTAPE0
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
NOTE: When configuring to use this pin as output high for IIC, the internal pullup device remains active
when PTAPE2 is set. It is automatically disabled to save power when output low.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0
PTC5 PTC1 PTB5
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12.1 Introduction
The system integration module (SIM) provides system control and chip configuration
registers.
12.1.1 Features
The features of the SIM module are listed below.
• Reset status and device ID information
• System interconnection configuration and special pin enable
• Pin re-map control
• System clock gating control and clock divide
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reset 0 0 0 0 0 1 0 0 * * * * * * * *
LVD 0 0 0 0 0 1 0 0 * * * * * * * *
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SACKERR
LOCKUP
MDMAP
WDOG
POR
LOC
LVD
R 0 0 SW 0 PIN 0 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
LVD 0 0 0 0 0 0 0 0 u* 0 0 0 0 0 1 0
* Notes:
• RevID field: Decided by device revision number.
• PINID field: Decided by device pin number.
• u = Unaffected by reset.
0 Reset is not caused by peripheral failure to acknowledge attempt to enter Stop mode.
1 Reset is caused by peripheral failure to acknowledge attempt to enter Stop mode.
12 This field is reserved.
Reserved This read-only field is reserved and always has the value 0.
11 MDM-AP System Reset Request
MDMAP
Indicates a reset has been caused by the host debugger system setting of the System Reset Request field
in the MDM-AP Control Register.
0 Reset is not caused by host debugger system setting of the System Reset Request bit.
1 Reset is caused by host debugger system setting of the System Reset Request bit.
10 Software
SW
Indicates a reset has been caused by software setting of SYSRESETREQ bit in Application Interrupt and
Reset Control Register in the ARM core.
NOTE: This bit POR to 1, LVR to uncertain value and reset to 0 at any other conditions.
NOTE: This field is reset to 1 on POR and LVR, and reset to 0 on other reset.
NOTE
RSTPE and NMIE are write-once only on each reset.
Address: 4004_8000h base + 4h offset = 4004_8004h
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DLYACT
R
CLKOE
DELAY ADHWT BUSREF
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
POR/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LVD
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0 0 0 0
TXDME
RXDCE
ACTRG
RSTPE
SWDE
Reset 0 0 0 0 0 0 0 0 0 0 0 0 1 u* u* 0
POR/ 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
LVD
* Notes:
• u = Unaffected by reset.
000 Bus
001 Bus divided by 2
010 Bus divided by 4
011 Bus divided by 8
100 Bus divided by 16
101 Bus divided by 32
110 Bus divided by 64
111 Bus divided by 128
15 UART0_TX Modulation Select
TXDME
Enables the UART0_TX output modulated by FTM0 channel 0.
0 No synchronization triggered.
1 Generates a PWM synchronization trigger to the FTM2 modules.
00 FTM0_CH0 pin
01 ACMP0 OUT
10 ACMP1 OUT
11 RTC overflow
5 ACMP Trigger FTM2 selection
ACTRG
Selects the two ACMP outputs as the trigger0 input of FTM2
0 ACMP0 out
1 ACMP1 out
4 This field is reserved.
Reserved This read-only field is reserved and always has the value 0.
3 Single Wire Debug Port Pin Enable
SWDE
Enables the PTA4/ACMP0_OUT/SWD_DIO pin to function as SWD_DIO, and PTA0/KBI0_P0/
FTM0_CH0/RTCO/ACMP0_IN2/ADC0_SE0/SWD_CLK pin function as SWD_CLK. When clear, the two
pins function as PTA4 and PTA0. This pin defaults to the SWD_DIO and SWD_CLK function following any
MCU reset.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FTM2CLKPS
FTM0CLKPS
PWTCLKPS
R 0 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0
UART0PS
FTM2PS3
FTM2PS2
FTM0PS1
FTM0PS0
SPI0PS
I2C0PS
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0 0 0 0 0 0
ACMP1
ACMP0
UART0
ADC IRQ KBI1 KBI0 SPI0 I2C
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0 0 0 0
FLASH
FTM2
FTM0
Reset 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R ID[31:0]
W
Reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
The read-only SIM_UUIDML register contains a series of number to identify the unique
device in the family.
Address: 4004_8000h base + 14h offset = 4004_8014h
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R ID[63:32]
W
Reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 ID[80:64]
W
Reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0 0 0 0
OUTDIV2
OUTDIV3
OUTDIV1
W
Reset 0 0 u* u* 0 0 0 u* 0 0 0 u* 0 0 0 0
POR/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LVD
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
POR/ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LVD
* Notes:
• u = Unaffected by reset.
00 Same as ICSOUTCLK.
01 ICSOUTCLK divides by 2.
10 ICSOUTCLK divides by 3.
11 ICSOUTCLK divides by 4.
0 Same as ICSOUTCLK.
1 ICSOUTCLK divides by 2.
Reserved This field is reserved.
This read-only field is reserved and always has the value 0.
13.1 Introduction
This chapter describes the functionality of the individual modules in the chip’s low-
power modes and the operation of Power Management Controller module.
vDD
LVDV:LVWV
R1
LVD0
-
LVD1
LVD
+
LVW0
LVW1
LVW2 -
LVW3 LVW
+
vBG
Bandgap
R7
vss
Bit 7 6 5 4 3 2 1 0
Read LVWF 0
LVWIE LVDRE LVDSE LVDE BGBE
Write LVWACK 0
Reset 0 0 0 1 1 1 0 0
NOTE: LVWF will be set in the case when VSupply transitions below the trip point or after reset and VSupply
is already below VLVW. LVWF may be 1 after power-on-reset, therefore, to use LVW interrupt
function, before enabling LVWIE, LVWF must be cleared by writing LVWACK first.
NOTE: This field can be written only one time after reset. Additional writes are ignored.
If LVDRE = 0, use LVW to monitor status because no flag was assert.
NOTE: This field can be written only one time after reset. Additional writes are ignored.
Bit 7 6 5 4 3 2 1 0
Read 0 0
LVDV LVWV
Write
Reset 0 0 0 0 0 0 0 0
14.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The Miscellaneous Control Module (MCM) provides a myriad of miscellaneous control
functions.
14.1.1 Features
The MCM includes the following features:
• Program-visible information on the platform configuration
• Flash controller speculation buffer and cache configurations
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Read 0 ASC
Write
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Read 0 AMC
Write
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
The cache in flash controller is enabled and caching both instruction and data type fetches
after reset. It is possible to have these states for the cache:
DFCC DFCIC DFCDA Description
0 0 0 Cache is on for both
instruction and data.
0 0 1 Cache is on for instruction
and off for data.
0 1 0 Cache is off for instruction
and on for data.
0 1 1 Cache is off for both
instruction and data.
1 X X Cache is off.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
ESFC
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0
DFCDA
DFCIC
DFCC
DFCS
EFDS
CFCC
Reset 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
15.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The peripheral bridge converts the crossbar switch interface to an interface that can
access most of the slave peripherals on this chip.
The peripheral bridge occupies 64 MB of the address space, which is divided into
peripheral slots of 4 KB. (It might be possible that all the peripheral slots are not used.
See the memory map chapter for details on slot assignments.) The bridge includes
separate clock enable inputs for each of the slots to accommodate slower peripherals.
15.1.1 Features
Key features of the peripheral bridge are:
• Supports peripheral slots with 8-, 16-, and 32-bit datapath width
• Transfer attributes
• Byte enables
• Write data
The peripheral bridge selects and captures read data from the peripheral interface and
returns it to the crossbar switch.
The register maps of the peripherals are located on 4-KB boundaries. Each peripheral is
allocated one or more 4-KB block(s) of the memory map.
The AIPS-Lite module uses the data width of accessed peripheral to perform proper data
byte lane routing; bus decomposition (bus sizing) is performed when the access size is
larger than the peripheral's data width.
16.1 Introduction
The Watchdog Timer (WDOG) module is an independent timer that is available for
system use. It provides a safety feature to ensure that software is executing as planned
and that the CPU is not stuck in an infinite loop or executing unintended code. If the
WDOG module is not serviced (refreshed) within a certain period, it resets the MCU.
16.1.1 Features
Features of the WDOG module include:
• Configurable clock source inputs independent from the bus clock
• Internal 32 kHz RC oscillator
• Internal 1 kHz RC oscillator
• External clock source
• Programmable timeout period
• Programmable 16-bit timeout value
• Optional fixed 256 clock prescaler when longer timeout periods are needed
• Robust write sequence for counter refresh
• Refresh sequence of writing 0x02A6 and then 0x80B4 within 16 bus clocks
• Window mode option for the refresh mechanism
• Programmable 16-bit window value
Backup Reset
MUX
32K CLK
Counter Control 128 Bus CPU Reset
MUX
Bit 7 6 5 4 3 2 1 0
Read EN INT UPDATE TST DBG WAIT STOP
Write
Reset 1 0 0 0 0 0 0 0
0 Watchdog disabled.
1 Watchdog enabled.
0 Updates not allowed. After the initial configuration, the watchdog cannot be later modified without
forcing a reset.
1 Updates allowed. Software can modify the watchdog configuration registers within 128 bus clocks
after performing the unlock write sequence.
4–3 Watchdog Test
TST
Enables the fast test mode. The test mode allows software to exercise all bits of the counter to
demonstrate that the watchdog is functioning properly. See the Fast testing of the watchdog section.
This write-once field is cleared (0:0) on POR only. Any other reset does not affect the value of this field.
Bit 7 6 5 4 3 2 1 0
Read FLG 0 0
WIN PRES CLK
Write w1c
Reset 0 0 0 0 0 0 0 1
0 No interrupt occurred.
1 An interrupt occurred.
5 This field is reserved.
Reserved This read-only field is reserved and always has the value 0.
4 Watchdog Prescalar
PRES
This write-once bit enables a fixed 256 pre-scaling of watchdog counter reference clock. (The block
diagram shows this clock divider option.)
This write-once field indicates the clock source that feeds the watchdog counter. See the Clock source
section.
00 Bus clock.
01 1 kHz internal low-power oscillator (LPOCLK).
10 32 kHz internal oscillator (ICSIRCLK).
11 External clock source.
Bit 7 6 5 4 3 2 1 0
Read CNTHIGH
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read CNTLOW
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read TOVALHIGH
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read TOVALLOW
Write
Reset 0 0 0 0 0 1 0 0
Bit 7 6 5 4 3 2 1 0
Read WINHIGH
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read WINLOW
Write
Reset 0 0 0 0 0 0 0 0
WDOG counter
WDOG_TOVALH and
WDOG_TOVALL
WDOG_WINH and
WDOG_WINL Refresh opportunity
in window mode
0 Time
Refresh opportunity (not in window mode)
Note
Before starting the refresh sequence, disable global interrupts.
Otherwise, an interrupt could effectively invalidate the refresh
sequence if writing the four bytes takes more than 16 bus
clocks. Re-enable interrupts when the sequence is finished.
/* Refresh watchdog */
...
}
once after reset. Otherwise, the WDOG uses the reset values by default. If window mode
is not used (CS2[WIN] is 0), writing to WDOG_WINH:L is not required to make the new
configuration take effect.
NOTE
When the programmer switches clock sources during
reconfiguration, the watchdog hardware holds the counter at
zero for 2.5 periods of the previous clock source and 2.5
periods of the new clock source after the configuration time
period (128 bus clocks) ends. This delay ensures a smooth
KE04 Sub-Family Reference Manual, Rev. 3, Feburary 2014
Freescale Semiconductor, Inc. 197
Functional description
5. Confirm the WDOG flag in the system reset register is set, indicating that the
watchdog caused the reset. (The POR flag remains clear.)
6. Confirm that WDOG_CS1[TST] shows a test (10b or 11b) was performed.
If confirmed, the count and compare functions work for the selected byte. Repeat the
procedure, selecting the other byte in step 2.
NOTE
WDOG_CS1[TST] is cleared by a POR only and not affected
by other resets.
17.1 Introduction
The Bit Manipulation Engine (BME) provides hardware support for atomic read-modify-
write memory operations to the peripheral address space in Cortex-M0+ based
microcontrollers.
This architectural capability is also known as "decorated storage" as it defines a
mechanism for providing additional semantics for load and store operations to memory-
mapped peripherals beyond just the reading and writing of data values to the addressed
memory locations. In the BME definition, the "decoration", that is, the additional
semantic information, is encoded into the peripheral address used to reference the
memory.
By combining the basic load and store instructions of the ARM Cortex-M instruction set
architecture (v6M, v7M) with the concept of decorated storage provided by the BME, the
resulting implementation provides a robust and efficient read-modify-write capability to
this class of ultra low-end microcontrollers. The resulting architectural capability defined
by this core platform function is targeted at the manipulation of n-bit fields in peripheral
registers and is consistent with I/O hardware addressing in the Embedded C standard. For
most BME commands, a single core read or write bus cycle is converted into an atomic
read-modify-write, that is, an indivisible "read followed by a write" bus sequence.
BME decorated references are only available on system bus transactions generated by the
processor core and targeted at the standard 512 KB peripheral address space based at
0x4000_00001 and SRAM_U space based at 0x2000_0000. The decoration semantic is
embedded into address bits[28:19], creating a 448 MB space at addresses 0x4400_0000–
1. To be perfectly accurate, the peripheral address space occupies a 516 KB region: 512 KB based at 0x4000_0000 plus a 4
KB space based at 0x400F_F000 for GPIO accesses. This organization provides compatibility with the Kinetis K Family.
Attempted accesses to the memory space located between 0x4008_0000 - 0x400F_EFFF are error terminated due to an
illegal address.
17.1.1 Overview
The following figure is a generic block diagram of the processor core and platform for
this class of ultra low-end microcontrollers.
Cortex-M0+ Core
Dbg Fetch CM0+ Core Platform
AGU Dec Rn
NVIC SHFT
LD/ST
ALU MUL
IO Port
32
RAM
PRAM Array
GPIO
BME
m0 s1
AXBS Slave
-Lite 32 Peripherals
s2 PBRIDGE
s0
32
NVM
FMC
Array
As shown in the block diagram, the BME module interfaces to the master port on the
crossbar switch allowing it to support atomic read-modify-write operations to the
SRAM_U (shown as platform RAM (PRAM) in the figure) and the Peripheral Bridge
(PBRIDGE) controller. The BME hardware microarchitecture is a 2-stage pipeline design
matching the protocol of the AMBA-AHB system bus interfaces. The PBRIDGE module
converts the AHB system bus protocol into the IPS/APB protocol used by the attached
slave peripherals.
17.1.2 Features
The key features of the BME include:
• Lightweight implementation of decorated storage for selected address spaces
• Additional access semantics encoded into the reference address
• Resides between processor core and a switch master port
• Two-stage pipeline design matching the AHB system bus protocol
• Combinationally passes non-decorated accesses to slave bus controllers
• Conversion of decorated loads and stores from processor core into atomic read-
modify-writes
• Decorated loads support unsigned bit field extracts, load-and-{set,clear} 1-bit
operations
• Decorated stores support bit field inserts, logical AND, OR, and XOR operations
• Support for byte, halfword and word-sized decorated operations
• Supports minimum signal toggling on AHB output bus to reduce power dissipation
The peripheral address space occupies a 516 KB region: 512 KB based at 0x4000_0000
plus a 4 KB space based at 0x400F_F000 for GPIO accesses; the decorated address space
is mapped to the 448 MB region located at 0x4400_0000–0x5FFF_FFFF. The decorated
address space associated with the SRAM_U is the 448 MB region mapped at
0x2400_0000 - 0x3FFF_FFFF.
mx_hattr next
mx_hwrite next
mx_hwdata wdata
mx_hrdata
mx_hready
sx_hattr next
sx_hwrite next
sx_hrdata rdata
sx_hready
control_state_dp1
control_state_dp2
All the decorated store operations follow the same execution template shown in Figure
17-2, a two-cycle read-modify-write operation:
1. Cycle x, 1st AHB address phase: Write from input bus is translated into a read
operation on the output bus using the actual memory address (with the decoration
removed) and then captured in a register.
2. Cycle x+1, 2nd AHB address phase: Write access with the registered (but actual)
memory address is output
3. Cycle x+1, 1st AHB data phase: Memory read data is modified using the input bus
write data and the function defined by the decoration and captured in a data register;
the input bus cycle is stalled.
4. Cycle x+2, 2nd AHB data phase: Registered write data is sourced onto the output
write data bus.
NOTE
Any wait states inserted by the slave device are simply passed
through the BME back to the master input bus, stalling the
AHB transaction cycle for cycle.
See Figure 17-3 where addr[30:29] = 01 for SRAM_U, addr[30:29] = 10 for peripheral,
addr[28:26] = 001 specifies the AND operation, and mem_addr[19:0] specifies the
address offset into the space based at 0x2000_0000 for SRAM_U, and 0x4000_0000 for
peripherals. The "-" indicates an address bit "don't care".
The decorated AND write operation is defined in the following pseudo-code as:
ioand<sz>(accessAddress, wdata) // decorated store AND
tmp = mem[accessAddress & 0xE00FFFFF, size] // memory read
tmp = tmp & wdata // modify
mem[accessAddress & 0xE00FFFFF, size] = tmp // memory write
where the operand size <sz> is defined as b(yte, 8-bit), h(alfword, 16-bit) and w(ord, 32-
bit). This notation is used throughout the document.
In the cycle definition tables, the notations AHB_ap and AHB_dp refer to the address and
data phases of the BME AHB transaction. The cycle-by-cycle BME operations are
detailed in the following table.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ioorb 0 * * 0 1 0 - - - - - - mem_addr
ioorh 0 * * 0 1 0 - - - - - - mem_addr 0
ioorw 0 * * 0 1 0 - - - - - - mem_addr 0 0
See Figure 17-4,where addr[30:29] = 01 for SRAM_U, addr[30:29] =10 for peripheral,
addr[28:26] = 010 specifies the OR operation, and mem_addr[19:0] specifies the address
offset into the space based at 0x2000_0000 for SRAM_U, and 0x4000_0000 for
peripherals. The "-" indicates an address bit "don't care".
The decorated OR write operation is defined in the following pseudo-code as:
ioor<sz>(accessAddress, wdata) // decorated store OR
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ioxorb 0 * * 0 1 1 - - - - - - mem_addr
ioxorh 0 * * 0 1 1 - - - - - - mem_addr 0
ioxorw 0 * * 0 1 1 - - - - - - mem_addr 0 0
See Figure 17-5, where addr[30:29] = 01 for SRAM_U, addr[30:29] =10 for peripheral,
addr[28:26] = 011 specifies the XOR operation, and mem_addr[19:0] specifies the
address offset into the peripheral space based at 0x2000_0000 for SRAM_U, and
0x4000_0000 for peripherals. The "-" indicates an address bit "don't care".
The decorated XOR write operation is defined in the following pseudo-code as:
ioxor<sz>(accessAddress, wdata) // decorated store XOR
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
iobfib 0 * * 1 - - b b b - w w w mem_addr
iobfih 0 * * 1 - b b b b w w w w mem_addr 0
iobfiw 0 * * 1 b b b b b w w w w mem_addr 0 0
The "-" indicates an address bit "don't care". Note, unlike the other decorated store
operations, BFI uses addr[19] as the least significant bit in the "w" specifier and not as an
address bit.
The decorated BFI write operation is defined in the following pseudo-code as:
iobfi<sz>(accessAddress, wdata) // decorated bit field insert
The write data operand (wdata) associated with the store instruction contains the bit field
to be inserted. It must be properly aligned within a right-aligned container, that is, within
the lower 8 bits for a byte operation, the lower 16 bits for a halfword, or the entire 32 bits
for a word operation.
To illustrate, consider the following example of the insertion of the 3-bit field "xyz" into
an 8-bit memory container, initially set to "abcd_efgh". For all cases, w is 2, signaling a
bit field width of 3.
if b = 0 and the decorated store (strb) Rt register[7:0] = ----_-xyz,
then destination is "abcd_exyz"
if b = 1 and the decorated store (strb) Rt register[7:0] = ----_xyz-,
then destination is "abcd_xyzh"
if b = 2 and the decorated store (strb) Rt register[7:0] = ---x_yz--,
then destination is "abcx_yzgh"
if b = 3 and the decorated store (strb) Rt register[7:0] = --xy_z---,
then destination is "abxy_zfgh"
if b = 4 and the decorated store (strb) Rt register[7:0] = -xyz_----,
then destination is "axyz_efgh"
if b = 5 and the decorated store (strb) Rt register[7:0] = xyz-_----,
then destination is "xyzd_efgh"
if b = 6 and the decorated store (strb) Rt register[7:0] = yz--_----,
then destination is "yzcd_efgh"
if b = 7 and the decorated store (strb) Rt register[7:0] = z---_----,
then destination is "zbcd_efgh"
Note from the example, when the starting bit position plus the field width exceeds the
container size, only part of the source bit field is inserted into the destination memory
location. Stated differently, if (b + w+1) > container_width, only the low-order
"container_width - b" bits are actually inserted.
The cycle-by-cycle BME operations are detailed in the following table.
Table 17-4. Cycle definitions of decorated store: bit field insert
Pipeline stage Cycle
x x+1 x+2
BME AHB_ap Forward addr to memory; Recirculate captured addr + <next>
Decode decoration; Convert attr to memory as slave_wt
master_wt to slave_rd;
Capture address, attributes
Table 17-4. Cycle definitions of decorated store: bit field insert (continued)
Pipeline stage Cycle
x x+1 x+2
BME AHB_dp <previous> Perform memory read; Form Perform write sending
bit mask; Form bitwise registered data to memory
((mask) ? wdata : rdata)) and
capture destination data in
register
mx_hattr next
mx_hwrite next
mx_hwdata
mx_hrdata orig_1bit
mx_hready
sx_hwrite next
sx_hrdata rdata
sx_hready
control_state_dp1
control_state_dp2
Figure 17-7. Decorated load: load-and-set 1-bit field insert timing diagram
Decorated load-and-{set, clear} 1-bit operations follow the execution template shown in
the above figure: a 2-cycle read-modify-write operation:
1. Cycle x, first AHB address phase: Read from input bus is translated into a read
operation on the output bus with the actual memory address (with the decoration
removed) and then captured in a register
2. Cycle x+1, second AHB address phase: Write access with the registered (but actual)
memory address is output
3. Cycle x+1, first AHB data phase: The "original" 1-bit memory read data is captured
in a register, while the 1-bit field is set or clear based on the function defined by the
decoration with the modified data captured in a register; the input bus cycle is stalled
4. Cycle x+2, second AHB data phase: The selected original 1-bit is right-justified,
zero-filled and then driven onto the input read data bus, while the registered write
data is sourced onto the output write data bus
NOTE
Any wait states inserted by the slave device are simply passed
through the BME back to the master input bus, stalling the
AHB transaction cycle for cycle.
A generic timing diagram of a decorated load showing an unsigned peripheral bit field
operation is shown in the following figure.
1 2 3 4
5..v_wxyz next
next
next
ubfx
400v_wxyz next
next
next
rdata
5..v_wxyz rdata
Figure 17-8. Decorated load: unsigned bit field insert timing diagram
The decorated unsigned bit field extract follows the same execution template shown in
the above figure, a 2-cycle read operation:
• Cycle x, 1st AHB address phase: Read from input bus is translated into a read
operation on the output bus with the actual memory address (with the decoration
removed) and then captured in a register
• Cycle x+1, 2nd AHB address phase: Idle cycle
• Cycle x+1, 1st AHB data phase: A bit mask is generated based on the starting bit
position and the field width; the mask is AND'ed with the memory read data to
isolate the bit field; the resulting data is captured in a data register; the input bus
cycle is stalled
• Cycle x+2, 2nd AHB data phase: Registered data is logically right-aligned for proper
alignment and driven onto the input read data bus
NOTE
Any wait states inserted by the slave device are simply passed
through the BME back to the master input bus, stalling the
AHB transaction cycle for cycle.
See Figure 17-9 where addr[30:29] = 01 for SRAM_U, addr[30:29] = 10 for peripheral,
addr[28:26] = 010 specifies the load-and-clear 1 bit operation, addr[25:21] is "b", the bit
identifier, and mem_addr[19:0] specifies the address offset into the space based at
0x2000_0000 for SRAM_U, and 0x4000_0000 for peripheral. The "-" indicates an
address bit "don't care".
The decorated load-and-clear 1-bit read operation is defined in the following pseudo-code
as:
rdata = iolac1<sz>(accessAddress) // decorated load-and-clear 1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
iolaslb 0 * * 0 1 1 - - b b b - mem_addr
iolaslh 0 * * 0 1 1 - b b b b - mem_addr 0
iolaslw 0 * * 0 1 1 b b b b b - mem_addr 0 0
See Figure 17-11, where addr[30:29] = 01 for SRAM_U, addr[30:29] = 10 for peripheral,
addr[28] = 1 specifies the unsigned bit field extract operation, addr[27:23] is "b", the LSB
identifier, addr[22:19] is "w", the bit field width minus 1 identifier, and mem_addr[18:0]
specifies the address offset into the space based at 0x2000_0000 for SRAM_U, and
0x4000_0000 for peripheral. The "-" indicates an address bit "don't care". Note, unlike
the other decorated load operations, UBFX uses addr[19] as the least significant bit in the
"w" specifier and not as an address bit.
The decorated unsigned bit field extract read operation is defined in the following
pseudo-code as:
rdata = ioubfx<sz>(accessAddress) // unsigned bit field extract
Like the BFI operation, when the starting bit position plus the field width exceeds the
container size, only part of the source bit field is extracted from the destination memory
location. Stated differently, if (b + w+1) > container_width, only the low-order
"container_width - b" bits are actually extracted. The cycle-by-cycle BME operations are
detailed in the following table.
Table 17-7. Cycle definitions of decorated load: unsigned bit field extract
Pipeline Stage Cycle
x x+1 x+2
BME AHB_ap Forward addr to memory; Idle AHB address phase <next>
Decode decoration; Capture
address, attributes
BME AHB_dp <previous> Perform memory read; Form Logically right shift registered
bit mask; Form (rdata & mask) data; Return justified rdata to
and capture destination data master
in register
involving accesses to the GPIO. Recall the use of address[19] varies by decorated
operation; for AND, OR, XOR, LAC1 and LAS1, this bit functions as a true address bit,
while for BFI and UBFX, this bit defines the least significant bit of the "w" bit field
specifier.
As a result, undecorated GPIO references and decorated AND, OR, XOR, LAC1 and
LAS1 operations can use the standard 0x400F_F000 base address, while decorated BFI
and UBFX operations must use the alternate 0x4000_F000 base address. Another
implementation can simply use 0x400F_F000 as the base address for all undecorated
GPIO accesses and 0x4000_F000 as the base address for all decorated accesses. Both
implementations are supported by the hardware.
Table 17-8. Decorated peripheral and GPIO address details
Peripheral address space Description
0x4000_0000–0x4007_FFFF Undecorated (normal) peripheral accesses
0x4008_0000–0x400F_EFFF Illegal addresses; attempted references are aborted and error terminated
0x400F_F000–0x400F_FFFF Undecorated (normal) GPIO accesses using standard address
0x4010_0000–0x43FF_FFFF Illegal addresses; attempted references are aborted and error terminated
0x4400_0000–0x4FFF_FFFF Decorated AND, OR, XOR, LAC1, LAS1 references to peripherals and GPIO based at
either 0x4000_F000 or 0x400F_F000
0x5000_0000–0x5FFF_FFFF Decorated BFI, UBFX references to peripherals and GPIO only based at 0x4000_F000
#define IOANDH(ADDR,WDATA) \
__asm("ldr r3, =(1<<26);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"strh r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOANDB(ADDR,WDATA) \
__asm("ldr r3, =(1<<26);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"strb r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOORW(ADDR,WDATA) \
__asm("ldr r3, =(1<<27);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"str r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOORH(ADDR,WDATA) \
__asm("ldr r3, =(1<<27);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"strh r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOORB(ADDR,WDATA) \
__asm("ldr r3, =(1<<27);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"strb r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOXORW(ADDR,WDATA) \
__asm("ldr r3, =(3<<26);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"str r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOXORH(ADDR,WDATA) \
__asm("ldr r3, =(3<<26);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"strh r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
#define IOXORB(ADDR,WDATA) \
__asm("ldr r3, =(3<<26);" \
"orr r3, %[addr];" \
"mov r2, %[wdata];" \
"strb r2, [r3];" \
:: [addr] "r" (ADDR), [wdata] "r" (WDATA) : "r2", "r3");
18.1 Introduction
The FTMRE module implements the following:
• Program flash (flash) memory
The flash memory is ideal for single-supply applications allowing for field
reprogramming without requiring external high voltage sources for program or erase
operations. The flash module includes a memory controller that executes commands to
modify flash memory contents. The user interface to the memory controller consists of
the indexed Flash Common Command Object (FCCOB) register which is written to with
the command, global address, data, and any required command parameters. The memory
controller must complete the execution of a command before the FCCOB register can be
written to with a new command.
CAUTION
A flash byte or longword must be in the erased state before
being programmed. Cumulative programming of bits within a
flash byte or longword is not allowed.
The flash memory is read as bytes. Read access time is one bus cycle for bytes. For flash
memory, an erased bit reads 1 and a programmed bit reads 0.
18.2 Feature
MKE04Z8 contains a piece of 8 KB flash memory. This flash block is divided into 16
sectors of 512 bytes.
Table 18-1. Flash memory addressing
Device Global address Size (Bytes) Description
MKE04Z8VTG4(R)
Flash block contains flash
MKE04Z8VWJ4(R) 0x0000–0x1FFF 8 KB
configuration field.
MKE04Z8VFK4(R)
The figure below shows a general flowchart of the flash command write sequence.
START
Read: FCLKDIV
register
Yes
ACCERR No
Access Error and
or FPVIOL Set?
Protection Violation Check Results from previous Command
Yes
More No
Parameters? Write: FSTAT register
(to launch command)
Yes
Clear CCIF 0x80
No
Bit Polling for CCIF Set?
Command Completion Check
Yes
END
CAUTION
Programming or erasing the flash memory cannot be performed
if the bus clock runs at less than 0.8 MHz. Setting
FCLKDIV[FDIV] too high can destroy the flash memory due to
overstress. Setting FCLKDIV[FDIV] too low can result in
incomplete programming or erasure of the flash memory cells.
When the FCLKDIV register is written, FCLKDIV[FDIVLD] is set automatically. If
FCLKDIV[FDIVLD] is 0, the FCLKDIV register has not been written since the last
reset. If the FCLKDIV register has not been written, any flash program or erase
command loaded during a command write sequence will not execute and
FSTAT[ACCERR] will be set.
Table 18-3 shows the generic flash command format. The high byte of the first word in
the CCOB array contains the command code, followed by the parameters for this specific
flash command. For details on the FCCOB settings required by each command, see the
flash command descriptions in Flash command summary .
Table 18-3. FCCOB – flash command mode typical usage
CCOBIX[2:0] Byte FCCOB parameter fields in flash command mode
HI FCMD[7:0] defining flash command
000
LO Global address [23:16]
HI Global address [15:8]
001
LO Global address [7:0]
HI Data 0 [15:8]
010
LO Data 0 [7:0]
HI Data 1 [15:8]
011
LO Data 1 [7:0]
HI Data 2 [15:8]
100
LO Data 2 [7:0]
HI Data 3 [15:8]
101
LO Data 3 [7:0]
The contents of the FCCOB parameter fields are transferred to the memory controller
when the user clears the FSTAT[CCIF] command completion flag by writing 1. The
CCIF flag will remain clear until the flash command has completed. Upon completion,
the memory controller will return FSTAT[CCIF] to 1 and the FCCOB register will be
used to communicate any results.
The following table presents the valid flash commands, as enabled by the combination of
the functional MCU mode with the MCU security state of unsecured or secured.
MCU secured state is selected by FSEC[SEC].
Table 18-4. Flash commands by mode and security state
Unsecured Secured
FCMD Command
U1 U2
0x01 Erase verify all blocks * *
0x02 Erase verify block * *
0x03 Erase verify flash section * *
0x04 Read once * *
0x06 Program flash * *
0x07 Program once * *
0x08 Erase all block * *
0x09 Erase flash block * *
Flash command
CCIE complete interrupt request
CCIF
18.3.6 Protection
The FPROT register can be set to protect regions in the flash memory from accidental
programing or erasing. The memory region growing upward from global address 0x0000
in the flash memory can be activated for protection. The flash memory addresses covered
by these protectable regions are shown in the flash memory map.
1, 2, 4, 8 KB
0x0_1000 Flash protected/unprotected lower region
Movable end
protection
Default protection settings as well as security information that allows the MCU to restrict
access to the flash module are stored in the flash configuration field as described in the
table below.
Table 18-6. Flash configuration field
Global address Size (Bytes) Description
Backdoor comparison key. See Verify backdoor access key command and
0x0400–0x0407 8
Unsecuring the MCU using backdoor key access.
0x0408–0x040B
4 Reserved
1
1. 0x0_0408–0x040B and 0x040C–0x0_040F form a flash longword in each address range and must be programmed in a
single command write sequence. Each byte in these longwords that are marked as reserved must be programmed to
0xFF. Alternatively, the Flash phrase 0x0408-0x040F can also be programmed in a single command write sequence.
The flash module provides protection to the MCU. During the reset sequence, the FPROT
register is loaded with the contents of the flash protection byte in the flash configuration
field at global address 0x040D in flash memory. The protection functions depend on the
configuration of bit settings in FPROT register.
FPLDIS = 1 FPLDIS = 0
Scenario 7 5
FPLS[1:0]
0x0_0000
FPOPEN = 1
FLASHEND
Scenario 3 1
0x0_0000
FPLS[1:0]
FPOPEN = 0
FLASHEND
Unprotected region
The general guideline is that flash protection can only be added and not removed. The
following table specifies all valid transitions between flash protection scenarios. Any
attempt to write an invalid scenario to the FPROT register will be ignored. The contents
of the FPROT register reflect the active protection scenario. See the FPROT[FPLS] field
descriptions for additional restrictions.
Table 18-8. Flash protection scenario transitions
From protection To protection scenario1
scenario
1 3 5 7
1 × ×
3 ×
5 × ×
7 × × × ×
The flash protection address range is listed in the following two tables regarding the
scenarios in the table above.
Table 18-9. Flash protection lower address range
FPLS[1:0] Global address range Protected size
00 0x0000–0x03FF 1 KB
01 0x0000–0x07FF 2 KB
10 0x0000–0x0FFF 4 KB
11 0x0000–0x1FFF 8 KB
All possible flash protection scenarios are shown in Figure 18-4. Although the protection
scheme is loaded from the flash memory at global address 0x040D during the reset
sequence, it can be changed by the user.
18.3.7 Security
The flash module provides security information to the MCU. The flash security state is
defined by FSEC[SEC]. During reset, the flash module initializes the FSEC register using
data read from the security byte of the flash configuration field. The security state out of
reset can be permanently changed by programming the security byte, assuming that the
MCU is starting from a mode where the necessary flash erase and program commands are
available and that the upper region of the flash is unprotected. If the flash security byte is
successfully programmed, its new value will take effect after the next MCU reset.
The following subsections describe these security-related subjects:
The verify backdoor access key command is monitored by the memory controller and an
illegal key will prohibit future use of the verify backdoor access key command. A reset of
the MCU is the only method to re-enable the verify backdoor access key command. The
security as defined in the flash security byte is not changed by using the verify backdoor
access key command sequence. The backdoor keys stored in addresses 0x400–0x407 are
unaffected by the verify backdoor access key command sequence. The verify backdoor
access key command sequence has no effect on the program and erase protections
defined in the flash protection register, FPROT.
After the backdoor keys have been correctly matched, the MCU will be unsecured. After
the MCU is unsecured, the sector containing the flash security byte can be erased and the
flash security byte can be reprogrammed to the unsecure state, if desired. In the unsecure
state, the user has full control of the contents of the backdoor keys by programming
addresses 0x400–0x407 in the flash configuration field.
0x08 Erase All Block An erase of all flash blocks is possible only when the FPROT[FPHDIS],
FPROT[FPLDIS] and FPROT[FPOEN] and the bit are set prior to launching the
command
Erases a flash block
0x09 Erase Flash Block An erase of the full flash block is possible only when FPROT[FPLDIS],
FPROT[FPHDIS], and FPROT[FPOEN] are set prior to launching the command.
0x0A Erase Flash Sector Erases all bytes in a flash sector
Supports a method of releasing MCU security by erasing all flash blocks and
0x0B Unsecure Flash
verifying that all flash blocks are erased
0x0C Verify Backdoor Access key Supports a method of releasing MCU security by verifying a set of security keys
0x0D Set User Margin Level Specifies a user margin read level for all flash blocks
0x0E Set Factory Margin Level Specifies a factory margin read level for all flash blocks
CAUTION
An flash longword must be in the erased state before being
programmed. Cumulative programming of bits within an flash
longword is not allowed.
Upon clearing FSTAT[CCIF] to launch the Erase Verify All Blocks command, the
memory controller will verify that the entire flash memory space is erased. The
FSTAT[CCIF] flag will set after the erase verify all blocks operation has completed. If all
blocks are not erased, it means blank check failed and both FSTAT[MGSTAT] bits will
be set.
Table 18-12. Erase verify all blocks command error handling
Register Error bit Error condition
ACCERR Set if CCOBIX[2:0] != 000 at command launch
FPVIOL None
FSTAT Set if any errors have been encountered during the read1 or if blank check
MGSTAT1
failed
Set if any non-correctable errors have been encountered during the read
MGSTAT0
or if blank check failed
Upon clearing FSTAT[CCIF] to launch the erase verify block command, the memory
controller will verify that the selected flash block is erased. The FSTAT[CCIF] flag will
set after the erase verify block operation has completed. If the block is not erased, it
means blank check failed and both FSTAT[MGSTAT] bits will be set.
Table 18-14. Erase Verify Block command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] != 000 at command launch
ACCERR
Set if an invalid global address [23:0] is supplied1
FPVIOL None
FSTAT Set if any errors have been encountered during the read or if blank check
MGSTAT1
failed
Set if any non-correctable errors have been encountered during the read
MGSTAT0
or if blank check failed
Upon clearing FSTAT[CCIF] to launch the erase verify flash section command, the
memory controller will verify that the selected section of flash memory is erased. The
FSTAT[CCIF] flag will set after the erase verify flash section operation has completed. If
the section is not erased, it means blank check failed and both FSTAT[MGSTAT] bits
will be set.
Table 18-16. Erase Verify Flash Section command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] != 010 at command launch
FSTAT ACCERR Set if command not available in current mode (see Table 18-4)
Set if an invalid global address [23:0] is supplied (see Table 18-1)1
Table 18-16. Erase Verify Flash Section command error handling (continued)
Register Error bit Error condition
Set if a misaligned long words address is supplied (global address[1:0] !=
00)
Set if the requested section crosses flash address boundary
FPVIOL None
Set if any errors have been encountered during the read2 or if blank check
MGSTAT1
failed
Set if any non-correctable errors have been encountered during the read2
MGSTAT0
or if blank check failed
Upon clearing FSTAT[CCIF] to launch the read once command, a read once phrase is
fetched and stored in the FCCOB indexed register. The FSTAT[CCIF] flag will set after
the read once operation has completed. Valid phrase index values for the read once
command range from 0x0000 to 0x0007. During execution of the read once command,
any attempt to read addresses within flash block will return invalid data.
Upon clearing FSTAT[CCIF] to launch the Program Flash command, the memory
controller will program the data words to the supplied global address and will then
proceed to verify the data words read back as expected. The FSTAT[CCIF] flag will set
after the program flash operation has completed.
Table 18-20. Program Flash command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] ≠ 011 or 101 at command launch
FSTAT ACCERR Set if command not available in current mode (see Table 18-4)
Set if an invalid global address [23:0] is supplied (see Table 18-1.1
Upon clearing FSTAT[CCIF] to launch the program once command, the memory
controller first verifies that the selected phrase is erased. If erased, then the selected
phrase will be programmed and then verified with read back. The FSTAT[CCIF] flag will
remain clear, setting only after the program once operation has completed.
The reserved nonvolatile information register accessed by the Program Once command
cannot be erased, and any attempt to program one of these phrases a second time will not
be allowed. Valid phrase index values for the program once command range from 0x0000
to 0x0007. During execution of the program once command, any attempt to read
addresses within flash will return invalid data.
1. If a program once phrase is initially programmed to 0xFFFF_FFFF_FFFF_FFFF, the program once command will be
allowed to execute again on that same phrase.
Upon clearing FSTAT[CCIF] to launch the Erase All Blocks command, the memory
controller will erase the entire NVM memory space and verify that it is erased. If the
memory controller verifies that the entire NVM memory space was properly erased,
security will be released. Therefore, the device is in unsecured state. During the execution
of this command (FSTAT[CCIF] = 0) the user must not write to any NVM module
register. The FSTAT[CCIF] flag will set after the erase all blocks operation has
completed.
Table 18-24. Erase All Blocks command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] ≠ 000 at command launch
ACCERR
Set if command not available in current mode (see Table 18-4)
FPVIOL Set if any area of the flash memory is protected
FSTAT
MGSTAT1 Set if any errors have been encountered during the verify operation1
Set if any non-correctable errors have been encountered during the verify
MGSTAT0
operation1
Upon clearing FSTAT[CCIF] to launch the erase flash block command, the memory
controller will erase the selected flash block and verify that it is erased. The
FSTAT[CCIF] flag will set after the erase flash block operation has completed.
Table 18-27. Erase flash block command error handling
Register Error Bit Error Condition
Set if CCOBIX[2:0] != 001 at command launch
ACCERR Set if command not available in current mode (see Table 18-4)
Set if an invalid global address [23:16] is supplied1
FSTAT FPVIOL Set if an area of the selected flash block is protected
MGSTAT1 Set if any errors have been encountered during the verify operation2
Set if any non-correctable errors have been encountered during the verify
MGSTAT0
operation2
Upon clearing FSTAT[CCIF] to launch the erase flash sector command, the memory
controller will erase the selected flash sector and then verify that it is erased. The
FSTAT[CCIF] flag will be set after the erase flash sector operation has completed.
Table 18-29. Erase flash sector command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] != 001 at command launch
FSTAT ACCERR
Set if command not available in current mode (see Table 18-4)
Upon clearing FSTAT[CCIF] to launch the unsecure flash command, the memory
controller will erase the entire flash memory space and verify that it is erased. If the
memory controller verifies that the entire flash memory space was properly erased,
security will be released. If the erase verify is not successful, the unsecure flash operation
sets FSTAT[MGSTAT1] and terminates without changing the security state. During the
execution of this command (FSTAT[CCIF] = 0), the user must not write to any flash
module register. The FSTAT[CCIF] flag is set after the unsecure flash operation has
completed.
Table 18-31. Unsecure flash command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] != 000 at command launch
ACCERR
Set if command is not available in current mode (see Table 18-4)
FSTAT
FPVIOL Set if any area of the flash memory is protected
MGSTAT1 Set if any errors have been encountered during the verify operation1
Set if any non-correctable errors have been encountered during the verify
MGSTAT0
operation1
Upon clearing FSTAT[CCIF] to launch the verify backdoor access key command, the
memory controller will check the FSEC[KEYEN] bits to verify that this command is
enabled. If not enabled, the memory controller sets the FSTAT[ACCERR] bit. If the
command is enabled, the memory controller compares the key provided in FCCOB to the
backdoor comparison key in the flash configuration field with Key 0 compared to
0x0400, and so on. If the backdoor keys match, security will be released. If the backdoor
keys do not match, security is not released and all future attempts to execute the verify
backdoor access key command are aborted (set FSTAT[ACCERR]) until a reset occurs.
The FSTAT[CCIF] flag is set after the verify backdoor access key operation has
completed.
Table 18-33. Verify backdoor access key command error handling
Register Error bit Error condition
Set if CCOBIX[2:0] ≠ 100 at command launch
Set if an incorrect backdoor key is supplied
ACCERR
Set if backdoor key access has not been enabled (KEYEN[1:0] ≠ 10
FSTAT Set if the backdoor key has mismatched since the last reset
FPVIOL None
MGSTAT1 None
MGSTAT0 None
Upon clearing FSTAT[CCIF] to launch the set user margin level command, the memory
controller will set the user margin level for the targeted block and then set the
FSTAT[CCIF] flag.
Note
Valid margin level settings for the set user margin level command are defined in the
following tables.
Table 18-35. Valid set user margin level settings
CCOB
Level description
(CCOBIX = 010)
0x0000 Return to normal level
0x0001 User margin-1 level1
0x0002 User margin-0 level2
Note
User margin levels can be used to check that NVM memory
contents have adequate margin for normal level read operations.
If unexpected results are encountered when checking NVM
memory contents at user margin levels, a potential loss of
information has been detected.
Upon clearing FSTAT[CCIF] to launch the set factory margin level command, the
memory controller will set the factory margin level for the targeted block and then set the
FSTAT[CCIF] flag.
Note
Valid margin level settings for the set factory margin level command are defined in the
following tables.
Table 18-38. Valid set factory margin level settings
CCOB
Level description
(CCOBIX = 010)
0x0000 Return to normal level
0x0001 User margin-1 level1
0x0002 User margin-0 level2
0x0003 Factory margin-1 level1
0x0004 Factory margin-0 level2
CAUTION
Factory margin levels must only be used during verify of the
initial factory programming.
Note
Factory margin levels can be used to check that Flash memory
contents have adequate margin for data retention at the normal
level setting. If unexpected results are encountered when
checking flash memory contents at factory margin levels, the
fash memory contents must be erased and reprogrammed.
Bit 7 6 5 4 3 2 1 0
Read 0 CCOBIX
Write
Reset 0 0 0 0 0 0 0 0
Selects which word of the FCCOB register array is being read or written to.
Bit 7 6 5 4 3 2 1 0
Write
Reset x* x* x* x* x* x* x* x*
* Notes:
00 Disabled
01 Disabled
10 Enabled
11 Disabled
5–2 This field is reserved.
Reserved
SEC Flash Security Bits
Defines the security state of the MCU. If the flash module is unsecured using backdoor key access, the
SEC field is forced to 10.
00 Secured
01 Secured
10 Unsecured
11 Secured
Bit 7 6 5 4 3 2 1 0
Read FDIVLD
FDIVLCK FDIV
Write
Reset 0 0 0 0 0 0 0 0
FDIV[5:0] must be set to effectively divide BUSCLK down to 1MHz to control timed events during flash
program and erase algorithms. Refer to the table in the Writing the FCLKDIV register for the
recommended values of FDIV based on the BUSCLK frequency.
The FSTAT register reports the operational status of the flash module.
Address: 4002_0000h base + 5h offset = 4002_0005h
Bit 7 6 5 4 3 2 1 0
One or more MGSTAT flag bits are set if an error is detected during execution of a flash command or
during the flash reset sequence.
NOTE: Reset value can deviate from the value shown if a double bit fault is detected during the reset
sequence.
Bit 7 6 5 4 3 2 1 0
Read 0 ERSAREQ 0
CCIE
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read CCOB
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read CCOB
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
* Notes:
0 When FPOPEN is clear, the FPLDIS field defines unprotected address ranges as specified by the
corresponding FPLS field.
1 When FPOPEN is set, the FPLDIS field enables protection for the address range specified by the
corresponding FPLS field.
6 Reserved Nonvolatile Bit
RNV6
The RNV bit must remain in the erased state.
5–3 Reserved Nonvolatile Bit
RNV
The RNV bit must remain in the erased state.
2 Flash Protection Lower Address Range Disable
FPLDIS
The FPLDIS bit determines whether there is a protected/unprotected area in a specific region of the flash
memory beginning with global address 0x0_0000.
0 Protection/Unprotection enabled.
1 Protection/Unprotection disabled.
FPLS Flash Protection Lower Address Size
The FPLS bits determine the size of the protected/unprotected area in flash memory. The FPLS bits can
only be written to while the FPLDIS bit is set.
Bit 7 6 5 4 3 2 1 0
Read NV
Write
Reset x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
The NV[7:0] bits are available as nonvolatile bits. During the reset sequence, the FOPT register is loaded
from the flash nonvolatile byte in the flash configuration field at global address 0x40F located in flash
memory.
19.1 Introduction
The Flash Memory Controller (FMC) is a memory acceleration unit. A list of features
provided by the FMC can be found here.
• an interface between bus masters and the 32-bit program flash memory.
• a buffer and a cache that can accelerate program flash memory data transfers.
19.1.1 Overview
The Flash Memory Controller manages the interface between bus masters and the 32-bit
program flash memory. The FMC receives status information detailing the configuration
of the flash memory and uses this information to ensure a proper interface. The FMC
supports 8-bit, 16-bit, and 32-bit read operations from the program flash memory. A write
operation to program flash memory results in a bus error.
In addition, the FMC provides two separate mechanisms for accelerating the interface
between bus masters and program flash memory. A 32-bit speculation buffer can prefetch
the next 32-bit flash memory location, and a 4-way, 2-set program flash memory cache
can store previously accessed program flash memory data for quick access times.
19.1.2 Features
The features of FMC module include:
• Interface between bus masters and the 32-bit program flash memory:
• 8-bit, 16-bit, and 32-bit read operations to nonvolatile flash memory.
• Acceleration of data transfer from the program flash memory to the device:
• 32-bit prefetch speculation buffer for program flash accesses with controls for
instruction/data access
• 4-way, 2-set, 32-bit line size program flash memory cache for a total of eight 32-
bit entries with invalidation control
20.1 Introduction
The internal clock source (ICS) module provides clock source choices for the MCU. The
module contains a frequency-locked loop (FLL) as a clock source that is controllable by
either an internal or an external reference clock. The module can provide this FLL clock
or either of the internal or external reference clocks as a source for the MCU system
clock. There are also signals provided to control a low-power oscillator (OSC) module.
These signals configure and enable the OSC module to generate its external crystal/
resonator clock (OSC_OUT) used by peripheral modules and as the ICS external
reference clock source. The ICS external reference clock can be the external crystal/
resonator (OSC_OUT) supplied by an OSC, or it can be another external clock source.
The ICS clock source chosen is passed through a reduced bus divider (BDIV) which
allows a lower final output clock frequency to be derived.
20.1.1 Features
The key features of the ICS module are given below:
• Frequency-locked loop (FLL) is trimmable for accuracy
• Internal or external reference clocks can be used to control the FLL.
• Reference divider is provided for external clock.
• Internal reference clock has 9 trim bits available.
• Internal or external reference clocks can be selected as the clock source for the MCU.
• Whichever clock is selected as the source can be divided down.
• 3-bit select for clock divider is provided
• Allowable dividers are: 1, 2, 4, 8, 16, 32, 64, 128 if OSC_CR[RANGE] = 0; 32,
64, 128, 256, 512, 1024 if OSC_CR[RANGE] = 1.
• FLL Engaged Internal mode is automatically selected out of reset.
• Selectable digitally-controlled oscillators (DCO) optimized frequency ranges
• FLL lock detector and external clock monitor
IREFSTEN BDIV
Internal / 2n
Reference ICSOUT
Clock n=0-7
LP
/ 2n Filter DCO
n=0-7
IREFS
RDIV
ICSFFCLK
IREFST CLKST LOLIE LOLS LOCK CME
Bit 7 6 5 4 3 2 1 0
Read CLKS RDIV IREFS IRCLKEN IREFSTEN
Write
Reset 0 0 0 0 0 1 0 0
1. Reset default
2 Internal Reference Select
IREFS
Selects the reference clock source for the FLL.
0 ICSIRCLK is inactive.
1 ICSIRCLK is active.
0 Internal Reference Stop Enable
IREFSTEN
Controls whether or not the internal reference clock remains enabled when the ICS enters Stop mode.
1. Reset default
Bit 7 6 5 4 3 2 1 0
Read 0
BDIV LP
Write
Reset 0 0 1 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read SCTRIM
Write
Reset x* x* x* x* x* x* x* x*
* Notes:
• x = Undefined at reset.
Controls the slow internal reference clock frequency by controlling the internal reference clock period. The
bits are binary weighted. In other words, bit 1 adjusts twice as much as bit 0. Increasing the binary value in
SCTRIM will increase the period, and decreasing the value will decrease the period. An additional fine trim
bit is available as the ICS_C4[SCFTRIM]. SCTRIM is loaded during reset from a factory programmed
location if the device is not in any debug mode.
Bit 7 6 5 4 3 2 1 0
Read 0 0
LOLIE CME SCFTRIM
Write
Reset 0 0 0 0 0 0 0 x*
* Notes:
• x = Undefined at reset.
NOTE: SCFTRIM is loaded during reset from a factory programmed location when not in any debug
mode.
Bit 7 6 5 4 3 2 1 0
Write w1c
Reset 0 0 0 1 0 0 0 0
0 FLL has not lost lock since LOLS was last cleared.
1 FLL has lost lock since LOLS was last cleared.
6 Lock Status
LOCK
Indicates whether the FLL has acquired lock. Lock detection is disabled when FLL is disabled. If the lock
status bit is set then changing the value of any of the following fields IREFS, RDIV[2:0], or, if in FEI or FBI
modes, TRIM[7:0] will cause the lock status bit to clear and stay cleared until the FLL has reacquired lock.
Stop mode entry will also cause the lock status bit to clear and stay cleared until the FLL has reacquired
lock.
IREFS=1
CLKS=00
FLL Engaged
Internal (FEI)
IREFS=0 IREFS=1
CLKS=10 CLKS=01
Debug Enabled Debug Enabled
or LP =0 or LP=0
IREFS=0 IREFS=1
CLKS=10 CLKS=01
Debug Disabled Debug Disabled
and LP=1 and LP=1
FLL Engaged
External (FEE)
IREFS=0
CLKS=00
In FLL engaged external mode, the ICSOUT clock is derived from the FLL clock which
is controlled by the external reference clock source.The FLL loop locks the frequency to
1280 times the external reference frequency, as selected by ICS_C1[RDIV] and
OSC_CR[RANGE ]. The external reference clock is enabled.
20.4.1.7 Stop
NOTE
The DCO frequency changes from the pre-stop value to its reset
value and the FLL need to re-acquire the lock before the
frequency is stable. Timing sensitive operations must wait for
the FLL acquisition time, tAcquire, before executing.
Stop mode is entered whenever the MCU enters a STOP state. In this mode, all ICS clock
signals are static except in the following cases:
ICSIRCLK will be active in Stop mode when all the following conditions occur:
• 1b is written to ICS_C1[IRCLKEN].
• 1b is written to ICS_C1[IREFSTEN].
21.1 Introduction
21.1.1 Overview
The OSC module provides the clock source for the MCU. The OSC module, in
conjunction with an external crystal or resonator, generates a clock for the MCU that can
be used as reference clock or bus clock.
EXTAL XTAL
Digital Wrapper
Mux
HGO OSC_OUT
High Gain
RANGE 32 k/4-24 MHz
Oscillator
OSCOS XTL_CLK
EN
Low Power
4-24 MHz
ICS_OSC_EN Oscillator
4096
EN Counter
Low Power
STOP
32 kHz
OSCEN Oscillator
OSCSTEN
CNT_DONE_4096
OSC_INIT HARD BLOCK
Crystal or Resonator
RS
Cx Cy
RF
Crystal or Resonator
Bit 7 6 5 4 3 2 1 0
Read 0 0 OSCINIT
OSCEN OSCSTEN OSCOS RANGE HGO
Write
Reset 0 0 0 0 0 0 0 0
0 Low-power mode
1 High-gain mode
0 OSC Initialization
OSCINIT
This field is set after the initialization cycles of oscillator are completed.
Off
• Oscillator OFF
EN
• OSC_OUT = Static
EN EN
&& OSCOS && OSCOS
Start-Up Start-Up
• Oscillator On, not yet stable • Oscillator On
• OSC_OUT = Static • OSC_OUT = EXTAL
CNT_DONE_4096
Stable
21.6.1.1 Off
The off state is entered whenever the EN signal is negated. Upon entering this state,
XTL_CLK and OSC_OUT is static. The EXTAL and XTAL pins are also decoupled
from all other oscillator circuitry in this state. The OSC module circuitry is configured to
draw minimal current.
The oscillator input buffer in this mode is single-ended. It provides low pass frequency
filtering as well as hysteresis for voltage filtering and converts the output to logic levels.
21.6.3 Counter
The oscillator output clock (OSC_OUT) is gated off until the counter has detected 4096
cycles of its input clock (XTL_CLK). Once 4096 cycles are complete, the counter passes
XTL_CLK onto OSC_OUT. This counting timeout is used to guarantee output clock
stability.
22.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The cyclic redundancy check (CRC) module generates 16/32-bit CRC code for error
detection.
The CRC module provides a programmable polynomial, WAS, and other parameters
required to implement a 16-bit or 32-bit CRC standard.
The 16/32-bit code is calculated for 32 bits of data at a time.
22.1.1 Features
Features of the CRC module include:
• Hardware CRC generator circuit using a 16-bit or 32-bit programmable shift register
• Programmable initial seed value and polynomial
• Option to transpose input data or output data (the CRC result) bitwise or bytewise.
This option is required for certain CRC standards. A bytewise transpose operation is
not possible when accessing the CRC data register via 8-bit accesses. In this case, the
user's software must perform the bytewise transpose function.
• Option for inversion of final CRC result
• 32-bit CPU register programming interface
MUX
[7:0] CRC Data
Logic Logic [15:8]
[7:0]
Checksum
CRC Polynomial CRC Engine
Register Data
[31:24]
[23:16] Combine
Polynomial
[15:8] Logic
[7:0]
16-/32-bit Select
TCRC
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
HU HL LU LL
Reset 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
When CTRL[WAS] is 1, values written to this field are part of the seed value. When CTRL[WAS] is 0, data
written to this field is used for CRC checksum generation.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
HIGH LOW
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0 0
TCRC
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
00 No transposition.
01 Bits in bytes are transposed; bytes are not transposed.
10 Both bits in bytes and bytes are transposed.
11 Only bytes are transposed; no bits in a byte are transposed.
29–28 Type Of Transpose For Read
TOTR
Identifies the transpose configuration of the value read from the CRC Data register. See the description of
the transpose feature for the available transpose options.
00 No transposition.
01 Bits in bytes are transposed; bytes are not transposed.
10 Both bits in bytes and bytes are transposed.
11 Only bytes are transposed; no bits in a byte are transposed.
27 This field is reserved.
Reserved This read-only field is reserved and always has the value 0.
26 Complement Read Of CRC Data Register
FXOR
Some CRC protocols require the final checksum to be XORed with 0xFFFFFFFF or 0xFFFF. Asserting
this bit enables on the fly complementing of read data.
0 No XOR on reading.
1 Invert or complement the read value of the CRC Data register.
25 Write CRC Data Register As Seed
WAS
When asserted, a value written to the CRC data register is considered a seed value. When deasserted, a
value written to the CRC data register is taken as data for CRC computation.
No transposition occurs.
2. CTRL[TOT] or CTRL[TOTR] is 01
Bits in a byte are transposed, while bytes are not transposed.
reg[31:0] becomes {reg[24:31], reg[16:23], reg[8:15], reg[0:7]}
31 24 23 16 15 8 7 0
24 31 16 23 8 15 0 7
31 0
0 31
31 24 23 16 15 8 7 0
7 0 15 8 23 16 31 24
NOTE
For 8-bit and 16-bit write accesses to the CRC data register, the
data is transposed with zeros on the unused byte or bytes
(taking 32 bits as a whole), but the CRC is calculated on the
valid byte(s) only. When reading the CRC data register for a
16-bit CRC result and using transpose options 10 and 11, the
resulting value after transposition resides in the CRC[HU:HL]
fields. The user software must account for this situation when
reading the 16-bit CRC result, so reading 32 bits is preferred.
23.1 Introduction
The external interrupt (IRQ) module provides a maskable interrupt input.
23.2 Features
Features of the IRQ module include:
• A dedicated external interrupt pin IRQ
• IRQ Interrupt Control bits
• Programmable edge-only or edge and level interrupt sensitivity
• Automatic interrupt acknowledge
• Internal pullup device
A low level applied to the external interrupt request (IRQ) pin can latch a CPU interrupt
request. The following figure shows the structure of the IRQ module:
IRQACK
RESET
TO CPU
SYNCHRONIZER
BUSCLK
VDD
IRQF
CLR
1 D Q
SYNCHRONIZER
IRQ 0 CK
S IRQPE
STOP STOP
BYPASS
IRQEDG
External interrupts are managed by the IRQSC status and control register. When the IRQ
function is enabled, synchronous logic monitors the pin for edge-only or edge-and-level
events. When the MCU is in Stop mode and system clocks are shut down, a separate
asynchronous path is used so that the IRQ, if enabled, can wake the MCU.
When enabling the IRQ pin for use, IRQSC[IRQF] will be set,
and must be cleared prior to enabling the interrupt. When
configuring the pin for falling edge and level sensitivity in a 3
V system, it is necessary to wait at least cycles between
clearing the flag and enabling the interrupt.
Bit 7 6 5 4 3 2 1 0
Read 0 IRQF 0
IRQPDD IRQEDG IRQPE IRQIE IRQMOD
Write IRQACK
Reset 0 0 0 0 0 0 0 0
0 No IRQ request
1 IRQ event is detected.
2 IRQ Acknowledge
IRQACK
This write-only field 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.
1 IRQ Interrupt Enable
IRQIE
This read/write control field determines whether IRQ events generate an interrupt request.
24.1 Introduction
The 12-bit analog-to-digital converter (ADC) is a successive approximation ADC
designed for operation within an integrated microcontroller system-on-chip.
24.1.1 Features
Features of the ADC module include:
• Linear Successive Approximation algorithm with 8-, 10-, or 12-bit resolution
• Up to 12 external analog inputs, external pin inputs, and 5 internal analog inputs
including internal bandgap, temperature sensor, and references
• Output formatted in 8-, 10-, or 12-bit right-justified unsigned format
• Single or Continuous Conversion (automatic return to idle after single conversion)
• Support up to eight result FIFO with selectable FIFO depth
• Configurable sample time and conversion speed/power
• Conversion complete flag and interrupt
• Input clock selectable from up to four sources
• Operation in Wait or Stop modes for lower noise operation
• Asynchronous clock source for lower noise operation
• Selectable asynchronous hardware conversion trigger
• Automatic compare with interrupt for less-than, or greater-than or equal-to,
programmable value
AD CHANNEL FIFO
AD RESULT FIFO
5 5-bit ch 2 12-bit AD result
4 5-bit ch 3 12-bit AD result
3 5-bit ch 4 12-bit AD result
2 5-bit ch 5 12-bit AD result
1 5-bit ch 6 12-bit AD result
0 5-bit ch 7 12-bit AD result
AD10
ANALOG MUX
ASYNC
CLOCK
GENERATOR
ADICLK ADIV
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
COCO
R 0
ADCO
AIEN ADCH
Reset 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1
0 One conversion following a write to the ADC_SC1 when software triggered operation is selected, or
one conversion following assertion of ADHWT when hardware triggered operation is selected. When
the FIFO function is enabled (AFDEP > 0), a set of conversion are triggered when
ADC_SC2[ADTRG]=0 or both ADC_SC2[ADTRG]=1 and ADC_SC4[HTRGME]=1.
1 Continuous conversions are initiated following a write to ADC_SC1 when software triggered operation
is selected. Continuous conversions are initiated by an ADHWT event when hardware triggered
operation is selected. When the FIFO function is enabled (AFDEP > 0), a set of conversions are loop
triggered.
ADCH Input Channel Select
The ADCH bits form a 5-bit field that selects one of the input channels.
00000-01011 AD0-AD11
01100-10011 VSS
10100-10101 Reserved
10110 Temperature Sensor
10111 Bandgap
11000-11100 Reserved
11101 VREFH
11110 VREFL
11111 Module disabled
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FEMPTY
ADACT
FFULL
R 0
ADTRG
ACFGT
ACFE
REFSEL
Reset 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
ADLSMP
ADLPC
ADIV MODE ADICLK
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
00 8-bit conversion (N = 8)
01 10-bit conversion (N = 10)
10 12-bit conversion (N = 12)
11 Reserved
ADICLK Input Clock Select
ADICLK bits select the input clock source to generate the internal clock ADCK.
00 Bus clock
01 Bus clock divided by 2
10 Alternate clock (ALTCLK)
11 Asynchronous clock (ADACK)
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0 0
HTRGME
ASCANE
ACFSEL
AFDEP
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FIFO Depth enables the FIFO function and sets the depth of FIFO. When AFDEP is cleared, the FIFO is
disabled. When AFDEP is set to nonzero, the FIFO function is enabled and the depth is indicated by the
AFDEP bits. The ADC_SC1[ADCH] and ADC_R must be accessed by FIFO mode when FIFO function is
enabled. ADC starts conversion when the analog channel FIFO is upon the level indicated by AFDEP bits.
The COCO bit is set when the set of conversions are completed and the result FIFO is upon the level
indicated by AFDEP bits.
ADC_R is updated each time a conversion completes except when automatic compare is
enabled and the compare condition is not met.
When FIFO is enabled, the result FIFO is read via ADC_R. The ADC conversion
completes when the input channel FIFO is fulfilled at the depth indicated by the AFDEP.
The AD result FIFO can be read via ADC_R continuously by the order set in analog
input channel ADCH.
If the MODE bits are changed, any data in ADC_R becomes invalid.
Address: 4003_B000h base + 10h offset = 4003_B010h
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 ADR
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This register holds the compare value. Bits ADCV11:ADCV0 are compared to the 12 bits
of the result following a conversion in 12-bit mode.
Address: 4003_B000h base + 14h offset = 4003_B014h
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 CV
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 ADPC
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HTRGMASKE
HTRGMASKS
R 0
EL
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
• The bus clock divided by 2: For higher bus clock rates, this allows a maximum
divide by 16 of the bus clock.
• ALTCLK, that is, alternate clock which is OSC_OUT
• The asynchronous clock (ADACK): This clock is generated from a clock source
within the ADC module. When selected as the clock source, this clock remains active
while the MCU is in Wait or Stop mode and allows conversions in these modes for
lower noise operation.
Whichever clock is selected, its frequency must fall within the specified frequency range
for ADCK. If the available clocks are too slow, the ADC does not perform according to
specifications. If the available clocks are too fast, the clock must be divided to the
appropriate frequency. This divider is specified by the ADC_SC3[ADIV] bits and can be
divide-by 1, 2, 4, or 8.
When a conversion is aborted, the contents of the data register, ADC_R, are not altered.
However, they continue to be the values transferred after the completion of the last
successful conversion. If the conversion was aborted by a reset, ADC_R returns to their
reset states.
The maximum total conversion time is determined by the selected clock source and the
divide ratio. The clock source is selectable by the ADC_SC3[ADICLK] bits, and the
divide ratio is specified by the ADC_SC3[ADIV] bits. For example, in 10-bit mode, with
the bus clock selected as the input clock source, the input clock divide-by-1 ratio
selected, and a bus frequency of 8 MHz, then the conversion time for a single conversion
as given below:
Note
The ADCK frequency must be between fADCK minimum and
fADCK maximum to meet ADC specifications.
Note
The compare function can not work in continuous conversion
mode when FIFO enabled.
ADC_R read
ADC_R
ADCH write 0 12-bit AD result
ADCH
1 12-bit AD result
5-bit ch 7
2 12-bit AD result
5-bit ch 6
AD CHANNEL FIFO
AD RESULT FIFO
3 12-bit AD result
5-bit ch 5
4 12-bit AD result
5-bit ch 4
5 12-bit AD result
5-bit ch 3
6 12-bit AD result
5-bit ch 2
7 12-bit AD result
5-bit ch 1
8 12-bit AD result
5-bit ch 0
9 12-bit AD result
10 12-bit AD result
FIFO Read/Write Logic reset
11 12-bit AD result
BUS CLK
If software trigger is enabled, the next analog channel is fetched from analog input
channel FIFO as soon as a conversion completes and its result is stored in the result
FIFO. When all conversions set in the analog input channel FIFO completes, the
ADC_SC1[COCO] bit is set and an interrupt request will be submitted to CPU if the
ADC_SC1[AIEN] bit is set.
If single hardware trigger mode is enabled(ADC_SC2[ADTRG]= 1 and
ADC_SC4[HTRGME]=0 ), the next analog is fetched from analog input channel FIFO
only when this conversion completes, its result is stored in the result FIFO, and the next
hardware trigger is fed to ADC module. If multi hardware tigger mode is
enabled(ADC_SC2[ADTRG]=1 and ADC_SC4[HTRGME]=1), the next analog is
fetched from analog input channel FIFO only when this conversion completes, its result
is stored in the result FIFO, and next conversion will start without waiting for next
hardware trigger. When all conversions set in the analog input channel FIFO completes,
the ADC_SC1[COCO] bit is set and an interrupt request will be submitted to CPU if the
ADC_SC1[AIEN] bit is set.
In single conversion in which ADC_SC1[ADCO] bit is clear, the ADC stops conversions
when ADC_SC1[COCO] bit is set until the channel FIFO is fulfilled again or new
hardware trigger occur.
KE04 Sub-Family Reference Manual, Rev. 3, Feburary 2014
Freescale Semiconductor, Inc. 321
Functional description
The FIFO also provides scan mode to simplify the dummy work of input channel FIFO.
When the ADC_SC4[ASCANE] bit is set in FIFO mode, the FIFO will always use the
first dummied channel in spite of the value in the input channel FIFO. The ADC
conversion start to work in FIFO mode as soon as the first channel is dummied. The
following write operation to the input channel FIFO will cover the first channel element
in this FIFO. In scan FIFO mode, the ADC_SC1[COCO] bit is set when the result FIFO
is fulfilled according to the depth indicated by the ADC_SC4[AFDEP] bits.
In continuous conversion in which the ADC_SC1[ADCO] bit is set, the ADC starts next
conversion immediately when all conversions are completed. ADC module will fetch the
analog input channel from the beginning of analog input channel FIFO.
0 n max
The nth AD
channel fetch max = AFDEP
The nth AD
channel fetch
when n hardware trigger occurs max = AFDEP
when last hardware trigger occurs
Channel FIFO fulfilled
Start FIFOed Conversion
when 1st hardware trigger occurs
0 n max If new trigger occurs, the new set conversions will be generated
0 n max If new trigger occurs, the new set conversions will be generated
0 n max 0 n
A conversion complete event sets the ADC_SC1[COCO] and generates an ADC interrupt
to wake the MCU from Stop mode if the ADC interrupt is enabled (ADC_SC1[AIEN] =
1). In fifo mode, ADC cannot complete the conversion operation fully or wake the MCU
from Stop mode.
Note
The ADC module can wake the system from low-power stop
and cause the MCU to begin consuming run-level currents
without generating a system level interrupt. To prevent this
scenario, the data transfer blocking mechanism must be cleared
when entering Stop and continuing ADC conversions.
3. Update status and control register 1 (ADC_SC1) to select whether conversions will
be continuous or completed only once, and to enable or disable conversion complete
interrupts. The input channel on which conversions will be performed is also selected
here.
//4-Level FIFO
ADC_SC4 = ADC_SC4_AFDEP1_MASK | ADC_SC4_AFDEP0_MASK;
NOTE
ADC_R is 16-bit ADC result register, combined from
ADC_RH and ADC_RL
representation). If the input is equal to or less than VREFL, the converter circuit converts it
to 0x000. Input voltages between VREFH and VREFL are straight-line linear conversions.
There is a brief current associated with VREFL when the sampling capacitor is charging.
The input is sampled for 3.5 cycles of the ADCK source when ADC_SC3[ADLSMP] is
low, or 23.5 cycles when ADC_SC3[ADLSMP] is high.
For minimal loss of accuracy due to current injection, pins adjacent to the analog input
pins should not be transitioning during conversions.
There are some situations where external system activity causes radiated or conducted
noise emissions or excessive VDD noise is coupled into the ADC. In these situations, or
when the MCU cannot be placed in wait or Stop or I/O activity cannot be halted, these
recommended actions may reduce the effect of noise on the accuracy:
• Place a 0.01 µF capacitor (CAS) on the selected input channel to VREFL or VSSA (this
improves noise issues, but affects the sample rate based on the external analog source
resistance).
• Average the result by converting the analog input many times in succession and
dividing the sum of the results. Four samples are required to eliminate the effect of a
1LSB, one-time error.
• Reduce the effect of synchronous noise by operating off the asynchronous clock
(ADACK) and averaging. Noise that is synchronous to ADCK cannot be averaged
out.
There is an inherent quantization error due to the digitization of the result. For 8-bit or
10-bit conversions the code transitions when the voltage is at the midpoint between the
points where the straight line transfer function is exactly represented by the actual
transfer function. Therefore, the quantization error will be ± 1/2 lsb in 8- or 10-bit mode.
As a consequence, however, the code width of the first (0x000) conversion is only 1/2 lsb
and the code width of the last (0xFF or 0x3FF) is 1.5 lsb.
For 12-bit conversions the code transitions only after the full code width is present, so the
quantization error is -1 lsb to 0 lsb and the code width of each step is 1 lsb.
25.1 Introduction
The analog comparator module (ACMP) provides a circuit for comparing two analog
input voltages. The comparator circuit is designed to operate across the full range of the
supply voltage (rail-to-rail operation).
The analog mux provides a circuit for selecting an analog input signal from four
channels. One signal provided by the 6-bit DAC. The mux circuit is designed to operate
across the full range of the supply voltage. The 6-bit DAC is 64-tap resistor ladder
network which provides a selectable voltage reference for applications where voltage
reference is needed. The 64-tap resistor ladder network divides the supply reference Vin
into 64 voltage level. A 6-bit digital signal input selects output voltage level, which varies
from Vin to Vin/64. Vin can be selected from two voltage sources.
25.1.1 Features
ACMP features include:
• Operational over the whole supply range of 2.7 V to 5.5 V
• On-chip 6-bit resolution DAC with selectable reference voltage from VDD or internal
bandgap
• Configurable hysteresis
• Selectable interrupt on rising edge, falling edge, or both rising or falling edges of
comparator output
• Selectable inversion on comparator output
• Up to four selectable comparator inputs
• Operational in Stop mode
DACREF
VDDA
MUX
Bandgap
ACPSEL
DACVAL
MUX
DACEN ACNSEL
+
External Output
–
ACMP0
MUX
Edge Control Interrupt
ACMP1
ACMP2 HYST Logic
Read ACO
ACE HYST ACF ACIE ACOPE ACMOD
Write
Reset 0 0 0 0 0 0 0 0
0 20 mV.
1 30 mV.
5 ACMP Interrupt Flag Bit
ACF
Synchronously set by hardware when ACMP output has a valid edge defined by ACMOD. The setting of
this bit lags the ACMPO to bus clocks. Clear ACF bit by writing a 0 to this bit. Writing a 1 to this bit has no
effect.
4 ACMP Interrupt Enable
ACIE
Enables an ACMP CPU interrupt.
Read 0 0
ACPSEL ACNSEL
Write
Reset 0 0 0 0 0 0 0 0
00 External reference 0
01 External reference 1
10 External reference 2
11 DAC output
Selects the output voltage using the given formula: Voutput= (Vin/64)x(DACVAL[5:0]+1) The Voutput range is
from Vin/64 to Vin, the step is Vin/64
Read 0 ACIPE
Write
Reset 0 0 0 0 0 0 0 0
This 3-bit field controls if the corresponding ACMP external pin can be driven by an analog input.
reference inputs and one internal reference input from the DAC output. The positive input
of ACMP is selected by ACMP_C0[ACPSEL] and the negative input is selected by
ACMP_C0[ACNSEL]. Any pair of the eight inputs can be compared by configuring the
ACMPC0 with the appropriate value.
After the ACMP is enabled by setting ACMP_CS[ACE], the comparison result appears
as a digital output. Whenever a valid edge defined in ACMP_CS[ACMOD] occurs,
ACMP_CS[ACF] is asserted. If ACMP_CS[ACIE] is set, a ACMP CPU interrupt occurs.
The valid edge is defined by ACMP_CS[ACMOD]. When ACMP_CS[ACMOD] = 00b
or 10b, only the falling-edge on ACMP output is valid. When ACMP_CS[ACMOD] =
01b, only rising-edge on ACMP output is valid. When ACMP_CS[ACMOD] = 11b, both
the rising-edge and falling-edge on the ACMP output are valid.
The ACMP output is synchronized by the bus clock to generate ACMP_CS[ACO] so that
the CPU can read the comparison. In stop3 mode, if the output of ACMP is changed,
ACMPO cannot be updated in time. The output can be synchronized and
ACMP_CS[ACO] can be updated upon the waking up of the CPU because of the
availability of the bus clock. ACMP_CS[ACO] changes following the comparison result,
so it can serve as a tracking flag that continuously indicates the voltage delta on the
inputs.
If a reference input external to the chip is selected as an input of ACMP, the
corresponding ACMP_C2[ACIPE] bit must be set to enable the input from pad interface.
If the output of the ACMP needs to be put onto the external pin, the ACMP_CS[ACOPE]
bit must enable the ACMP pin function of pad logic.
25.6 Resets
During a reset the ACMP is configured in the default mode. Both CMP and DAC are
disabled.
25.7 Interrupts
If the bus clock is available when a valid edge defined in ACMP_CS[ACMOD] occurs,
the ACMP_CS[ACF] is asserted. If ACMP_CS[ACIE] is set, a ACMP interrupt event
occurs. The ACMP_CS[ACF] bit remains asserted until the ACMP interrupt is cleared by
software. When in stop mode, a valid edge on ACMP output generates an asynchronous
interrupt that can wake the MCU from stop. The interrupt can be cleared by writing a 0 to
the ACMP_CS[ACF] bit.
26.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The FlexTimer module (FTM) is a two-to-eight channel timer that supports input capture,
output compare, and the generation of PWM signals to control electric motor and power
management applications. The FTM time reference is a 16-bit counter that can be used as
an unsigned or signed counter.
Motor control and power conversion features have been added through a dedicated set of
registers and defaults turn off all new features. The new features, such as hardware
deadtime insertion, polarity, fault control, and output forcing and masking, greatly reduce
loading on the execution software and are usually each controlled by a group of registers.
FlexTimer input triggers can be from comparators, ADC, or other submodules to initiate
timer functions automatically. These triggers can be linked in a variety of ways during
integration of the sub modules so please note the options available for used FlexTimer
configuration.
Several FlexTimers may be synchronized to provide a larger timer with their counters
incrementing in unison, assuming the initialization, the input clocks, the initial and final
counting values are the same in each FlexTimer.
All main user access registers are buffered to ease the load on the executing software. A
number of trigger options exist to determine which registers are updated with this user
defined data.
26.1.2 Features
The FTM features include:
• FTM source clock is selectable
• Source clock can be the system clock, the fixed frequency clock, or an external
clock
• Fixed frequency clock is an additional clock input to allow the selection of an on
chip clock source other than the system clock
• Selecting external clock connects FTM clock to a chip level input pin therefore
allowing to synchronize the FTM counter with an off chip clock source
• Prescaler divide-by 1, 2, 4, 8, 16, 32, 64, or 128
• 16-bit counter
• It can be a free-running counter or a counter with initial and final value
• The counting can be up or up-down
• Each channel can be configured for input capture, output compare, or edge-aligned
PWM mode
• In Input Capture mode:
• The capture can occur on rising edges, falling edges or both edges
• An input filter can be selected for some channels
• In Output Compare mode the output signal can be set, cleared, or toggled on match
• All channels can be configured for center-aligned PWM mode
• Each pair of channels can be combined to generate a PWM signal with independent
control of both edges of PWM signal
• The FTM channels can operate as pairs with equal outputs, pairs with
complementary outputs, or independent channels with independent outputs
• The deadtime insertion is available for each complementary pair
• Generation of match triggers
• Software control of PWM outputs
• Up to 4 fault inputs for global fault control
• The polarity of each channel is configurable
• The generation of an interrupt per channel
• The generation of an interrupt when the counter overflows
• The generation of an interrupt when the fault condition is detected
• Synchronized loading of write buffered FTM registers
• Write protection for critical registers
• Backwards compatible with TPM
• Testing of input captures for a stuck at zero and one conditions
• Dual edge capture for pulse and period width measurement
real time reference or provide the interrupt sources needed to wake the MCU from Wait
mode, the power can then be saved by disabling FTM functions before entering Wait
mode.
CLKS
FTMEN
no clock selected
(FTM counter disable) PS
system clock
fixed frequency clock
external clock prescaler
synchronizer
(1, 2, 4, 8, 16, 32, 64 or 128)
CPWMS
CAPTEST INITTRIGEN initialization
CNTIN trigger
FAULTM[1:0]
FTM counter TOIE timer overflow
MOD TOF interrupt
FFVAL[3:0]
FAULTIE
FAULTIN
FAULTnEN*
FAULTF
FFLTRnEN*
FAULTFn*
fault control fault interrupt
fault input n* *where n = 3, 2, 1, 0
fault condition
channel 0
input input capture output modes logic
mode logic C0V (generation of channels 0 and 1 outputs signals in output channel 0
compare, EPWM, CPWM and combine modes according to output signal
initialization, complementary mode, inverting, software output channel 1
input capture C1V control, deadtime insertion, output mask, fault control output signal
channel 1 mode logic and polarity control)
input
DECAPEN
COMBINE0 CH1F channel 1
interrupt channel 1
CPWMS CH1IE CH1TRIG match trigger
MS1B:MS1A
ELS1B:ELS1A
channel 6
input input capture output modes logic
mode logic C6V channel 6
(generation of channels 6 and 7 outputs signals in output
compare, EPWM, CPWM and combine modes according to output signal
initialization, complementary mode, inverting, software output channel 7
input capture C7V control, deadtime insertion, output mask, fault control output signal
channel 7 mode logic and polarity control)
input
DECAPEN
COMBINE3 CH7F channel 7 channel 7
CPWMS CH7IE
interrupt CH7TRIG match trigger
MS7B:MS7A
ELS7B:ELS7A
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TOF
R 0
CPWMS
TOIE CLKS PS
W 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Selects one of 8 division factors for the clock source selected by CLKS. The new prescaler factor affects
the clock source on the next system clock cycle after the new value is updated into the register bits.
This field is write protected. It can be written only when MODE[WPDIS] = 1.
000 Divide by 1
001 Divide by 2
010 Divide by 4
011 Divide by 8
100 Divide by 16
101 Divide by 32
110 Divide by 64
111 Divide by 128
R 0
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 CHF 0 0
CHIE MSB MSA ELSB ELSA
W 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
If FTMEN = 0, this write coherency mechanism may be manually reset by writing to the
CnSC register whether Debug mode is active or not.
Address: Base address + 10h offset + (8d × i), where i=0d to 7d
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 VAL
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Captured FTM counter value of the input modes or the match value for the output modes
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH7F
CH6F
CH5F
CH4F
CH3F
CH2F
CH1F
CH0F
R 0
W 0 0 0 0 0 0 0 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PWMSYNC
0
CAPTEST
R
FAULTIE
FTMEN
WPDIS
FAULTM INIT
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 No restrictions. Software and hardware triggers can be used by MOD, CnV, OUTMASK, and FTM
counter synchronization.
1 Software trigger can only be used by MOD and CnV synchronization, and hardware triggers can only
be used by OUTMASK and FTM counter synchronization.
2 Write Protection Disable
WPDIS
When write protection is enabled (WPDIS = 0), write protected bits cannot be written. When write
protection is disabled (WPDIS = 1), write protected bits can be written. The WPDIS bit is the negation of
the WPEN bit. WPDIS is cleared when 1 is written to WPEN. WPDIS is set when WPEN bit is read as a 1
and then 1 is written to WPDIS. Writing 0 to WPDIS has no effect.
0 Only the TPM-compatible registers (first set of registers) can be used without any restriction. Do not
use the FTM-specific registers.
1 All registers including the FTM-specific registers (second set of registers) are available for use with no
restrictions.
NOTE
The software trigger, SWSYNC bit, and hardware triggers
TRIG0, TRIG1, and TRIG2 bits have a potential conflict if
used together when SYNCMODE = 0. Use only hardware or
software triggers but not both at the same time, otherwise
unpredictable behavior is likely to happen.
The selection of the loading point, CNTMAX and CNTMIN
bits, is intended to provide the update of MOD, CNTIN, and
CnV registers across all enabled channels simultaneously. The
use of the loading point selection together with SYNCMODE =
0 and hardware trigger selection, TRIG0, TRIG1, or TRIG2
bits, is likely to result in unpredictable behavior.
The synchronization event selection also depends on the
PWMSYNC (MODE register) and SYNCMODE (SYNCONF
register) bits. See PWM synchronization.
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYNCHOM
R 0
SWSYNC
CNTMAX
CNTMIN
REINIT
TRIG2
TRIG1
TRIG0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 Trigger is disabled.
1 Trigger is enabled.
5 PWM Synchronization Hardware Trigger 1
TRIG1
Enables hardware trigger 1 to the PWM synchronization. Hardware trigger 1 happens when a rising edge
is detected at the trigger 1 input signal.
0 Trigger is disabled.
1 Trigger is enabled.
4 PWM Synchronization Hardware Trigger 0
TRIG0
Enables hardware trigger 0 to the PWM synchronization. Hardware trigger 0 occurs when a rising edge is
detected at the trigger 0 input signal.
0 Trigger is disabled.
1 Trigger is enabled.
3 Output Mask Synchronization
SYNCHOM
Selects when the OUTMASK register is updated with the value of its buffer.
0 OUTMASK register is updated with the value of its buffer in all rising edges of the system clock.
1 OUTMASK register is updated with the value of its buffer only by the PWM synchronization.
2 FTM Counter Reinitialization By Synchronization (FTM counter synchronization)
REINIT
Determines if the FTM counter is reinitialized when the selected trigger for the synchronization is detected.
The REINIT bit configures the synchronization when SYNCMODE is zero.
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
CH7OI
CH6OI
CH5OI
CH4OI
CH3OI
CH2OI
CH1OI
CH0OI
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
CH7OM
CH6OM
CH5OM
CH4OM
CH3OM
CH2OM
CH1OM
CH0OM
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DECAPEN3
DECAPEN2
0 0
COMBINE3
COMBINE2
FAULTEN3
FAULTEN2
R
SYNCEN3
SYNCEN2
DECAP3
DECAP2
COMP3
COMP2
DTEN3
DTEN2
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DECAPEN1
DECAPEN0
0 COMBINE1 0
COMBINE0
FAULTEN1
FAULTEN0
R
SYNCEN1
SYNCEN0
DECAP1
DECAP0
COMP1
COMP0
DTEN1
DTEN0
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 The channel (n+1) output is the same as the channel (n) output.
1 The channel (n+1) output is the complement of the channel (n) output.
24 Combine Channels For n = 6
COMBINE3
Enables the combine feature for channels (n) and (n+1).
This field is write protected. It can be written only when MODE[WPDIS] = 1.
0 The channel (n+1) output is the same as the channel (n) output.
1 The channel (n+1) output is the complement of the channel (n) output.
16 Combine Channels For n = 4
COMBINE2
Enables the combine feature for channels (n) and (n+1).
This field is write protected. It can be written only when MODE[WPDIS] = 1.
0 The channel (n+1) output is the same as the channel (n) output.
1 The channel (n+1) output is the complement of the channel (n) output.
8 Combine Channels For n = 2
COMBINE1
Enables the combine feature for channels (n) and (n+1).
This field is write protected. It can be written only when MODE[WPDIS] = 1.
0 The channel (n+1) output is the same as the channel (n) output.
1 The channel (n+1) output is the complement of the channel (n) output.
Selects the deadtime insertion value for the deadtime counter. The deadtime counter is clocked by a
scaled version of the system clock. See the description of DTPS.
Deadtime insert value = (DTPS × DTVAL).
DTVAL selects the number of deadtime counts inserted as follows:
When DTVAL is 0, no counts are inserted.
When DTVAL is 1, 1 count is inserted.
When DTVAL is 2, 2 counts are inserted.
This pattern continues up to a possible 63 counts.
This field is write protected. It can be written only when MODE[WPDIS] = 1.
Reserved
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TRIGF
R
INITTRIGEN
CH1TRIG
CH0TRIG
CH5TRIG
CH4TRIG
CH3TRIG
CH2TRIG
Reserved
W 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
Reserved POL7 POL6 POL5 POL4 POL3 POL2 POL1 POL0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FAULTF3
FAULTF2
FAULTF1
FAULTF0
FAULTIN
FAULTF
R 0 0
WPEN
W 0 0 0 0 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This register selects the filter value for the fault inputs, enables the fault inputs and the
fault inputs filter.
Address: Base address + 7Ch offset
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FAULT3EN
FAULT2EN
FAULT1EN
FAULT0EN
FFLTR3EN
FFLTR2EN
FFLTR1EN
FFLTR0EN
R 0
FFVAL
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This register selects the number of times that the FTM counter overflow should occur
before the TOF bit to be set, the FTM behavior in Debug modes, the use of an external
global time base, and the global time base signal generation.
Address: Base address + 84h offset
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0
GTBEOUT
R
GTBEEN
BDMMODE NUMTOF
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Selects the ratio between the number of counter overflows to the number of times the TOF bit is set.
NUMTOF = 0: The TOF bit is set for each counter overflow.
NUMTOF = 1: The TOF bit is set for the first counter overflow but not for the next overflow.
NUMTOF = 2: The TOF bit is set for the first counter overflow but not for the next 2 overflows.
NUMTOF = 3: The TOF bit is set for the first counter overflow but not for the next 3 overflows.
This pattern continues up to a maximum of 31.
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
FLT3POL
FLT2POL
FLT1POL
FLT0POL
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 The fault input polarity is active high. A 1 at the fault input indicates a fault.
1 The fault input polarity is active low. A 0 at the fault input indicates a fault.
2 Fault Input 2 Polarity
FLT2POL
Defines the polarity of the fault input.
This field is write protected. It can be written only when MODE[WPDIS] = 1.
0 The fault input polarity is active high. A 1 at the fault input indicates a fault.
1 The fault input polarity is active low. A 0 at the fault input indicates a fault.
1 Fault Input 1 Polarity
FLT1POL
Defines the polarity of the fault input.
This field is write protected. It can be written only when MODE[WPDIS] = 1.
0 The fault input polarity is active high. A 1 at the fault input indicates a fault.
1 The fault input polarity is active low. A 0 at the fault input indicates a fault.
0 Fault Input 0 Polarity
FLT0POL
Defines the polarity of the fault input.
This field is write protected. It can be written only when MODE[WPDIS] = 1.
0 The fault input polarity is active high. A 1 at the fault input indicates a fault.
1 The fault input polarity is active low. A 0 at the fault input indicates a fault.
HWRSTCNT
0
HWWRBUF
R
HWINVC
HWSOC
HWOM
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HWTRIGMOD
SYNCMODE
0 SWRSTCNT 0 0 0
SWWRBUF
R
SWINVC
SWSOC
CNTINC
SWOM
SWOC
INVC
E
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
INV3EN
INV2EN
INV1EN
INV0EN
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
CH7OCV
CH6OCV
CH5OCV
CH4OCV
CH3OCV
CH2OCV
CH1OCV
CH0OCV
CH7OC
CH6OC
CH5OC
CH4OC
CH3OC
CH2OC
CH1OC
CH0OC
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0
CH7SEL
CH6SEL
CH5SEL
CH4SEL
CH3SEL
CH2SEL
CH1SEL
CH0SEL
LDOK
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
prescaler counter 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
FTM counter 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2
The external clock passes through a synchronizer clocked by the system clock to assure
that counter transitions are properly aligned to system clock transitions.Therefore, to
meet Nyquist criteria considering also jitter, the frequency of the external clock source
must not exceed 1/4 of the system clock frequency.
26.4.2 Prescaler
The selected counter clock source passes through a prescaler that is a 7-bit counter. The
value of the prescaler is selected by the PS[2:0] bits. The following figure shows an
example of the prescaler counter and FTM counter.
FTM counting is up.
PS[2:0] = 001
CNTIN = 0x0000
MOD = 0x0003
prescaler counter 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
FTM counter 0 1 2 3 0 1 2 3 0 1
26.4.3 Counter
The FTM has a 16-bit counter that is used by the channels either for input or output
modes. The FTM counter clock is the selected clock divided by the prescaler.
The FTM counter has these modes of operation:
• Up counting
• Up-down counting
26.4.3.1 Up counting
Up counting is selected when:
• CPWMS = 0
CNTIN defines the starting value of the count and MOD defines the final value of the
count, see the following figure. The value of CNTIN is loaded into the FTM counter, and
the counter increments until the value of MOD is reached, at which point the counter is
reloaded with the value of CNTIN.
The FTM period when using up counting is (MOD – CNTIN + 0x0001) × period of the
FTM counter clock.
The TOF bit is set when the FTM counter changes from MOD to CNTIN.
FTM counting is up.
CNTIN = 0xFFFC (in two's complement is equal to -4)
MOD = 0x0004
TOF bit
FTM counter 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2
TOF bit
Note
• FTM operation is only valid when the value of the CNTIN
register is less than the value of the MOD register, either in
the unsigned counting or signed counting. It is the
responsibility of the software to ensure that the values in
the CNTIN and MOD registers meet this requirement. Any
values of CNTIN and MOD that do not satisfy this criteria
can result in unpredictable behavior.
• MOD = CNTIN is a redundant condition. In this case, the
FTM counter is always equal to MOD and the TOF bit is
set in each rising edge of the FTM counter clock.
• When MOD = 0x0000, CNTIN = 0x0000, for example
after reset, and FTMEN = 1, the FTM counter remains
stopped at 0x0000 until a non-zero value is written into the
MOD or CNTIN registers.
• Setting CNTIN to be greater than the value of MOD is not
recommended as this unusual setting may make the FTM
operation difficult to comprehend. However, there is no
restriction on this configuration, and an example is shown
in the following figure.
FTM counting is up
MOD = 0x0005
CNTIN = 0x0015
FTM counter 0x0005 0x0015 0x0016 ... 0xFFFE 0xFFFF 0x0000 0x0001 0x0002 0x0003 0x0004 0x0005 0x0015 0x0016 ...
...
TOF bit
Figure 26-126. Example of up counting when the value of CNTIN is greater than the
value of MOD
FTM counter 0 1 2 3 4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4
TOF bit
Note
It is expected that the up-down counting be used only with
CNTIN = 0x0000.
FTM counter ... 0x0003 0x0004 ... 0xFFFE 0xFFFF 0x0000 0x0001 0x0002 0x0003 0x0004 0x0005 0x0006 ...
TOF bit
FTM counter
NUMTOF[4:0] 0x02
TOF counter 0x01 0x02 0x00 0x01 0x02 0x00 0x01 0x02
FTM counter
NUMTOF[4:0] 0x00
is filter
enabled? channel (n) interrupt
0 0 CHnIE
CHnF
synchronizer rising edge
0 1
channel (n) input DQ DQ edge
detector CnV
Filter* 1
system clock CLK CLK 1
falling edge
0 0
was falling
edge selected?
* Filtering function is only available in the inputs of channel 0, 1, 2, and 3 FTM counter
If the channel input does not have a filter enabled, then the input signal is always delayed
3 rising edges of the system clock, that is, two rising edges to the synchronizer plus one
more rising edge to the edge detector. In other words, the CHnF bit is set on the third
rising edge of the system clock after a valid edge occurs on the channel input.
Note
The Input Capture mode must be used only with CNTIN =
0x0000.
CHnFVAL[3:0]
Logic to control
channel (n) input after the filter counter
the synchronizer filter output
S Q
filter counter Logic to define
C
the filter output
divided by 4
CLK
system clock
When there is a state change in the input signal, the counter is reset and starts counting
up. As long as the new state is stable on the input, the counter continues to increment.
When the counter is equal to CHnFVAL[3:0], the state change of the input signal is
validated. It is then transmitted as a pulse edge to the edge detector.
If the opposite edge appears on the input signal before it can be validated, the counter is
reset. At the next input transition, the counter starts counting again. Any pulse that is
shorter than the minimum value selected by CHnFVAL[3:0] (× 4 system clocks) is
regarded as a glitch and is not passed on to the edge detector. A timing diagram of the
input filter is shown in the following figure.
The filter function is disabled when CHnFVAL[3:0] bits are zero. In this case, the input
signal is delayed 3 rising edges of the system clock. If (CHnFVAL[3:0] ≠ 0000), then the
input signal is delayed by the minimum pulse width (CHnFVAL[3:0] × 4 system clocks)
plus a further 4 rising edges of the system clock: two rising edges to the synchronizer,
one rising edge to the filter output, plus one more to the edge detector. In other words,
CHnF is set (4 + 4 × CHnFVAL[3:0]) system clock periods after a valid edge occurs on
the channel input.
The clock for the counter in the channel input filter is the system clock divided by 4.
counter
CHnFVAL[3:0] = 0010
(binary value)
Time
filter output
TOF bit
Figure 26-134. Example of the Output Compare mode when the match toggles the
channel output
TOF bit
Figure 26-135. Example of the Output Compare mode when the match clears the
channel output
MOD = 0x0005
CnV = 0x0003
counter channel (n) counter channel (n) counter
overflow match overflow match overflow
TOF bit
Figure 26-136. Example of the Output Compare mode when the match sets the channel
output
If (ELSnB:ELSnA = 0:0) when the counter reaches the value in the CnV register, the
CHnF bit is set and the channel (n) interrupt is generated if CHnIE = 1, however the
channel (n) output is not modified and controlled by FTM.
Note
The Output Compare mode must be used only with CNTIN =
0x0000.
The CHnF bit is set and the channel (n) interrupt is generated if CHnIE = 1 at the channel
(n) match (FTM counter = CnV), that is, at the end of the pulse width.
This type of PWM signal is called edge-aligned because the leading edges of all PWM
signals are aligned with the beginning of the period, which is the same for all channels
within an FTM.
counter overflow counter overflow counter overflow
period
pulse
width
Figure 26-137. EPWM period and pulse width with ELSnB:ELSnA = 1:0
If (ELSnB:ELSnA = 0:0) when the counter reaches the value in the CnV register, the
CHnF bit is set and the channel (n) interrupt is generated if CHnIE = 1, however the
channel (n) output is not controlled by FTM.
If (ELSnB:ELSnA = 1:0), then the channel (n) output is forced high at the counter
overflow when the CNTIN register value is loaded into the FTM counter, and it is forced
low at the channel (n) match (FTM counter = CnV). See the following figure.
MOD = 0x0008
CnV = 0x0005
counter channel (n) counter
overflow match overflow
TOF bit
If (ELSnB:ELSnA = X:1), then the channel (n) output is forced low at the counter
overflow when the CNTIN register value is loaded into the FTM counter, and it is forced
high at the channel (n) match (FTM counter = CnV). See the following figure.
MOD = 0x0008
CnV = 0x0005 counter channel (n) counter
overflow match overflow
TOF bit
If (CnV = 0x0000), then the channel (n) output is a 0% duty cycle EPWM signal and
CHnF bit is not set even when there is the channel (n) match. If (CnV > MOD), then the
channel (n) output is a 100% duty cycle EPWM signal and CHnF bit is not set even when
there is the channel (n) match. Therefore, MOD must be less than 0xFFFF in order to get
a 100% duty cycle EPWM signal.
Note
The EPWM mode must be used only with CNTIN = 0x0000.
counter overflow channel (n) match channel (n) match counter overflow
FTM counter = (FTM counting (FTM counting FTM counter =
MOD is down) is up) MOD
Figure 26-140. CPWM period and pulse width with ELSnB:ELSnA = 1:0
If (ELSnB:ELSnA = 0:0) when the FTM counter reaches the value in the CnV register,
the CHnF bit is set and the channel (n) interrupt is generated (if CHnIE = 1), however the
channel (n) output is not controlled by FTM.
If (ELSnB:ELSnA = 1:0), then the channel (n) output is forced high at the channel (n)
match (FTM counter = CnV) when counting down, and it is forced low at the channel (n)
match when counting up. See the following figure.
MOD = 0x0008 counter counter
CnV = 0x0005 overflow overflow
channel (n) match in channel (n) match in channel (n) match in
down counting up counting down counting
TOF bit
If (ELSnB:ELSnA = X:1), then the channel (n) output is forced low at the channel (n)
match (FTM counter = CnV) when counting down, and it is forced high at the channel (n)
match when counting up. See the following figure.
MOD = 0x0008 counter counter
overflow overflow
CnV = 0x0005
channel (n) match in channel (n) match in channel (n) match in
down counting up counting down counting
TOF bit
If (CnV = 0x0000) or CnV is a negative value, that is (CnV[15] = 1), then the channel (n)
output is a 0% duty cycle CPWM signal and CHnF bit is not set even when there is the
channel (n) match.
If CnV is a positive value, that is (CnV[15] = 0), (CnV ≥ MOD), and (MOD ≠ 0x0000),
then the channel (n) output is a 100% duty cycle CPWM signal and CHnF bit is not set
even when there is the channel (n) match. This implies that the usable range of periods
set by MOD is 0x0001 through 0x7FFE, 0x7FFF if you do not need to generate a 100%
duty cycle CPWM signal. This is not a significant limitation because the resulting period
is much longer than required for normal applications.
The CPWM mode must not be used when the FTM counter is a free running counter.
Note
The CPWM mode must be used only with CNTIN = 0x0000.
If (ELSnB:ELSnA = X:1), then the channel (n) output is forced high at the beginning of
the period (FTM counter = CNTIN) and at the channel (n+1) match (FTM counter = C(n
+1)V). It is forced low at the channel (n) match (FTM counter = C(n)V). See the
following figure.
In Combine mode, the ELS(n+1)B and ELS(n+1)A bits are not used in the generation of
the channels (n) and (n+1) output. However, if (ELSnB:ELSnA = 0:0) then the channel
(n) output is not controlled by FTM, and if (ELS(n+1)B:ELS(n+1)A = 0:0) then the
channel (n+1) output is not controlled by FTM.
channel (n+1) match
FTM counter
channel (n) match
The following figures illustrate the PWM signals generation using Combine mode.
FTM counter
MOD
C(n+1)V
C(n)V
CNTIN
Figure 26-144. Channel (n) output if (CNTIN < C(n)V < MOD) and (CNTIN < C(n+1)V <
MOD) and (C(n)V < C(n+1)V)
C(n)V
CNTIN
Figure 26-145. Channel (n) output if (CNTIN < C(n)V < MOD) and (C(n+1)V = MOD)
FTM counter
MOD
C(n+1)V
C(n)V = CNTIN
Figure 26-146. Channel (n) output if (C(n)V = CNTIN) and (CNTIN < C(n+1)V < MOD)
FTM counter
MOD = C(n+1)V
C(n)V
CNTIN
Figure 26-147. Channel (n) output if (CNTIN < C(n)V < MOD) and (C(n)V is Almost Equal
to CNTIN) and (C(n+1)V = MOD)
C(n+1)V
C(n)V = CNTIN
Figure 26-148. Channel (n) output if (C(n)V = CNTIN) and (CNTIN < C(n+1)V < MOD) and
(C(n+1)V is Almost Equal to MOD)
FTM counter
C(n+1)V
MOD
CNTIN
C(n)V
Figure 26-149. Channel (n) output if C(n)V and C(n+1)V are not between CNTIN and MOD
MOD
C(n+1)V = C(n)V
CNTIN
Figure 26-150. Channel (n) output if (CNTIN < C(n)V < MOD) and (CNTIN < C(n+1)V <
MOD) and (C(n)V = C(n+1)V)
FTM counter
MOD
C(n)V =
C(n+1)V = CNTIN
CNTIN
C(n)V
C(n+1)V
CNTIN
Figure 26-153. Channel (n) output if (CNTIN < C(n)V < MOD) and (CNTIN < C(n+1)V <
MOD) and (C(n)V > C(n+1)V)
FTM counter
MOD
C(n+1)V
CNTIN
C(n)V
Figure 26-154. Channel (n) output if (C(n)V < CNTIN) and (CNTIN < C(n+1)V < MOD)
C(n)V
CNTIN
C(n+1)V
Figure 26-155. Channel (n) output if (C(n+1)V < CNTIN) and (CNTIN < C(n)V < MOD)
FTM counter
C(n)V
MOD
C(n+1)V
CNTIN
Figure 26-156. Channel (n) output if (C(n)V > MOD) and (CNTIN < C(n+1)V < MOD)
C(n+1)V
MOD
C(n)V
CNTIN
Figure 26-157. Channel (n) output if (C(n+1)V > MOD) and (CNTIN < C(n)V < MOD)
FTM counter
C(n+1)V
MOD = C(n)V
CNTIN
Figure 26-158. Channel (n) output if (C(n+1)V > MOD) and (CNTIN < C(n)V = MOD)
• FTMEN = 1
• DECAPEN = 0
• COMBINE = 1
• CPWMS = 0, and
• COMP = 1
In Complementary mode, the channel (n+1) output is the inverse of the channel (n)
output.
So, the channel (n+1) output is the same as the channel (n) output when:
• FTMEN = 1
• DECAPEN = 0
• COMBINE = 1
• CPWMS = 0, and
• COMP = 0
channel (n+1) match
FTM counter
channel (n) match
Figure 26-159. Channel (n+1) output in Complementary mode with (ELSnB:ELSnA = 1:0)
FTM counter
channel (n) match
Figure 26-160. Channel (n+1) output in Complementary mode with (ELSnB:ELSnA = X:1)
If (HWTRIGMODE = 0) then the TRIGn bit is cleared when 0 is written to it or when the
trigger n event is detected.
In this case, if two or more hardware triggers are enabled (for example, TRIG0 and
TRIG1 = 1) and only trigger 1 event occurs, then only TRIG1 bit is cleared. If a trigger n
event occurs together with a write setting TRIGn bit, then the synchronization is initiated,
but TRIGn bit remains set due to the write operation.
system clock
TRIG0 bit
trigger_0 input
synchronized trigger_0
by system clock
trigger 0 event
Note
All hardware trigger inputs have the same behavior.
If HWTRIGMODE = 1, then the TRIGn bit is only cleared when 0 is written to it.
NOTE
The HWTRIGMODE bit must be 1 only with enhanced PWM
synchronization (SYNCMODE = 1).
software trigger event occurred; see Boundary cycle and loading points and the following
figure. If (PWMSYNC = 0) and (REINIT = 1) then SWSYNC bit is cleared when the
software trigger event occurs.
If SYNCMODE = 1 then the SWSYNC bit is also cleared by FTM according to the
SWRSTCNT bit. If SWRSTCNT = 0 then SWSYNC bit is cleared at the next selected
loading point after that the software trigger event occurred; see the following figure. If
SWRSTCNT = 1 then SWSYNC bit is cleared when the software trigger event occurs.
system clock
SWSYNC bit
PWM synchronization
selected loading point
up counting mode
begin
legacy =0
PWM synchronization SYNCMODE
bit ?
=1
enhanced PWM synchronization
software hardware
trigger trigger
0= TRIGn
=0
SWSYNC
bit ? bit ?
=1
=1
FTM counter is reset by
software trigger
=0
=1 wait hardware trigger n
SWRSTCNT
bit ?
end end
In the case of legacy PWM synchronization, the MOD register synchronization depends
on PWMSYNC and REINIT bits according to the following description.
If (SYNCMODE = 0), (PWMSYNC = 0), and (REINIT = 0), then this synchronization is
made on the next selected loading point after an enabled trigger event takes place. If the
trigger event was a software trigger, then the SWSYNC bit is cleared on the next selected
loading point. If the trigger event was a hardware trigger, then the trigger enable bit
(TRIGn) is cleared according to Hardware trigger. Examples with software and hardware
triggers follow.
system clock
SWSYNC bit
Figure 26-165. MOD synchronization with (SYNCMODE = 0), (PWMSYNC = 0), (REINIT =
0), and software trigger was used
system clock
TRIG0 bit
trigger 0 event
If (SYNCMODE = 0), (PWMSYNC = 0), and (REINIT = 1), then this synchronization is
made on the next enabled trigger event. If the trigger event was a software trigger, then
the SWSYNC bit is cleared according to the following example. If the trigger event was a
hardware trigger, then the TRIGn bit is cleared according to Hardware trigger. Examples
with software and hardware triggers follow.
system clock
SWSYNC bit
Figure 26-167. MOD synchronization with (SYNCMODE = 0), (PWMSYNC = 0), (REINIT =
1), and software trigger was used
system clock
TRIG0 bit
trigger 0 event
system clock
SWSYNC bit
begin
1= =0
SYNCMODE
no = rising edge
of system bit ?
clock ?
legacy
= yes PWM synchronization
update OUTMASK
with its buffer value
end
update OUTMASK
end with its buffer value
=1
HWTRIGMODE
bit ?
=0
end
system clock
SWSYNC bit
system clock
TRIG0 bit
trigger 0 event
system clock
TRIG0 bit
trigger 0 event
begin
update INVCTRL register at
each rising edge of system clock update INVCTRL register by
PWM synchronization
0= INVC =1
bit ?
1= =0
SYNCMODE
bit ?
no = rising edge
of system end
clock ?
= yes
update INVCTRL
with its buffer value
end
update INVCTRL
wait hardware trigger n
with its buffer value
update INVCTRL
end with its buffer value
=1
HWTRIGMODE
bit ?
=0
end
The SWOCTRL register can be updated at each rising edge of system clock (SWOC = 0)
or by the enhanced PWM synchronization (SWOC = 1 and SYNCMODE = 1) according
to the following flowchart.
In the case of enhanced PWM synchronization, the SWOCTRL register synchronization
depends on SWSOC and HWSOC bits.
begin
update SWOCTRL register at
each rising edge of system clock update SWOCTRL register by
0= =1 PWM synchronization
SWOC
bit ?
1= =0
SYNCMODE
bit ?
no = rising edge
of system end
clock ?
= yes
update SWOCTRL
with its buffer value
end
update SWOCTRL
wait hardware trigger n
with its buffer value
update SWOCTRL
end with its buffer value
=1
HWTRIGMODE
bit ?
=0
end
FTM counter
channel (n) match
synchronization event
The FTM counter synchronization can be done by either the enhanced PWM
synchronization (SYNCMODE = 1) or the legacy PWM synchronization (SYNCMODE
= 0). However, the FTM counter must be synchronized only by the enhanced PWM
synchronization.
In the case of enhanced PWM synchronization, the FTM counter synchronization
depends on SWRSTCNT and HWRSTCNT bits according to the following flowchart.
begin
legacy =0
PWM synchronization SYNCMODE
bit ?
=1
enhanced PWM synchronization
end
=1
HWTRIGMODE
bit ?
=0
end
In the case of legacy PWM synchronization, the FTM counter synchronization depends
on REINIT and PWMSYNC bits according to the following description.
If (SYNCMODE = 0), (REINIT = 1), and (PWMSYNC = 0) then this synchronization is
made on the next enabled trigger event. If the trigger event was a software trigger then
the SWSYNC bit is cleared according to the following example. If the trigger event was a
hardware trigger then the TRIGn bit is cleared according to Hardware trigger. Examples
with software and hardware triggers follow.
system clock
SWSYNC bit
Figure 26-178. FTM counter synchronization with (SYNCMODE = 0), (REINIT = 1),
(PWMSYNC = 0), and software trigger was used
system clock
TRIG0 bit
trigger 0 event
Figure 26-179. FTM counter synchronization with (SYNCMODE = 0), (HWTRIGMODE = 0),
(REINIT = 1), (PWMSYNC = 0), and a hardware trigger was used
system clock
TRIG0 bit
trigger 0 event
Figure 26-180. FTM counter synchronization with (SYNCMODE = 0), (HWTRIGMODE = 0),
(REINIT = 1), (PWMSYNC = 1), and a hardware trigger was used
26.4.12 Inverting
The invert functionality swaps the signals between channel (n) and channel (n+1)
outputs. The inverting operation is selected when:
• FTMEN = 1
• DECAPEN = 0
• COMBINE = 1
• COMP = 1
• CPWMS = 0, and
• INVm = 1 (where m represents a channel pair)
The INVm bit in INVCTRL register is updated with its buffer value according to
INVCTRL register synchronization
In High-True (ELSnB:ELSnA = 1:0) Combine mode, the channel (n) output is forced low
at the beginning of the period (FTM counter = CNTIN), forced high at the channel (n)
match and forced low at the channel (n+1) match. If the inverting is selected, the channel
(n) output behavior is changed to force high at the beginning of the PWM period, force
low at the channel (n) match and force high at the channel (n+1) match. See the following
figure.
FTM counter
channel (n) match
INVCTRL register
synchronization
INV(m) bit
NOTE
INV(m) bit selects the inverting to the pair channels (n) and (n+1).
Figure 26-181. Channels (n) and (n+1) outputs after the inverting in High-True
(ELSnB:ELSnA = 1:0) Combine mode
Note that the ELSnB:ELSnA bits value should be considered because they define the
active state of the channels outputs. In Low-True (ELSnB:ELSnA = X:1) Combine mode,
the channel (n) output is forced high at the beginning of the period, forced low at the
channel (n) match and forced high at the channel (n+1) match. When inverting is
selected, the channels (n) and (n+1) present waveforms as shown in the following figure.
FTM counter
channel (n) match
INVCTRL register
synchronization
INV(m) bit
NOTE
INV(m) bit selects the inverting to the pair channels (n) and (n+1).
Figure 26-182. Channels (n) and (n+1) outputs after the inverting in Low-True
(ELSnB:ELSnA = X:1) Combine mode
Note
The inverting feature must be used only in Combine mode.
The following figure shows the channels (n) and (n+1) outputs signals when the software
output control is used. In this case the channels (n) and (n+1) are set to Combine and
Complementary mode.
channel (n+1) match
FTM counter
channel (n) match
CH(n)OC buffer
CH(n+1)OC buffer
CH(n)OC bit
CH(n+1)OC bit
NOTE
CH(n)OCV = 1 and CH(n+1)OCV = 0.
Software output control forces the following values on channels (n) and (n+1) when the
COMP bit is zero.
Table 26-183. Software ouput control behavior when (COMP = 0)
CH(n)OC CH(n+1)OC CH(n)OCV CH(n+1)OCV Channel (n) Output Channel (n+1) Output
0 0 X X is not modified by SWOC is not modified by SWOC
1 1 0 0 is forced to zero is forced to zero
1 1 0 1 is forced to zero is forced to one
1 1 1 0 is forced to one is forced to zero
1 1 1 1 is forced to one is forced to one
Software output control forces the following values on channels (n) and (n+1) when the
COMP bit is one.
Table 26-184. Software ouput control behavior when (COMP = 1)
CH(n)OC CH(n+1)OC CH(n)OCV CH(n+1)OCV Channel (n) Output Channel (n+1) Output
0 0 X X is not modified by SWOC is not modified by SWOC
1 1 0 0 is forced to zero is forced to zero
1 1 0 1 is forced to zero is forced to one
Note
• The software output control feature must be used only in
Combine mode.
• The CH(n)OC and CH(n+1)OC bits should be equal.
• The COMP bit must not be modified when software output
control is enabled, that is, CH(n)OC = 1 and/or CH(n
+1)OC = 1.
• Software output control has the same behavior with
disabled or enabled FTM counter (see the CLKS field
description in the Status and Control register).
when the channel (n+1) match (FTM counter = C(n+1)V) occurs, the channel (n+1)
output remains at the high value until the end of the deadtime delay when the channel (n
+1) output is cleared.
channel (n+1) match
FTM counter
channel (n) match
Figure 26-184. Deadtime insertion with ELSnB:ELSnA = 1:0, POL(n) = 0, and POL(n+1) =
0
FTM counter
channel (n) match
Figure 26-185. Deadtime insertion with ELSnB:ELSnA = X:1, POL(n) = 0, and POL(n+1) =
0
NOTE
The deadtime feature must be used only in Combine and
Complementary modes.
• and the deadtime delay is greater than or equal to the channel (n) duty cycle ((C(n
+1)V – C(n)V) × system clock), then the channel (n) output is always the inactive
value (POL(n) bit value).
• and the deadtime delay is greater than or equal to the channel (n+1) duty cycle
((MOD – CNTIN + 1 – (C(n+1)V – C(n)V) ) × system clock), then the channel (n+1)
output is always the inactive value (POL(n+1) bit value).
Although, in most cases the deadtime delay is not comparable to channels (n) and (n+1)
duty cycle, the following figures show examples where the deadtime delay is comparable
to the duty cycle.
channel (n+1) match
FTM counter
channel (n) match
Figure 26-186. Example of the deadtime insertion (ELSnB:ELSnA = 1:0, POL(n) = 0, and
POL(n+1) = 0) when the deadtime delay is comparable to channel (n+1) duty cycle
FTM counter
channel (n) match
Figure 26-187. Example of the deadtime insertion (ELSnB:ELSnA = 1:0, POL(n) = 0, and
POL(n+1) = 0) when the deadtime delay is comparable to channels (n) and (n+1) duty
cycle
FTM counter
CHnOM bit
The following table shows the output mask result before the polarity control.
Table 26-185. Output mask result for channel (n) before the polarity
control
CHnOM Output Mask Input Output Mask Result
0 inactive state inactive state
active state active state
1 inactive state inactive state
active state
Note
The output mask feature must be used only in Combine mode.
(FFVAL[3:0] 0000)
and (FFLTRnEN*)
FLTnPOL
synchronizer fault input n* value
0
fault input n* D Q D Q fault input
polarity rising edge
control FAULTFn*
Fault filter detector
(5-bit counter) 1
system clock CLK CLK
* where n = 3, 2, 1, 0
If the fault control and fault input n are enabled and a rising edge at the fault input n
signal is detected, a fault condition has occurred and the FAULTFn bit is set. The
FAULTF bit is the logic OR of FAULTFn[3:0] bits. See the following figure.
fault input 0 value
fault input 1 value
FAULTIN
fault input 2 value
fault input 3 value
If the fault control is enabled (FAULTM[1:0] ≠ 0:0), a fault condition has occurred and
(FAULTEN = 1), then outputs are forced to their safe values:
• Channel (n) output takes the value of POL(n)
• Channel (n+1) takes the value of POL(n+1)
The fault interrupt is generated when (FAULTF = 1) and (FAULTIE = 1). This interrupt
request remains set until:
• Software clears the FAULTF bit by reading FAULTF bit as 1 and writing 0 to it
• Software clears the FAULTIE bit
• A reset occurs
Note
The fault control must be used only in Combine mode.
FTM counter
FAULTIN bit
FAULTF bit
FTM counter
FAULTIN bit
FAULTF bit
Note
The polarity control must be used only in Combine mode.
26.4.18 Initialization
The initialization forces the CHnOI bit value to the channel (n) output when a one is
written to the INIT bit.
The initialization depends on COMP and DTEN bits. The following table shows the
values that channels (n) and (n+1) are forced by initialization when the COMP and
DTEN bits are zero.
Table 26-186. Initialization behavior when (COMP = 0 and DTEN = 0)
CH(n)OI CH(n+1)OI Channel (n) Output Channel (n+1) Output
0 0 is forced to zero is forced to zero
0 1 is forced to zero is forced to one
1 0 is forced to one is forced to zero
1 1 is forced to one is forced to one
The following table shows the values that channels (n) and (n+1) are forced by
initialization when (COMP = 1) or (DTEN = 1).
Table 26-187. Initialization behavior when (COMP = 1 or DTEN = 1)
CH(n)OI CH(n+1)OI Channel (n) Output Channel (n+1) Output
0 X is forced to zero is forced to one
1 X is forced to one is forced to zero
Note
The initialization feature must be used only in Combine mode
and with disabled FTM counter. See the description of the
CLKS field in the Status and Control register.
FTM counter
DECAPEN
COMBINE(m)
CPWMS
C(n)V
MS(n)B CH(n)OC
generation of channel
channel (n) (n)
output
output signal signal
software deadtime polarity
complementary output fault
initialization inverting output insertion control
mode mask control
control
generation of channel
(n+1)
channel (n+1)
output
output signal signal
C(n+1)V
MS(n+1)B
MS(n+1)A
ELS(n+1)B
ELS(n+1)A
NOTE
The channels (n) and (n+1) are in output compare, EPWM, CPWM or combine modes.
Figure 26-193. Priority of the features used at the generation of channels (n) and (n+1)
outputs signals
Note
The Initialization feature must not be used with Inverting and
Software output control features.
The FTM is able to generate multiple triggers in one PWM period. Because each trigger
is generated for a specific channel, several channels are required to implement this
functionality. This behavior is described in the following figure.
the beginning of new PWM cycles
MOD
(a)
(b)
(c)
(d)
NOTE
(a) CH0TRIG = 0, CH1TRIG = 0, CH2TRIG = 0, CH3TRIG = 0, CH4TRIG = 0, CH5TRIG = 0
(b) CH0TRIG = 1, CH1TRIG = 0, CH2TRIG = 0, CH3TRIG = 0, CH4TRIG = 0, CH5TRIG = 0
(c) CH0TRIG = 0, CH1TRIG = 0, CH2TRIG = 0, CH3TRIG = 1, CH4TRIG = 1, CH5TRIG = 1
(d) CH0TRIG = 1, CH1TRIG = 1, CH2TRIG = 1, CH3TRIG = 1, CH4TRIG = 1, CH5TRIG = 1
Note
The channel match trigger must be used only in Combine mode.
system clock
FTM counter 0x0C 0x0D 0x0E 0x0F 0x00 0x01 0x02 0x03 0x04 0x05
initialization trigger
Figure 26-195. Initialization trigger is generated when the FTM counting achieves the
CNTIN register value
CNTIN = 0x0000
MOD = 0x000F
CPWMS = 0
system clock
FTM counter 0x04 0x05 0x06 0x00 0x01 0x02 0x03 0x04 0x05 0x06
write to CNT
initialization trigger
Figure 26-196. Initialization trigger is generated when there is a write to CNT register
CNTIN = 0x0000
MOD = 0x000F
CPWMS = 0
system clock
FTM counter 0x04 0x05 0x06 0x07 0x00 0x01 0x02 0x03 0x04 0x05
FTM counter
synchronization
initialization trigger
Figure 26-197. Initialization trigger is generated when there is the FTM counter
synchronization
CNTIN = 0x0000
MOD = 0x000F
CPWMS = 0
system clock
CLKS[1:0] bits 00 01
initialization trigger
Figure 26-198. Initialization trigger is generated if (CNT = CNTIN), (CLKS[1:0] = 0:0), and
a value different from zero is written to CLKS[1:0] bits
The initialization trigger output provides a trigger signal that is used for on-chip modules.
Note
The initialization trigger must be used only in Combine mode.
CAPTEST bit
FTM counter 0x1053 0x1054 0x1055 0x1056 0x78AC 0x78AD 0x78AE 0x78AF 0x78B0
write 0x78AC
write to CNT
CHnF bit
0x0300 0x78AC
CnV
NOTE
- FTM counter configuration: (FTMEN = 1), (CAPTEST = 1), (CPWMS = 0), (CNTIN = 0x0000), and (MOD = 0xFFFF)
- FTM channel n configuration: input capture mode - (DECAPEN = 0), (COMBINE = 0), and (MSnB:MSnA = 0:0)
FTMEN
DECAPEN
is filter DECAP
enabled? channel (n)
MS(n)A CH(n)IE interrupt
ELS(n)B:ELS(n)A
CH(n)F
synchronizer ELS(n+1)B:ELS(n+1)A
0 C(n)V[15:0]
channel (n) input D Q D Q Dual edge capture
mode logic
channel (n+1)
Filter* 1 CH(n+1)IE interrupt
system clock CLK CLK
CH(n+1)F
C(n+1)V[15:0]
FTM counter
* Filtering function for dual edge capture mode is only available in the channels 0 and 2
The MS(n)A bit defines if the Dual Edge Capture mode is one-shot or continuous.
The ELS(n)B:ELS(n)A bits select the edge that is captured by channel (n), and ELS(n
+1)B:ELS(n+1)A bits select the edge that is captured by channel (n+1). If both
ELS(n)B:ELS(n)A and ELS(n+1)B:ELS(n+1)A bits select the same edge, then it is the
period measurement. If these bits select different edges, then it is a pulse width
measurement.
In the Dual Edge Capture mode, only channel (n) input is used and channel (n+1) input is
ignored.
If the selected edge by channel (n) bits is detected at channel (n) input, then CH(n)F bit is
set and the channel (n) interrupt is generated (if CH(n)IE = 1). If the selected edge by
channel (n+1) bits is detected at channel (n) input and (CH(n)F = 1), then CH(n+1)F bit is
set and the channel (n+1) interrupt is generated (if CH(n+1)IE = 1).
The C(n)V register stores the value of FTM counter when the selected edge by channel
(n) is detected at channel (n) input. The C(n+1)V register stores the value of FTM
counter when the selected edge by channel (n+1) is detected at channel (n) input.
In this mode, a coherency mechanism ensures coherent data when the C(n)V and C(n
+1)V registers are read. The only requirement is that C(n)V must be read before C(n
+1)V.
Note
• The CH(n)F, CH(n)IE, MS(n)A, ELS(n)B, and ELS(n)A
bits are channel (n) bits.
• The CH(n+1)F, CH(n+1)IE, MS(n+1)A, ELS(n+1)B, and
ELS(n+1)A bits are channel (n+1) bits.
• The Dual Edge Capture mode must be used with
ELS(n)B:ELS(n)A = 0:1 or 1:0, ELS(n+1)B:ELS(n+1)A =
0:1 or 1:0 and the FTM counter in Free running counter.
In this mode, the DECAP bit is automatically cleared by FTM when the edge selected by
channel (n+1) is captured. Therefore, while DECAP bit is set, the one-shot capture is in
process. When this bit is cleared, both edges were captured and the captured values are
ready for reading in the C(n)V and C(n+1)V registers.
Similarly, when the CH(n+1)F bit is set, both edges were captured and the captured
values are ready for reading in the C(n)V and C(n+1)V registers.
positive polarity pulse width. The CH(n)F bit is set when the first edge of this pulse is
detected, that is, the edge selected by ELS(n)B:ELS(n)A bits. The CH(n+1)F bit is set
and DECAP bit is cleared when the second edge of this pulse is detected, that is, the edge
selected by ELS(n+1)B:ELS(n+1)A bits. Both DECAP and CH(n+1)F bits indicate when
two edges of the pulse were captured and the C(n)V and C(n+1)V registers are ready for
reading.
4 8 12 16 20 24
3 28
7 11 15 19
FTM counter 23 27
2 6 10 14 18 22 26
1 5 9 13 17 21 25
DECAPEN bit
set DECAPEN
DECAP bit
set DECAP
C(n)V 1 3 5 7 9 15 19
CH(n)F bit
clear CH(n)F
C(n+1)V 2 4 6 8 10 16 20 22 24
CH(n+1)F bit
clear CH(n+1)F
problem 1 problem 2
Note
- The commands set DECAPEN, set DECAP, clear CH(n)F, and clear CH(n+1)F are made by the user.
- Problem 1: channel (n) input = 1, set DECAP, not clear CH(n)F, and clear CH(n+1)F.
- Problem 2: channel (n) input = 1, set DECAP, not clear CH(n)F, and not clear CH(n+1)F.
Figure 26-201. Dual Edge Capture – One-Shot mode for positive polarity pulse width
measurement
The following figure shows an example of the Dual Edge Capture – Continuous mode
used to measure the positive polarity pulse width. The DECAPEN bit selects the Dual
Edge Capture mode, so it remains set. While the DECAP bit is set the configured
measurements are made. The CH(n)F bit is set when the first edge of the positive polarity
pulse is detected, that is, the edge selected by ELS(n)B:ELS(n)A bits. The CH(n+1)F bit
is set when the second edge of this pulse is detected, that is, the edge selected by ELS(n
+1)B:ELS(n+1)A bits. The CH(n+1)F bit indicates when two edges of the pulse were
captured and the C(n)V and C(n+1)V registers are ready for reading.
4 8 12 16 20 24 28
3 7 11 15 19
FTM counter 23 27
2 6 10 14 18 22 26
1 5 9 13 17 21 25
DECAPEN bit
set DECAPEN
DECAP bit
set DECAP
C(n)V 1 3 5 7 9 11 15 19 21 23
CH(n)F bit
clear CH(n)F
C(n+1)V 2 4 6 8 10 12 16 20 22 24
CH(n+1)F bit
clear CH(n+1)F
Note
- The commands set DECAPEN, set DECAP, clear CH(n)F, and clear CH(n+1)F are made by the user.
Figure 26-202. Dual Edge Capture – Continuous mode for positive polarity pulse width
measurement
The period measurement can be made in One-Shot Capture mode or Continuous Capture
mode.
The following figure shows an example of the Dual Edge Capture – One-Shot mode used
to measure the period between two consecutive rising edges. The DECAPEN bit selects
the Dual Edge Capture mode, so it remains set. The DECAP bit is set to enable the
measurement of next period. The CH(n)F bit is set when the first rising edge is detected,
that is, the edge selected by ELS(n)B:ELS(n)A bits. The CH(n+1)F bit is set and DECAP
bit is cleared when the second rising edge is detected, that is, the edge selected by ELS(n
+1)B:ELS(n+1)A bits. Both DECAP and CH(n+1)F bits indicate when two selected
edges were captured and the C(n)V and C(n+1)V registers are ready for reading.
4 8 12 16 20 24
3 28
7 11 15 19 23
FTM counter 2 6 27
10 14 18
1 22 26
5 9 13 17 21 25
DECAPEN bit
set DECAPEN
DECAP bit
set DECAP
C(n)V 1 3 5 6 7 14 17 18 20 27
CH(n)F bit
clear CH(n)F
C(n+1)V 2 4 6 7 9 15 18 20 23 26
CH(n+1)F bit
clear CH(n+1)F
Note
- The commands set DECAPEN, set DECAP, clear CH(n)F, and clear CH(n+1)F are made by the user.
- Problem 1: channel (n) input = 0, set DECAP, not clear CH(n)F, and not clear CH(n+1)F.
- Problem 2: channel (n) input = 1, set DECAP, not clear CH(n)F, and clear CH(n+1)F.
- Problem 3: channel (n) input = 1, set DECAP, not clear CH(n)F, and not clear CH(n+1)F.
Figure 26-203. Dual Edge Capture – One-Shot mode to measure of the period between
two consecutive rising edges
The following figure shows an example of the Dual Edge Capture – Continuous mode
used to measure the period between two consecutive rising edges. The DECAPEN bit
selects the Dual Edge Capture mode, so it remains set. While the DECAP bit is set the
configured measurements are made. The CH(n)F bit is set when the first rising edge is
detected, that is, the edge selected by ELS(n)B:ELS(n)A bits. The CH(n+1)F bit is set
when the second rising edge is detected, that is, the edge selected by ELS(n+1)B:ELS(n
+1)A bits. The CH(n+1)F bit indicates when two edges of the period were captured and
the C(n)V and C(n+1)V registers are ready for reading.
4 8 12 16 20 24 28
3 7 11 15 19 23
FTM counter 2 6 10 14
27
18 22 26
1 5 9 13 17 21 25
DECAPEN bit
set DECAPEN
DECAP bit
set DECAP
C(n)V 1 3 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 26
CH(n)F bit
clear CH(n)F
C(n+1)V 2 4 6 7 8 9 10 11 12 13 15 16 17 19 20 21 22 23 24 25 27
CH(n+1)F bit
clear CH(n+1)F
Note
- The commands set DECAPEN, set DECAP, clear CH(n)F, and clear CH(n+1)F are made by the user.
Figure 26-204. Dual Edge Capture – Continuous mode to measure of the period between
two consecutive rising edges
+1) are in Dual Edge Capture – Continuous mode for positive polarity pulse width
measurement. Thus, the channel (n) is configured to capture the FTM counter value when
there is a rising edge at channel (n) input signal, and channel (n+1) to capture the FTM
counter value when there is a falling edge at channel (n) input signal.
When a rising edge occurs in the channel (n) input signal, the FTM counter value is
captured into channel (n) capture buffer. The channel (n) capture buffer value is
transferred to C(n)V register when a falling edge occurs in the channel (n) input signal.
C(n)V register has the FTM counter value when the previous rising edge occurred, and
the channel (n) capture buffer has the FTM counter value when the last rising edge
occurred.
When a falling edge occurs in the channel (n) input signal, the FTM counter value is
captured into channel (n+1) capture buffer. The channel (n+1) capture buffer value is
transferred to C(n+1)V register when the C(n)V register is read.
In the following figure, the read of C(n)V returns the FTM counter value when the event
1 occurred and the read of C(n+1)V returns the FTM counter value when the event 2
occurred.
event 1 event 2 event 3 event 4 event 5 event 6 event 7 event 8 event 9
FTM counter 1 2 3 4 5 6 7 8 9
channel (n) 1 3 5 7 9
capture buffer
C(n)V 1 3 5 7
channel (n+1) 2 4 6 8
capture buffer
C(n+1)V 2
C(n)V register must be read prior to C(n+1)V register in dual edge capture one-shot and
continuous modes for the read coherency mechanism works properly.
Note that if BDMMODE[1:0] = 2’b00 then the channels outputs remain at the value
when the chip enters in Debug mode, because the FTM counter is stopped. However, the
following situations modify the channels outputs in this Debug mode.
• Write any value to CNT register; see Counter reset. In this case, the FTM counter is
updated with the CNTIN register value and the channels outputs are updated to the
initial value – except for those channels set to Output Compare mode.
• FTM counter is reset by PWM Synchronization mode; see FTM counter
synchronization. In this case, the FTM counter is updated with the CNTIN register
value and the channels outputs are updated to the initial value – except for channels
in Output Compare mode.
• In the channels outputs initialization, the channel (n) output is forced to the CH(n)OI
bit value when the value 1 is written to INIT bit. See Initialization.
Note
The BDMMODE[1:0] = 2’b00 must not be used with the Fault
control. Even if the fault control is enabled and a fault condition
exists, the channels outputs values are updated as above.
(a)
(b)
(c)
(d)
(e)
(f)
NOTE
(a) LDOK = 0, CH0SEL = 0, CH1SEL = 0, CH2SEL = 0, CH3SEL = 0, CH4SEL = 0, CH5SEL = 0, CH6SEL = 0, CH7SEL = 0
(b) LDOK = 1, CH0SEL = 0, CH1SEL = 0, CH2SEL = 0, CH3SEL = 0, CH4SEL = 0, CH5SEL = 0, CH6SEL = 0, CH7SEL = 0
(c) LDOK = 0, CH0SEL = 0, CH1SEL = 0, CH2SEL = 0, CH3SEL = 1, CH4SEL = 0, CH5SEL = 0, CH6SEL = 0, CH7SEL = 0
(d) LDOK = 1, CH0SEL = 0, CH1SEL = 0, CH2SEL = 0, CH3SEL = 0, CH4SEL = 0, CH5SEL = 0, CH6SEL = 1, CH7SEL = 0
(e) LDOK = 1, CH0SEL = 1, CH1SEL = 0, CH2SEL = 1, CH3SEL = 0, CH4SEL = 1, CH5SEL = 0, CH6SEL = 1, CH7SEL = 0
(f) LDOK = 1, CH0SEL = 1, CH1SEL = 1, CH2SEL = 1, CH3SEL = 1, CH4SEL = 1, CH5SEL = 1, CH6SEL = 1, CH7SEL = 1
After enabling the loading points, the LDOK bit must be set for the load to occur. In this
case, the load occurs at the next enabled loading point according to the following
conditions:
Table 26-190. Conditions for loads occurring at the next enabled loading point
When a new value was written Then
To the MOD register The MOD register is updated with its write buffer value.
Table 26-190. Conditions for loads occurring at the next enabled loading point (continued)
When a new value was written Then
To the CNTIN register and CNTINC = 1 The CNTIN register is updated with its write buffer value.
To the C(n)V register and SYNCENm = 1 – where m indicates The C(n)V register is updated with its write buffer value.
the pair channels (n) and (n+1)
To the C(n+1)V register and SYNCENm = 1 – where m The C(n+1)V register is updated with its write buffer value.
indicates the pair channels (n) and (n+1)
NOTE
• If ELSjB and ELSjA bits are different from zero, then the
channel (j) output signal is generated according to the
configured output mode. If ELSjB and ELSjA bits are zero,
then the generated signal is not available on channel (j)
output.
• If CHjIE = 1, then the channel (j) interrupt is generated
when the channel (j) match occurs.
• At the intermediate load neither the channels outputs nor
the FTM counter are changed. Software must set the
intermediate load at a safe point in time.
• The intermediate load feature must be used only in
Combine mode.
gtb_in
gtb_in
gtb_out
The GTB functionality is implemented by the GTBEEN and GTBEOUT bits in the
CONF register, the input signal gtb_in, and the output signal gtb_out. The GTBEEN bit
enables gtb_in to control the FTM counter enable signal:
• If GTBEEN = 0, each one of FTM modules works independently according to their
configured mode.
• If GTBEEN = 1, the FTM counter update is enabled only when gtb_in is 1.
In the configuration described in the preceding figure, FTM modules A and B have their
FTM counters enabled if at least one of the gtb_out signals from one of the FTM modules
is 1. There are several possible configurations for the interconnection of the gtb_in and
gtb_out signals, represented by the example glue logic shown in the figure. Note that
these configurations are chip-dependent and implemented outside of the FTM modules.
See the chip configuration details for the chip's specific implementation.
NOTE
• In order to use the GTB signals to synchronize the FTM
counter of different FTM modules, the configuration of
each FTM module should guarantee that its FTM counter
starts counting as soon as the gtb_in signal is 1.
• The GTB feature does not provide continuous
synchronization of FTM counters, meaning that the FTM
counters may lose synchronization during FTM operation.
The GTB feature only allows the FTM counters to start
their operation synchronously.
FTM counter XXXX 0x0000 0x0010 0x0011 0x0012 0x0013 0x0014 0x0015 0x0016 0x0017 0x0018 . . .
CLKS[1:0] XX 00 01
NOTES:
– CNTIN = 0x0010
– Channel (n) is in low-true combine mode with CNTIN < C(n)V < C(n+1)V < MOD
– C(n)V = 0x0015
Figure 26-208. FTM behavior after reset when the channel (n) is in Combine mode
The following figure shows an example when the channel (n) is in Output Compare mode
and the channel (n) output is toggled when there is a match. In the Output Compare
mode, the channel output is not updated to its initial value when there is a write to CNT
register (item 3). In this case, use the software output control (Software output control) or
the initialization (Initialization) to update the channel output to the selected value (item
4).
(4) use of software output control or initialization
to update the channel output to the zero
(3) write any value
(1) FTM reset to CNT register (5) write 1 to SC[CLKS]
FTM counter XXXX 0x0000 0x0010 0x0011 0x0012 0x0013 0x0014 0x0015 0x0016 0x0017 . . .
CLKS[1:0] XX 00 01
NOTES:
– CNTIN = 0x0010
– Channel (n) is in output compare and the channel (n) output is toggled when there is a match
– C(n)V = 0x0014
Figure 26-209. FTM behavior after reset when the channel (n) is in Output Compare
mode
27.1 Introduction
27.1.1 Features
The pulse width timer (PWT) includes the following features:
• Automatic measurement of pulse width with 16-bit resolution
• Separate positive and negative pulse width measurements
• Programmable triggering edge for starting measurement
• Programmable measuring time between successive alternating edges, rising edges or
falling edges
• Programmable prescaler from clock input as 16-bit counter time base
• Two selectable clock sources—bus clock and alternative clock
• Four selectable pulse inputs
• Programmable interrupt generation upon pulse width value updated and counter
overflow
/2 /2 /2 /2 /2 /2 /2
SYNC
ALT_CLK
PRE[2:0]
PCLKS PWTCLK
PWTSR
PWTEN 16 bit free running counter
PWTOV
16
PWT_R2[NPW] PWT_R1[PPW]
PWTIN0 Overflow
PWTIN1 Edge Detect and Capture Control Logic Interrupt
PWTIN2
PWTIN3 PWTIN
PWTRDY
POVIE
PINSEL[1:0] EDGE[1:0]
PWTIE Data
PINEN0
Interrupt
PINEN1
Decode
PRDYIE
PINEN2
PINEN3
NOTE
The PWT_CLK depends on the Chip input clock. For this chip
it is TIMER_CLK.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R PPW
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0
PWTRDY
PRDYIE
PWTOV
PWTEN
PCLKS
PWTIE
POVIE
PINSEL EDGE PRE
PWTSR
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
00 PWTIN[0] is enabled.
01 PWTIN[1] is enabled.
Table continues on the next page...
00 The first falling-edge starts the pulse width measurement, and on all the subsequent falling edges,
the pulse width is captured.
01 The first rising edge starts the pulse width measurement, and on all the subsequent rising and falling
edges, the pulse width is captured.
10 The first falling edge starts the pulse width measurement, and on all the subsequent rising and falling
edges, the pulse width is captured.
11 The first-rising edge starts the pulse width measurement, and on all the subsequent rising edges, the
pulse width is captured.
10–8 PWT Clock Prescaler (CLKPRE) Setting
PRE
Selects the value by which the clock is divided to clock the PWT counter.
0 No action taken.
1 Writing 1 to this field will perform soft reset to PWT.
2 This field is reserved.
Reserved This read-only field is reserved and always has the value 0.
1 PWT Pulse Width Valid
PWTRDY
Indicates that the PWT Pulse Width register(s) has been updated and is ready to be read. This field is
cleared by reading PWTRDY and then writing 0 to PWTRDY bit when PWTRDY is set. Writing 1 to this
field has no effect. PWTRDY setting is associated with the EDGE[1:0] bits.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R PWTC NPW
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
counter would overflow. See the chip configuration chapters to check the slave clock
frequency to PWT. Also, if there isn't any valid edge of the PWTIN width for a long
time, the PWT counter would overflow as well.
When EDGE[1:0] is 00, the first falling edge is the trigger edge from which the pulse
width begins to be measured. The counter value is uploaded to PWT_R1[PPW] upon
each of the subsequent falling edges. When EDGE[1:0] is 11, the first rising edge is the
trigger edge from which the pulse width begins to be measured. The counter value is
uploaded to PWT_R2[NPW] upon each successive rising-edge. In these two cases, the
period of PWTIN is measured.
When EDGE[1:0] is 01, the first rising edge is the trigger edge. The pulse width begins to
be measured from this edge. PWT_R1[PPW] is uploaded upon each of the subsequent
falling edges. PWT_R2[NPW] is uploaded upon each successive rising edge. When
EDGE[1:0] is 10, the first falling edge is the trigger edge from which the pulse width is
measured. PWT_R2[NPW] is uploaded on each successive rising edge and
PWT_R1[PPW] is uploaded on each successive falling edge. In these two cases, the
positive pulse and negative pulse are measured separately and the positive pulse width is
uploaded into PWT_R1[PPW]. The negative pulse width is uploaded into
PWT_R2[NPW].
The following figure illustrates the trigger edge detection and pulse width registers
update of PWT.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Reset
PWTEN
PWTIN
EDGE=00
EDGE=01
Upload counter
to PWTR2[NPW]
Clear the pre-counter. Upload counter
Trigger to measure and start counting up from 0. to PWTR1[PPW]
EDGE=10
Upload counter
to PWTR2[NPW]
EDGE=11
Figure 27-4. Trigger edge detection and pulse width registers update
If another pulse measurement is completed and the pulse width registers are updated, the
clearing of the PWT_R1[PWTRDY] flag fails, that is, PWT_R1[PWTRDY] will still be
set, but the 16-bit read buffer(s) will be updated again as long as the action is cleared..
The user should complete the pulse width data reading before clearing
PWT_R1[PWTRDY] to avoid missing data. This mechanism assures that the second
pulse measurement will not be lost in case the MCU does not have enough time to read
the first one ready for read. The mechanism is automatically restarted by an MCU reset ,
writing 1 to PWT_R1[PWTSR] or writing a 0 to PWT_R1[PWTEN] followed by writing
a 1 to it.
The following figure illustrates the buffering mechanism of pulse width register:
PWTIN CPU BUS
PWTRDY
PPW
Read buffer upload control
Read Data
16-bit Counter
NPW
Buffer of NPW
EDGE[1:0]
When PWT completes any pulse width measurement, a signal is generated to reset
PWT_R2[CNTC] and the clock prescaler output after the data has been uploaded to the
pulse width registers. To assure that there is no missing count, PWT_R2[CNTC] and the
clock prescaler output are reset in a bus clock cycle after the completion of a pulse width
measurement.
27.5 Reset
27.5.1 General
27.6 Interrupts
data ready interrupt can be generated. PWT_R1[PWTIE] controls the interrupt generation
of the PWT module. The functionality of the PWT is not affected while the interrupt is
being generated.
BUSCLK
PWTCLK
PWTCNT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 0
BUSCLK
PWTCLK
PWTCNT 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 1011 0
BUSCLK
PWTCLK
PWTCNT 0 1 2 3 4 5 0 1 2 3 4 5 0
PWTIN
counter read result: 5 pwtclk counter read result: 5 pwtclk
actual pulse width: 5 pwtclk + err actual pulse width: 5 pwtclk + err
BUSCLK
PWTCLK
PWTCNT 0 1 2 0 1 2
28.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The PIT module is an array of timers that can be used to raise interrupts and triggers.
PIT
Peripheral bus
PIT
registers
load_value
Timer 1
Interrupts
Triggers
Timer n
Peripheral
bus clock
NOTE
See the chip configuration details for the number of PIT
channels used in this MCU.
28.1.2 Features
The main features of this block are:
• Ability of timers to generate trigger pulses
• Ability of timers to generate interrupts
• Maskable interrupts
• Independent timeout periods for each timer
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
R 0
MDIS FRZ
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
R TVL
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
NOTE: • If the timer is disabled, do not use this field as its value is unreliable.
• The timer uses a downcounter. The timer values are frozen in Debug mode if MCR[FRZ] is
set.
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 CHN TIE TEN
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 Timer n is disabled.
1 Timer n is enabled.
R 0
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 TIF
W w1c
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
28.4.1.1 Timers
The timers generate triggers at periodic intervals, when enabled. The timers load the start
values as specified in their LDVAL registers, count down to 0 and then load the
respective start value again. Each time a timer reaches 0, it will generate a trigger pulse
and set the interrupt flag.
All interrupts can be enabled or masked by setting TCTRLn[TIE]. A new interrupt can be
generated only after the previous one is cleared.
If desired, the current counter value of the timer can be read via the CVAL registers.
The counter period can be restarted, by first disabling, and then enabling the timer with
TCTRLn[TEN]. See the following figure.
Trigger
event
p1 p1 p1 p1
The counter period of a running timer can be modified, by first disabling the timer,
setting a new load value, and then enabling the timer again. See the following figure.
Timer enabled Disable timer, Re-enable
Start value = p1 Set new load value timer
Trigger
event p2 p2 p2
p1
p1
It is also possible to change the counter period without restarting the timer by writing
LDVAL with the new load value. This value will then be loaded after the next trigger
event. See the following figure.
Timer enabled New start
Start value = p1 Value p2 set
Trigger
event
p1 p1 p1 p2 p2
28.4.2 Interrupts
All the timers support interrupt generation. See the MCU specification for related vector
addresses and priorities.
Timer interrupts can be enabled by setting TCTRLn[TIE]. TFLGn[TIF] are set to 1 when
a timeout occurs on the associated timer, and are cleared to 0 by writing a 1 to the
corresponding TFLGn[TIF].
// turn on PIT
PIT_MCR = 0x00;
// Timer 1
PIT_LDVAL1 = 0x0003E7FF; // setup timer 1 for 256000 cycles
PIT_TCTRL1 = TIE; // enable Timer 1 interrupts
PIT_TCTRL1 |= TEN; // start Timer 1
// Timer 3
PIT_LDVAL3 = 0x0016E35F; // setup timer 3 for 1500000 cycles
PIT_TCTRL3 |= TEN; // start Timer 3
// turn on PIT
PIT_MCR = 0x00;
// Timer 2
PIT_LDVAL2 = 0x00000009; // setup Timer 2 for 10 counts
PIT_TCTRL2 = TIE; // enable Timer 2 interrupt
PIT_TCTRL2 |= CHN; // chain Timer 2 to Timer 1
PIT_TCTRL2 |= TEN; // start Timer 2
// Timer 1
PIT_LDVAL1 = 0x23C345FF; // setup Timer 1 for 600 000 000 cycles
PIT_TCTRL1 = TEN; // start Timer 1
29.1 Introduction
The real-time counter (RTC) consists of one 16-bit counter, one 16-bit comparator,
several binary-based and decimal-based prescaler dividers, three clock sources, one
programmable periodic interrupt, and one programmable external toggle pulse output.
This module can be used for time-of-day, calendar or any task scheduling functions. It
can also serve as a cyclic wake-up from low-power modes, Stop and Wait without the
need of external components.
29.2 Features
Features of the RTC module include:
• 16-bit up-counter
• 16-bit modulo match limit
• Software controllable periodic interrupt on match
• Software selectable clock sources for input to prescaler with programmable 16 bit
prescaler
• OSC 32.768KHz nominal.
• LPO (~1 kHz)
• Bus clock
• Internal reference clock (32 kHz)
RTCMOD
16-bit modulo
16-bit latch
16-bit modulo
1
D Q RTIF
16-bit comparator RTC
EXT CLK R
INTERRUPT
LPO CLK CLOCK REQUEST
16-bit counter
BUS CLK DIVIDER
IRC CLK
RTIE
D Q
OUTPUT
Q
TOGLE
RTC_SC contains the real-time interrupt status flag (RTIF), and the toggle output enable
bit (RTCO).
Address: 4003_D000h base + 0h offset = 4003_D000h
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
R 0
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 0 0
RTCO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
000 Off
001 If RTCLKS = x0, it is 1; if RTCLKS = x1, it is 128.
010 If RTCLKS = x0, it is 2; if RTCLKS = x1, it is 256.
011 If RTCLKS = x0, it is 4; if RTCLKS = x1, it is 512.
100 If RTCLKS = x0, it is 8; if RTCLKS = x1, it is 1024.
101 If RTCLKS = x0, it is 16; if RTCLKS = x1, it is 2048.
110 If RTCLKS = x0, it is 32; if RTCLKS = x1, it is 100.
111 If RTCLKS = x0, it is 64; if RTCLKS = x1, it is 1000.
7 Real-Time Interrupt Flag
RTIF
This status bit indicates the RTC counter register reached the value in the RTC modulo register. Writing a
logic 0 has no effect. Writing a logic 1 clears the bit and the real-time interrupt request. Reset clears RTIF
to 0.
0 RTC counter has not reached the value in the RTC modulo register.
1 RTC counter has reached the value in the RTC modulo register.
6 Real-Time Interrupt Enable
RTIE
This read/write bit enables real-time interrupts. If RTIE is set, then an interrupt is generated when RTIF is
set. Reset clears RTIE to 0.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 MOD
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This read/write field contains the modulo value used to reset the count to 0x0000 upon a compare match
and set SC[RTIF] status field. A value of 0x0000 sets SC[RTIF] on each rising-edge of the prescaler
output. Reset sets the modulo to 0x0000.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0 CNT
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This read-only field contains the current value of the 16-bit counter, read CNT[7:0] first and, then
CNT[15:8]. Writes have no effect to this register. Reset or writing different values to SC[RTCLKS] and
SC[RTCPS] clear the count to 0x0000.
The RTC Modulo register (RTC_MOD) allows the compare value to be set to any value
from 0x0000 to 0xFFFF. When the counter is active, the counter increments at the
selected rate until the count matches the modulo value. When these values match, the
counter resets to 0x0000 and continues counting. The Real-Time Interrupt Flag
(RTC_SC[RTIF]) is set whenever a match occurs. The flag sets on the transition from the
modulo value to 0x0000. The modulo value written to RTC_MOD is latched until the
RTC counter overflows or RTC_SC[RTCPS] is selected nonzero.
The RTC allows for an interrupt to be generated whenever RTC_SC[RTIF] is set. To
enable the real-time interrupt, set the Real-Time Interrupt Enable field (RTC_SC[RTIE]).
RTC_SC[RTIF] is cleared by writing a 1 to RTC_SC[RTIF].
The RTC also allows an output to external pinout by toggling the level. RTC_SC[RTCO]
must be set to enable toggling external pinout. The level depends on the previous state of
the pinout when the counter overflows if this function is active.
OSC (32768Hz)
RTCLKS = 00b
RTC Clock
RTCPS = 001b
RTCCNT
RTCPS = 001b 32765 32766 32767 0 1 2 3 4
RTIF
16-bit modulo 32767 32767 32767 32766 32766 32766 32766 32766
RTCO
In the above example, the external clock source is selected. The prescaler is set to
RTC_SC[RTCPS] = 001b or passthrough. The actual modulo value used by 16-bit
comparator is 32767, when the modulo value in the RTC_MOD register is set to 32766.
When the counter, RTC_CNT, reaches the modulo value of 32767, the counter overflows
to 0x00 and continues counting. The modulo value is updated by fetching from
RTC_MOD register. The real-time interrupt flag, RTC_SC[RTIF], sets when the counter
value changes from 0x7FFF to 0x0000. The RTC_SC[RTCO] toggles as well when the
RTC_SC[RTIF] is set.
/* Configure RTC to interrupt every 1 second from OSC (32.768KHz) clock source */
RTC_MOD = 511; // overflow every 32 times
RTC_SC = RTC_SC_RTCPS_MASK; // external 32768 clock selected with 1/64 predivider.
RTC_SC = RTC_SC_RTIF_MASK | RTC_SC_RTIE_MASK; // interrupt cleared and enabled
/**********************************************************************
Function Name : RTC_ISR
Notes : Interrupt service routine for RTC module.
**********************************************************************/
void RTC_ISR(void)
{
/* Clears the interrupt flag, RTIF, and interrupt request */
RTC_SC |= RTC_SC_RTIF_MASK;
/* 60 seconds in a minute */
if (Seconds > 59)
{
Minutes++;
Seconds = 0;
}
/* 60 minutes in an hour */
if (Minutes > 59)
{
Hours++;
Minutes = 0;
}
/* 24 hours in a day */
if (Hours > 23)
{
Days ++;
Hours = 0;
}
}
30.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The serial peripheral interface (SPI) module provides for full-duplex, synchronous, serial
communication between the MCU and peripheral devices. These peripheral devices can
include other microcontrollers, analog-to-digital converters, shift registers, sensors, and
memories, among others.
The SPI runs at a baud rate up to the bus clock divided by two in master mode and up to
the bus clock divided by four in slave mode. Software can poll the status flags, or SPI
operation can be interrupt driven.
NOTE
For the actual maximum SPI baud rate, refer to the Chip
Configuration details and to the device’s Data Sheet.
SPI pad cannot be configured as high drive pad.
The SPI also includes a hardware match feature for the receive data buffer.
30.1.1 Features
The SPI includes these distinctive features:
• Master mode or slave mode operation
• Full-duplex or single-wire bidirectional mode
MOSI MOSI
MISO MISO
8 BITS 8 BITS
SPSCK SPSCK
CLOCK
GENERATOR
SS SS
bits of data, the data is transferred into the double-buffered receiver where it can be read
from SPIx_D. Pin multiplexing logic controls connections between MCU pins and the
SPI module.
When the SPI is configured as a master, the clock output is routed to the SPSCK pin, the
shifter output is routed to MOSI, and the shifter input is routed from the MISO pin.
When the SPI is configured as a slave, the SPSCK pin is routed to the clock input of the
SPI, the shifter output is routed to MISO, and the shifter input is routed from the MOSI
pin.
In the external SPI system, simply connect all SPSCK pins to each other, all MISO pins
together, and all MOSI pins together. Peripheral devices often use slightly different
names for these pins.
M
MOSI
SPE S (MOMI)
BIDIROE
SHIFT SHIFT Rx BUFFER Tx BUFFER
LSBFE
DIRECTION CLOCK FULL EMPTY
MASTER CLOCK
M
BUS RATE SPIBR CLOCK
CLOCK SPSCK
CLOCK GENERATOR LOGIC SLAVE CLOCK
S
MASTER/SLAVE MASTER/
MSTR
MODE SELECT SLAVE
MOD-
SSOE
MODE FAULT
SS
DETECTION
SPRF
8-BIT COMPARATOR
SPMF
SPIxM SPMIE
SPTEF
SPTIE
INTERRUPT
MODF
REQUEST
SPIE
The SPI has 8-bit registers to select SPI options, to control baud rate, to report SPI status,
to hold an SPI data match value, and for transmit/receive data.
SPI memory map
Absolute
Address Width Section/
address Register name Access Reset value
offset (hex) (in bits) page
(hex)
0 4007_6000 SPI Control Register 1 (SPI0_C1) 8 R/W 04h 30.3.1/505
1 4007_6001 SPI Control Register 2 (SPI0_C2) 8 R/W 00h 30.3.2/507
2 4007_6002 SPI Baud Rate Register (SPI0_BR) 8 R/W 00h 30.3.3/508
3 4007_6003 SPI Status Register (SPI0_S) 8 R 20h 30.3.4/509
5 4007_6005 SPI Data Register (SPI0_D) 8 R/W 00h 30.3.5/510
7 4007_6007 SPI Match Register (SPI0_M) 8 R/W 00h 30.3.6/511
This read/write register includes the SPI enable control, interrupt enables, and
configuration options.
Address: 4007_6000h base + 0h offset = 4007_6000h
Bit 7 6 5 4 3 2 1 0
Read SPIE SPE SPTIE MSTR CPOL CPHA SSOE LSBFE
Write
Reset 0 0 0 0 0 1 0 0
0 First edge on SPSCK occurs at the middle of the first cycle of a data transfer.
1 First edge on SPSCK occurs at the start of the first cycle of a data transfer.
1 Slave Select Output Enable
SSOE
This bit is used in combination with the Mode Fault Enable (MODFEN) field in the C2 register and the
Master/Slave (MSTR) control bit to determine the function of the SS pin.
0 When C2[MODFEN] is 0: In master mode, SS pin function is general-purpose I/O (not SPI). In slave
mode, SS pin function is slave select input.
When C2[MODFEN] is 1: In master mode, SS pin function is SS input for mode fault. In slave mode,
SS pin function is slave select input.
1 When C2[MODFEN] is 0: In master mode, SS pin function is general-purpose I/O (not SPI). In slave
mode, SS pin function is slave select input.
When C2[MODFEN] is 1: In master mode, SS pin function is automatic SS output. In slave mode: SS
pin function is slave select input.
0 LSB First (shifter direction)
LSBFE
This bit does not affect the position of the MSB and LSB in the data register. Reads and writes of the data
register always have the MSB in bit 7.
0 SPI serial data transfers start with the most significant bit.
1 SPI serial data transfers start with the least significant bit.
This read/write register is used to control optional features of the SPI system. Bit 6 is not
implemented and always reads 0.
Address: 4007_6000h base + 1h offset = 4007_6001h
Bit 7 6 5 4 3 2 1 0
Read SPMIE Reserved Reserved MODFEN BIDIROE Reserved SPISWAI SPC0
Write
Reset 0 0 0 0 0 0 0 0
0 Mode fault function disabled, master SS pin reverts to general-purpose I/O not controlled by SPI
1 Mode fault function enabled, master SS pin acts as the mode fault input or the slave select output
3 Bidirectional Mode Output Enable
BIDIROE
When bidirectional mode is enabled because SPI pin control 0 (SPC0) is set to 1, BIDIROE determines
whether the SPI data output driver is enabled to the single bidirectional SPI I/O pin. Depending on whether
the SPI is configured as a master or a slave, it uses the MOSI (MOMI) or MISO (SISO) pin, respectively,
as the single SPI data I/O pin. When SPC0 is 0, BIDIROE has no meaning or effect.
0 SPI uses separate pins for data input and data output (pin mode is normal).
In master mode of operation: MISO is master in and MOSI is master out.
In slave mode of operation: MISO is slave out and MOSI is slave in.
1 SPI configured for single-wire bidirectional operation (pin mode is bidirectional).
In master mode of operation: MISO is not used by SPI; MOSI is master in when BIDIROE is 0 or
master I/O when BIDIROE is 1.
In slave mode of operation: MISO is slave in when BIDIROE is 0 or slave I/O when BIDIROE is 1;
MOSI is not used by SPI.
Use this register to set the prescaler and bit rate divisor for an SPI master. This register
may be read or written at any time.
Address: 4007_6000h base + 2h offset = 4007_6002h
Bit 7 6 5 4 3 2 1 0
This 4-bit field selects one of nine divisors for the SPI baud rate divider. The input to this divider comes
from the SPI baud rate prescaler. Refer to the description of “SPI Baud Rate Generation” for details.
Bit 7 6 5 4 3 2 1 0
Write
Reset 0 0 1 0 0 0 0 0
0 Value in the receive data buffer does not match the value in the M register
1 Value in the receive data buffer matches the value in the M register
Bit 7 6 5 4 3 2 1 0
Read Bits[7:0]
Write
Reset 0 0 0 0 0 0 0 0
This register contains the hardware compare value. When the value received in the SPI
receive data buffer equals this hardware compare value, the SPI Match Flag in the S
register (S[SPMF]) sets.
Address: 4007_6000h base + 7h offset = 4007_6007h
Bit 7 6 5 4 3 2 1 0
Read Bits[7:0]
Write
Reset 0 0 0 0 0 0 0 0
30.4.1 General
The SPI system is enabled by setting the SPI enable (SPE) bit in SPI Control Register 1.
While C1[SPE] is set, the four associated SPI port pins are dedicated to the SPI function
as:
• Slave select (SS)
• Serial clock (SPSCK)
An SPI transfer is initiated in the master SPI device by reading the SPI status register
(SPIx_S) when S[SPTEF] = 1 and then writing data to the transmit data buffer (write to
SPIxD ). When a transfer is complete, received data is moved into the receive data buffer.
The SPIxD register acts as the SPI receive data buffer for reads and as the SPI transmit
data buffer for writes.
The Clock Phase Control (CPHA) and Clock Polarity Control (CPOL) bits in the SPI
Control Register 1 (SPIx_C1) select one of four possible clock formats to be used by the
SPI system. The CPOL bit simply selects a non-inverted or inverted clock. C1[CPHA] is
used to accommodate two fundamentally different protocols by sampling data on odd
numbered SPSCK edges or on even numbered SPSCK edges.
The SPI can be configured to operate as a master or as a slave. When the MSTR bit in
SPI Control Register 1 is set, master mode is selected; when C1[MSTR] is clear, slave
mode is selected.
• If C2[MODFEN] and C1[SSOE] are set, the SS pin is configured as slave select
output. The SS output becomes low during each transmission and is high when
the SPI is in idle state. If C2[MODFEN] is set and C1[SSOE] is cleared, the SS
pin is configured as input for detecting mode fault error. If the SS input becomes
low this indicates a mode fault error where another master tries to drive the
MOSI and SPSCK lines. In this case, the SPI immediately switches to slave
mode by clearing C1[MSTR] and also disables the slave output buffer MISO (or
SISO in bidirectional mode). As a result, all outputs are disabled, and SPSCK,
MOSI and MISO are inputs. If a transmission is in progress when the mode fault
occurs, the transmission is aborted and the SPI is forced into idle state. This
mode fault error also sets the Mode Fault (MODF) flag in the SPI Status Register
(SPIx_S). If the SPI Interrupt Enable bit (SPIE) is set when S[ MODF] gets set,
then an SPI interrupt sequence is also requested. When a write to the SPI Data
Register in the master occurs, there is a half SPSCK-cycle delay. After the delay,
SPSCK is started within the master. The rest of the transfer operation differs
slightly, depending on the clock format specified by the SPI clock phase bit,
CPHA, in SPI Control Register 1 (see SPI clock formats).
Note
A change of C1[CPOL], C1[CPHA], C1[SSOE], C1[LSBFE],
C2[MODFEN], C2[SPC0], C2[BIDIROE] with C2[SPC0] set,
SPPR2-SPPR0 and SPR3-SPR0 in master mode abort a
transmission in progress and force the SPI into idle state. The
remote slave cannot detect this, therefore the master has to
ensure that the remote slave is set back to idle state.
The SS pin is the slave select input. Before a data transmission occurs, the SS pin of
the slave SPI must be low. SS must remain low until the transmission is complete. If
SS goes high, the SPI is forced into an idle state.
The SS input also controls the serial data output pin. If SS is high (not selected), the
serial data output pin is high impedance. If SS is low, the first bit in the SPI Data
Register is driven out of the serial data output pin. Also, if the slave is not selected
(SS is high), then the SPSCK input is ignored and no internal shifting of the SPI shift
register occurs.
Although the SPI is capable of duplex operation, some SPI peripherals are capable of
only receiving SPI data in a slave mode. For these simpler devices, there is no serial
data out pin.
Note
When peripherals with duplex capability are used, take care not
to simultaneously enable two receivers whose serial outputs
drive the same system slave's serial data output line.
As long as no more than one slave device drives the system slave's serial data output line,
it is possible for several slaves to receive the same transmission from a master, although
the master would not receive return information from all of the receiving slaves.
If the CPHA bit in SPI Control Register 1 is clear, odd numbered edges on the SPSCK
input cause the data at the serial data input pin to be latched. Even numbered edges cause
the value previously latched from the serial data input pin to shift into the LSB or MSB
of the SPI shift register, depending on the LSBFE bit.
If C1[CPHA] is set, even numbered edges on the SPSCK input cause the data at the serial
data input pin to be latched. Odd numbered edges cause the value previously latched
from the serial data input pin to shift into the LSB or MSB of the SPI shift register,
depending on C1[LSBFE].
When C1[CPHA] is set, the first edge is used to get the first data bit onto the serial data
output pin. When C1[CPHA] is clear and the SS input is low (slave selected), the first bit
of the SPI data is driven out of the serial data output pin. After the eighth shift, the
transfer is considered complete and the received data is transferred into the SPI Data
register. To indicate transfer is complete, the SPRF flag in the SPI Status Register is set.
Note
A change of the bits C2[BIDIROE] with C2[SPC0] set,
C1[CPOL], C1[CPHA], C1[SSOE], C1[LSBFE],
C2[MODFEN], and C2[SPC0] in slave mode will corrupt a
transmission in progress and must be avoided.
BIT TIME #
(REFERENCE) 1 2 ... 6 7 8
SPSCK
(CPOL = 0)
SPSCK
(CPOL = 1)
SAMPLE IN
(MISO OR MOSI)
MOSI
(MASTER OUT)
MISO
(SLAVE OUT)
SS OUT
(MASTER)
SS IN
(SLAVE)
When C1[CPHA] = 1, the slave begins to drive its MISO output when SS goes to active
low, but the data is not defined until the first SPSCK edge. The first SPSCK edge shifts
the first bit of data from the shifter onto the MOSI output of the master and the MISO
output of the slave. The next SPSCK edge causes both the master and the slave to sample
the data bit values on their MISO and MOSI inputs, respectively. At the third SPSCK
edge, the SPI shifter shifts one bit position which shifts in the bit value that was just
sampled, and shifts the second data bit value out the other end of the shifter to the MOSI
and MISO outputs of the master and slave, respectively.
When C1[CPHA] = 1, the slave's SS input is not required to go to its inactive high level
between transfers. In this clock format, a back-to-back transmission can occur, as
follows:
1. A transmission is in progress.
2. A new data byte is written to the transmit buffer before the in-progress transmission
is complete.
3. When the in-progress transmission is complete, the new, ready data byte is
transmitted immediately.
Between these two successive transmissions, no pause is inserted; the SS pin remains
low.
The following figure shows the clock formats when C1[CPHA] = 0. At the top of the
figure, the eight bit times are shown for reference with bit 1 starting as the slave is
selected (SS IN goes low), and bit 8 ends at the last SPSCK edge. The MSB first and
LSB first lines show the order of SPI data bits depending on the setting in LSBFE. Both
variations of SPSCK polarity are shown, but only one of these waveforms applies for a
specific transfer, depending on the value in CPOL. The SAMPLE IN waveform applies
to the MOSI input of a slave or the MISO input of a master. The MOSI waveform applies
to the MOSI output pin from a master and the MISO waveform applies to the MISO
output from a slave. The SS OUT waveform applies to the slave select output from a
master (provided C2[MODFEN] and C1[SSOE] = 1). The master SS output goes to
active low at the start of the first bit time of the transfer and goes back high one-half
SPSCK cycle after the end of the eighth bit time of the transfer. The SS IN waveform
applies to the slave select input of a slave.
BIT TIME #
(REFERENCE) 1 2 ... 6 7 8
SPSCK
(CPOL = 0)
SPSCK
(CPOL = 1)
SAMPLE IN
(MISO OR MOSI)
MOSI
(MASTER OUT)
MSB FIRST BIT 7 BIT 6 ... BIT 2 BIT 1 BIT 0
LSB FIRST BIT 0 BIT 1 ... BIT 5 BIT 6 BIT 7
MISO
(SLAVE OUT)
SS OUT
(MASTER)
SS IN
(SLAVE)
When C1[CPHA] = 0, the slave begins to drive its MISO output with the first data bit
value (MSB or LSB depending on LSBFE) when SS goes to active low. The first SPSCK
edge causes both the master and the slave to sample the data bit values on their MISO
and MOSI inputs, respectively. At the second SPSCK edge, the SPI shifter shifts one bit
position which shifts in the bit value that was just sampled and shifts the second data bit
value out the other end of the shifter to the MOSI and MISO outputs of the master and
slave, respectively. When C1[CPHA] = 0, the slave's SS input must go to its inactive high
level between transfers.
SPPR2:SPPR1:SPPR0 SPR3:SPR2:SPR1:SPR0
30.4.6.1 SS Output
The SS output feature automatically drives the SS pin low during transmission to select
external devices and drives the SS pin high during idle to deselect external devices. When
the SS output is selected, the SS output pin is connected to the SS input pin of the
external device.
The SS output is available only in master mode during normal SPI operation by asserting
C1[SSOE] and C2[MODFEN] as shown in the description of C1[SSOE].
The mode fault feature is disabled while SS output is enabled.
Note
Be careful when using the SS output feature in a multimaster
system because the mode fault feature is not available for
detecting system errors between masters.
The direction of each serial I/O pin depends on C2[BIDIROE]. If the pin is configured as
an output, serial data from the shift register is driven out on the pin. The same pin is also
the serial input to the shift register.
The SPSCK is an output for the master mode and an input for the slave mode.
SS is the input or output for the master mode, and it is always the input for the slave
mode.
The bidirectional mode does not affect SPSCK and SS functions.
Note
In bidirectional master mode, with the mode fault feature
enabled, both data pins MISO and MOSI can be occupied by
the SPI, though MOSI is normally used for transmissions in
bidirectional mode and MISO is not used by the SPI. If a mode
fault occurs, the SPI is automatically switched to slave mode. In
this case, MISO becomes occupied by the SPI and MOSI is not
used. Consider this scenario if the MISO pin is used for another
purpose.
The mode fault flag is cleared automatically by a read of the SPI Status Register (with
MODF set) followed by a write to SPI Control Register 1. If the mode fault flag is
cleared, the SPI becomes a normal master or slave again.
Note
Care must be taken when expecting data from a master while
the slave is in a Wait mode or a Stop mode where the peripheral
bus clock is stopped but internal logic states are retained. Even
though the shift register continues to operate, the rest of the SPI
is shut down (that is, an SPRF interrupt is not generated until an
exit from Stop or Wait mode). Also, the data from the shift
register is not copied into the SPIx_D registers until after the
slave SPI has exited Wait or Stop mode. An SPRF flag and
SPIx_D copy is only generated if Wait mode is entered or
exited during a transmission. If the slave enters Wait mode in
idle mode and exits Wait mode in idle mode, neither an SPRF
nor a SPIx_D copy occurs.
30.4.9 Reset
The reset values of registers and signals are described in the Memory Map and Register
Descriptions content, which details the registers and their bitfields.
• If a data transmission occurs in slave mode after a reset without a write to SPIx_D,
the transmission consists of "garbage" or the data last received from the master
before the reset.
• Reading from SPIx_D after reset always returns zeros.
30.4.10 Interrupts
The SPI originates interrupt requests only when the SPI is enabled (the SPE bit in the
SPIx_C1 register is set). The following is a description of how the SPI makes a request
and how the MCU should acknowledge that request. The interrupt vector offset and
interrupt priority are chip dependent.
Four flag bits, three interrupt mask bits, and one interrupt vector are associated with the
SPI system. The SPI interrupt enable mask (SPIE) enables interrupts from the SPI
receiver full flag (SPRF) and mode fault flag (MODF). The SPI transmit interrupt enable
mask (SPTIE) enables interrupts from the SPI transmit buffer empty flag (SPTEF). The
SPI match interrupt enable mask bit (SPIMIE) enables interrupts from the SPI match flag
(SPMF). When one of the flag bits is set, and the associated interrupt mask bit is set, a
hardware interrupt request is sent to the CPU. If the interrupt mask bits are cleared,
software can poll the associated flag bits instead of using interrupts. The SPI interrupt
service routine (ISR) should check the flag bits to determine which event caused the
interrupt. The service routine should also clear the flag bit(s) before returning from the
ISR (usually near the beginning of the ISR).
30.4.10.1 MODF
MODF occurs when the master detects an error on the SS pin. The master SPI must be
configured for the MODF feature (see the description of the C1[SSOE] bit). Once MODF
is set, the current transfer is aborted and the master (MSTR) bit in the SPIx_C1 register
resets to 0.
The MODF interrupt is reflected in the status register's MODF flag. Clearing the flag also
clears the interrupt. This interrupt stays active while the MODF flag is set. MODF has an
automatic clearing process that is described in the SPI Status Register.
30.4.10.2 SPRF
SPRF occurs when new data has been received and copied to the SPI receive data buffer.
After SPRF is set, it does not clear until it is serviced. SPRF has an automatic clearing
process that is described in the SPI Status Register details. If the SPRF is not serviced
before the end of the next transfer (that is, SPRF remains active throughout another
transfer), the subsequent transfers are ignored and no new data is copied into the Data
register.
30.4.10.3 SPTEF
SPTEF occurs when the SPI transmit buffer is ready to accept new data.
After SPTEF is set, it does not clear until it is serviced. SPTEF has an automatic clearing
process that is described in the SPI Status Register details.
30.4.10.4 SPMF
SPMF occurs when the data in the receive data buffer is equal to the data in the SPI
Match Register.
1. Update the Control Register 1 (SPIx_C1) to enable the SPI and to control interrupt
enables. This register also sets the SPI as master or slave, determines clock phase and
polarity, and configures the main SPI options.
2. Update the Control Register 2 (SPIx_C2) to enable additional SPI functions such as
the SPI match interrupt feature, the master mode-fault function, and bidirectional
mode output as well as to control and other optional features.
3. Update the Baud Rate Register (SPIx_BR) to set the prescaler and bit rate divisor for
an SPI master.
4. Update the Hardware Match Register (SPIx_M) with the value to be compared to the
receive data register for triggering an interrupt if hardware match interrupts are
enabled.
5. In the master, read SPIx_S while S[SPTEF] = 1, and then write to the transmit data
register (SPIx_D) to begin transfer.
SPIx_C2 = 0x80(%10000000)
Bit 7 SPMIE = 1 SPI hardware match interrupt enabled
Bit 6 = 0 Unimplemented
Bit 5 = 0 Reserved
Bit 4 MODFEN = 0 Disables mode fault function
Bit 3 BIDIROE = 0 SPI data I/O pin acts as input
SPIx_C2 = 0x80(%10000000)
Bit 2 = 0 Reserved
Bit 1 SPISWAI = 0 SPI clocks operate in wait mode
Bit 0 SPC0 = 0 uses separate pins for data input and output
SPIx_BR = 0x00(%00000000)
Bit 7 = 0 Reserved
Bit 6:4 = 000 Sets prescale divisor to 1
Bit 3:0 = 0000 Sets baud rate divisor to 2
SPIx_S = 0x00(%00000000)
Bit 7 SPRF = 0 Flag is set when receive data buffer is full
Bit 6 SPMF = 0 Flag is set when SPIx_M = receive data buffer
Bit 5 SPTEF = 0 Flag is set when transmit data buffer is empty
Bit 4 MODF = 0 Mode fault flag for master mode
Bit 3:0 = 0 Reserved
SPIx_M = 0xXX
Holds bits 0–7 of the hardware match buffer.
SPIx_D = 0xxx
Holds bits 0–7 of the data to be transmitted by the transmit buffer and received by the receive buffer.
RESET
INITIALIZE SPI
SPIxC1 = 0x54
SPIxC2 = 0x80
SPIxBR = 0x00
YES
SPTEF = 1 NO
?
YES
WRITE TO
SPIxD
SPRF = 1 NO
?
YES
READ
SPIxD
SPMF = 1 NO
?
YES
READ SPMF WHILE SET
TO CLEAR FLAG,
THEN WRITE A 1 TO IT
CONTINUE
31.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The inter-integrated circuit (I2C, I2C, or IIC) module provides a method of
communication between a number of devices.
The interface is designed to operate up to 100 kbit/s with maximum bus loading and
timing. The I2C device is capable of operating at higher baud rates, up to a maximum of
clock/20, with reduced bus loading. The maximum communication length and the
number of devices that can be connected are limited by a maximum bus capacitance of
400 pF. The I2C module also complies with the System Management Bus (SMBus)
Specification, version 2.
31.1.1 Features
The I2C module has the following features:
• Compatible with The I2C-Bus Specification
• Multimaster operation
• Software programmable for one of 64 different serial clock frequencies
• Software-selectable acknowledge bit
• Interrupt-driven byte-by-byte data transfer
• Arbitration-lost interrupt with automatic mode switching from master to slave
• Calling address identification interrupt
• START and STOP signal generation and detection
• Repeated START signal generation and detection
• Acknowledge bit generation and detection
Input
Sync
In/Out
START Data
STOP Shift
Arbitration Register
Control
Clock
Control Address
Compare
SCL SDA
This section describes in detail all I2C registers accessible to the end user.
I2C memory map
Absolute
Width Section/
address Register name Access Reset value
(in bits) page
(hex)
4006_6000 I2C Address Register 1 (I2C0_A1) 8 R/W 00h 31.3.1/532
4006_6001 I2C Frequency Divider register (I2C0_F) 8 R/W 00h 31.3.2/533
4006_6002 I2C Control Register 1 (I2C0_C1) 8 R/W 00h 31.3.3/534
4006_6003 I2C Status register (I2C0_S) 8 R/W 80h 31.3.4/535
4006_6004 I2C Data I/O register (I2C0_D) 8 R/W 00h 31.3.5/537
4006_6005 I2C Control Register 2 (I2C0_C2) 8 R/W 00h 31.3.6/538
4006_6006 I2C Programmable Input Glitch Filter register (I2C0_FLT) 8 R/W 00h 31.3.7/539
4006_6007 I2C Range Address register (I2C0_RA) 8 R/W 00h 31.3.8/540
4006_6008 I2C SMBus Control and Status register (I2C0_SMB) 8 R/W 00h 31.3.9/541
31.3.10/
4006_6009 I2C Address Register 2 (I2C0_A2) 8 R/W C2h
542
31.3.11/
4006_600A I2C SCL Low Timeout Register High (I2C0_SLTH) 8 R/W 00h
543
31.3.12/
4006_600B I2C SCL Low Timeout Register Low (I2C0_SLTL) 8 R/W 00h
543
Bit 7 6 5 4 3 2 1 0
Read 0
AD[7:1]
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read MULT ICR
Write
Reset 0 0 0 0 0 0 0 0
00 mul = 1
01 mul = 2
10 mul = 4
11 Reserved
ICR ClockRate
Prescales the I2C module clock for bit rate selection. This field and the MULT field determine the I2C baud
rate, the SDA hold time, the SCL start hold time, and the SCL stop hold time. For a list of values
corresponding to each ICR setting, see I2C divider and hold values.
The SCL divider multiplied by multiplier factor (mul) determines the I2C baud rate.
I2C baud rate = I2C module clock speed (Hz)/(mul × SCL divider)
The SDA hold time is the delay from the falling edge of SCL (I2C clock) to the changing of SDA (I2C data).
SDA hold time = I2C module clock period (s) × mul × SDA hold value
The SCL start hold time is the delay from the falling edge of SDA (I2C data) while SCL is high (start
condition) to the falling edge of SCL (I2C clock).
SCL start hold time = I2C module clock period (s) × mul × SCL start hold value
The SCL stop hold time is the delay from the rising edge of SCL (I2C clock) to the rising edge of SDA (I2C
data) while SCL is high (stop condition).
SCL stop hold time = I2C module clock period (s) × mul × SCL stop hold value
For example, if the I2C module clock speed is 8 MHz, the following table shows the possible hold time
values with different ICR and MULT selections to achieve an I2C baud rate of 100 kbit/s.
Table continues on the next page...
Bit 7 6 5 4 3 2 1 0
Read 0 0
IICEN IICIE MST TX TXAK WUEN
Write RSTA
Reset 0 0 0 0 0 0 0 0
0 Disabled
1 Enabled
6 I2C Interrupt Enable
IICIE
Enables I2C interrupt requests.
0 Disabled
1 Enabled
5 Master Mode Select
MST
When MST is changed from 0 to 1, a START signal is generated on the bus and master mode is selected.
When this bit changes from 1 to 0, a STOP signal is generated and the mode of operation changes from
master to slave.
0 Slave mode
1 Master mode
4 Transmit Mode Select
TX
Table continues on the next page...
0 Receive
1 Transmit
3 Transmit Acknowledge Enable
TXAK
Specifies the value driven onto the SDA during data acknowledge cycles for both master and slave
receivers. The value of SMB[FACK] affects NACK/ACK generation.
0 An acknowledge signal is sent to the bus on the following receiving byte (if FACK is cleared) or the
current receiving byte (if FACK is set).
1 No acknowledge signal is sent to the bus on the following receiving data byte (if FACK is cleared) or
the current receiving data byte (if FACK is set).
2 Repeat START
RSTA
Writing 1 to this bit generates a repeated START condition provided it is the current master. This bit will
always be read as 0. Attempting a repeat at the wrong time results in loss of arbitration.
1 Wakeup Enable
WUEN
The I2C module can wake the MCU from low power mode with no peripheral bus running when slave
address matching occurs.
0 Normal operation. No interrupt generated when address matching in low power mode.
1 Enables the wakeup function in low power mode.
0 This field is reserved.
Reserved This read-only field is reserved and always has the value 0.
Bit 7 6 5 4 3 2 1 0
IAAS sets before the ACK bit. The CPU must check the SRW bit and set TX/RX accordingly. Writing the
C1 register with any value clears this bit.
0 Not addressed
1 Addressed as a slave
5 Bus Busy
BUSY
Indicates the status of the bus regardless of slave or master mode. This bit is set when a START signal is
detected and cleared when a STOP signal is detected.
0 Bus is idle
1 Bus is busy
4 Arbitration Lost
ARBL
This bit is set by hardware when the arbitration procedure is lost. The ARBL bit must be cleared by
software, by writing 1 to it.
0 Not addressed
1 Addressed as a slave
2 Slave Read/Write
SRW
When addressed as a slave, SRW indicates the value of the R/W command bit of the calling address sent
to the master.
NOTE: To clear the I2C bus stop or start detection interrupt: In the interrupt service
routine, first clear the STOPF or STARTF bit in the Input Glitch Filter register by
writing 1 to it, and then clear the IICIF bit. If this sequence is reversed, the IICIF
bit is asserted again.
0 No interrupt pending
1 Interrupt pending
0 Receive Acknowledge
RXAK
0 Acknowledge signal was received after the completion of one byte of data transmission on the bus
1 No acknowledge signal detected
Bit 7 6 5 4 3 2 1 0
Read DATA
Write
Reset 0 0 0 0 0 0 0 0
In master transmit mode, when data is written to this register, a data transfer is initiated. The most
significant bit is sent first. In master receive mode, reading this register initiates receiving of the next byte
of data.
NOTE: When making the transition out of master receive mode, switch the I2C mode before reading the
Data register to prevent an inadvertent initiation of a master receive data transfer.
In slave mode, the same functions are available after an address match occurs.
The C1[TX] bit must correctly reflect the desired direction of transfer in master and slave modes for the
transmission to begin. For example, if the I2C module is configured for master transmit but a master
receive is desired, reading the Data register does not initiate the receive.
Reading the Data register returns the last byte received while the I2C module is configured in master
receive or slave receive mode. The Data register does not reflect every byte that is transmitted on the I2C
bus, and neither can software verify that a byte has been written to the Data register correctly by reading it
back.
Bit 7 6 5 4 3 2 1 0
Read 0
GCAEN ADEXT SBRC RMEN AD[10:8]
Write
Reset 0 0 0 0 0 0 0 0
0 Disabled
1 Enabled
6 Address Extension
ADEXT
Controls the number of bits used for the slave address.
0 The slave baud rate follows the master baud rate and clock stretching may occur
1 Slave baud rate is independent of the master baud rate
3 Range Address Matching Enable
RMEN
This bit controls the slave address matching for addresses between the values of the A1 and RA registers.
When this bit is set, a slave address matching occurs for any address greater than the value of the A1
register and less than or equal to the value of the RA register.
0 Range mode disabled. No address matching occurs for an address within the range of values of the
A1 and RA registers.
1 Range mode enabled. Address matching occurs when a slave receives an address within the range of
values of the A1 and RA registers.
AD[10:8] Slave Address
Table continues on the next page...
Bit 7 6 5 4 3 2 1 0
If the SHEN bit is set to 1 and the I2C module is in an idle or disabled state when the MCU signals to enter
stop mode, the module immediately acknowledges the request to enter stop mode.
If SHEN is cleared to 0 and the overall data transmission or reception that was suspended by stop mode
entry was incomplete: To resume the overall transmission or reception after the MCU exits stop mode,
software must reinitialize the transfer by resending the address of the slave.
If the I2C Control Register 1's IICIE bit was set to 1 before the MCU entered stop mode, system software
will receive the interrupt triggered by the I2C Status Register's TCF bit after the MCU wakes from the stop
mode.
0 Stop holdoff is disabled. The MCU's entry to stop mode is not gated.
1 Stop holdoff is enabled.
6 I2C Bus Stop Detect Flag
STOPF
Hardware sets this bit when the I2C bus's stop status is detected. The STOPF bit must be cleared by
writing 1 to it.
Controls the width of the glitch, in terms of I2C module clock cycles, that the filter must absorb. For any
glitch whose size is less than or equal to this width setting, the filter does not allow the glitch to pass.
0h No filter/bypass
1-Fh Filter glitches up to width of n I2C module clock cycles, where n=1-15d
Bit 7 6 5 4 3 2 1 0
Read 0
RAD
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
NOTE: After the host responds to a device that used the alert response address, you must use software
to put the device's address on the bus. The alert protocol is described in the SMBus specification.
NOTE: The low timeout function is disabled when the SLT register's value is 0.
Bit 7 6 5 4 3 2 1 0
Read 0
SAD
Write
Reset 1 1 0 0 0 0 1 0
Bit 7 6 5 4 3 2 1 0
Read
SSLT[15:8]
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read SSLT[7:0]
Write
Reset 0 0 0 0 0 0 0 0
All devices connected to it must have open drain or open collector outputs. A logic AND
function is exercised on both lines with external pull-up resistors. The value of these
resistors depends on the system.
Normally, a standard instance of communication is composed of four parts:
1. START signal
2. Slave address transmission
3. Data transfer
4. STOP signal
The STOP signal should not be confused with the CPU STOP instruction. The following
figure illustrates I2C bus system communication.
SDA AD7 AD6 AD5 AD4 AD3 AD2 AD1 R/W XXX D7 D6 D5 D4 D3 D2 D1 D0
SDA AD7 AD6 AD5 AD4 AD3 AD2 AD1 R/W XX AD7 AD6 AD5 AD4 AD3 AD2 AD1 R/W
Start Calling Address Read/ Ack Repeated New Calling Address No Stop
Read/
Signal Bit Start Ack Signal
Write Write
Signal Bit
SCL2
SCL1
SCL
31.4.1.8 Handshaking
The clock synchronization mechanism can be used as a handshake in data transfers. A
slave device may hold SCL low after completing a single byte transfer (9 bits). In this
case, it halts the bus clock and forces the master clock into wait states until the slave
releases SCL.
low period, the resulting SCL bus signal's low period is stretched. In other words, the
SCL bus signal's low period is increased to be the same length as the slave's SCL low
period.
After the master-transmitter has sent the first byte of the 10-bit address, the slave-receiver
sees an I2C interrupt. User software must ensure that for this interrupt, the contents of the
Data register are ignored and not treated as valid data.
After the master-receiver has sent the first byte of the 10-bit address, the slave-transmitter
sees an I2C interrupt. User software must ensure that for this interrupt, the contents of the
Data register are ignored and not treated as valid data.
• AD[7:1] in Address Register 1, which contains the I2C primary slave address, always
participates in the address matching process. It provides a 7-bit address.
• If the ADEXT bit is set, AD[10:8] in Control Register 2 participates in the address
matching process. It extends the I2C primary slave address to a 10-bit address.
Additional conditions that affect address matching include:
• If the GCAEN bit is set, general call participates the address matching process.
• If the ALERTEN bit is set, alert response participates the address matching process.
• If the SIICAEN bit is set, Address Register 2 participates in the address matching
process.
• If the RMEN bit is set, when the Range Address register is programmed to a nonzero
value, any address within the range of values of Address Register 1 (excluded) and
the Range Address register (included) participates in the address matching process.
The Range Address register must be programmed to a value greater than the value of
Address Register 1.
When the I2C module responds to one of these addresses, it acts as a slave-receiver and
the IAAS bit is set after the address cycle. Software must read the Data register after the
first byte transfer to determine that the address is matched.
31.4.4.1 Timeouts
The TTIMEOUT,MIN parameter allows a master or slave to conclude that a defective device
is holding the clock low indefinitely or a master is intentionally trying to drive devices
off the bus. The slave device must release the bus (stop driving the bus and let SCL and
SDA float high) when it detects any single clock held low longer than TTIMEOUT,MIN.
Devices that have detected this condition must reset their communication and be able to
receive a new START condition within the timeframe of TTIMEOUT,MAX.
SMBus defines a clock low timeout, TTIMEOUT, of 35 ms, specifies TLOW:SEXT as the
cumulative clock low extend time for a slave device, and specifies TLOW:MEXT as the
cumulative clock low extend time for a master device.
ClkAck ClkAck
T LOW:MEXT T LOW:MEXT T LOW:MEXT
SCL
SDA
A master is allowed to abort the transaction in progress to any slave that violates the
TLOW:SEXT or TTIMEOUT,MIN specifications. To abort the transaction, the master issues a
STOP condition at the conclusion of the byte transfer in progress. When a slave, the I2C
module must not cumulatively extend its clock cycles for a period greater than
TLOW:SEXT during any message from the initial START to the STOP. When CSMBCLK
TIMEOUT SEXT occurs, SEXT rises and also triggers SLTF.
NOTE
CSMBCLK TIMEOUT SEXT and CSMBCLK TIMEOUT
MEXT are optional functions that are implemented in the
second step.
have the ability to generate the not acknowledge after the transfer of each byte and before
the completion of the transaction. This requirement is important because SMBus does not
provide any other resend signaling. This difference in the use of the NACK signaling has
implications on the specific implementation of the SMBus port, especially in devices that
handle critical system data such as the SMBus host and the SBS components.
NOTE
In the last byte of master receive slave transmit mode, the
master must send a NACK to the bus, so FACK must be
switched off before the last byte transmits.
31.4.5 Resets
The I2C module is disabled after a reset. The I2C module cannot cause a core reset.
31.4.6 Interrupts
The I2C module generates an interrupt when any of the events in the table found here
occur, provided that the IICIE bit is set.
The interrupt is driven by the IICIF bit (of the I2C Status Register) and masked with the
IICIE bit (of the I2C Control Register 1). The IICIF bit must be cleared (by software) by
writing 1 to it in the interrupt routine. The SMBus timeouts interrupt is driven by SLTF
and masked with the IICIE bit. The SLTF bit must be cleared by software by writing 1 to
it in the interrupt routine. You can determine the interrupt type by reading the Status
Register.
NOTE
In master receive mode, the FACK bit must be set to zero
before the last byte transfer.
Table 31-31. Interrupt summary
Interrupt source Status Flag Local enable
Complete 1-byte transfer TCF IICIF IICIE
Match of received calling address IAAS IICIF IICIE
Arbitration lost ARBL IICIF IICIE
I2C bus stop detection STOPF IICIF IICIE & SSIE
I2C bus start detection STARTF IICIF IICIE & SSIE
SMBus SCL low timeout SLTF IICIF IICIE
SMBus SCL high SDA low timeout SHTF2 IICIF IICIE & SHTF2IE
Wakeup from stop or wait mode IAAS IICIF IICIE & WUEN
2. SDA is sampled as low when the master drives high during the acknowledge bit of a
data receive cycle.
3. A START cycle is attempted when the bus is busy.
4. A repeated START cycle is requested in slave mode.
5. A STOP condition is detected when the master did not request it.
The routine shown in the following figure encompasses both master and slave I2C
operations. For slave operation, an incoming I2C message that contains the proper
address begins I2C communication. For master operation, communication must be
initiated by writing the Data register. An example of an I2C driver which implements
many of the steps described here is available in AN4342: Using the Inter-Integrated
Circuit on ColdFire+ and Kinetis .
Clear IICIF
Y N
Master
mode?
Tx Rx Y Arbitration
Tx/Rx?
lost?
Last byte Y
Clear ARBL N
transmitted?
N Y N Y
Last byte
RXAK=0? IIAAS=1? IIAAS=1?
to be read?
Y N Y N Data transfer
Address transfer see note 2
Y see note 1
Y End of Y 2nd to Rx
(read)
address cycle last byte to be SRW=1? Tx/Rx?
(master Rx)? read?
N N N (write) Tx
Y
Write next Generate stop ACK from
byte to Data reg Set TXACK signal (MST=0) Set TX mode
receiver?
Switch to Switch to
Set Rx mode
Rx mode Rx mode
RTI
Notes:
1. If general call is enabled, check to determine if the received address is a general call address (0x00).
If the received address is a general call address, the general call must be handled by user software.
2. When 10-bit addressing addresses a slave, the slave sees an interrupt following the first byte of the extended address.
Ensure that for this interrupt, the contents of the Data register are ignored and not treated as a valid data transfer.
Entry of ISR
Y SLTF=1 or
SHTF2=1?
Clear IICIF Y
Y N
Master
mode?
Tx Rx Y Arbitration
Tx/Rx?
lost?
Y Y
Last byte Last byte N
Clear ARBL
transmitted? to be read?
N N
Y 2nd to
N last byte to be N Y
RXAK=0? read? IAAS=1? IAAS=1?
N
Y Y N
Read data from Address transfer
Data reg (see note 1)
and soft CRC Y
Y End of (read)
address cycle Read data and SRW=1? Tx/Rx?
(master Rx)? Rx
Soft CRC
N N (write) Tx
Set TXAK to
proper value
RTI
Notes:
1. If general call or SIICAEN is enabled, check to determine if the received address is a general call address (0x00) or an SMBus
device default address. In either case, they must be handled by user software.
2. In receive mode, one bit time delay may be needed before the first and second data reading, to wait for the possible longest time
period (in worst case) of the 9th SCL cycle.
3. This read is a dummy read in order to reset the SMBus receiver state machine.
32.1 Introduction
32.1.1 Features
Features of UART module include:
• Full-duplex, standard non-return-to-zero (NRZ) format
• Double-buffered transmitter and receiver with separate enables
• Programmable baud rates (13-bit modulo divider)
• Interrupt-driven or polled operation:
• Transmit data register empty and transmission complete
• Receive data register full
• Receive overrun, parity error, framing error, and noise error
• Idle receiver detect
• Active edge on receive pin
• Break detect supporting LIN
• Hardware parity generation and checking
• Programmable 8-bit or 9-bit character length
• Programmable 1-bit or 2-bit stop bits
• Receiver wakeup by idle-line or address-mark
• Optional 13-bit break character generation / 11-bit break character detection
• Selectable transmitter output polarity
(Write-Only)
LOOPS
UART_D – Tx Buffer RSRC
Loop
To Receive
11-BIT Transmit Shift Register Control
M Data In
Start
Stop
H 8 7 6 5 4 3 2 1 0 L To TxD Pin
1 Baud
Rate Clock
lsb
SHIFT DIRECTION
TXINV
Load From UARTx_D
T8
PE Parity
Generation
PT
SBK TO TxD
Transmit Control
TxD Direction Pin Logic
TXDIR
BRK13
TDRE
TIE
Tx Interrupt
TC
Request
TCIE
Internal Bus
(Read-only)
16 x Baud
Divide
Rate Clock UART_D – Rx Buffer
By 16
From
Transmitter
11-Bit Receive Shift Register
LOOPS
Start
Single-Wire
Stop
M
lsb
Loop Control
RSRC
LBKDE H 8 7 6 5 4 3 2 1 0 L
From RxD Pin
All 1s
msb
RXINV Data Recovery Shift Direction
WAKE Wakeup
RWU RWUID
ILT Logic
RDRF
RIE
IDLE
ILIE
Rx Interrupt
Request
LBKDIF
LBKDIE
From RxD Pin
Active Edge
RXEDGIF
Detect
RXEDGIE
OR
ORIE
FE
FEIE
Error Interrupt
Request
NF
NEIE
PE Parity
PF
PT
Checking
PEIE
This register, along with UART_BDL, controls the prescale divisor for UART baud rate
generation. To update the 13-bit baud rate setting SBR[12:0], first write to UART_BDH
to buffer the high half of the new value and then write to UART_BDL. The working
value in UART_BDH does not change until UART_BDL is written.
Address: 4006_A000h base + 0h offset = 4006_A000h
Bit 7 6 5 4 3 2 1 0
Read LBKDIE RXEDGIE SBNS SBR
Write
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
Read SBR
Write
Reset 0 0 0 0 0 1 0 0
These 13 bits in SBR[12:0] are referred to collectively as BR, which set the modulo divide rate for the
UART baud rate generator. When BR is cleared, the UART baud rate generator is disabled to reduce
supply current. When BR is 1 - 8191, the UART baud rate equals BUSCLK/(16×BR).
This read/write register controls various optional features of the UART system.
Address: 4006_A000h base + 2h offset = 4006_A002h
Bit 7 6 5 4 3 2 1 0
Read LOOPS UARTSWAI RSRC M WAKE ILT PE PT
Write
Reset 0 0 0 0 0 0 0 0
0 Provided LOOPS is set, RSRC is cleared, selects internal loop back mode and the UART does not
use the RxD pins.
1 Single-wire UART mode where the TxD pin is connected to the transmitter output and receiver input.
4 9-Bit or 8-Bit Mode Select
M
This field configures the UART to be operated in 9-bit or 8-bit data mode.
0 Idle-line wake-up.
1 Address-mark wake-up.
2 Idle Line Type Select
ILT
Setting this field to 1 ensures that the stop bits and logic 1 bits at the end of a character do not count
toward the 10 or 11 bit times of logic high level needed by the idle line detection logic.
0 Even parity.
1 Odd parity.
Bit 7 6 5 4 3 2 1 0
Read TIE TCIE RIE ILIE TE RE RWU SBK
Write
Reset 0 0 0 0 0 0 0 0
0 Receiver off.
1 Receiver on.
1 Receiver Wakeup Control
RWU
A 1 can be written to this field to place the UART receiver in a standby state where it waits for automatic
hardware detection of a selected wake-up condition. The wake-up condition is an idle line between
messages, WAKE = 0, idle-line wake-up, or a logic 1 in the most significant data bit in a character, WAKE
= 1, address-mark wake-up. Application software sets RWU and, normally, a selected hardware condition
automatically clears RWU.
Bit 7 6 5 4 3 2 1 0
Write
Reset 1 1 0 0 0 0 0 0
0 No overrun.
1 Receive overrun (new UART data lost).
2 Noise Flag
NF
The advanced sampling technique used in the receiver takes seven samples during the start bit and three
samples in each data bit and the stop bits. If any of these samples disagrees with the rest of the samples
within any bit time in the frame, the flag NF is set at the same time as RDRF is set for the character. To
clear NF, read UART_S1 and then read the UART data register (UART_D).
Table continues on the next page...
0 No framing error detected. This does not guarantee the framing is correct.
1 Framing error.
0 Parity Error Flag
PF
PF is set at the same time as RDRF when parity is enabled (PE = 1) and the parity bit in the received
character does not agree with the expected parity value. To clear PF, read UART_S1 and then read the
UART data register (UART_D).
0 No parity error.
1 Parity error.
Bit 7 6 5 4 3 2 1 0
Read 0 RAF
LBKDIF RXEDGIF RXINV RWUID BRK13 LBKDE
Write
Reset 0 0 0 0 0 0 0 0
NOTE: Setting RXINV inverts the RxD input for all cases: data bits, start and stop bits, break, and idle.
0 During receive standby state (RWU = 1), S1[IDLE] does not get set upon detection of an idle
character.
1 During receive standby state (RWU = 1), S1[IDLE] gets set upon detection of an idle character.
2 Break Character Generation Length
BRK13
BRK13 selects a longer transmitted break character length. Detection of a framing error is not affected by
the state of this field.
0 Break character is transmitted with length of 10 bit times (if M = 0, SBNS = 0) or 11 (if M = 1, SBNS =
0 or M = 0, SBNS = 1) or 12 (if M = 1, SBNS = 1).
1 Break character is transmitted with length of 13 bit times (if M = 0, SBNS = 0) or 14 (if M = 1, SBNS =
0 or M = 0, SBNS = 1) or 15 (if M = 1, SBNS = 1).
1 LIN Break Detection Enable
LBKDE
LBKDE enables the break detection. While LBKDE is set, S1[FE] and S1[RDRF] flags are prevented from
setting.
Bit 7 6 5 4 3 2 1 0
Read R8
T8 TXDIR TXINV ORIE NEIE FEIE PEIE
Write
Reset 0 0 0 0 0 0 0 0
NOTE: Setting TXINV inverts the TxD output for all cases: data bits, start and stop bits, break, and idle.
This register is actually two separate registers. Reads return the contents of the read-only
receive data buffer and writes go to the write-only transmit data buffer. Reads and writes
of this register are also involved in the automatic flag clearing mechanisms for the UART
status flags.
Address: 4006_A000h base + 7h offset = 4006_A007h
Bit 7 6 5 4 3 2 1 0
Read R7T7 R6T6 R5T5 R4T4 R3T3 R2T2 R1T1 R0T0
Write
Reset 0 0 0 0 0 0 0 0
Divide By
16 Tx Baud Rate
UART Module Clock SBR[12:0]
UART communications require the transmitter and receiver, which typically derive baud
rates from independent clock sources, to use the same baud rate. Allowed tolerance on
this baud frequency depends on the details of how the receiver synchronizes to the
leading edge of the start bit and how bit sampling is performed.
The MCU resynchronizes to bit boundaries on every high-to-low transition. In the worst
case, there are no such transitions in the full 10- or 11-bit or 12-bittime character frame
so any mismatch in baud rate is accumulated for the whole character time. For a
Freescale UART system whose bus frequency is driven by a crystal, the allowed baud
rate mismatch is about ±4.5 percent for 8-bit data format and about ±4 percent for 9-bit
data format. Although baud rate modulo divider settings do not always produce baud
rates that exactly match standard rates, it is normally possible to get within a few percent,
which is acceptable for reliable communications.
during the bit time. In the case of the start bit, the bit is assumed to be 0 if at least two of
the samples at UART_D[RT3], UART_D[RT5], and UART_D[RT7] are 0 even if one or
all of the samples taken at UART_D[RT8], UART_D[RT9], and UART_D[RT10] are 1s.
If any sample in any bit time, including the start and stop bits, in a character frame fails to
agree with the logic level for that bit, the noise flag (UART_S1[NF]) is set when the
received character is transferred to the receive data buffer.
The falling edge detection logic continuously looks for falling edges. If an edge is
detected, the sample clock is resynchronized to bit times. This improves the reliability of
the receiver in the presence of noise or mismatched baud rates. It does not improve worst
case analysis because some characters do not have any extra falling edges anywhere in
the character frame.
In the case of a framing error, provided the received character was not a break character,
the sampling logic that searches for a falling edge is filled with three logic 1 samples so
that a new start bit can be detected almost immediately.
In the case of a framing error, the receiver is inhibited from receiving any new characters
until the framing error flag is cleared. The receive shift register continues to function, but
a complete character cannot transfer to the receive data buffer if UART_S1[FE] remains
set.
UART_BDH[SBNS] selects 1-bit or 2-bit stop bit number that determines how many bit
times of idle are needed to constitute a full character time, 10 or 11 or 12 bit times
because of the start and stop bits.
When UARTI_C2[RWU] is 1 and UART_S2[RWUID] is 0, the idle condition that wakes
up the receiver does not set UART_S1[IDLE]. The receiver wakes up and waits for the
first data character of the next message that sets UART_S1[RDRF] and generates an
interrupt, if enabled. When UART_S2[RWUID] is 1, any idle condition sets
UART_S1[IDLE] flag and generates an interrupt if enabled, regardless of whether
UART_C2[RWU] is 0 or 1.
The idle-line type (UART_C1[ILT]) control bit selects one of two ways to detect an idle
line. When UART_C1[ILT] is cleared, the idle bit counter starts after the start bit so the
stop bit and any logic 1s at the end of a character count toward the full character time of
idle. When UART_C1[ILT] is set, the idle bit counter does not start until after a stop bit
time, so the idle detection is not affected by the data in the last character of the previous
message.
The UART transmitter has two status flags that can optionally generate hardware
interrupt requests. Transmit data register empty (UART_S1[TDRE]) indicates when there
is room in the transmit data buffer to write another transmit character to UART_D. If the
transmit interrupt enable (UART_C2[TIE]) bit is set, a hardware interrupt is requested
when UART_S1[TDRE] is set. Transmit complete (UART_S1[TC]) indicates that the
transmitter is finished transmitting all data, preamble, and break characters and is idle
with TxD at the inactive level. This flag is often used in systems with modems to
determine when it is safe to turn off the modem. If the transmit complete interrupt enable
(UART_C2[TCIE]) bit is set, a hardware interrupt is requested when UART_S1[TC] is
set. Instead of hardware interrupts, software polling may be used to monitor the
UART_S1[TDRE] and UART_S1[TC] status flags if the corresponding UART_C2[TIE]
or UART_C2[TCIE] local interrupt masks are cleared.
When a program detects that the receive data register is full (UART_S1[RDRF] = 1), it
gets the data from the receive data register by reading UART_D. The UART_S1[RDRF]
flag is cleared by reading UART_S1 while UART_S1[RDRF] is set and then reading
UART_D.
When polling is used, this sequence is naturally satisfied in the normal course of the user
program. If hardware interrupts are used, UART_S1 must be read in the interrupt service
routine (ISR). Normally, this is done in the ISR anyway to check for receive errors, so the
sequence is automatically satisfied.
The IDLE status flag includes logic that prevents it from getting set repeatedly when the
RxD line remains idle for an extended period of time. IDLE is cleared by reading
UART_S1 while UART_S1[IDLE] is set and then reading UART_D. After
UART_S1[IDLE] has been cleared, it cannot become set again until the receiver has
received at least one new character and has set UART_S1[RDRF].
If the associated error was detected in the received character that caused
UART_S1[RDRF] to be set, the error flags - noise flag (UART_S1[NF]), framing error
(UART_S1[FE]), and parity error flag (UART_S1[PF]) - are set at the same time as
UART_S1[RDRF]. These flags are not set in overrun cases.
If UART_S1[RDRF] was already set when a new character is ready to be transferred
from the receive shifter to the receive data buffer, the overrun (UART_S1[OR]) flag is
set instead of the data along with any associated NF, FE, or PF condition is lost.
At any time, an active edge on the RxD serial data input pin causes the
UART_S2[RXEDGIF] flag to set. The UART_S2[RXEDGIF] flag is cleared by writing a
1 to it. This function depends on the receiver being enabled (UART_C2[RE] = 1).
MSB STOP
RECEIVER
RT CLOCK
RT1
RT2
RT3
RT4
RT5
RT6
RT7
RT8
RT9
RT10
RT11
RT12
RT13
RT14
RT15
RT16
DATA
SAMPLES
For an 8-bit data and 1 stop bit character, data sampling of the stop bit takes the receiver
9 bit times x 16 RT cycles +10 RT cycles =154 RT cycles.
With the misaligned character shown in Figure 32-20, the receiver counts 154 RT cycles
at the point when the count of the transmitting device is 9 bit times x 16 RT cycles + 3
RT cycles = 147 RT cycles.
The maximum percent difference between the receiver count and the transmitter count of
a slow 8-bit data and 1 stop bit character with no errors is:
((154 - 147) / 154) x 100 = 4.54%
For a 9-bit data or 2 stop bits character, data sampling of the stop bit takes the receiver 10
bit times x 16 RT cycles + 10 RT cycles = 170 RT cycles.
With the misaligned character shown in Figure 32-20, the receiver counts 170 RT cycles
at the point when the count of the transmitting device is 10 bit times x 16 RT cycles + 3
RT cycles = 163 RT cycles.
The maximum percent difference between the receiver count and the transmitter count of
a slow 9-bit or 2 stop bits character with no errors is:
((170 - 163) / 170) X 100 = 4.12%
For a 9-bit data and 2 stop bit character, data sampling of the stop bit takes the receiver
11 bit times x 16 RT cycles + 10 RT cycles = 186 RT cycles.
With the misaligned character shown in Figure 32-20, the receiver counts 186 RT cycles
at the point when the count of the transmitting device is 11 bit times x 16 RT cycles + 3
RT cycles = 179 RT cycles.
The maximum percent difference between the receiver count and the transmitter count of
a slow 9-bit and 2 stop bits character with no errors is: ((186 - 179) / 186) X 100 = 3.76%
RECEIVER
RT CLOCK
RT1
RT2
RT3
RT4
RT5
RT6
RT7
RT8
RT9
RT10
RT11
RT12
RT13
RT14
RT15
RT16
DATA
SAMPLES
For an 8-bit data and 1 stop bit character, data sampling of the stop bit takes the receiver
9 bit times x 16 RT cycles + 10 RT cycles = 154 RT cycles.
With the misaligned character shown in Figure 32-21, the receiver counts 154 RT cycles
at the point when the count of the transmitting device is 10 bit times x 16 RT cycles =
160 RT cycles.
The maximum percent difference between the receiver count and the transmitter count of
a fast 8-bit and 1 stop bit character with no errors is:
((154 - 160) / 154) x 100 = 3.90%
For a 9-bit data or 2 stop bits character, data sampling of the stop bit takes the receiver 10
bit times x 16 RT cycles + 10 RT cycles = 170 RT cycles.
KE04 Sub-Family Reference Manual, Rev. 3, Feburary 2014
Freescale Semiconductor, Inc. 583
Functional description
With the misaligned character shown in, the receiver counts 170 RT cycles at the point
when the count of the transmitting device is 11 bit times x 16 RT cycles = 176 RT cycles.
The maximum percent difference between the receiver count and the transmitter count of
a fast 9-bit or 2 stop bits character with no errors is:
((170 - 176) / 170) x 100 = 3.53%
For a 9-bit data and 2 stop bits character, data sampling of the stop bit takes the receiver
11 bit times x 16 RT cycles + 10 RT cycles = 186 RT cycles.
With the misaligned character shown in, the receiver counts 186 RT cycles at the point
when the count of the transmitting device is 12 bit times x 16 RT cycles = 192 RT cycles.
The maximum percent difference between the receiver count and the transmitter count of
a fast 9-bit and 2 stop bits character with no errors is:
((186 - 192) / 186) x 100 = 3.23%
33.1 Introduction
NOTE
For the chip-specific implementation details of this module's
instances, see the chip configuration information.
The general-purpose input and output (GPIO) module is accessible via the peripheral bus
and also communicates to the processor core via a zero wait state interface (IOPORT) for
maximum pin performance. The GPIO registers support 8-bit, 16-bit or 32-bit accesses.
The GPIO data direction and output data registers control the direction and output data of
each pin when the pin is configured for the GPIO function. The GPIO input data register
displays the logic value on each pin when the pin is configured for any digital function,
provided the corresponding Port Control and Interrupt module for that pin is enabled.
Efficient bit manipulation of the general-purpose outputs is supported through the
addition of set, clear, and toggle write-only registers for each port output data register.
33.1.1 Features
• Features of the GPIO module include:
• Port Data Input register visible in all digital pin-multiplexing modes
• Port Data Input register with corresponding set/clear/toggle registers
• Port Data Direction register
• Zero wait state access to GPIO registers through IOPORT
NOTE
The GPIO module is clocked by system clock.
NOTE
Not all pins within each port are implemented on each device.
See the chapter on signal multiplexing for the number of GPIO
ports available in the device.
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
PTB7
PTB6
PTB5
PTB4
PTB3
PTB2
PTB1
PTB0
PTD7
PTD6
PTD5
PTD4
PTD3
PTD2
PTD1
PTD0
PTC7
PTC6
PTC5
PTC4
PTC3
PTC2
PTC1
PTC0
PTA7
PTA6
PTA5
PTA4
PTA3
PTA2
PTA1
PTA0
Port pin
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
PDO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Register bits for unbonded pins return a undefined value when read.
0 Logic level 0 is driven on pin, provided pin is configured for general-purpose output.
1 Logic level 1 is driven on pin, provided pin is configured for general-purpose output.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
W PTSO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing to this register will update the contents of the corresponding bit in the PDOR as follows:
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
W PTCO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing to this register will update the contents of the corresponding bit in the Port Data Output Register
(PDOR) as follows:
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
W PTTO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing to this register will update the contents of the corresponding bit in the PDOR as follows:
NOTE
Do not modify pin configuration registers associated with pins
not available in your selected package. All unbonded pins not
available in your package will default to DISABLE state for
lowest power consumption.
Address: 400F_F000h base + 10h offset = 400F_F010h
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R PDI
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reads 0 at the unimplemented pins for a particular device. Pins that are not configured for a digital
function read 0. If the Port Control and Interrupt module is disabled, then the corresponding bit in PDIR
does not update.
0 Pin logic level is logic 0, or is not configured for use by digital function.
1 Pin logic level is logic 1.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
PDD
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 Pin is configured as general-purpose input, for the GPIO function. The pin will be high-Z if the port
input is disabled in GPIOx_PIDR register.
1 Pin is configured as general-purpose output, for the GPIO function.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
PID
Reset 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 Pin is configured for General Purpose Input, provided the pin is configured for any digital function.
1 Pin is not configured as General Purpose Input.Corresponding Port Data Input Register bit will read
zero.
Accesses via the IOPORT interface occur in parallel with any instruction fetches and will
therefore complete in a single cycle. This aliased Fast GPIO memory map is called
FGPIO.
Any read or write access to the FGPIO memory space that is outside the valid memory
map results in a bus error. All register accesses complete with zero wait states, except
error accesses which complete with one wait state.
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5
PTB7 4 3 2 1 0
PTB6
PTB5
PTB4
PTB3
PTB2
PTB1
PTB0
PTD7
PTD6
PTD5
PTD4
PTD3
PTD2
PTD1
PTD0
PTC7
PTC6
PTC5
PTC4
PTC3
PTC2
PTC1
PTC0
PTA7
PTA6
PTA5
PTA4
PTA3
PTA2
PTA1
PTA0
Port pin
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
PDO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 Logic level 0 is driven on pin, provided pin is configured for general-purpose output.
1 Logic level 1 is driven on pin, provided pin is configured for general-purpose output.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
W PTSO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing to this register will update the contents of the corresponding bit in the PDOR as follows:
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
W PTCO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing to this register will update the contents of the corresponding bit in the Port Data Output Register
(PDOR) as follows:
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R 0
W PTTO
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Writing to this register will update the contents of the corresponding bit in the PDOR as follows:
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R PDI
W
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reads 0 at the unimplemented pins for a particular device. Pins that are not configured for a digital
function read 0. If the Port Control and Interrupt module is disabled, then the corresponding bit in PDIR
does not update.
0 Pin logic level is logic 0, or is not configured for use by digital function.
1 Pin logic level is logic 1.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
PDD
Reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 Pin is configured as general-purpose input, for the GPIO function. The pin will be high-Z if the port
input is disabled in FPIOx_PIDR register.
1 Pin is configured as general-purpose output, for the GPIO function.
Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
R
W
PID
Reset 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 Pin is configured for General Purpose Input, provided the pin is configured for any digital function.
1 Pin is not configured as General Purpose Input. Corresponding Port Data Input Register bit will read
zero.
To facilitate efficient bit manipulation on the general-purpose outputs, pin data set, pin
data clear, and pin data toggle registers exist to allow one or more outputs within one port
to be set, cleared, or toggled from a single register write.
The corresponding Port Control and Interrupt module does not need to be enabled to
update the state of the port data direction registers and port data output registers including
the set/clear/toggle registers.
33.4.3 IOPORT
The GPIO registers are also aliased to the IOPORT interface on the Cortex-M0+ from
address 0xF800_0000. Accesses via the IOPORT interface occur in parallel with any
instruction fetches and will therefore complete in a single cycle.
34.1 Introduction
34.1.1 Features
The KBI features include:
• Up to eight keyboard interrupt pins with individual pin enable bits
• Each keyboard interrupt pin is programmable as:
• falling-edge sensitivity only
• rising-edge sensitivity only
• both falling-edge and low-level sensitivity
• both rising-edge and high-level sensitivity
• One software-enabled keyboard interrupt
• Exit from low-power modes
KBACK BUSCLK
1 VDD RESET
KBF
0 CLR
KBIxP0 S KBIPE0 D Q
SYNCHRONIZER
CK
KBEDG0
1 INTERRUPT FF KBIx
INTERRUPT
KBIxPn 0 REQUEST
S KBIPEn KBMOD
KBIE
KBEDGn
Read 0 KBF
KBIE KBMOD
Write KBACK
Reset 0 0 0 0 0 0 0 0
Each of the KBIPEn bits enable the corresponding KBI interrupt pin.
Each of the KBEDGn bits selects the falling edge/low-level or rising edge/high-level function of the
corresponding pin.