APPLICATION NOTE
R01AN1713EJ0101 Rev. 1.01 Page
1
of 36
Nov. 6, 2015
RX63N Group, RX631 Group
True/False Determination of RTC Time Information
on Cold Start
Abstract
This document describes the method to determine whether power is supplied from the VBATT while the voltage on the
VCC pin is dropped when using the realtime clock (RTC) and the battery backup function together. The RTC clock
settings and registers are used to determine whether the RTC continues operation or the RTC is initialized.
Products
- RX63N Group 177-pin and 176-pin packages with a ROM size between 768 KB and 2 MB
- RX63N Group 145-pin and 144-pin packages with a ROM size between 768 KB and 2 MB
- RX63N Group 100-pin package with a ROM size between 768 KB and 2 MB
- RX631 Group 177-pin and 176-pin packages with a ROM size between 256 KB and 2 MB
- RX631 Group 145-pin and 144-pin packages with a ROM size between 256 KB and 2 MB
- RX631 Group 100-pin package with a ROM size between 256 KB and 2 MB
- RX631 Group 64-pin package with a ROM size between 256 KB and 512 KB
When using this application note with other Renesas MCUs, careful evaluation is recommended after making
modifications to comply with the alternate MCU.
R01AN1713EJ0101
Rev. 1.01
Nov. 6, 2015
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
2
of 36
Nov. 6, 2015
Contents
1. Specifications ..................................................................................................................................... 3
2. Operation Confirmation Conditions .................................................................................................... 5
3. Reference Application Notes .............................................................................................................. 5
4. Hardware ............................................................................................................................................ 6
4.1 Hardware Configuration ............................................................................................................... 6
4.2 Pins Used ..................................................................................................................................... 6
5. Software ............................................................................................................................................. 7
5.1 Operation Overview ..................................................................................................................... 7
5.2 Battery Backup Function .............................................................................................................. 8
5.3 Programming/Erasing the E2 DataFlash ..................................................................................... 9
5.3.1 Erasing the E2 DataFlash ..................................................................................................... 9
5.3.2 Programming the E2 DataFlash ........................................................................................... 9
5.3.3 Changes in the Simple Flash API ......................................................................................... 9
5.4 File Composition ........................................................................................................................ 10
5.5 Option-Setting Memory .............................................................................................................. 11
5.6 Constants ................................................................................................................................... 12
5.7 Structure/Union List ................................................................................................................... 13
5.8 Variables .................................................................................................................................... 14
5.9 Functions .................................................................................................................................... 15
5.10 Function Specifications .............................................................................................................. 16
5.11 Flowcharts .................................................................................................................................. 20
5.11.1 Main Processing ................................................................................................................ 20
5.11.2 Port Initialization ................................................................................................................ 21
5.11.3 Determination of RTC Initialization Requirement .............................................................. 22
5.11.4 Setting the Validity of the Alarm Time Information ............................................................ 24
5.11.5 Determination of the Backup Time Information for Use .................................................... 25
5.11.6 Verification of the RTC Time Information Value ................................................................ 26
5.11.7 Comparison of the RTC Time Information with the Backup Time Information .................. 27
5.11.8 Verifying the Range of the RTC Time Information ............................................................ 28
5.11.9 Reading the RTC Time Information ................................................................................... 29
5.11.10 Clock Initialization ............................................................................................................ 30
5.11.11 Sub-Clock Oscillation Setting .......................................................................................... 31
5.11.12 RTC Initialization ............................................................................................................. 32
5.11.13 RTC Periodic Interrupt Handling ..................................................................................... 33
5.11.14 Backup Processing for the RTC Time Information .......................................................... 34
6. Sample Code .................................................................................................................................... 36
7. Reference Documents ...................................................................................................................... 36
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
3
of 36
Nov. 6, 2015
1. Specifications
After a reset, the software determines whether to continue the RTC count operation or initialize the RTC, then performs
the operation according to the determination.
The battery backup function enables the RTC and the sub-clock oscillator to continue operating with power supplied by
the VBATT even when the voltage on the VCC pin is dropped. The RTC must be initialized only when the voltage on
the VCC pin continues being dropped and power supply from the VBATT is stopped. But after both of them hung a
VCC pin and a VBATT pin on 0V once when the voltage of VBATT was lower than a guarantee area after changing to
VBATT, please do a power-on reset.
The VBATT circuit is assumed that it takes 15 minutes for charging the connected capacitor at a maximum, and the
fully charged capacitor can supply power for at least 10 days.
In this application note, the following are verified for determination:
If the VCC voltage is recovered and the reset is released within the period the VBATT can supply power.
If the charging time for the VBATT is enough.
If the values stored in the RTC registers are correct after a reset.
The RTC time information displayed on the Debug LCD of the RSK is updated every second while the VCC voltage is
retained.
Also the RTC time information (backup) stored in the E2 DataFlash is updated in the following timings:
After a reset and 1 second elapses.
After 15 minutes, which is time required to charge the capacitor connected to the VBATT.
When the hour counter (RHRCNT) for the RTC time information is updated.
Table 1.1 lists the Peripheral Functions and Their Applications and Figure 1.1 shows the Operation Overview.
Table 1.1 Peripheral Functions and Their Applications
Peripheral Function
Application
RTCa
Clock counter
VBATT
Power supply to the RTC and the sub-clock oscillator.
E2 DataFlash
Backup for the RTC time information
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
4
of 36
Nov. 6, 2015
Reset with the
RES# pin
VPOR
Operating
RTC Undefined
RES# pin Low
High
VCC
RTC time information is
not correct
RTC initialized
Power-on
reset
VBATT
Cold start Cold startWarm start
Operating
Before 15
minutes elapse
Cold start
Before 10
days elapse
Cold start
15 minutes
elapsed 15 minutes
elapsed 10 days or
more elapsed
Undefined Operating
RTC time information is
correct, VBATT is not
charged enough
RTC initialized
RTC time information is
correct, VBATT is fully
charged
RTC not initialized
RTC time information is
correct
RTC not initialized
RTC time information is
not correct
RTC initialized
Figure 1.1 Operation Overview
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
5
of 36
Nov. 6, 2015
2. Operation Confirmation Conditions
The sample code accompanying this application note has been run and confirmed under the conditions below.
Table 2.1 Operation Confirmation Conditions
Item
Contents
MCU used
R5F563NBDDFC (RX63N Group)
Operating frequencies
- Main clock: 12 MHz
- Sub-clock: 32.768 kHz
- PLL: 192 MHz (main clock divided by 1 and multiplied by 16)
- LOCO: 125 kHz
- System clock (ICLK): 96 MHz (PLL divided by 2)
- Peripheral module clock B (PCLKB): 48 MHz (PLL divided by 4)
Operating voltage
3.3 V, VBATT is VBATT or greater
Integrated development
environment
Renesas Electronics Corporation
High-performance Embedded Workshop Version 4.09.01
C compiler
Renesas Electronics Corporation
C/C++ Compiler Package for RX Family V.1.02 Release 01
Compile options
-cpu=rx600 -output=obj="$(CONFIGDIR)\$(FILELEAF).obj" -debug -nologo
(The default setting is used in the integrated development environment.)
iodefine.h version
Version 1.8
Endian
Little endian
Operating mode
Single-chip mode
Processor mode
Supervisor mode
Sample code version
Version 1.01
Board used
Renesas Starter Kit+ for RX63N (product part no.: R0K50563NC000BE)
3. Reference Application Notes
For additional information associated with this document, refer to the following application notes.
- RX63N Group, RX631 Group Initial Setting Rev. 1.10 (R01AN1245EJ)
- RX600 & RX200 Series Simple Flash API for RX Rev.2.40 (R01AN0544EU)
- RX Family Using the Simple Flash API for RX without the r_bsp Module Rev1.00 (R01AN1890EU)
- Renesas Starter Kit Sample Code for Hi-performance Embedded Workshop Rev.1.00 (R01AN1395EG)
- RX Family Coding Example of Wait Processing by Software Rev. 1.00 (R01AN1852EJ0100)
The initial setting functions, Debug LCD output functions, simple flash API functions, coding example of wait
processing by software functions in the reference application notes are used in the sample code accompanying this
application note. The revision numbers of the reference application notes are as of when these application notes were
made. However the latest version is always recommended. Visit the Renesas Electronics Corporation website to check
and download the latest version.
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
6
of 36
Nov. 6, 2015
4. Hardware
4.1 Hardware Configuration
Figure 4.1 shows the Connection Example.
Figure 4.1 Connection Example
In this application note, the maximum charging time is 15 minutes and the shortest discharging time (time to retain
power) is 10 days.
Note that the charging and discharging time vary depending on the circuit structure of the VBATT pins. Make sure to
use the charge and discharge time carefully evaluated and confirmed in the user system.
4.2 Pins Used
Table 4.1 lists the Pins Used and Their Functions.
Table 4.1 Pins Used and Their Functions
Pin Name
I/O
Function
P03
Output
LED0 output to indicate completion of the RTC initialization
P05
Output
LED1 output to indicate E2 DataFlash backup error
P87
Output
Debug LCD Data bit 7 output
P86
Output
Debug LCD Data bit 6 output
P85
Output
Debug LCD Data bit 5 output
P84
Output
Debug LCD Data bit 4 output
PJ5
Output
Debug LCD Enable output
PF5
Output
Debug LCD Register select output
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
7
of 36
Nov. 6, 2015
5. Software
5.1 Operation Overview
In this application note, the RTC time information is validated using the items below as criteria. According to the
validation, the RTC is determined to continue operation or be initialized. Figure 5.1 shows the Validation Procedure.
- RTC count source: Sub-clock operating
- RTC control register: Same value as the initial value
- RTC automatic adjustment setting: Same value as the initial value when this setting is enabled
- RTC time information: Values that are correct as the time information and within 10 days from the backup time
information in the E2 DataFlash.
- RTC alarm information: Values that are correct as the time information and within 10 days from the backup time
information in the E2 DataFlash.
- Charge detection in the VBATT circuit: Cold start and 15 minutes elapsed from the previous RTC initialization.
RTC initial setting values are as follows:
- Hours mode: 12-hour mode
- Initial time setting: 00:00:00, Tuesday, January 1, 2013
- Alarm setting: Disabled
- RTCOUT output: Output disabled
- Automatic adjustment: Not used
- Count source: Sub-clock for standard clock loads
- Time capture: Not used
- Interrupts: The periodic interrupt (PRD) is generated every second.
The alarm interrupt and the carry interrupt are disabled.
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
8
of 36
Nov. 6, 2015
Validation
return
Values
in the RTC control register
match the initial setting
values?
Matched
Not matched
Values
in the time error adjustment
register match the initial
setting values?
Not matched
When the time-error adjustment function is used:
The time
register has valid
values?
Yes
No
The hour
alarm register has a valid
value?
Yes
No
Continue the count Initialize the RTC
VBATT fully charged?
Yes
No
Difference
between the current time
and the backup time is within
10 days?
Yes
No
Warm start?
Yes
No
Matched
When the alarm function is used:
Figure 5.1 Validation Procedure
5.2 Battery Backup Function
With the connected circuit in this application note, an output voltage of VBATT or greater on the VBATT pin can be
retained for at least 10 days, and the capacitor can be fully charged within 15 minutes.
Note that the charging and discharging time vary depending on the connected circuit. Make sure to use the charging and
discharging time carefully evaluated and confirmed in the user system.
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
9
of 36
Nov. 6, 2015
5.3 Programming/Erasing the E2 DataFlash
In this application note, addresses 0010 0000h to 0010 003Fh (64 bytes) of the E2 DataFlash are used. 10 bytes of the
RTC time information is overwritten and stored in addresses 0010 0000h to 0010 0009h and 0010 0020h to 0010 0029h
alternately. Data is not retained for the other areas in the 64 bytes of the E2 DataFlash.
For details on the other Simple Flash API used for programming/erasing, refer to the RX600 & RX200 Series Simple
Flash API for RX.
5.3.1 Erasing the E2 DataFlash
To erase the E2 DataFlash, the R_FlashEraseRange function of the Simple Flash API for RX is used. The erase error
can be determined by the return value from the R_FlashEraseRang function or the register value in the FlashError
function.
5.3.2 Programming the E2 DataFlash
To program the E2 DataFlash, the R_FlashWrite function of the Simple Flash API for RX is used. The program error
can be determined by the return value from the R_FlashWrite function or the register value in the FlashError function.
5.3.3 Changes in the Simple Flash API
Programming and erasing of the E2 DataFlash is performed using the program in the flash memory (ROM). The main
loop can be executed during programming or erasing.
In this application note, r_flash_api_rx_config.h is changed in the Simple Flash API.
Table 5.1 shows Changes in r_flash_api_rx_config.h.
Table 5.1 Changes in r_flash_api_rx_config.h
Changed Item
Description
Code After the Change
Settings in the
Simple Flash API
No programming
performed in the ROM
// #define
FLASH_API_RX_CFG_ENABLE_ROM_PROGRAMMING
Data to be programmed is
stored in the RAM buffer.
#define FLASH_API_RX_CFG_FLASH_TO_FLASH
E2 DataFlash operation is
executed in background.
#define FLASH_API_RX_CFG_DATA_FLASH_BGO
Flash API is not
transferred to the RAM
// #define FLASH_API_RX_CFG_COPY_CODE_BY_API
Note: When VCC power is cut off or reset during programming or erasing the E2 DataFlash, the RTC time
information becomes incorrect. Thus the RTC is initialized after a reset.
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
10
of 36
Nov. 6, 2015
5.4 File Composition
Table 5.2 and Table 5.3 list the files used in this application notes. Table 5.4 and Table 5.5 list the functions and setting
values in the reference application notes. Table 5.6 lists files from the simple flash API module.
Files generated by the integrated development environment are not included in this table.
Table 5.2 Files Used in the Sample Code
File Name
Outline
main.c
Main processing, port setting
r_init_clock_an1713.c
Clock initialization
r_init_clock_an1713.h
Header file for r_init_clock_an1713.c
rtc_func.c
RTC register determination, RTC initialization, and periodic interrupt handling
rtc_func.h
Header file for rtc_func.c
flash_write.c
Processing for backing up the RTC time information to the E2 DataFlash
Table 5.3 Standard Include Files
File Name
Outline
stdbool.h
Defines macros regarding the boolean type and value.
stdint.h
Defines macros declaring the integer type with the specified width.
machine.h
Defines types of built-in function for the RX Family.
Table 5.4 Functions and Setting Values in the RX63N Group, RX631 Group Initial Setting Application
Note
File Name
Function
Description
r_init_stop_module.c
R_INIT_StopModule()
r_init_stop_module.h
Module-stop state is canceled for DMAC/DTC,
EXDMAC, RAM0, and RAM1.
r_init_non_existent_port.c
R_INIT_NonExistentPort()
r_init_non_existent_port.h
176 pin package is specified.
r_delay.c
R_DELAY_Us()
The waiting time is set.
r_delay.h
Table 5.5 Functions and Setting Values in the Sample Code Accompanying the Renesas Starter Kit
for RX63N High-performance Embedded Workshop
File Name
Function
Description
lcd.c
- Init_LCD()
- Display_LCD()
lcd.h
rskrx63ndef.h
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
11
of 36
Nov. 6, 2015
Table 5.6 Simple Flash API Modules
(RX600 & RX200 Series Simple Flash API for RX Application Note)
Module Name
Outline
r_flash_api_rx
RX Simple Flash API programs for RX600 and RX200 Series
u_bsp
Board support package for users (1)
Note:
1. The module is modified following the application note “Using the Simple Flash API for RX without the
r_bsp Module”.
5.5 Option-Setting Memory
Table 5.7 lists the Option-Setting Memory Configured in the Sample Code. When necessary, set a value suited to the
user system.
Table 5.7 Option-Setting Memory Configured in the Sample Code
Symbol
Address
Setting Value
Contents
OFS0
FFFF FF8Fh to FFFF FF8Ch
FFFF FFFFh
The IWDT is stopped after a reset.
The WDT is stopped after a reset.
OFS1
FFFF FF8Bh to FFFF FF88h
FFFF FFFBh
The voltage monitor 0 reset is enabled
after a reset.
HOCO oscillation is disabled after a
reset.
MDES
FFFF FF83h to FFFF FF80h
FFFF FFFFh
Little endian
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
12
of 36
Nov. 6, 2015
5.6 Constants
Table 5.8 lists the Constants Used in the Sample Code.
Table 5.8 Constants Used in the Sample Code
Constant Name
Setting Value
Contents
RTC_INIT_RES
1
Reset with the RTC initialization required
RTC_RUN_RES
0
Reset with the RTC initialization not required
RTC_BACKUP_INIT
2
Backup of the RTC time information is requested.
(Initialization source, backup request after 1 second)
RTC_BACKUP_ACK
1
Backup of the RTC time information is requested.
(backup request after 15 minutes and every hour)
RTC_BACKUP_NACK
0
Backup of the RTC time information is not requested.
VBATT_FULL_CHARGE
1
VBATT circuit is fully charged.
VBATT_EMPTY
0
VBATT circuit is not charged enough.
MASK_DATA_SEC
0x01
Execution flag of second data verification, data for
verifying the flag
MASK_DATA_MIN
0x02
Execution flag of minute data verification, data for
verifying the flag
MASK_DATA_HR
0x04
Execution flag of hour data verification, data for
verifying the flag
MASK_DATA_WK
0x08
Execution flag of day-of-week data verification, data
for verifying the flag
MASK_DATA_DAY
0x10
Execution flag of day data verification, data for
verifying the flag
MASK_DATA_MON
0x20
Execution flag of month data verification, data for
verifying the flag
MASK_DATA_YR
0x40
Execution flag of year data verification, data for
verifying the flag
ALL_DATA_CHECK
0x7F
Execution flag of all data verification
ADDRESS_BLOCK_DB0
0x100000
Start address of the DB0 block
ADDRESS_BLOCK_DB1
0x100020
Start address of the DB1 block
BUFF_SIZE
10
Sizes for storing the time information and
programming
WRITE_BUSY
2
Programming mode (programming)
ERASE_BUSY
1
Programming mode (erasing)
WRITE_READY
0
Programming mode (preparing)
SELECT_SUB
PATTERN_D
Selection of the sub-clock setting pattern
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
13
of 36
Nov. 6, 2015
5.7 Structure/Union List
Figure 5.2 shows the Structure/Union Used in the Sample Code.
/* **** Time data **** */
typedef struct
{
uint8_t second; /* Second */
uint8_t minute; /* Minute */
uint8_t hour; /* Hour */
uint8_t dayweek; /* Day of the week */
uint8_t day; /* Day */
uint8_t month; /* Month */
uint16_t year; /* Year */
uint8_t charge_VBATT; /* VBATT charge info */
uint8_t write_cnt; /* Backup counter */
} time_bcd_t;
Figure 5.2 Structure/Union Used in the Sample Code
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
14
of 36
Nov. 6, 2015
5.8 Variables
Table 5.9 lists the Global Variables, Table 5.10 lists the static Variables, and Table 5.11 lists the const Variable.
Table 5.9 Global Variables
Type
Variable Name
Contents
Function Used
uint8_t
init_RTC
RTC initialization request flag
- main
- enable_RTC_an1713
- CGC_subclk_as_RTC_an1713
uint32_t
time_data
Buffer to obtain time information
- check_RTC
- flash_check
- check_RTC_flash
- check_RTC_after10days
- enable_RTC_an1713
- Excep_RTC_PRD
- time_backup
uint8_t
flash_write
Backup request flag for the RTC
time information
- main
- check_RTC
- enable_RTC_an1713
- Excep_RTC_PRD
int8_t
write_counter
Backup counter
- main
- check_RTC
- flash_check
- check_RTC_flash
- check_RTC_after10days
- Excep_RTC_PRD
uint8_t
write_mode
Programming mode
- Excep_RTC_PRD
- flash_check
uint8_t
lcd_buffer[9]
Buffer for Debug LCD
- main
- uint32_ToBCDString
uint8_t
flash_is_ready
Flash processing end flag
- time_backup
- check_RTC
- Excep_RTC_PRD
Table 5.10 static Variables
Type
Variable Name
Contents
Function Used
static uint8_t
charge_min_count
Charge time (minutes) counter for the
VBATT circuit
- check_RTC
- Excep_RTC_PRD
static uint8_t
check_time_data
Time information check required/time
information check not required
- check_RTC
- Set_register_enable
- flash_check
- check_RTC_clock
static uint8_t
prog_buff
Time information for backup
- time_backup
Table 5.11 const Variable
Type
Variable Name
Contents
Function Used
const static uint32_t
backup_address[2] =
{ADDRESS_BLOCK_DB0,
ADDRESS_BLOCK_DB1};
- Start address of the DB0
block
- Start address of the DB1
block
- check_RTC
- flash_check
- check_RTC_flash
- check_RTC_after10days
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
15
of 36
Nov. 6, 2015
5.9 Functions
Table 5.12 lists the Functions.
Table 5.12 Functions
Function Name
Outline
File the Function is in
main
Main processing
main.c
port_init
Port output setting
main.c
check_RTC
Determination of RTC initialization requirement
rtc_func.c
Set_register_enable
Setting the validity of the alarm time information
rtc_func.c
flash_check
Determination of the backup time information for use
rtc_func.c
check_RTC_clock
Verification of the RTC time information value
rtc_func.c
check_RTC_flash
Comparison of the RTC time information with the
backup time information
rtc_func.c
check_RTC_after10days
Verifying the range of the RTC time information
rtc_func.c
rtc_time_read
Reading the RTC time information
rtc_func.c
R_INIT_Clock_an1713
Clock initialization
r_init_clock_an1713.c
CGC_subclk_as_RTC_
an1713
Sub-clock setting
(sub-clock is used for the RTC count source and not
used for the system clock)
r_init_clock_an1713.c
enable_RTC_an1713
RTC initialization
rtc_func.c
Excep_RTC_PRD
RTC periodic interrupt handling
rtc_func.c
time_backup
Backup processing for the RTC time information
flash_write.c
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
16
of 36
Nov. 6, 2015
5.10 Function Specifications
The following tables list the sample code function specifications.
main
Outline
Main processing
Header
None
Declaration
void main(void)
Description
After initialization, if a backup request of the RTC time information is generated, the
backup processing function is called.
Arguments
None
Return Value
None
Remarks
In the main loop processing, do not rewrite registers that are write protected while
operating in E2 DataFlash P/E mode. When additional processing is added to the
main loop, and if operating in E2 DataFlash P/E mode, any processing including the
additional processing is executed in E2 DataFlash P/E mode.
port_init
Outline
Port initialization
Header
None
Declaration
static void port_init(void)
Description
Initializes the ports.
Arguments
None
Return Value
None
check_RTC
Outline
Determination of RTC initialization requirement
Header
rtc_func.h
Declaration
uint8_t check_RTC(void)
Description
Compares the RTC register value with the RTC initial setting value specified by the
enable_RTC_an1713 function, performs processing and verification regarding the
backup time information, determines cold/warm start, verifies the charge status of the
VBATT circuit at a backup timing, and then determines whether to continue the RTC
operation or initialize the RTC.
Arguments
None
Return Value
RTC_INIT_RES: RTC time information is invalid.
RTC_RUN_RES: RTC time information is valid.
flash_check
Outline
Determination of the backup time information for use
Header
rtc_func.h
Declaration
static uint8_t flash_check(void)
Description
Verifies the backup counters DB0 and DB1, and determines data to be used for the
subsequent comparison processing. If the backup counter is invalid, reads the
backup time information to determine the data to be used for the subsequent
comparison processing.
Arguments
None
Return Value
RTC_INIT_RES: RTC time information is invalid.
RTC_RUN_RES: RTC time information is valid.
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
17
of 36
Nov. 6, 2015
Set_register_enable
Outline
Setting the validity of the alarm time information
Header
rtc_func.h
Declaration
static void Set_register_enable(void)
Description
Only when the ENB bit of the alarm time information is set to 1, the ENB bit of the
RTC alarm register is read to verify the register value.
Arguments
None
Return Value
None
check_RTC_clock
Outline
Verification of the RTC time information value
Header
rtc_func.h
Declaration
static unsigned char check_RTC_clock(void)
Description
Verifies that the register value of the RTC time information is correct.
Arguments
None
Return Value
RTC_INIT_RES: RTC time information is invalid.
RTC_RUN_RES: RTC time information is valid.
check_RTC_flash
Outline
Comparison of the RTC time information with the backup time information
Header
rtc_func.h
Declaration
static unsigned char check_RTC_flash(void)
Description
Compares the RTC time information with the backup time information and verifies the
RTC time information is newer than the backup time information.
Arguments
None
Return Value
RTC_INIT_RES: RTC time information is invalid.
RTC_RUN_RES: RTC time information is valid.
check_RTC_after10days
Outline
Verifying the range of the RTC time information
Header
rtc_func.h
Declaration
static unsigned char check_RTC_after10days(void)
Description
Compares the RTC time information with the backup time information and verifies the
RTC time information is within normal range (10 days after the backup time
information).
Arguments
None
Return Value
RTC_INIT_RES: RTC time information is invalid.
RTC_RUN_RES: RTC time information is valid.
rtc_time_read
Outline
Reading the RTC time information
Header
None
Declaration
static void rtc_time_read(void)
Description
Reads the RTC time information and stores it in the RAM area for the RTC time
information.
Arguments
None
Return Value
None
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
18
of 36
Nov. 6, 2015
R_INIT_Clock_an1713
Outline
Clock initialization
Header
r_init_clock.h
Declaration
void R_INIT_Clock_an1713(void)
Description
Initializes the clock.
Arguments
None
Return Value
None
Remarks
The sample code selects processing which uses PLL as the system clock and the
sub-clock as the RTC count source.
Refer to the RX63N Group, RX631 Group Initial Setting Rev. 1.10 application note
for details on this function.
CGC_subclk_as_RTC_an1713
Outline
Sub-clock setting
Header
r_init_clock.h
Declaration
void CGC_subclk_as_RTC_an1713(void)
Description
Configures the setting when the sub-clock is used as the RTC count source and not
used as the system clock.
Arguments
None
Return Value
None
Remarks
Refer to pattern D in the RX63N Group, RX631 Group Initial Setting Rev. 1.10
application note for details on this function.
enable_RTC_an1713
Outline
RTC Initialization
Header
None
Declaration
static void enable_RTC_an1713(void)
Description
Performs the initialization when the RTC is used (setting for clock provision and RTC
software reset).
Arguments
None
Return Value
None
Excep_RTC_PRD
Outline
RTC periodic interrupt handling
Header
rtc_func.h
Declaration
static void Excep_RTC_PRD(void)
Description
Reads the RTC time information in this interrupt handling and displays it on the
Debug LCD.
After a reset and time required to charge the VBATT circuit elapsed, updates the
VBATT charge flag and the backup counter and sets the backup request.
Also updates the backup counter every hour and sets the backup request.
Arguments
None
Return Value
None
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
19
of 36
Nov. 6, 2015
time_backup
Outline
Backup processing for the RTC time information
Header
None
Declaration
void time_backup(uint32_t time_data, uint8_t write_block)
Description
Stores the RTC time information in the E2 DataFlash.
The RTC time information is stored in 10-byte area from the start address of block 0
or block 1 in the E2 DataFlash. The block to store data is determined with bit 0 of the
backup counter.
Arguments
uint32_t time_data:
uint8_t write_block
RTC time information data to be backed up
Data to specify the area used for backup
Return Value
None
Remarks
The program placed in the ROM area is executed even when the CPU is
programming/erasing E2 DataFlash.
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
20
of 36
Nov. 6, 2015
5.11 Flowcharts
5.11.1 Main Processing
Figure 5.3 shows the Main Processing.
main
Disable maskable interrupts I flag 0
Port initialization
port_init()
Stop processing for active
peripheral functions after a reset
R_INIT_StopModule()
Nonexistent port initialization
R_INIT_NonExistentPort()
Determination of RTC
initialization requirement
check_RTC()
Clock initialization
R_INIT_Clock_an1713()
Debug LCD initialization
init_LCD()
Debug LCD output
Display_LCD() Displays "RTC" on the first line of the Debug LCD.
Debug LCD output
Display_LCD() Displays "00:00:00" on the second line of the Debug LCD.
Set warm start RSTSR1 register
CWSF bit 1: Warm start
Enable maskable interrupts I flag 1
Backup request
for RTC time information is
generated?
No
Yes
Backup processing for
the RTC time information
time_backup() Sets the RTC time information and sets bit 0 of the backup
counter as the argument. The backup information is stored in
DB0 or DB1 in the E2 DataFlash according to the argument.
True/false determination
of RTC time information
and RTC initialization
Debug LCD initialization
Verifies whether the RTC time information backup
request is generated in the RTC periodic interrupt.
Figure 5.3 Main Processing
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
21
of 36
Nov. 6, 2015
5.11.2 Port Initialization
Figure 5.4 shows the Port Initialization.
return
PORT8.PODR register
Bits B7 to B4 0000b: P84 to P87 (DLCD): Outputs 0 as an initial value.
PORT8.PDR register
Bits B7 to B4 1111b: P84 to P87 (DLCD): Output
PORT0.PODR register
B3 bit 1: P03 (LED0): High level
B5 bit 1: P05 (LED1): High level
PORT0.PDR register
B3 bit 1: P03 (LED0): Output
B5 bit 1: P05 (LED1): Output
PORTJ.PODR register
B5 bit 0: PJ5 (DLCDRS): Outputs 0 as an initial value.
PORTF.PODR register
B5 bit 0: PF5 (DLCDE): Outputs 0 as an initial value.
PORTJ.PDR register
B5 bit 1: PJ5 (DLCDRS): Output
PORTF.PDR register
B5 bit 1: PF5 (DLCDE): Output
port_init
Set the port output for LED0 and LED1
Set the Debug LCD data output
Set the Debug LCD reset output
and enable output
Figure 5.4 Port Initialization
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
22
of 36
Nov. 6, 2015
5.11.3 Determination of RTC Initialization Requirement
Figure 5.5 and Figure 5.6 show the Determination of RTC Initialization Requirement.
check_RTC
Sub-clock oscillated?
Yes
No
RTC control
registers 1 to 4 match initial
setting values?
Yes
No
Automatic
adjustment function being
used?
Yes
No
Time error
adjustment register value
matches the initial setting
value?
Yes
No
Enable reading of the E2 DataFlash
(DB0/DB1) DFLRE0 register
DBRE00 bit 1: Read enabled for block 0000 to 0063
Verification of the RTC time
information value
check_RTC_clock()
Time information
(return value) is valid?
Yes
No
return(RTC_INIT_RES)
Initialize variables
Determination of the backup
time information for use
flash_check()
Time information
for use determined?
Yes
No
Reading the RTC time
information
rtc_time_read()
Time information
(return value) is valid?
Yes
No
A
Buffer to obtain time information 0000 0000h
Charge time counter for the VBATT circuit 00h
Backup counter 00h
Programming mode 0: Preparing
Backup request flag 0: Not requested
Flash processing end flag 1: Completed
Comparison of the RTC time
information with the backup time
information
check_RTC_flash()
Compares the RTC I/O registers
with RTC initial setting values and
verifies settings.
Determines the backup time
information (DB0/DB1) for use.
Compares the RTC time
information (year, month, day,
hour, minute, and second) with the
backup time information and
verifies the information.
1/128 second wait
R_DELAY_Us()
Figure 5.5 Determination of RTC Initialization Requirement (1/2)
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
23
of 36
Nov. 6, 2015
return(RTC_INIT_RES)
return(RTC_RUN_RES)
A
flash_write RTC_BACKUP_INIT(2)
Alarm function used?
Read the alarm time registers
No
Yes
Setting the validity of the alarm
time information
Set_register_enable()
Verification of the RTC time
information value
check_RTC_clock()
Values
in the alarm time registers
match initial setting
values?
No
Yes
Comparison of the RTC time
information with the backup time
information
check_RTC_clock()
Time
information (return value) is
valid?
Yes
No
Cold start?
Verifying the range of the RTC
time information
check_RTC_after10days()
Time information
(return value) is within normal
range?
No
Yes
VBATT
charge flag indicates "fully
charged"?
No
Yes
Reset the VBATT charge flag
(status: not enough charged).
Set the time information backup
request to "initialization required".
RCR1.AIE: 0: An alarm interrupt request is disabled.
1: An alarm interrupt request is enabled.
Compares the RTC alarm time registers
(year, month, day, hour, minute, and
second) with the backup time information
when the alarm function is enabled, and
verifies the information.
Verifies whether the VBATT circuit is fully
charged at the previous backup timing.
If the circuit is not fully charged, the RTC
is initialized even if it is within 10 days
from the previous backup.
If the circuit is fully charged at the
precious backup timing, the VBATT
charge flag is reset (status: not enough
charged) and the state is held for 15
minutes from this point.
Figure 5.6 Determination of RTC Initialization Requirement (2/2)
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
24
of 36
Nov. 6, 2015
5.11.4 Setting the Validity of the Alarm Time Information
Figure 5.7 shows the Setting the Validity of the Alarm Time Information.
Set_register_enable
Clear the information for verification
Second data is valid?
The second data is to be verified
Yes
No
Minute data is valid?
The minute data is to be verified
Hour data is valid?
The hour data is to be verified
Yes
No
Yes
No
Day-of-week data is
valid?
The day-of-week data is to be verified
Day data is valid?
The day data is to be verified
Yes
No
Yes
No
Month data is valid?
The month data is to be verified
Yes
No
Year data is valid?
The year data is to be verified
Yes
No
return
RSECAR.ENB: 1: This register value is compared
with the RSECCNT value.
RMINAR.ENB: 1: This register value is compared
with the RMINCNT value.
RHRAR.ENB: 1: This register value is compared
with the RHRCNT value.
RWKAR.ENB: 1: This register value is compared
with the RWKCNT value.
RDAYAR.ENB: This register value is compared
with the RDAYCNT value.
RMONAR.ENB: This register value is compared
with the RMONCNT value.
RYRAREN.ENB: The RYRAR register value is compared
with the RYRCNT value.
Figure 5.7 Setting the Validity of the Alarm Time Information
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
25
of 36
Nov. 6, 2015
5.11.5 Determination of the Backup Time Information for Use
Figure 5.8 shows the Determination of the Backup Time Information for Use.
Yes
No
return(RTC_INIT_RES)
return(RTC_RUN_RES)
return(RTC_RUN_RES)return(RTC_RUN_RES)
return(RTC_RUN_RES)
return(RTC_RUN_RES)
flash_check
Read the backup counter (DB0)
Read the backup counter (DB1)
Backup
counter (DB0) != backup
counter (DB1) + 1? Set the backup counter (DB0) as
the backup counter used
Backup
counter (DB0) + 1 != backup
counter (DB1)?
Yes
No
Set the backup counter (DB1) as
the backup counter used
return(RTC_RUN_RES)
Read the backup time information
(DB0)
Verification of the RTC time
information value
check_RTC_clock()
Read the backup time information
(DB1)
Verification of the RTC time
information value
check_RTC_clock()
Any of the
time information read
is valid? The read
DB0 data is older than DB1
data?
Yes
No
Yes
No
Set the backup counter (DB0) as
the backup counter used Set the backup counter (DB1) as
the backup counter used
The read time
information DB0
is invalid?
Yes
No
Set the backup counter (DB0) as
the backup counter used
The read time
information DB1
is invalid? Set the backup counter (DB1) as
the backup counter used
No
Yes
Figure 5.8 Determination of the Backup Time Information for Use
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
26
of 36
Nov. 6, 2015
5.11.6 Verification of the RTC Time Information Value
Figure 5.9 shows the Verification of the RTC Time Information Value.
When the month data is:
1, 3, 5, 7, 8, 10, or 12: The day data must be between
1 to 31.
4, 6, 9, or 11: The day data must be between 1 to 30.
2: The day data must be between 1 to 29.
check_RTC_clock
Second
data is to be verified and
between 0 to 59?
Yes
No
Minute
data is to be verified and
between 0 to 59?
Yes
No
Display
of the time information is
12-hour clock?
Yes
No
Hour data
is to be verified and between
0 to 11?
return(RTC_INIT_RES)
Hour data
is to be verified and between
0 to 23?
Day-of-week
data is to be verified and
between 0 to 6?
Yes
No
Year
data is to be verified and
between 0 to 99?
Yes
No
Month
data is to be verified and
between 1 to 12?
Yes
No
Day data
is to be verified and appropriate
for the month?
Yes
No
return(RTC_INIT_RES)return(RTC_RUN_RES)
No
Yes
No
Yes
Figure 5.9 Verification of the RTC Time Information Value
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
27
of 36
Nov. 6, 2015
5.11.7 Comparison of the RTC Time Information with the Backup Time Information
Figure 5.10 shows the Comparison of the RTC Time Information with the Backup Time Information.
check_RTC_flash
Determine the flash data for use
Backup
year data < RTC year
data(1)?
Backup
year data = RTC year
data(1)?
Yes
No
Backup
month data < RTC month
data(1)?
Yes
No
No
Yes
Backup
month data = RTC month
data(1)?
Backup
day data < RTC day
data(1)?
No
Yes
No
return(RTC_RUN_RES) return(RTC_INIT_RES)
Note:
1. Data in the RTC time information (in the RAM).
Yes
Figure 5.10 Comparison of the RTC Time Information with the Backup Time Information
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
28
of 36
Nov. 6, 2015
5.11.8 Verifying the Range of the RTC Time Information
Figure 5.11 shows Verifying the Range of the RTC Time Information.
check_RTC_after10days
Make date data (year, month, and
day) from the backup time information
Day data of the date data + 10h
Day data is outside the
appropriate range? When the month data is:
1, 3, 5, 7, 8, 10, or 12: The day data must be
between 1 to 31.
4, 6, 9, or 11: The day data must be between 1 to 30.
2: The day data must be between 1 to 29.
No
Yes
If the month data is 12, set the month data to 1.
For the other months, adds 1 to the month data.
When the month data is:
1, 3, 5, 7, 8, 10, or 12: Sets the day data - 31 as the day data.
4, 6, 9, or 11: Sets the day data - 30 as the day data.
2: Sets the day data - 29 as the day data.
Increment the month data
Set the number of days that exceed
the range for the month
Year data made <
RTC year data(1)?
No
Yes
Year data made =
RTC year data(1)?
Month data made <
RTC month data(1)?
No
Yes
No
Yes
Month data made =
RTC month data(1)?
No
Day data made <
RTC day data(1)?
No
Yes
Yes
return(RTC_RUN_RES) return(RTC_INIT_RES)
Note:
1. Data in the RTC time information (in the RAM).
Figure 5.11 Verifying the Range of the RTC Time Information
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
29
of 36
Nov. 6, 2015
5.11.9 Reading the RTC Time Information
Figure 5.12 shows the Reading the RTC Time Information.
Yes
No
IR062 register
IR flag 0
time.second RSECCNT register
time.minute RMINCNT register
time.hour RHRCNT register
time.dayweek RWKCNT register
time.day RDAYCNT register
time.month RMONCNT register
time.year 2000h | RYRCNT register
Read the IR062 register
IR bit: 0: No interrupt request [IR(RTC,CUP)] is generated.
1: An interrupt request [IR(RTC,CUP)] is generated.
RCR1 register
CIE flag 1
rtc_time_read
Enable the CPU interrupt request
Clear the CPU interrupt request
Read the second counter
Read the minute counter
Read the hour counter
Read the day-of-week counter
Read the day counter
Read the month counter
Read the year counter
A carry occurred?
Disable the CPU interrupt request
return
RCR1 register
CIE flag 0
Figure 5.12 Reading the RTC Time Information
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
30
of 36
Nov. 6, 2015
5.11.10 Clock Initialization
Figure 5.13 shows the Clock Initialization.
Uses the sub-clock as the RTC count source without using the system clock (pattern D)
SCKCR register 21C2 1211h
PCKB[3:0] bits = 0010b: Divide-by-4 is selected for peripheral module clock B (PCLKB).
PCKA[3:0] bits = 0001b: Divide-by-2 is selected for peripheral module clock A (PCLKA).
BCK[3:0] bits = 0010b: Divide-by-4 is selected for the external bus clock (BCLK).
PSTOP0 bit = 1: SDCLK pin output is disabled (fixed high).
PSTOP1 bit = 1: BCLK pin output is disabled (fixed high).
ICK[3:0] bits = 0001b: Divide-by-2 is selected for the system clock (ICLK).
FCK[3:0] bits = 0010b: Divide-by-4 is selected for the FlashIF clock (FCLK).
SCKCR2 register 0012h
IEBCK[3:0] bits = 0010b: Divide-by-4 is selected for the IEBUS clock (IECLK).
UCK[3:0] bits = 0001b: USB not used
BCKCR register 00h
BCLKDIV bit = 0: BCLK (no division)
R_INIT_Clock_an1713
Disable write protection PRCR register A503h
PRC0 bit = 1: Enable writing to the registers related to the clock generation circuit.
PRC1 bit = 1: Enable writing to the registers related to the low power consumption.
Main clock oscillation setting
CGC_oscillation_main()
Configure the Sub-clock setting (1)
CGC_subclk_as_RTC_an1713()
PLL oscillation setting (2)
CGC_oscillation_PLL()
Set the division ratio for
the internal clock (3)
Specify the BCLK pin output setting (3)
Switch the system clock (3)
Turn off the HOCO power supply (3) HOCOCR register 01h
HCSTP bit = 1: HOCO is stopped.
HOCOPCR register 01h
HOCOPCNT bit = 1: Turns the power supply of the HOCO off.
Enable write protection PRCR register A500h
PRC0 bit = 0: Disable writing to the registers related to the clock generation circuit.
PRC1 bit = 0: Disable writing to the registers related to the low power consumption.
return
Notes:
1. Select the sub-clock pattern according to the user system.
2. The PLL oscillation setting is not necessary when PLL is not used.
3. Set an appropriate value according to the user system.
Figure 5.13 Clock Initialization
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
31
of 36
Nov. 6, 2015
5.11.11 Sub-Clock Oscillation Setting
Figure 5.14 shows the Sub-Clock Oscillation Setting.
SOSCCR register 01h
SOSTP bit = 1: Sub-clock oscillator is stopped.
RCR3 register
RTCEN bit 0: Sub-clock oscillator is stopped.
RCR3 register 0Ch
RTCDV[2:0] bits = 110b: Standard driving ability for the clock
Waits for the sub-clock oscillation stabilization wait time (2.6 sec.).
Sub-clock oscillation setting
Function: oscillation_subclk
RCR4 register
RCKSEL bit 0: The sub-clock is selected.
No
Yes rtc_reg_check_result REG_OK_MAIN or REG_NG
CGC_subclk_as_RTC_an1713
Sub-clock
is used as the RTC count
source?
Specify the RTC count source
RTC initialization
requested?
Yes
No
Stop the sub-clock oscillator
Wait for 5 cycles of
the sub-clock using CMT0
cmt0_wait() Waits for 5 cycles of the sub-clock (approx. 152 µs).
Set the sub-clock driving ability
Set the sub-clock oscillator wait
control register (1) SOSCWTCR register 00h
SSTS[4:0] bits = 00000b: Wait for 2 cycles (approx. 61 µs)
Operate the sub-clock oscillator SOSCCR register 00h
SOSTP bit = 0: Sub-clock oscillator is operating.
Wait for the sub-clock oscillation
stabilization wait time using
CMT0 (2)
cmt0_wait()
Initialization when using the RTC
enable_RTC_an1713()
Processing when not using the
sub-clock as the system clock
(RTC count source is the sub-clock)
Function: no_use_subclk_as_sysclk
Set the SOSTP bit to 1 since
the sub-clock is not used as the
system clock. SOSCCR register 01h
SOSTP bit = 1
return
Notes:
1. Set the sub-clock oscillator wait control register to a value greater than or equal to the sub-clock oscillator start-up time recommended by the crystal/ceramic
resonator manufacturer minus the minimum value of the sub-clock oscillation stabilization wait offset time (1.8 sec.).
2. The time includes six clocks of the RTC count source.
Figure 5.14 Sub-Clock Oscillation Setting
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
32
of 36
Nov. 6, 2015
5.11.12 RTC Initialization
Figure 5.15 shows the RTC Initialization.
RCR3 register 0Dh
RTCDV bit 110b: Standard driving ability for the clock
Time information (time_data) 00:00:00: Time information
VBATT charge flag (charge_VBATT) Not charged enough: Time information
PORT0.PODR register
B3 bit 0: P03(LED0): Low level
flash_write RTC_BACKUP_INIT(2)
enable_RTC_an1713
RTC initialization
requested?
Set the RCR3 register RCR3 register
RTCEN bit 1: Sub-clock oscillator is operating.
Stop counters and the prescaler RCR2 register RCR2 register & 7Eh
START bit = 0: Counters and prescaler are stopped
RTC reset completed?
Yes
No
No
Yes
Set the date and time to
Tuesday, January 1, 2013, 00:00:00
Reset the RCR3 register
RSECCNT register 00h: 00 is set to the second counter.
RMINCNT register 00h: 00 is set to the minute counter.
RHRCNT register 00h: 00 is set to the hour counter.
RWKCNT register 02h: 2 (Tuesday) is set to the day-of-week counter.
RDAYCNT register 01h: 01 is set to the date counter.
RMONCNT register 01h: 01 is set to the month counter.
RYRCNT register 0013h: 13 is set to the year counter.
Specify the time error adjustment RADJ register
ADJ[5:0] bits 000000b: Adjustment value not set
PMADJ[1:0] bits 00b: Adjustment is not performed.
Set the RTC 1-second periodic
interrupt RCR1 register E4h
AIE bit = 0: An alarm interrupt request is disabled.
CIE bit = 0: A carry interrupt request is disabled.
PIE bit = 1: A periodic interrupt request is enabled.
PES[3:0] bits = 1110b: A periodic interrupt is generated every 1 second.
Set the automatic adjustment RCR2 register 30h
START bit = 0: Year, month, day-of-week, date, hour, minute, second, and
64-Hz counters, and prescaler are stopped.
RTCOE bit = 0: RTCOUT output disabled.
AADJE bit = 1: Automatic adjustment is enabled.
AADJP bit = 1: The RADJ.ADJ[5:0] setting value is adjusted from the count
value of the prescaler every 10 seconds.
HR24 bit = 0: The RTC operates in 12-hour mode.
Turn on LED0
Initialize the backup information
Set the time information backup
request to 'initialization required'
Specify the RTC periodic
interrupt settings IR093 register
IR flag 0: Interrupt request [IR(RTC,PRD)] is cleared.
IPR093 register
IPR[3:0] bits 0001b: Interrupt priority level [IPR(RTC,PRD)] is level 1.
IER0B register
IEN5 bit 1: Interrupt request enable [IEN(RTC,PRD)] is enabled.
Start the RTC count operation RCR2 register
START bit = 1: Year, month, day-of-week, date, hour, minute, second, and
64-Hz counters, and prescaler operate normally.
Read the RTC time information Second data: time_data (uint32_t)(time.second & 0x0000007F)
Minute data: time_data time_data | (time.minute & 0x0000007F) << 8
Hour data: time_data time_data | (time.hour & 0x0000003F) << 16
return
Figure 5.15 RTC Initialization
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
33
of 36
Nov. 6, 2015
5.11.13 RTC Periodic Interrupt Handling
Figure 5.16 shows the RTC Periodic Interrupt Handling.
flash_write RTC_BACKUP_ACK (1)
old_change_minute time_data & 0x00003F00
old_change_hour time_data & 0x003F0000
time_data time_data | change_hour
time_data time_data | (time.minute & 0x0000007F) << 8
time_data (uint32_t)(time.second & 0x0000007F)
change_minute (time.minute & 0x0000007F) << 8
change_hour (time.hour & 0x0000003F) << 16
flash_write RTC_BACKUP_ACK (1)
Excep_RTC_PRD
Read previous time information
(hour, minute)
Read the RTC time information
rtc_time_read()
Make the current time data
(hour and minute)
Time information
backup request is 'initialization
required'?
Previous
time information = Current time
information?
Yes
No
Yes
No
Set the time information
backup request
VBATT circuit is
fully charged?
No
Yes
VBATT
circuit has been charged at
least 15 minutes?
Change the VBATT charge flag to
'fully charged'
Set the time information
backup request
Time
information backup request is
set?
No
Yes
Update the backup counter
(write_counter)
No
Yes
Set the programming mode to
'preparing'.
Set the current time data (second) in
32-bit integer type
Set the current time data (minute) in
32-bit integer type
Set the current time data (hour) in
32-bit integer type
Convert integer into BCD string
uint32_ToBCDString()
Debug LCD output
Display_LCD()
return
Sets the backup request
immediately after the
initialization or after an
hour elapses.
Verifies the charge status
of the VBATT circuit and
sets the backup request
after 15 minutes elapse.
Confirms that the backup
request is set and
prepares for backing up.
Make data and display it
on the Debug LCD.
Figure 5.16 RTC Periodic Interrupt Handling
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
34
of 36
Nov. 6, 2015
5.11.14 Backup Processing for the RTC Time Information
Figure 5.17 and Figure 5.18 show the Backup Processing for the RTC Time Information.
return
A
PORT0.PODR register
B5 bit 0: P05 (LED1): Low level
time_backup
return
Previous
flash processing end flag state
is 'completed'?
Clear the previous flash processing
end flag state
No
Yes
Programming
mode = Preparing?
Processing for E2 data flash
access setting
R_FlashDataAreaAccess()
Yes
No
Clear the previous flash processing
end flag state
Erasing the DB0/DB1 block
R_FlashEraseRange()
Command successfully issued?
Change the programming mode
to 'erasing' Turn on LED1
Yes
No
Programming mode
= Erasing?
Transfer the time information
(10 bytes) to a buffer for programming
Programming E2 DataFlash
(DB0,DB1)
R_FlashWrite()
Command
successfully issued?
Turn on LED1
No
Change the programming mode
to 'programming'
return
Yes
Yes
No
Figure 5.17 Backup Processing for the RTC Time Information (1/2)
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
35
of 36
Nov. 6, 2015
Obtains 10-byte data for verifying.
flash_write RTC_BACKUP_NACK(0)
return
A
Transfer the time information
(10 bytes) to a buffer for reading
Programming data
= Data for verifying?
PORT0.PODR register
B5 bit 0: P05 (LED1): Low level
Turn on LED1
No
Yes
All data verified?
Change the programming mode
to 'preparing'
Clear the RTC time information
backup request
Compares the programming data with data for verifying.
Figure 5.18 Backup Processing for the RTC Time Information (2/2)
RX63N Group, RX631 Group True/False Determination of RTC Time Information
on Cold Start
R01AN1713EJ0101 Rev. 1.01 Page
36
of 36
Nov. 6, 2015
6. Sample Code
Sample code can be downloaded from the Renesas Electronics website.
7. Reference Documents
Users Manual: Hardware
RX63N Group, RX631 Group Users Manual: Hardware Rev.1.80 (R01UH0041EJ)
The latest version can be downloaded from the Renesas Electronics website.
Technical Update/Technical News
The latest information can be downloaded from the Renesas Electronics website.
Users Manual: Development Tools
RX Family C/C++ Compiler Package V.1.01 Users Manual Rev.1.00 (R20UT0570EJ)
The latest version can be downloaded from the Renesas Electronics website.
Website and Support
Renesas Electronics website
http://www.renesas.com
Inquiries
http://www.renesas.com/contact/
A-1
REVISION HISTORY
RX63N Group, RX631 Group Application Note
True/False Determination of RTC Time Information on Cold Start
Rev.
Date
Description
Page
Summary
1.00
Apr. 1, 2014
First edition issued
1.01
Nov. 6, 2015
3
The specification was corrected.
27
A figure was corrected.
Program
The set value of OFS0 register and OFS1 register was corrected.
The waiting time to read time counter after a reset was added.
All trademarks and registered trademarks are the property of their respective owners.
General Precautions in the H a ndling of Micr oprocessing Unit and Micr ocontroller Uni t Prod ucts
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.
1. Handling of Unused Pins
Handle unused pins in accordance with the directions given under Handling of Unused Pins in the
manual.
The input pins of CMOS products are generally in the high-impedance state. In operation with an
unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, an
associated shoot-through current flows internally, and malfunctions occur due to the false
recognition of the pin state as an input signal become possible. Unused pins should be handled as
described under Handling of Unused Pins in the manual.
2. Proc es sing at Po wer-on
The state of the product is undef in ed at the m om ent when power is supp lied.
The states of internal circuits in the LSI are indeterminate and the states of register settings and
pins are undefined at the moment when power is supplied.
In a finished product where the reset signal is applied to the external reset pin, the states of pins
are not guaranteed from the moment when power is supplied until the reset process is completed.
In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function
are not guaranteed from the moment when power is supplied until the power reaches the level at
which resetting has been specified.
3. Prohibition of Access to Reserved Addresses
Access to reserved addresses is prohibited.
The reserved addresses are provided for the possible future expansion of functions. Do not access
these addresses; the correct operation of LSI is not guaranteed if they are accessed.
4. Clock Signals
After applying a reset, only release the reset line after the operating clock signal has become stable.
When switching the clock signal during program execution, wait until the target clock signal has
stabilized.
When the clock signal is generated with an external resonator (or from an external oscillator)
during a reset, ensure that the reset line is only released after full stabilization of the clock signal.
Moreover, when switching to a clock signal produced with an external resonator (or by an external
oscillator) while program execution is in progress, wait until the target clock signal is stable.
5. Differences between Products
Before changing from one product to another, i.e. to a product with a different part number, confirm
that the change will not lead to problems.
The characteristics of Microprocessing unit or Microcontroller unit products in the same group but
having a different part number may differ in terms of the internal memory capacity, layout pattern,
and other factors, which can affect the ranges of electrical characteristics, such as characteristic
values, operating margins, immunity to noise, and amount of radiated noise. When changing to a
product with a different part number, implement a sy stem-evaluation test for the given product.
Notice
1. Descripti on s of circuit s , soft war e an d other r el ated inf o r m ation in this doc ument ar e p r ov i de d on ly to illus trate t he o per a t i on of sem ic o nd uc tor products and a pplicat ion e x amples. You ar e fully respons i bl e f o r
the incorporatio n of t he s e ci rcuits, s oft ware, a nd i nform a tion in t h e de s ign o f your eq ui pm ent. Re nes as Elec tronics as s umes no responsibility for any losses incurred by you or third parties arising from the
use of these c i r c ui ts, sof tware, or i nform a tion.
2. Renesas E l ec troni c s h as u s ed r easonable c a r e in pr ep ar i ng the inf o rmat i on i nc lud ed in this do c u m ent, bu t Renes as Electron ics does n ot warr ant t ha t s u c h informatio n i s er r or free. Renes a s El ectr o nic s
assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
3. Renesas E l ec troni c s d oes not as s ume any liab il ity for infrin gem en t of pa tent s, co pyrights, or other intellec tual propert y rig h ts of third par ties by or aris in g from the use o f R e nesas Ele c tron ic s produc t s or
tech ni c a l in forma tion des c ribed in this do c um en t. N o lic e ns e , expr e s s , impl ied or oth er w ise, is g r anted he re by under an y pa t e nts, copyrights or other intellectual property rights of Renesas Electronics or
others.
4. You shou ld not alt er, m odi fy, copy , or otherwi s e m isappr opr i ate any Rene s as Electron ics pro duct, whet her in whole o r in pa r t. Renesas Electronics assumes no responsibility for any losses incurred by you or
thir d pa r ties ar is i ng f r o m s uch alt erati on , m o di f i c a t i on , copy or other wis e m isapprop r ia tion of Renesas Elec tronics pr oduct .
5. Renesas E l ec troni c s p ro du c ts ar e c la s s i fied ac c or d in g to the follow in g two quality gr a de s : "S tandar d " and " H ig h Quality" . Th e re c ommende d ap plic a tions for ea c h Renesas El ec tron ics prod uct depe nd s on
the product' s quali ty gr a de, as ind ic ated below .
"Standard": Comp uters ; of fice eq uipm e nt; c ommunic a tions e qui pm ent; test and mea s urement equipm en t; a udio a nd visual equ ipm en t; home electronic appliances; machine tools; personal electronic
equipme nt; and in dustr ial r obo ts etc.
"Hig h Quality": Trans po r tat io n eq uipm e nt (autom obil es, trains , ship s , et c .); tr aff ic c on trol s yst em s; a nti-disaster syst ems; anti-crime syst ems; and safety equipment etc.
Renesas E l ec troni c s p ro du c ts are nei ther intende d nor a uthoriz e d for use in prod uc ts or s y s tem s that m a y po s e a d ir e c t thr e at t o human lif e or bod ily i nj ur y (art ific ial life sup port de v i c es or sys tems , sur g ical
implantations etc.), or may cause serious property damages (nuclear reactor control systems, military equipment etc.). You must check t he quality grade of each Renesas Electronics product before using it
in a particula r app li c ation. You may no t use any Ren esas E lec tron ics prod uct for any ap pl icatio n for whi c h i t i s no t i ntended. Renes as Elec tronics sh al l no t b e in any wa y li able for any damage s or lo s s e s
incur r ed by you or thir d partie s ar i s i ng from the use of any Rene s as Elec troni c s pr o du c t for wh ic h t h e product is no t inte nde d by Renes as E l ec troni c s .
6. You shou ld us e t h e Rene s a s E lect ro ni c s products des c r i be d in t h is docum e nt wit hin the ra ng e s p ec ified by Re nesas El ec tron ic s , esp ec i al ly wi th res pect to t he m aximum ratin g, oper ating su pply voltage
range, mov ement po wer voltage ran ge, heat radiation c ha ra c teri s tics , installat i on and other product char acte r is tics . Renes a s E l ectr oni c s shall hav e no l ia bi lity f o r m al func t i ons or damag es a r ising out of t he
use of R enes a s E le c troni c s products bey o nd s uc h s pe c i f i ed r a ng es.
7. Alt ho ugh R ene s as E l ec troni c s e nde av ors t o improv e the qua lity and r e li abil ity of it s pr od ucts , sem i c ondu c tor pr o ducts have sp ecific charact erist ics such as the occurrence of failure at a certain rate and
malf un c tions u nd er c ertai n u s e c ond itions . Furthe r, Renes a s E le c tron ic s products ar e no t subject to rad iation r es i s tance des ig n. Please be sur e to implement s a fety m ea s u re s to guar d them ag ains t t he
possi bili ty of phys i c al in ju r y , and inju r y or dam ag e c au s ed by fi r e in t h e event of t he f a il ur e o f a Re nes as Electron ic s produc t, such as safety design for hardware and software including but not limited to
redundan c y , f ir e c ontrol an d m a lfunction pr ev en tion, approp ri ate t r ea tment for aging degradat i on or any othe r a ppropri ate meas u res. B ec a us e t h e evaluat i on of mic r o c o m pu t e r s oft ware alone is v er y diffic ult,
please ev al ua te t he s afet y of t he final pr o ducts or s y stem s m a nu f a c ture d by y ou.
8. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please use Renesas Electronics
produc ts in c om p li an c e wi t h al l ap plicable laws a nd regulations that regulate the i nc l us io n or use of c o ntrolle d s u bs tance s , including without limitation, the EU RoHS Directive. Renesas Electronics assumes
no liability for dam ag es o r losses oc c u r r in g as a res ult of y ou r non c omplianc e wi th applicable laws a nd r eg ul ations .
9. Renesas E l ec troni c s p ro du c ts and techno lo gy m ay no t be us ed for or incorpo r ated int o any p r odu c ts or s y s tems whose m an ufactur e, use , or sal e i s pr oh ib ited under an y ap pl ic ab le dom e s tic or forei gn l aws o r
regulations . You shou ld not use Ren es a s E le c tronic s produ c ts or tec hnolo gy desc r ib ed in this do c u m ent for any pu r pose relating to military applications or use by the military, including but not limited to the
development of weapons of mass destruction. When exporting the Renesas Electronics products or technology described in this document , you s h ould comply w ith th e ap pl ic ab le e x po r t control la w s an d
regulations and follow the procedures required by such laws and regulations.
10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the prod uct with a t hird party, to no t i fy s uc h thir d pa r t y in adva nc e 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.
11. This document may not be reproduced or duplicated in any form, in whole or in part, without prior written consent of Renesas Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesa s E lectr o ni c s pr o duc ts, or if you ha v e a ny other in qu ir i es .
(Not e 1) " R e nes as Electronics" as us ed in this d oc ument m ean s Ren es a s E le c tronic s Corpor a tion and al s o i nc lud es its m aj or i ty- own e d s u bsidiari es.
(Not e 2) " R e nes as Electronics pr od uc t(s ) " mean s an y pr od uc t deve lo ped or manufactured by or for Ren es a s E le c tronic s.
http://www.renesas.com
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics America Inc.
2801 Scott Boulevard Santa Clara, CA 95050-2549, U.S.A.
Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited
9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3
Tel: +1-905-237-2004
Renesas El e ctronics Europe Li mi te d
Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K
Tel: +44-1628-585-100, Fax: +44-1628-585-900
Renesas El e ctronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany
Tel: +49-211-6503-0, Fax: +49-211-6503-1327
Renesas El e ctronics (China ) Co., Ltd.
Room 1709, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100191, P.R.China
Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas El e ctronics (Shanghai) Co., Ltd.
Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, P. R. China 200333
Tel: +86-21-2226-0888, Fax: +86-21-2226-0999
Renesas El e ctronics Hong Kong Limited
Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
Tel: +852-2265-6688, Fax: +852 2886-9022
Renesas El e ctronics Ta i w an Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan
Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949
Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas El e ctronics Malaysia S dn. Bhd.
Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia
Tel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas El e ctronics Indi a Pvt. Ltd.
No.777C, 100 Feet Road, HALII Stage, Indiranagar, Bangalore, India
Tel: +91-80-67208700, Fax: +91-80-67208777
Renesas Electronics Korea Co., Ltd.
12F., 234 Teheran-ro , Gangnam-Gu, Seoul, 135-080, Korea
Tel: +82-2-558-3737, Fax: +82-2-558-5141
SALES OFFICES
© 2015 Renesas Electronics Corporation. All rights reserved.
Colophon 5.0