Page 1
Middle-speed On-chip Oscillator IAR Introduction This application note explains how to receive data in UART communication during STOP mode using the RL78/G11 middle-speed on-chip oscillator. STOP mode is released when the INTP (external interrupt) pin detects the start bit. Operations return from STOP mode and UART data is received simultaneously.
UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Specification The RL78/G11 middle-speed on-chip oscillator can be used to receive data in UART communications during STOP mode. When the INTP (external interrupt) pin detects the start bit during STOP mode, STOP mode is released.
Applications notes related to this document are shown below. RL78/G13 Initialization CC-RL (R01AN2575EJ) RL78/G11 Serial Array Unit (UART Communication) IAR (R01AN3646EJ) RL78/G11 UART communication with middle speed on chip oscillator IAR (R01AN3621EJ) R01AN3634EJ0100 Rev.1.00 Page 4 of 85...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Hardware Explanation Hardware Structure Example Figure 4.1shows the hardware used in this application note. RESET LED1 RL78/G11 LED2 REGC External P55/RxD0/INTP11 target device P30/TO01 P00/TI03 P40/TOOL0 For on-chip debugging Figure 4.1 Hardware Configuration...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Pin List Table 4.1 provides a list of the pins used in application note and their functions. Table 4.1 List of Pins and Functions Pin Name Input/Output Function Output...
The middle-speed on-chip oscillator does not provide frequency accurate enough for UART communications and baud rate corrections are necessary. A detailed description on how to correct the baud rate is provided in the following document: “RL78/G11 UART communication with middle speed on chip oscillator IAR (R01AN3621EJ).”...
Page 8
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU initialization <Channel 1 setting conditions> Operating clock: middle-speed on-chip oscillator (MOCO) 4MHz Use 16-bit timers Software trigger start MOCO valid edge: falling edge ...
Page 9
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR main processing initialization <Setting conditions> UART0 reception status initialization Set variable g_status to “0” (OK). Set variable g_uart0_rx_count to “0” (receive count value = 0). Set variable g_uart0_rx_length to “1” (receive data number = 1).
Page 10
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Stop TAU0 channel 1 after HALT mode release Set TT0 register TT01 bit “1” (operation stop (stop trigger generated)). Set TOE0 register TOE01 bit to “0” (timer output disabled).
Page 11
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR When reception data is abnormal Framing error: set P31 to Low output/High output, LED1 blinks. Parity error: set P33 to Low output/High output, LED2 blinks. Overrun error: set P31 and P33 to Low output/High output, LED1/LED2 both blink.
Page 12
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Figure 5.1 Timing Chart R01AN3634EJ0100 Rev.1.00 Page 12 of 85 Feb. 15, 2017...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Correction Processing The following provides a detailed explanation of correction processing. Generating waveforms for measurement As shown in Figure 5.2, the middle-speed on-chip oscillator (MOCO) frequency is divided by N to generate a waveform for measurement.
Page 14
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Table 5.2 Measurement Results of MOCO Waveform Divided by N MOCO (4 MHz±12%) min: 3.52 MHz Typ: 4.00 MHz Max: 4.42 MHz HOCO Max: 24.24 MHz (24.24 / 3.52) N = (24.24 / 4.00) N =...
Page 15
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Baud rate correction In this application, UART is MOCO driven, with the frequency set to: f = 4MHz or f = CK00 = f / 2 = 2MHz. The target baud rate is 9600bps; the values for the upper 7 bits of the SDR register (SDR[15:9]) are calculated by the following expressions.
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART How to Receive UART Data in STOP Mode Generally, when MOCO (middle-speed on-chip oscillator) is selected as the system clock, the UART receive operation is disabled if the program is stopped due to SNOOZE mode.
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Constants Table 5.4 lists the constants used in the sample program. Table 5.4 Constants Constant Name Setting Description WAIT_MAX 240000 MAX wait value for LED blinking Global Variables Table 5.5 lists the global variables used in the sample program.
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Functions Table 5.6 shows the list of functions used in the sample code. Table 5.6 Functions Function Name Outline hdwinit Initialization function R_Systeminit Peripheral function initialization function R_PORT_Create Port initialization function...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Function Specifications The following shows function specifications for the sample code. Function name: hdwinit Outline Initialization function Header intrinsics.h Declaration void hdwinit(void) Description Initial setup of peripheral functions. Argument...
Page 20
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Function name: R_SAU0_Create Outline SAU0 initialization function Header r_cg_sau.h,intrinsics.h Declaration void R_ SAU0_Create(void) Description Initial setup of SAU0. Argument None Return value None Additional notes None Function name: R_UART0_Create...
Page 21
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Function name: R_UART0_Receive Outline UART0 reception status initialization function Header r_cg_sau.h Declaration MD_STATUS R_UART0_Receive(uint8_t * const rx_buf, uint16_t rx_num) Description Initial setup of UART0 reception status Argument uint8_t* const rx_buf...
Page 22
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Function name: R_TAU0_Channel3_Start Outline TAU0 channel 3 operation start function Header r_cg_tau.h Declaration void R_TAU0_Channel3_Start (void) Description Sets TAU0 channel 3 to operation enabled state. Argument None Return value...
Page 23
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Function name: r_tau0_channel3_interrupt Outline TAU0 channel 3 count complete interrupt function Header r_cg_tau.h Declaration __interrupt void r_tau0_channel3_interrupt(void) Description Stores result of pulse width measured by TAU0 channel 3 in global variable.
Page 24
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Function name: r_uart0_interrupt_error Outline UART0 error interrupt function Header r_cg_sau.h Declaration __interrupt void r_uart0_interrupt_error(void) Description Stores reception data in RAM, responds based on error detected in r_uart0_callback_error function. Argument...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Flowcharts Figure5.1 shows the entire flow of the sample code. Figure 5.1 Entire Flow R01AN3634EJ0100 Rev.1.00 Page 25 of 85 Feb. 15, 2017...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.1 Main processing Figure5.2 shows the flowchart for main processing (1/2). main Initialization setting function hdwinit() main initialization R_MAIN_UserInit() Shift to STOP mode Return to normal mode in INTP11 interrupt...
Page 27
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Figure5.3 shows the flowchart for main processing (2/2). Figure 5.3 Main Processing (2/2) R01AN3634EJ0100 Rev.1.00 Page 27 of 85 Feb. 15, 2017...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.2 Initialization Figure5.4Figure 5. shows the flowchart of the initialization process. hdwinit Disable maskable interrupts IE ← 0 Peripheral function initialization Port initialization CPU clock initialization R_Systeminit() TAU0 initialization...
Figure5.6 shows the flowchart for port initialization. Figure 5.6 Port Initialization Note Refer to the initialization flowchart in the RL78/G13 Initialization (R01AN2575EJ) Application Note for details on how to set unused ports. Note When designing circuits, always make sure unused ports are properly processed and all electrical characteristics are met.
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.5 TAU0 initialization Figure5.8 shows the flowchart for TAU0 initialization (1/2). Figure 5.8 TAU0 Initialization (1/2) R01AN3634EJ0100 Rev.1.00 Page 30 of 85 Feb. 15, 2017...
Page 31
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Figure5.9 shows the flowchart for TAU0 initialization (2/2). Figure 5.9 TAU0 Initialization (2/2) R01AN3634EJ0100 Rev.1.00 Page 31 of 85 Feb. 15, 2017...
Page 32
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Reset Release ・Peripheral reset control register 0 (PRR0) Release TAU from the reset state. Symbol: PRR0 IICA1RES ADCRES IICA0RES SAU0RES TAU0RES Bit 0 TAU0RES Reset control of timer array unit 0 Reset control of timer array unit 0 Reset state of timer array unit 0.
Page 33
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Operation Clock Selection ・Timer clock selection register 0 (TPS0) Set CK00 / CK01 = f Symbol: TPS0 Bit 7- 0 (n = 0, 1) Operation Clock (CK01/CK00) Selection...
Page 34
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 All Channel Operation Stop ・Timer channel stop register 0 (TT0) Set all TAU0 channels to operation stop state. Symbol: TT0 Bit 11 Trigger to stop operations of higher 8-bit timer when channel 3 is in 8-bit timer mode No trigger operation TEHm3 bit is cleared to 0 and the count operation is stopped.
Page 35
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 All Interrupts Disable ・Interrupt request flag register (MK0H/MK1L) Disable all TAU0 interrupts. ・Interrupt request flag register (IF0H/IF1L) Clear TAU interrupt request flags. Symbol: MK0H STMK1 SRMK0 STMK0 CSIMK10...
Page 36
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Interrupt Priority Level Setting ・Priority level flag registers (PR11L, PR01L) Set channels 1 and 3 to level 2. Symbol: PR11L SRPR11 TMPR103 TMPR102 TMPR101 TMPR103H TMPR101H IICAPR10 SREPR11...
Page 37
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 1 Initialization ・Timer mode register 01 (TMR01) Set TAU0 channel 1 as follows: ・Operation clock: CK00(24MHz) ・Operate as 16-bit timer ・Software trigger start ・TI01 pin valid edge: falling ・Interval timer mode...
Page 38
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Bit 7 – 6 Selection of Tlmn pin input valid edge Falling edge Rising edge Both edges (when low-level width is measured) Both edges (when high-level width is measured) Bit 3 –...
Page 39
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 1 Compare Value Setting ・Timer data register 01 (TDR01) Set TAU0 channel 1 compare value to 1295H. Symbol: TDR01 TAU0 Channel 1 Output Mode Setting ・Timer output mode register 0 (TOM0) Set the master channel mode output mode.
Page 40
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 1 Timer Output Setting ・Timer output register 0 (TO0) Set timer output value to 0. Symbol: TO0 Bit 1 Timer output of channel n Timer output value is 0.
Page 41
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 3 Initialization ・Timer mode register 03 (TMR03) Set TAU0 channel 3 as follows: ・Operation clock: CK00(24MHz) ・Single channel operations ・TI03 pin valid edge used as start trigger and capture trigger ・TI03 pin valid edge: rising...
Page 42
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Bit 7 – 6 Selection of Tlmn pin input valid edge Falling edge Rising edge Both edges (when low-level width is measured) Both edges (when high-level width is measured) Bit 3 –...
Page 43
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 3 Output Mode Setting ・Timer output mode register 0 (TOM0) Set master channel mode output mode. Symbol: TOM0 Bit 3 Control of channel n timer output mode...
Page 44
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 3 Timer Output Setting ・Timer output register 0 (TO0) Set timer output value to 0. Symbol: TO0 Bit 3 Timer output of channel n Timer output value is 0.
Page 45
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 TI03 Pin Noise Filter Disable ・Noise filter enable register 1 (NFEN1) Set noise filter to OFF. Symbol: NFEN1 TNFEN03 TNFEN02 TNFEN01 TNFEN00 Bit 3 TNFEN03 Enable/disable use of noise filter for TI03 pin input signal...
Page 46
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Symbol: PMC3 PMC33 PMC32 PMC31 PMC30 Bit 0 PMC30 Selection of Pmn pin digital input/output or analog input (m = 0-3; n = 0-7) Digital input/output (alternate function other than analog input)
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.6 SAU0 initialization Figure5.10 shows the flowchart for SAU0 initialization. R_SAU0_Create PRR0 register SAU0 reset release SAU0RES bit ← 1 : SAU0 is in reset state SAU0RES bit ← 0...
Page 48
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR SAU0 Reset Release ・Peripheral reset control register 0 (PRR0) Release SAU0 from reset state. Symbol: PRR0 IICA1RES ADCRES IICA0RES SAU0RES TAU0RES Bit 2 SAU0RES Control of serial array unit reset release...
Page 49
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR SAU0 Operation Clock Selection ・Serial clock selection register 0 (TPS0) Set to 12MHz. Symbol: SPS0 - - - - - - - - Bit 3 - 0 Operation Clock (CK00) Selection...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.7 UART0 initialization Figure5.11 shows the flowchart for UART0 initialization. Figure 5.11 UART0 Initialization R01AN3634EJ0100 Rev.1.00 Page 50 of 85 Feb. 15, 2017...
Page 51
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Communication Operation Stop ・Serial channel stop register 0 (ST0) Set UART0 to communication operation stop. Symbol: ST0 Bit 1 Trigger to start operations of channel n No trigger operation SEmn bit is cleared to 0 and the communication operation is stopped.
Page 52
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Transmission Completion Interrupt/Reception Error Interrupt ・Interrupt request flag register (MK0H) Disable UART0 transmission completion interrupt/reception error interrupt. ・Interrupt request flag register (IF0H) Clear UART0 transmission completion interrupt/reception error interrupt flag.
Page 53
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Interrupt Priority Level Settings ・Priority level flag registers (PR10L, PR00L) Set reception/reception error interrupt to level 3 (lowest priority level). Symbol: PR00H STPR01 SRPR00 STPR00 CSIPR010 TMPR000 SREPR00...
Page 54
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Channel 1 Error Flag Setting ・Serial flag clear trigger register 01 (SIR01) Clear all error flags. Symbol: SIR01 FECT PECT OVCT - - - - - - -...
Page 55
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Channel 1 Initialization ・Serial mode register 01 (SMR01) Set UART0 channel 1 as follows: ・Operation clock: CK00 ・Transfer clock: CK00 divided clock (divided-by-2) ・RxD0 pin valid edge ・Start bit detection: falling edge ・UART mode...
Page 56
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Channel 1 Serial Communication Operation Settings ・Serial communication operation setting register 01 (SCR01) Set UART0 channel 1 as follows: ・Operation mode: reception only ・Clock phase: type 1 ・Data transmission order: LSB first ・Data length: 8-bit data...
Page 57
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Bit 7 DIR01 Setting of data transfer order in CSI and UART modes Inputs/outputs data with MSB first. Inputs/outputs data with LSB first. Bit 5 - 4 SLC011 SLC010...
Page 58
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Channel 1 Baud Rate Setting ・ Serial data register 01 (SDR01) Set transfer clock to 9600bps. (9600bps = f ÷ 208 = 2MHz ÷ 208) Symbol: SDR01 Bit 15-9...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.9 Main initialization Figure5.13 shows the flowchart for main initialization. Figure 5.13 Main Initialization 5.9.10 UART0 reception status initialization Figure5.14 shows the flowchart for UART0 reception status initialization. R_UART0_Receive status ←...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.11 UART0 operation start function Figure5.15 shows the flowchart for the UART0 operation start function. R_UART0_Start SS0 register Enable UART0 operation SS01 bit ← 1 : Shift to communication wait state...
Page 65
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR UART0 Reception Complete/Reception Error Interrupt Enable ・Interrupt request flag register (MK0H) Enable UART0 interrupts. ・Interrupt request flag register (IF0H) Clear all UART0 interrupt request flags. Symbol: IF0H ST1IF SRIF0...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.12 TAU0 baud rate setting Figure5.16 shows the flowchart for TAU0 baud rate setting (1/2). Figure 5.16 TAU0 Baud Rate Setting (1/2) R01AN3634EJ0100 Rev.1.00 Page 66 of 85 Feb. 15, 2017...
Page 67
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Figure5.17 shows the flowchart for TAU0 baud rate setting (2/2). Figure 5.17 TAU0 Baud Rate Setting (2/2) R01AN3634EJ0100 Rev.1.00 Page 67 of 85 Feb. 15, 2017...
Page 68
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR CPU Clock Change Setting ・System clock control register (CKC) Change setting from high-speed to middle-speed on-chip oscillator clock. Symbol: CKC MCM0 MCS1 MCM1 Bit 0 MCM1 Operation control of main on-chip oscillator clock (f...
Page 69
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 1 Count Clock Setting ・Timer mode register 01 (TMR01) Set to valid edge of input signal. Symbol: TMR01 SPLIT Bit 12 CCS01 Selection of count clock (f...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.14 TAU0 channel 3 operation start function Figure5.19 shows the flowchart for TAU0 channel 3 operation start function. Figure 5.19 TAU0 Channel 3 Operation Start Function TAU0 Channel 3 Interrupt Enable ・Interrupt request flag register (IF1L)
Page 72
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR TAU0 Channel 3 Count Operation Enable ・Timer channel start register 0 (TS0) Set to count enabled state. Symbol: TS0 TS03 TS02 TS01 TS00 Bit 3 TS03 Operation enable (start) trigger for channel n No trigger operation TEmn bit is set to 1, goes to count operation enabled state.
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.18 Wait function for LED blinking Figure5.24 shows the flowchart for the wait function for LED blinking. r_processing_pause Initialize LED wait count to 0 g_wait_count ← 0 LED wait count update...
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR 5.9.21 UART0 reception complete interrupt processing Figure5.27 shows the flowchart for UART0 reception complete interrupt processing. r_uart0_interrupt_receive rx_data ← RXD0 Read reception data and set to variable Within specified number of data? UART0 reception data number overrun *gp_uart0_rx_address ←...
Download the sample code from the Renesas Electronics homepage. Reference Documents RL78/G11 User's Manual: Hardware (R01UH0637E) RL78 family User's Manual: Software (R01US0015E) (Please make sure you obtain the latest version from the Renesas Electronics homepage.) Technical Updates Obtain the latest information from the Renesas Electronics homepage. R01AN3634EJ0100 Rev.1.00 Page 84 of 85 Feb.
Page 85
RL78/G11 UART Reception in STOP Mode Using Middle-speed On-chip Oscillator IAR Website and Support Renesas Electronics Website http://www.renesas.com/ Inquiries http://www.renesas.com/contact/ All trademarks and registered trademarks are the property of their respective owners. R01AN3634EJ0100 Rev.1.00 Page 85 of 85 Feb. 15, 2017...
Page 86
Revision History Description Rev. Date Page Summary 1.00 Feb. 15, 2017 First edition issued...
Page 87
General Precautions in the Handling of Microprocessing Unit and Microcontroller Unit Products The following usage notes are applicable to all Microprocessing unit and Microcontroller unit products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products.
Page 88
10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the product with a third party, to notify such third party in advance of the contents and conditions set forth in this document, Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics products.
Need help?
Do you have a question about the RL78 and is the answer not in the manual?
Questions and answers