Cmsemicon BAT32G137 User manual

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 1 / 1052 V2.1.1
BAT32G137 User Manual
Ultra-low power 32-bit microcontroller based on ARM® Cortex®-M0+
Rev.2.1.1
intellectual property
*. Any patents
interlectual property rights will be forbidden and stopped by our company through any legal actions, and our company will claim the lost and
required for compensation of any damage to the company.
*The name of Cmsemicron Limited and logo are both trademarks of our company.
*this manual.
However, our company is not responsible for any usage about this munal. The applications and their purposes in this manual are just for
clarification,our company does not guarantee that these applications are feasible without further improvements and changes,and our
company does not recommend any usage of
products are not authorzed to be used for life-saving or life support devices and systems.our company has the right to change or improve the
product without any notification,for latest news, please visit our website: www.mcu.com.cn

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 2 / 1052 V2.1.1
Documentation Instructions
This manual is the technical reference manual for the BAT32G137 microcontroller product. The technical
reference manual is the application instruction material on how to use this series of products, including the
structure, function description, working mode and register configuration of each functional module.
The technical reference manual is a description of all functional modules of this series of products. If you want
to know the feature description of the product (that is, the functional configuration), you can refer to the respective
data sheet.
The data sheet information is as follows:
BAT32G137xx:BAT32G137_datasheet_vx.x.x. pdf
Usually in the early stage of chip selection, you shall first check the data sheet to evaluate whether the product
can meet the functional requirements of the design; after basically selecting the required product, you need to check
the technical reference manual to determine whether the working mode of each functional module does meet the
requirement;When determining the selection and entering the programming design stage, you need to read the
technical reference manual in detail to understand the specific implementation and register configuration of each
function. Refer to the data sheet for information on voltages, currents, drive capabilities, and pin assignments when
designing hardware。
For a detailed description of the Cortex-M0+ core, SysTick timer and NVIC, please refer to the respective ARM
documents.

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 3 / 1052 V2.1.1
Index
Documentation Instructions ................................................................................... 2
Chapter 1 CPU....................................................................................................................... 20
1.1 verview................................................................................................................................................................... 20
1.2 Cortex-M0+ core features...................................................................................................................................... 20
1.3 Debug features...................................................................................................................................................... 20
1.4 SWD interface pin.................................................................................................................................................. 22
1.5 ARM reference document...................................................................................................................................... 23
Chapter 2 Pin function.......................................................................................................... 24
2.1 port function........................................................................................................................................................... 24
2.2 port multiplex ......................................................................................................................................................... 24
2.3 Register for controlling port function...................................................................................................................... 25
2.3.1 Port Mode Register (PMxx) ................................................................................................................................. 27
2.3.2 Port Register (Pxx).............................................................................................................................................. 28
2.3.3 Pull-up resistance selection register (PUxx)........................................................................................................ 29
2.3.4 Port input mode register (PIMxx)......................................................................................................................... 30
2.3.5 Port output mode register (POMxx)..................................................................................................................... 31
2.3.6 Port mode control register (PMCxx) .................................................................................................................... 32
2.3.7 Peripheral I/O Redirection Register 0 (PIOR0).................................................................................................... 33
2.3.8 Peripheral I/O Redirection Register 1 (PIOR1).................................................................................................... 35
2.3.9 Peripheral I/O Redirection Register 2 (PIOR2).................................................................................................... 36
2.3.10 Peripheral I/O Redirection Register 3 (PIOR3).................................................................................................... 37
2.4 Handling of unused pins ........................................................................................................................................ 39
2.5 Register Settings When Using Multiplexing........................................................................................................... 40
2.5.1 The Basic principal of Using Multiplexing Function.............................................................................................. 40
2.5.2 Examples of Register Settings for Port and Multiplexing Functions Used ........................................................... 41
Chapter 3 system structure ................................................................................................. 51
3.1 Overview................................................................................................................................................................ 51
3.2 system address partitioning................................................................................................................................... 52
Chapter 4 clock generator.................................................................................................... 54
4.1 Function of clock generation circuit........................................................................................................................ 54
4.2 Structure of clock generating circuit....................................................................................................................... 56
4.3 Register for controlling clock generation circuit...................................................................................................... 58
4.3.1 Clock Run Mode Control Register (CMC)............................................................................................................ 59
4.3.2 System Clock Control Register (CKC)................................................................................................................. 60
4.3.3 Clock Operational Status Control Register (CSC)............................................................................................... 61
4.3.4 State register of the oscillation stabilization time counter (OSTC)....................................................................... 63
4.3.5 Oscillating Stable Time Select Register (OSTS).................................................................................................. 65
4.3.6 Peripheral Enable Registers 0, 1 (PER0, PER1)................................................................................................. 66
4.3.7 Secondary system clock provides mode control register (OSMC)....................................................................... 71
4.3.8 Frequency selection register (HOCODIV) for high speed internal oscillator........................................................ 72

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 4 / 1052 V2.1.1
4.3.9 High speed internal oscillator fine-tuned register (HIOTRM) ............................................................................... 73
4.4 System clock oscillating circuit............................................................................................................................... 74
4.4.1 X1 oscillating circuit............................................................................................................................................. 74
4.4.2 XT1 oscillating circuit........................................................................................................................................... 74
4.4.3 high speed internal oscillator............................................................................................................................... 78
4.4.4 low-speed internal oscillator ................................................................................................................................ 78
4.5 Operation of clock generation circuit...................................................................................................................... 79
4.6 clock control........................................................................................................................................................... 81
4.6.1 Example of high speed internal oscillator set-up ................................................................................................. 81
4.6.2 An example of X1 oscillation circuit..................................................................................................................... 83
4.6.3 Setting example of XT1 oscillation circuit............................................................................................................ 84
4.6.4 CPU Clock State Transition Diagram .................................................................................................................. 85
4.6.5 Conditions before CPU clock transfer and post-transfer processing ................................................................... 91
4.6.6 Time required to switch CPU clock and main system clock................................................................................. 93
4.6.7 Conditions before clock oscillation stops............................................................................................................. 94
Chapter 5 hardware divider.................................................................................................. 95
5.1 characteristics........................................................................................................................................................ 95
5.2 Feature Description ............................................................................................................................................... 95
5.3 Register for hardware divider................................................................................................................................. 95
5.3.1 division register (DIVIDEND)............................................................................................................................... 96
5.3.2 Divisor register (DIVISOR)................................................................................................................................... 96
5.3.3 quotient register (QUOTIENT)............................................................................................................................. 96
5.3.4 Remainder register (REMAINDER)..................................................................................................................... 96
5.3.5 status register (STATUS) .................................................................................................................................... 97
Chapter 6 Universal Timer Unit Timer4............................................................................... 98
6.1 Function of universal timer unit............................................................................................................................ 100
6.1.1 Stand-alone channel operation.......................................................................................................................... 100
6.1.2 multi-channel coordinated operation function.................................................................................................... 102
6.1.3 8-bit timer operation function (only for channel 1 and channel 3 of unit 0). ....................................................... 103
6.1.4 LIN-bus support (Cell 0-only channel 3)............................................................................................................ 103
6.2 Structure of universal timer unit........................................................................................................................... 104
6.2.1 Universal timer unit register list.......................................................................................................................... 107
6.2.2 Timer count register mn (TCRmn)..................................................................................................................... 108
6.2.3 timer data register mn (TDRmn)........................................................................................................................ 110
6.3 Register for controlling universal timer unit.......................................................................................................... 111
6.3.1 Peripheral Enable Register 0 (PER0)................................................................................................................ 112
6.3.2 Timer Clock Select Register m (TPSm)............................................................................................................. 113
6.3.3 timer mode register mn (TMRmn)...................................................................................................................... 116
6.3.4 timer status register mn (TSRmn)...................................................................................................................... 120
6.3.5 Timer channel allows state register m (TEm) to be ........................................................................................... 121
6.3.6 Timer channel start register m (TSm)................................................................................................................ 122
6.3.7 Timer channel stop register m (TTm). ............................................................................................................... 123
6.3.8 Timer Input-Output Selection Register (TIOS0, TIOS1) .................................................................................... 124

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 5 / 1052 V2.1.1
6.3.9 timer output allow register m (TOEm)................................................................................................................ 126
6.3.10 Timer output register m (TOm).......................................................................................................................... 127
6.3.11 Timer output level register m (TOLm)................................................................................................................ 128
6.3.12 Timer output mode register m (TOMm) ............................................................................................................. 129
6.3.13 Input switch control register (ISC)...................................................................................................................... 130
6.3.14 Noise Filter Admission Register (NFEN1) ......................................................................................................... 131
6.3.15 Register for controlling timer input/output pin port function................................................................................ 132
6.4 Basic rules for universal timer units ..................................................................................................................... 133
6.4.1 Basic Prinicpal of Multi-channel Coordinated Operation Function..................................................................... 133
6.4.2 Basic Principal of the 8-bit timer operation function (only for channel 1 and channel 3).................................... 135
6.5 Operation of counters .......................................................................................................................................... 136
6.5.1 Count Clock (fTCLK) ......................................................................................................................................... 136
6.5.2 Starting sequence of Counter............................................................................................................................ 138
6.5.3 Operation of counters........................................................................................................................................ 139
6.6 Control of channel output (TOmn pin).................................................................................................................. 144
6.6.1 Structure of TOmn pin output circuit.................................................................................................................. 144
6.6.2 Output settings for TOmn pins........................................................................................................................... 145
6.6.3 Precaution for Channel Output Operation ......................................................................................................... 146
6.6.4 One-time operation of TOmn bits ...................................................................................................................... 151
6.6.5 About timer interrupts and TOmn pin output at start of counting ....................................................................... 152
6.7 Control of timer input (TImn)................................................................................................................................ 153
6.7.1 Structure of TImn pin input circuit...................................................................................................................... 153
6.7.2 noise filter.......................................................................................................................................................... 153
6.7.3 Precautions When Operating Channel Inputs ................................................................................................... 154
6.8 Independent channel operation function of universal timer unit........................................................................... 155
6.8.1 Operation as Interval Timer/Square wave Output.............................................................................................. 155
6.8.2 Run as External Event Counter......................................................................................................................... 159
6.8.3 Operation as a frequency divider (only for channel 0 of cell 0).......................................................................... 162
6.8.4 Operation as an input pulse interval measurement ........................................................................................... 165
6.8.5 Operation as voltage high and low level width measurement of input signal..................................................... 168
6.8.6 Operation as delay counter ............................................................................................................................... 172
6.9 Multi-channel coordinated operation function of universal timer unit ................................................................... 175
6.9.1 Operation as single trigger pulse output function............................................................................................... 175
6.9.2 Operation as PWM Function.............................................................................................................................. 182
6.9.3 Operation as Multiple PWM Output Function..................................................................................................... 189
6.10 Precautions when using a universal timer unit..................................................................................................... 197
6.10.1 Precautions When Using Timer Output............................................................................................................. 197
Chapter 7 Timer A............................................................................................................... 198
7.1 Function of timer A............................................................................................................................................... 198
7.2 Structure of timer A.............................................................................................................................................. 199
7.3 Register for control timer A.................................................................................................................................. 200
7.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 200
7.3.2 Secondary system clock provides mode control register (OSMC)..................................................................... 201

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 6 / 1052 V2.1.1
7.3.3 timer A count register 0 (TA0)............................................................................................................................ 202
7.3.4 timer A control register 0 (TACR0). ................................................................................................................... 203
7.3.5 Timer AI/O control register 0 (TAIOC0) ............................................................................................................. 204
7.3.6 timer A control register 0 (TAMR0).................................................................................................................... 206
7.3.7 Timer A Event Pin Selection Register 0 (TAISR0)............................................................................................. 207
7.3.8 Port Mode Register x (PMx) .............................................................................................................................. 208
7.4 Operation of timer A............................................................................................................................................. 209
7.4.1 Reload register and counter override ................................................................................................................ 209
7.4.2 timer mode......................................................................................................................................................... 210
7.4.3 pulse output mode............................................................................................................................................. 211
7.4.4 Event Counter Mode.......................................................................................................................................... 212
7.4.5 pulse width measurement mode........................................................................................................................ 214
7.4.6 pulse period measurement mode...................................................................................................................... 215
7.4.7 Collaboration with EVENTC............................................................................................................................... 216
7.4.8 Output settings for each mode........................................................................................................................... 216
7.5 Precautions when using timer A .......................................................................................................................... 217
7.5.1 Start and stop control of count........................................................................................................................... 217
7.5.2 Access to flags (TEDGF and TUNDF bits of the TACR0 register)..................................................................... 217
7.5.3 Access to a counter register.............................................................................................................................. 217
7.5.4 Changes in Patterns.......................................................................................................................................... 218
7.5.5 Set-up steps for TAO and TAIO pins................................................................................................................. 218
7.5.6 When timer A not used...................................................................................................................................... 218
7.5.7 Stopping execution clock of timer A................................................................................................................... 218
7.5.8 Configuration steps for deep sleep mode (event counter mode)....................................................................... 219
7.5.9 Functional limitations in deep sleep mode (event counter mode only) .............................................................. 219
7.5.10 Forced count stop with TSTOP bit..................................................................................................................... 219
7.5.11 digital filter ......................................................................................................................................................... 219
7.5.12 The Case of Selecting fIL as Count Source....................................................................................................... 219
Chapter 8 Timer B............................................................................................................... 220
8.1 Function of timer B............................................................................................................................................... 220
8.2 Structure of timer B.............................................................................................................................................. 221
8.3 Register for control timer B.................................................................................................................................. 222
8.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 223
8.3.2 timer B mode register (TBMR)........................................................................................................................... 224
8.3.3 Timer B count control register (TBCNTC).......................................................................................................... 225
8.3.4 Timer B Control Register (TBCR)...................................................................................................................... 226
8.3.5 Timer B interrupt enable register (TBIER) ......................................................................................................... 227
8.3.6 Timer B Status Register (TBSR)........................................................................................................................ 228
8.3.7 Timer BI/O control register (TBIOR).................................................................................................................. 230
8.3.8 Timer B Counter (TB) ........................................................................................................................................ 232
8.3.9 timer b general register a, b, c, d....................................................................................................................... 233
8.3.10 port register and port mode register .................................................................................................................. 235
8.4 Operation of timer B............................................................................................................................................. 236

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 7 / 1052 V2.1.1
8.4.1 Common Issues Concerning Multiple Models and Functions............................................................................ 236
8.4.2 timer mode (input capture function)................................................................................................................... 241
8.4.3 timer mode (output comparison function).......................................................................................................... 244
8.4.4 PWM mode........................................................................................................................................................ 248
8.4.5 phase counting mode........................................................................................................................................ 252
8.5 timer B interrupt................................................................................................................................................... 255
8.6 Precautions when using timer B .......................................................................................................................... 257
8.6.1 Phase difference, overlap and pulse width in phase counting mode................................................................. 257
8.6.2 mode switching.................................................................................................................................................. 257
8.6.3 Switch of count source ...................................................................................................................................... 257
8.6.4 Set-up steps for TBIO0 and TBIO1 pins............................................................................................................ 258
8.6.5 external clock TBCLK0 and TBCLK1................................................................................................................. 258
8.6.6 Read and write access to SFR.......................................................................................................................... 258
8.6.7 Input capture operation when stopping count.................................................................................................... 259
Chapter 9 timer C................................................................................................................ 260
9.1 Function of timer C .............................................................................................................................................. 260
9.2 Structure of timer C.............................................................................................................................................. 261
9.3 Register for controlling timer C ............................................................................................................................ 262
9.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 262
9.3.2 timer C count register (TC)................................................................................................................................ 263
9.3.3 timer C count buffer register (TCBUF)............................................................................................................... 263
9.3.4 timer C control register 1 (TCCR1).................................................................................................................... 264
9.3.5 timer C control register 1 (TCCR2).................................................................................................................... 265
9.3.6 timer C status register (TCSR) .......................................................................................................................... 266
9.4 Operation of timer C ............................................................................................................................................ 267
9.4.1 count source...................................................................................................................................................... 267
9.4.2 Timer C starts counting actions......................................................................................................................... 267
9.4.2.1 Select the Timer M signal as the setting and action for the trigger.................................................................. 268
9.4.2.2 Select the settings and actions when the software fires.................................................................................. 269
9.4.3 Timer C counts stop actions.............................................................................................................................. 270
9.4.3.1 Select Comparator 1 as Trigger Settings and Actions..................................................................................... 270
9.4.3.2 Settings and actions when software is triggered ............................................................................................. 270
9.4.4 Input capture action........................................................................................................................................... 271
9.4.5 timer C count reset action.................................................................................................................................. 272
9.4.6 Interruption of timer C........................................................................................................................................ 274
9.5 Precautions for Using Timer C............................................................................................................................. 275
9.5.1 Read/write of register ........................................................................................................................................ 275
9.5.2 overflow interrupt............................................................................................................................................... 275
9.5.3 Input capture and timer C count reset actions................................................................................................... 275
9.5.4 Steps when timer C and timer M and comparator 1 are linked.......................................................................... 275
Chapter 10 Timer M.............................................................................................................. 276
10.1 Function of timer M.............................................................................................................................................. 276
10.2 Structure of timer M............................................................................................................................................. 277

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 8 / 1052 V2.1.1
10.3 Register for controlling timer M............................................................................................................................ 278
10.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 279
10.3.2 timer M EVENTC register (TMELC)................................................................................................................... 280
10.3.3 Timer M Start Register (TMSTR)....................................................................................................................... 281
10.3.4 timer M mode register (TMMR).......................................................................................................................... 282
10.3.5 Timer M PWM Function Selection Register (TMPMR) ...................................................................................... 283
10.3.6 Timer M Functional Control Register (TMFCR)................................................................................................. 284
10.3.7 Timer M outputs master permissive register 1 (TMOER1) ................................................................................ 285
10.3.8 Timer M outputs Master Permissive Register 2 (TMOER2)............................................................................... 286
10.3.9 Timer M Output Control Register (TMOCR) ...................................................................................................... 287
10.3.10 timer m digital filter function selection register i (TMDFi) (i=0,1)........................................................................ 290
10.3.11 Timer M control register i (TMCRi) (i=0,1)......................................................................................................... 292
10.3.12 Timer MI/O control register Ai(TMIORAi) (i=0,1) ............................................................................................... 297
10.3.13 Timer MI/O control register Ci(TMIORCi) (i=0,1)............................................................................................... 299
10.3.14 Timer M Status Register 0 (TMSR0) ................................................................................................................. 301
10.3.15 Timer M Status Register 1 (TMSR1) ................................................................................................................. 306
10.3.16 timer m interrupt enable register i (TMIERi) (i=0,1) ........................................................................................... 312
10.3.17 timer MPWM function output level control register i (TMPOCRi) (i=0,1)............................................................ 313
10.3.18 timer M counter i (TMi) (i=0,1)........................................................................................................................... 314
10.3.19 timer m general register ai, bi, ci, di................................................................................................................... 316
10.3.20 Port Mode Register (PMxx, PMCxx).................................................................................................................. 325
10.4 Common Issues on Multiple Models.................................................................................................................... 326
10.4.1 count source...................................................................................................................................................... 326
10.4.2 buffer operation ................................................................................................................................................. 327
10.4.3 synchronous operation ...................................................................................................................................... 330
10.4.4 Forced Cutoff of Pulse Output........................................................................................................................... 331
10.4.5 Events entered from the Event Coordination Controller(EVENTC).................................................................... 333
10.4.6 Events output to the event Coordination Controller(EVENTC)/data transfer controller (DMA) .......................... 334
10.5 Operation of timer M............................................................................................................................................ 335
10.5.1 Input capture function........................................................................................................................................ 335
10.5.2 output comparison function ............................................................................................................................... 340
10.5.3 PWM function.................................................................................................................................................... 345
10.5.4 Reset synchronous PWM mode........................................................................................................................ 350
10.5.5 complementary PWM mode .............................................................................................................................. 353
10.5.6 PWM3 mode...................................................................................................................................................... 358
10.6 Timer M interrupt ................................................................................................................................................. 360
10.7 Precautions when using timer M.......................................................................................................................... 363
10.7.1 Read and write access to SFR.......................................................................................................................... 363
10.7.2 mode switching.................................................................................................................................................. 363
10.7.3 count source...................................................................................................................................................... 364
10.7.4 Input capture function........................................................................................................................................ 364
10.7.5 Set-up steps for TMIOAi, TMIOBi, TMIOCi, TMIODi pins (i=0,1)....................................................................... 364
10.7.6 external clock TMCLK ....................................................................................................................................... 365
10.7.7 complementary PWM mode .............................................................................................................................. 365

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 9 / 1052 V2.1.1
10.8 PWMOP............................................................................................................................................................... 370
10.8.1 Features of PWMOP ......................................................................................................................................... 371
10.8.2 Register for PWMOP......................................................................................................................................... 371
10.8.3 Running of PWMOP.......................................................................................................................................... 377
10.8.3.1output forced cut-off ........................................................................................................................................ 377
10.8.3.2Hardware Undoing (HS_SEL=0) ..................................................................................................................... 377
10.8.3.3Software Undoing (HS_SEL=1)....................................................................................................................... 387
10.8.3.4Hazard countermeasure.................................................................................................................................. 393
10.8.3.5Output Force Cutoff of Source Checked Out and Unchecked Out.................................................................. 394
10.8.3.6The time sequence diagram when the value of the counter of timer M reaches 0000 H................................. 394
10.8.3.7Configuration Steps......................................................................................................................................... 396
10.8.4 Precautions........................................................................................................................................................ 397
Chapter 11 real-time clock .................................................................................................. 398
11.1 The Function of Real-time Clock.......................................................................................................................... 398
11.2 Structure of real-time clock.................................................................................................................................. 398
11.3 Register for controlling real-time clock................................................................................................................. 400
11.3.1 Peripheral Enable Register 0 (PER0)................................................................................................................ 401
11.3.2 Real-time clock selection register (RTCCL)....................................................................................................... 402
11.3.3 Real-time clock control register 0 (RTCC0)....................................................................................................... 403
11.3.4 Real-time clock control register 1 (RTCC1)....................................................................................................... 404
11.3.5 Clock error correction register (SUBCUD)......................................................................................................... 406
11.3.6 Second Count Register (SEC)........................................................................................................................... 407
11.3.7 Minute Count Register (MIN)............................................................................................................................. 407
11.3.8 Hour count register (HOUR).............................................................................................................................. 408
11.3.9 Day count register (DAY)................................................................................................................................... 410
11.3.10 Week count register (WEEK)............................................................................................................................. 411
11.3.11 Month count register (MONTH) ......................................................................................................................... 412
11.3.12 Year count register (YEAR)............................................................................................................................... 412
11.3.13 Alarm clock minute register (ALARMWM) ......................................................................................................... 413
11.3.14 Alarm clock hour register (ALARMWH) ............................................................................................................. 413
11.3.15 Alarm clock week register (ALARMWW)........................................................................................................... 413
11.3.16 port mode register and port register .................................................................................................................. 414
11.4 Operation of real-time clock................................................................................................................................. 415
11.4.1 Real Time clock Operation start ........................................................................................................................ 415
11.4.2 Transition to sleep mode after start of operation ............................................................................................... 416
11.4.3 Real-time clock counter reading and writing...................................................................................................... 417
11.4.4 Alarm setting for real-time clock ........................................................................................................................ 419
11.4.5 1 Hz output of real-time clock............................................................................................................................ 420
11.4.6 Example of clock deviation calibration for a real-time clock............................................................................... 421
Chapter 12 15-bit interval timer .......................................................................................... 423
12.1 The function of a 15-bit interval timer................................................................................................................... 423
12.2 Structure of 15-bit interval timer........................................................................................................................... 423
12.3 Register for controlling 15-bit interval timer.......................................................................................................... 424

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 10 / 1052 V2.1.1
12.3.1 Peripheral Enable Register 0 (PER0)................................................................................................................ 424
12.3.2 Real-time clock selection register (RTCCL)....................................................................................................... 425
12.3.3 Control register for 15-bit interval timer (ITMC) ................................................................................................. 426
12.4 Operation of a 15-bit interval timer....................................................................................................................... 427
12.4.1 Run-time sequence of 15-bit interval timer........................................................................................................ 427
12.4.2 The operation of the counter is started after returning from the sleep mode and the transfer to the sleep mode is
repeated............................................................................................................................................................ 428
Chapter 13 Clock output/buzzer output control circuit .................................................... 429
13.1 The Function of Clock Output/Buzzer Output Control Circuit............................................................................... 429
13.2 Structure of clock output/buzzer output control circuit ......................................................................................... 430
13.3 Register for control clock output/buzzer output control circuit.............................................................................. 430
13.3.1 Clock output selection register n (CKSn)........................................................................................................... 430
13.3.2 Register for controlling clock output/buzzer output pin port function.................................................................. 432
13.4 Operation of clock output/buzzer output control circuit ........................................................................................ 433
13.4.1 Operation of the Output Pin............................................................................................................................... 433
13.5 Precautions for Clock Output/Buzzer Output Control Circuit................................................................................ 433
Chapter 14 watchdog timer................................................................................................. 434
14.1 Function of watchdog timer.................................................................................................................................. 434
14.2 Structure of watchdog timer................................................................................................................................. 434
14.3 Register for controlling watchdog timer................................................................................................................ 436
14.3.1 Watchdog timer enable register (WDTE)........................................................................................................... 436
14.3.2 WDTCFG configuration register (WDTCFG0/1/2/3) .......................................................................................... 437
14.4 Operation of watchdog timer................................................................................................................................ 438
14.4.1 Operation control of watchdog timer.................................................................................................................. 438
14.4.2 Setting of overflow time of watchdog timer........................................................................................................ 439
14.4.3 Watchdog timer window settings during opening............................................................................................... 440
14.4.4 Setting of watchdog timer interval interrupt ....................................................................................................... 441
14.4.5 Operation of watchdog timer when WDTCFG is not configured........................................................................ 441
Chapter 15 A/D converter.................................................................................................... 442
15.1 Functions of A/D Converter.................................................................................................................................. 442
15.2 Register for controlling A/D converter.................................................................................................................. 444
15.2.1 Peripheral Enable Register 0 (PER0)................................................................................................................ 445
15.2.2 Mode register 0 (ADM0) for A/D converter ........................................................................................................ 446
15.2.3 Mode register 1 for A/D converter (ADM1) ........................................................................................................ 451
15.2.4 Mode register 2 for A/D converter (ADM2) ........................................................................................................ 452
15.2.5 A/D converter trigger mode register (ADTRG)................................................................................................... 453
15.2.6 Analog input channel assignment register (ADS).............................................................................................. 454
15.2.7 12-bit A/D conversion result register (ADCR).................................................................................................... 456
15.2.8 8-bit A/D conversion result register (ADCRH).................................................................................................... 457
15.2.9 Conversion Result Compare Upper Value Setting Register (ADUL) ................................................................. 458
15.2.10 Translation Results Compare Lower Limit Settings Register (ADLL) ................................................................ 458
15.2.11 A/D Sample Time Control Register (ADNSMP)................................................................................................. 459

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 11 / 1052 V2.1.1
15.2.12 A/D Sample Time Extension Register (ADSMPWAIT) ...................................................................................... 460
15.2.13 A/D test register (ADTES) ................................................................................................................................. 461
15.2.14 A/D status register (ADFLG).............................................................................................................................. 462
15.2.15 A/D charge/discharge control register (ADNDIS)............................................................................................... 463
15.2.16 Register for controlling analog input pin port function........................................................................................ 464
15.3 Input voltage and conversion results ................................................................................................................... 465
15.4 Operation mode of the A/D Converter ................................................................................................................. 466
15.4.1 Software trigger mode (select mode, continuous conversion mode) ................................................................. 466
15.4.2 Software Trigger Mode (Select Mode, Single Conversion Mode)...................................................................... 467
15.4.3 Software Trigger Mode (Scan Mode, Continuous Conversion Mode)................................................................ 468
15.4.4 Software Trigger Mode (Scan Mode, Single Conversion Mode)........................................................................ 469
15.4.5 Hardware triggers no-wait mode (select mode, continuous conversion mode) ................................................. 470
15.4.6 Hardware triggers no-wait mode (select mode, Single Conversion Mode)........................................................ 471
15.4.7 Hardware triggered no-wait mode (scan mode, continuous conversion mode)................................................. 472
15.4.8 Hardware triggered no-wait mode (scan mode, Single Conversion Mode)........................................................ 473
15.4.9 Hardware triggered wait mode (select mode, continuous conversion mode) .................................................... 474
15.4.10 Hardware triggered wait mode (select mode, Single Conversion Mode)........................................................... 475
15.4.11 Hardware triggered wait mode (scan mode, continuous conversion mode) ...................................................... 476
15.4.12 Hardware triggered wait mode (scan mode, Single Conversion Mode)............................................................. 477
15.5 Converter Set-up Flowchart................................................................................................................................. 478
15.5.1 Settings for software trigger mode..................................................................................................................... 478
15.5.2 Hardware Trigger No Wait Mode Settings......................................................................................................... 479
15.5.3 Settings for Hardware Trigger Wait Mode ......................................................................................................... 480
15.5.4 Settings when selecting the output voltage/internal reference voltage of the temperature sensor .................... 481
15.5.5 Settings for test mode........................................................................................................................................ 482
Chapter 16 D/A Converter ................................................................................................... 483
16.1 Function of D/A Converter ................................................................................................................................... 483
16.2 Structure of D/A converter ................................................................................................................................... 484
16.3 Register for controlling D/A converter.................................................................................................................. 485
16.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 485
16.3.2 Mode register (DAM) for D/A converter. ............................................................................................................ 486
16.3.3 D/A conversion value setting register i(DACSi) (i=0,1)...................................................................................... 486
16.3.4 event output target selection register n(ELSELRn), n=00~21 ........................................................................... 487
16.3.5 Register for controlling analog input pin port function........................................................................................ 487
16.4 Operation of D/A Converter ................................................................................................................................. 488
16.4.1 Normal mode operation..................................................................................................................................... 488
16.4.2 Operation of Real-time Output Mode................................................................................................................. 489
16.4.3 Output Timing of D/A Conversion Values.......................................................................................................... 490
16.5 Precautions of using the D/A converter ............................................................................................................... 491
Chapter 17 comparator........................................................................................................ 492
17.1 Function of comparator........................................................................................................................................ 492
17.2 Structure of comparator....................................................................................................................................... 493
17.3 Register for control comparator ........................................................................................................................... 495

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 12 / 1052 V2.1.1
17.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 496
17.3.2 Comparator mode set-up register (COMPMDR)................................................................................................ 497
17.3.3 Comparator filter control register (COMPFIR) ................................................................................................... 498
17.3.4 Comparator output control register (COMPOCR).............................................................................................. 500
17.3.5 Comparator built-in reference voltage control register (CVRCTL) ..................................................................... 502
17.3.6 Comparator built-in reference voltage selection register (CiRVM)..................................................................... 503
17.3.7 Comparator 0 input signal selection control register (CMPSEL0)...................................................................... 504
17.3.8 Comparator 1 input signal selection control register (CMPSEL1)...................................................................... 505
17.3.9 Register for controlling analog input pin port function........................................................................................ 506
17.4 Operation Instructions.......................................................................................................................................... 507
17.4.1 Digital filter for comparator i (i=0,1).................................................................................................................... 509
17.4.2 comparator i interrupt (i=0,1)............................................................................................................................. 509
17.4.3 Event signal output to the Coordination Controller(EVENTC) ........................................................................... 510
17.4.4 Output of comparator i (i=0,1)............................................................................................................................ 511
17.4.5 Stop and provision of comparator clock............................................................................................................. 511
Chapter 18 programmable gain amplifier (PGA) ............................................................... 512
18.1 Function of Programmable Gain Amplifier........................................................................................................... 512
18.2 Structure of programmable gain amplifier............................................................................................................ 513
18.3 Register of programmable gain amplifier............................................................................................................. 514
18.3.1 Peripheral Enable Register 1 (PER1)................................................................................................................ 514
18.3.2 programmable gain amplifier control register (PGAnCTL)................................................................................. 515
18.3.3 Register for controlling analog input pin port function........................................................................................ 515
18.4 Operation of programmable gain amplifier........................................................................................................... 516
18.4.1 Starting operation steps of programmable gain amplifier .................................................................................. 516
18.4.2 Stopping operation step of programmable gain amplifier .................................................................................. 517
Chapter 19 universal serial communication unit .............................................................. 518
19.1 Functions of Universal Serial Communication Unit.............................................................................................. 520
19.1.1 3-wire Serial I/O (SSPI00, SSPI01, SSPI10, SSPI11, SSPI20,SSPI21)............................................................ 520
19.1.2 UART (UART0~UART2).................................................................................................................................... 521
19.1.3 Simple I2C (IIC00, IIC01, IIC10, IIC11, IIC20,IIC21) ......................................................................................... 522
19.2 Structure of universal serial communication unit.................................................................................................. 523
19.2.1 shift register....................................................................................................................................................... 526
19.2.2 Low 8-bit or low 9-bit for serial data register mn (SDRmn)................................................................................ 526
19.3 Register for controlling universal serial communication unit ................................................................................ 528
19.3.1 Peripheral Enable Register 0 (PER0)................................................................................................................ 529
19.3.2 Serial clock selection register m (SPSm)........................................................................................................... 530
19.3.3 Serial mode register mn (SMRmn).................................................................................................................... 531
19.3.4 Serial Communication Run Set-up Register mn (SCRmn)................................................................................ 533
19.3.5 Serial data register mn (SDRmn)....................................................................................................................... 535
19.3.6 Serial flag clear trigger register mn (SIRmn)...................................................................................................... 537
19.3.7 Serial state register mn (SSRmn)...................................................................................................................... 538
19.3.8 Serial channel start register m (SSm)................................................................................................................ 540
19.3.9 Serial channel stop register m (STm). ............................................................................................................... 541

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 13 / 1052 V2.1.1
19.3.10 Serial channel allows state register m (SEm).................................................................................................... 542
19.3.11 Serial output allows register m (SOEm)............................................................................................................. 543
19.3.12 Serial output register m (SOm).......................................................................................................................... 544
19.3.13 Serial output level register m (SOLm)................................................................................................................ 545
19.3.14 Input switch control register (ISC)...................................................................................................................... 547
19.3.15 Noise filter allows register 0 (NFEN0)................................................................................................................ 548
19.3.16 Register for controlling serial input/output pin port function............................................................................... 549
19.4 Idle Mode............................................................................................................................................................. 550
19.4.1 Unit Stop Operation........................................................................................................................................... 550
19.4.2 Stop by Channel................................................................................................................................................ 551
19.5 Operation of Serial I/O (SSPI00, SSPI01, SSPI10, SSPI11, SSPI20, SSPI21) Communication with 3 Lines ..... 552
19.5.1 master transmission .......................................................................................................................................... 553
19.5.2 master receive................................................................................................................................................... 561
19.5.3 Master send and receive ................................................................................................................................... 569
19.5.4 Slave send......................................................................................................................................................... 577
19.5.5 slave receive...................................................................................................................................................... 585
19.5.6 Slave send and receive..................................................................................................................................... 591
19.5.7 Calculation of transmission clock frequency...................................................................................................... 600
19.5.8 Processing steps for errors occurring during 3-wire serial I/O (SSPI00, SSPI01, SSPI10, SSPI11, SSPI20,
SSPI21) communication.................................................................................................................................... 602
19.6 Clock synchronization serial communication operation of slave selectioninput function...................................... 603
19.6.1 Slave send......................................................................................................................................................... 606
19.6.2 slave receive...................................................................................................................................................... 616
19.6.3 Slave send and Receive.................................................................................................................................... 623
19.6.4 Calculation of transmission clock frequency...................................................................................................... 633
19.6.5 Processing steps when an error occurs during clock synchronization serial communication of a slave selection
input function..................................................................................................................................................... 634
19.7 Operation of UART(UART0~UART2) Communication......................................................................................... 635
19.7.1 UART Send ....................................................................................................................................................... 636
19.7.2 UART Receive................................................................................................................................................... 645
19.7.3 Calculation of Baud Rate................................................................................................................................... 652
19.7.4 Processing steps when an error occurs during UART (UART0~UART2) communication................................. 656
19.8 Operation of LIN Communication......................................................................................................................... 657
19.8.1 LIN Send ........................................................................................................................................................... 657
19.8.2 LIN receiving...................................................................................................................................................... 660
19.9 Operation of Simple I2C (IIC00, IIC01, IIC10, IIC11, IIC20,IIC21) Communication............................................. 665
19.9.1 address segment sending ................................................................................................................................. 666
19.9.2 data transmission .............................................................................................................................................. 671
19.9.3 data receiving.................................................................................................................................................... 674
19.9.4 Generation of Stop Condition ............................................................................................................................ 678
19.9.5 Calculation of transfer rate ................................................................................................................................ 679
19.9.6 Processing steps when an error occurs in a simple I2C (IIC00, IIC01, IIC10, IIC11, IIC20, IIC21) communication
process.............................................................................................................................................................. 681
Chapter 20 serial interface IICA.......................................................................................... 682

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 14 / 1052 V2.1.1
20.1 The Function of Serial Interface IICA................................................................................................................... 682
20.2 Structure of Serial Interface IICA......................................................................................................................... 685
20.3 Register for controlling serial interface IICA......................................................................................................... 688
20.3.1 Peripheral Enable Register 0 (PER0)................................................................................................................ 689
20.3.2 IICA control register n0 (IICCTLn0)................................................................................................................... 689
20.3.3 IICA status register n (IICSn)............................................................................................................................. 694
20.3.4 IICA flag register n (IICFn)................................................................................................................................. 696
20.3.5 IICA control register n1 (IICCTLn1)................................................................................................................... 698
20.3.6 IICA Low level width setting register n (IICWLn)................................................................................................ 700
20.3.7 IICA High Level Width Setting Register n (IICWHn).......................................................................................... 700
20.3.8 Port mode register x (PMx)................................................................................................................................ 701
20.4 Functions of I2C bus mode.................................................................................................................................. 702
20.4.1 pin structure....................................................................................................................................................... 702
20.4.2 Method for setting transmission clock through IICWLn register and IICWHn register ....................................... 703
20.5 Definition and control method of I2C bus............................................................................................................. 704
20.5.1 Start Condition................................................................................................................................................... 704
20.5.2 Address ............................................................................................................................................................. 705
20.5.3 Assignment of transmission Direction................................................................................................................ 705
20.5.4 Acknowledge (ACK) .......................................................................................................................................... 706
20.5.5 stop condition .................................................................................................................................................... 707
20.5.6 waiting ............................................................................................................................................................... 708
20.5.7 Waitinging Release Method............................................................................................................................... 710
20.5.8 Generation Timing and Waiting Control of Interrupt Request (INTIICAn).......................................................... 711
20.5.9 Method for detecting address matching............................................................................................................. 712
20.5.10 error detection ................................................................................................................................................... 712
20.5.11 extension code .................................................................................................................................................. 713
20.5.12 arbitration .......................................................................................................................................................... 714
20.5.13 wake-up function ............................................................................................................................................... 716
20.5.14 communication reservation................................................................................................................................ 719
20.5.15 Other Precautions.............................................................................................................................................. 723
20.5.16 communication operation .................................................................................................................................. 724
20.5.17 I2C Generation Sequence of Interrupt Requests (INTIICAn)............................................................................. 732
20.6 Timing diagram.................................................................................................................................................... 753
Chapter 21 CAN Controller.................................................................................................. 769
21.1 Summary Description .......................................................................................................................................... 769
21.1.1 feature ............................................................................................................................................................... 769
21.1.2 Functional Overview.......................................................................................................................................... 770
21.1.3 configuration...................................................................................................................................................... 771
21.2 CAN protocol ....................................................................................................................................................... 772
21.2.1 frame format...................................................................................................................................................... 772
21.2.2 Frame Type....................................................................................................................................................... 773
21.2.3 data frames and remote frames......................................................................................................................... 773
21.2.4 error frame......................................................................................................................................................... 780

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 15 / 1052 V2.1.1
21.2.5 overload frame................................................................................................................................................... 781
21.3 Features............................................................................................................................................................... 782
21.3.1 bus priority setting ............................................................................................................................................. 782
21.3.2 bit filling ............................................................................................................................................................. 782
21.3.3 multi-master....................................................................................................................................................... 782
21.3.4 multicast ............................................................................................................................................................ 782
21.3.5 CAN Sleep Mode/CAN Stop Mode Features..................................................................................................... 782
21.3.6 error control function.......................................................................................................................................... 783
21.3.7 baud rate control................................................................................................................................................ 788
21.4 Connection to target system................................................................................................................................ 792
21.5 Internal register for CAN controller ...................................................................................................................... 793
21.5.1 CAN controller configuration.............................................................................................................................. 793
21.5.2 register access type........................................................................................................................................... 795
21.5.3 register bit configuration .................................................................................................................................... 804
21.6 Bit Settings/Clean-up........................................................................................................................................... 808
21.7 control register..................................................................................................................................................... 810
21.8 CAN controller initialization.................................................................................................................................. 848
21.8.1 CAN module initialization................................................................................................................................... 848
21.8.2 Initialization of message cache.......................................................................................................................... 848
21.8.3 Redefining message caching............................................................................................................................. 848
21.8.4 Transition from initialization to operation ........................................................................................................... 849
21.8.5 Reset CAN module error counter C0ERC ......................................................................................................... 850
21.9 message receiving............................................................................................................................................... 851
21.9.1 message receiving............................................................................................................................................. 851
21.9.2 read received data............................................................................................................................................. 852
21.9.3 Receive history list feature ................................................................................................................................ 853
21.9.4 mask function .................................................................................................................................................... 855
21.9.5 multi-buffer receive block function..................................................................................................................... 857
21.9.6 remote frame receiving...................................................................................................................................... 858
21.10 message sending................................................................................................................................................. 859
21.10.1 message sending .............................................................................................................................................. 859
21.10.2 Send History List Feature.................................................................................................................................. 861
21.10.3 Automatic Block Transfer (ABT)........................................................................................................................ 863
21.10.4 Transmission abort handling.............................................................................................................................. 864
21.10.5 remote frame transmission................................................................................................................................ 865
21.11 power saving mode.............................................................................................................................................. 866
21.11.1 CAN sleep mode ............................................................................................................................................... 866
21.11.2 CAN Stop Mode................................................................................................................................................. 868
21.11.3 Power-saving mode........................................................................................................................................... 869
21.12 interrupt function.................................................................................................................................................. 870
21.13 Diagnostic features and special operation modes ............................................................................................... 871
21.13.1 Receive only mode............................................................................................................................................ 871
21.13.2 single-shot mode............................................................................................................................................... 872
21.13.3 self-test mode.................................................................................................................................................... 873

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 16 / 1052 V2.1.1
21.13.4 Receive/Send Operation in Operation Mode..................................................................................................... 874
21.14 timestamp function............................................................................................................................................... 875
21.14.1 timestamp function ............................................................................................................................................ 875
21.15 Baud rate setting.................................................................................................................................................. 877
21.15.1 Baud rate setting ............................................................................................................................................... 877
21.15.2 Representative example of baud rate setting.................................................................................................... 881
21.16 Operation of CAN controller................................................................................................................................. 885
Chapter 22 IrDA.................................................................................................................... 910
22.1 Features of IrDA .................................................................................................................................................. 910
22.2 Register controlling IrDA...................................................................................................................................... 911
22.2.1 Peripheral Enable Register 0 (PER0s). ............................................................................................................. 911
22.2.2 IrDA control register (IRCR)............................................................................................................................... 912
22.3 Running of IrDA................................................................................................................................................... 913
22.3.1 Procedures for IrDA Communication................................................................................................................. 913
22.3.2 Send.................................................................................................................................................................. 914
22.3.3 Receive ............................................................................................................................................................. 914
22.3.4 Selection of high level pulse width..................................................................................................................... 915
22.4 Precautions when using IrDA............................................................................................................................... 915
Chapter 23 Enhanced DMA................................................................................................. 916
23.1 The Function of DMA........................................................................................................................................... 916
23.2 Structure of DMA................................................................................................................................................. 918
23.3 Register for controlling DMA................................................................................................................................ 919
23.3.1 DMA controls the allocation of data areas and DMA vector table areas............................................................ 920
23.3.2 Controlling Data Allocation ................................................................................................................................ 921
23.3.3 vector table........................................................................................................................................................ 923
23.3.4 Peripheral Enable Register 1 (PER1)................................................................................................................ 925
23.3.5 DMA control register j(DMACRj) (j=0~39). ........................................................................................................ 925
23.3.6 DMA block size register j(DMBLSj) (j=0~39). .................................................................................................... 927
23.3.7 DMA transfer times register j(DMACTj) (j=0~39)............................................................................................... 928
23.3.8 DMA transfer times reload register j (DMRLDj) (j=0~39)................................................................................... 929
23.3.9 DMA source address register j(DMSARj) (j=0~39)............................................................................................ 930
23.3.10 DMA destination address register j(DMDARj) (j=0~39)..................................................................................... 930
23.3.11 DMA Boot Enable Register i (DMAENi) (i=0~4)................................................................................................ 931
23.3.12 DMA base address register (DMABAR) ............................................................................................................ 933
23.4 Operation of DMA................................................................................................................................................ 934
23.4.1 Boot Source....................................................................................................................................................... 934
23.4.2 normal mode...................................................................................................................................................... 935
23.4.3 repetition mode.................................................................................................................................................. 938
23.4.4 chain transmission............................................................................................................................................. 942
23.5 Precautionswhen using DMA............................................................................................................................... 944
23.5.1 DMA control data and vector table settings....................................................................................................... 944
23.5.2 DMA controls the allocation of data areas and DMA vector table areas............................................................ 944
23.5.3 The number of execution clocks for DMA.......................................................................................................... 945

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 17 / 1052 V2.1.1
23.5.4 Response time for DMA .................................................................................................................................... 946
23.5.5 Start Source for DMA ........................................................................................................................................ 946
23.5.6 Operation in standby mode ............................................................................................................................... 947
Chapter 24 Coordination Controller(EVENTC) .................................................................. 948
24.1 Features of EVENTC........................................................................................................................................... 948
24.2 Structure of EVENTC........................................................................................................................................... 948
24.3 control register..................................................................................................................................................... 949
24.3.1 Output target selection register n(ELSELRn) (n=00~21)................................................................................... 950
24.4 Operation of EVENTC ......................................................................................................................................... 953
Chapter 25 Interrupt function.............................................................................................. 955
25.1 Types of interrupt functionality............................................................................................................................. 955
25.2 interrupt source and structure.............................................................................................................................. 955
25.3 Register for controlling interrupt function ............................................................................................................. 962
25.3.1 interrupt request flag register (IF00~IF31)......................................................................................................... 962
25.3.2 interrupt mask register (MK00~MK31)............................................................................................................... 963
25.1.1 external interrupt rising edge permit register (EGP0, EGP1), external interrupt falling edge permit register
(EGN0, EGN1)................................................................................................................................................... 966
25.4 Operation of interrupt handling ............................................................................................................................ 968
25.4.1 Acceptance of maskable interrupt requests....................................................................................................... 968
25.4.2 Acceptance of Unmaskable Interrupt Request .................................................................................................. 968
Chapter 26 key interrupt function....................................................................................... 969
26.1 Function of key interrupt ...................................................................................................................................... 969
26.2 Structure of key break.......................................................................................................................................... 969
26.3 Register for controlling key interrupt .................................................................................................................... 971
26.3.1 Key Return Mode Register (KRM)..................................................................................................................... 971
26.3.2 Port Mode Register (PMx)................................................................................................................................. 972
Chapter 27 standby function............................................................................................... 973
27.1 standby function................................................................................................................................................... 973
27.2 sleep mode.......................................................................................................................................................... 974
27.2.1 Sleep mode configuration.................................................................................................................................. 974
27.2.2 Exit from Sleep Mode ........................................................................................................................................ 979
27.3 deep sleep mode................................................................................................................................................. 979
27.3.1 deep sleep mode configuration.......................................................................................................................... 979
27.3.2 Exist form Deep sleep mode.............................................................................................................................. 982
Chapter 28 reset function.................................................................................................... 982
28.1 Register which identifies reset source ................................................................................................................. 987
28.1.1 Reset control flag register (RESF)..................................................................................................................... 987
Chapter 29 Power-on reset circuit...................................................................................... 990
29.1 Function of power-on reset circuit........................................................................................................................ 990
29.2 Structure of power-on reset circuit....................................................................................................................... 991
29.3 Operation of power-on reset circuit...................................................................................................................... 991

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 18 / 1052 V2.1.1
Chapter 30 voltage detection circuit .................................................................................. 995
30.1 Function of Voltage Detection Circuit................................................................................................................... 995
30.2 Structure of voltage detection circuit.................................................................................................................... 996
30.3 Register for controlling voltage detection circuit................................................................................................... 997
30.1.1 Voltage detection register (LVIM) ...................................................................................................................... 997
30.3.1 Voltage detection level register (LVIS) .............................................................................................................. 998
30.4 Operation of voltage detection circuit................................................................................................................. 1001
30.4.1 Settings when used as reset mode.................................................................................................................. 1001
30.4.2 Settings when used as interrupt mode ............................................................................................................ 1003
30.4.3 Settings when used as interrupt & reset mode................................................................................................ 1005
30.2 Precautions for Voltage Detection Circuits......................................................................................................... 1011
Chapter 31 Safety function................................................................................................ 1013
31.1 Summary of Safety Features............................................................................................................................. 1013
31.2 Register used by Safety function....................................................................................................................... 1014
31.3 Operation of Safety functions............................................................................................................................. 1014
31.3.1 Flash CRC Operation Function (High Speed CRC)......................................................................................... 1014
31.3.1.1Flash CRC control register (CRC0CTL) ........................................................................................................ 1015
31.3.1.2flash CRC operation result register (PGCRCL)............................................................................................. 1016
31.3.2 CRC Operation Function (Universal CRC) ...................................................................................................... 1018
31.3.2.1CRC input register (CRCIN).......................................................................................................................... 1018
31.3.2.2CRC Data Register (CRCD).......................................................................................................................... 1019
31.3.3 RAM Parity Error Detection ............................................................................................................................. 1020
31.3.3.1RAM parity error control register (RPECTL).................................................................................................. 1020
31.3.4 SFR Protection Features................................................................................................................................. 1022
31.3.4.1SFR Protection Control Register (SFRGD)................................................................................................... 1022
31.3.5 frequency detection function............................................................................................................................ 1023
31.3.5.1Timer Input Select Register 0 (TIS0)............................................................................................................. 1023
31.3.6 A/D Test Function............................................................................................................................................ 1024
31.3.6.1A/D test register (ADTES)............................................................................................................................. 1026
31.3.6.2Analog input channel assignment register (ADS).......................................................................................... 1026
31.3.7 Digital output signal level detection function of input/output pin ...................................................................... 1027
31.3.7.1Port mode selection register (PMS)............................................................................................................... 1027
31.3.8 Product Unique Identity Register..................................................................................................................... 1028
Chapter 32 temperature sensor........................................................................................ 1029
32.1 Function of temperature sensor......................................................................................................................... 1029
32.2 Register for temperature sensor........................................................................................................................ 1029
32.2.1 temperature sensor calibration data register TSN25....................................................................................... 1029
32.2.2 temperature sensor calibration data register TSN85....................................................................................... 1029
32.3 Instructions for Using a Temperature Sensor .................................................................................................... 1030
32.3.1 Principle of Using Temperature Sensor........................................................................................................... 1030
32.3.2 Method for using temperature sensor.............................................................................................................. 1031
Chapter 33 Option Bytes................................................................................................... 1032

BAT32G137 User's Guide |Documentation Usage Instructions
www.mcu.com.cn 19 / 1052 V2.1.1
33.1 Feature of option bytes...................................................................................................................................... 1032
33.1.1 User Option Bytes (000C0H~000C2H/010C0H~010C2H) .............................................................................. 1032
33.1.2 Flash Data Protection Option Bytes (000C3H/010C3H,50004H~500005H).................................................... 1034
33.2 Format of user option bytes............................................................................................................................... 1035
33.3 Format of Flash Data Protection Option bytes................................................................................................... 1041
Chapter 34 FLASH control ................................................................................................ 1042
34.1 FLASH Control Feature Description .................................................................................................................. 1042
34.2 FLASH memory structure .................................................................................................................................. 1042
34.3 Register controlling FLASH................................................................................................................................ 1043
34.3.1 Flash write protection register (FLPROT)........................................................................................................ 1043
34.3.2 FLASH Operation Control Register (FLOPMD1, FLOPMD2) .......................................................................... 1044
34.3.3 Flash erase control register (FLERMD)........................................................................................................... 1045
34.3.4 Flash Status Register (FLSTS)........................................................................................................................ 1046
34.3.5 Flash Full Slice Erase Time Control Register (FLCERCNT)............................................................................ 1046
34.3.6 Flash Page Erase Time Control Register (FLSERCNT).................................................................................. 1047
34.3.7 Flash write time control register (FLPROCNT)................................................................................................ 1048
34.4 FLASH operation method .................................................................................................................................. 1049
34.4.1 Page Erase (sector erase)............................................................................................................................... 1049
34.4.2 Full Chip Erase (chip erase)............................................................................................................................ 1050
34.4.3 Programming (word program).......................................................................................................................... 1050
34.1 flash read........................................................................................................................................................... 1051
34.2 Precautions for FLASH Operations.................................................................................................................... 1051
Appendix Revision Records................................................................................................ 1052

BAT32G137 user manual | Chapter 1 CPU
www.mcu.com.cn 20 / 1052 V2.1.1
Chapter 1 CPU
1.1 verview
This Chapter provides a brief introduction to the features and debugging features of the ARM Cortex-M0+
kernel on which this product is built. Please refer to the ARM documentation for details.
1.2 Cortex-M0+ core features
⚫ARM Cortex-M0+ processors are 32-bit RISC cores with a 2-stage pipeline that supports privileged and
user modes
⚫Memory Protection Units (MPUs) support 8 separate Zone (region) protection
⚫single cycle hardware multiplier
⚫Nested Vector Interrupt Controller (NVIC)
◼1 Unshielded Interrupt (NMI)
◼Supports 32 Masking Interrupt Requests (IRQs)
◼4 interrupt priority
⚫The system timer SysTick is a 24-bit countdown timer that can be selected for fCLK or fIL count clocks
⚫vector table offset register (VTOR)
◼The software can write VTOR to relocate the start address of the vector table to a different location
◼The default value for this register is 0x0000_0000, with low 8-bit write ignore, read to zero, that is,
offset 256 bytes aligned
1.3 Debug features
⚫2-wire SWD debug interface
⚫Support for pausing, resuming, and single-step execution procedures
⚫Access processor's kernel register and special function register
⚫4 Hardware Breakpoints (BPUs)
⚫Unlimited software breakpoints (BKPT instruction)
⚫2 data observation points (DWT)
⚫Access memory during kernel execution
⚫Micro Trace Cache (MTB) provides a simple instruction execution trace scheme
- MTB shared with user SRAM (0x2000_0000-0x2000_2 FFF zone)
- The base address of the MTB control register is 0x4001_9000
Table of contents
Other Cmsemicon Microcontroller manuals

Cmsemicon
Cmsemicon CMS80F731 Series User manual

Cmsemicon
Cmsemicon BAT32A2 9 Series User manual

Cmsemicon
Cmsemicon BAT32G1 9 Series User manual

Cmsemicon
Cmsemicon CMS32H6157 User manual

Cmsemicon
Cmsemicon BAT32A237 User manual

Cmsemicon
Cmsemicon SC7020 Series User manual

Cmsemicon
Cmsemicon SC8F577 Series User manual

Cmsemicon
Cmsemicon CMS32L051 User manual

Cmsemicon
Cmsemicon CMS80F751 Series User manual