APPLICATION NOTE RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 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 Page 1 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 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 R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 2 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 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 RTCa VBATT E2 DataFlash R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Application Clock counter Power supply to the RTC and the sub-clock oscillator. Backup for the RTC time information Page 3 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start Power-on reset Reset with the RES# pin VPOR VCC VBATT Before 15 minutes elapse 15 minutes elapsed Before 10 days elapse 15 minutes elapsed 10 days or more elapsed High RES# pin Undefined Low RTC Undefined Operating Cold start RTC time information is not correct RTC initialized Operating Operating Cold start RTC time information is correct, VBATT is not charged enough Warm start RTC time information is correct, VBATT is fully charged RTC initialized RTC not initialized Cold start Cold start RTC time information is correct RTC time information is not correct RTC not initialized RTC initialized Figure 1.1 Operation Overview R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 4 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 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 MCU used Operating frequencies Operating voltage Integrated development environment C compiler iodefine.h version Endian Operating mode Processor mode Sample code version Board used Contents R5F563NBDDFC (RX63N Group) - 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) 3.3 V, VBATT is VBATT or greater Renesas Electronics Corporation High-performance Embedded Workshop Version 4.09.01 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.) Version 1.8 Little endian Single-chip mode Supervisor mode Version 1.01 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. R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 5 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 4. Hardware 4.1 Hardware Configuration Figure 4.1 shows the Connection Example. RX63N Group VCC P03 LED0 output P05 LED1 output Debug LCD Electric double layer capacitor (EDLC) VBATT P87 P86 P85 P84 PJ5 PF5 DLCDD7 DLCDD6 DLCDD5 DLCDD4 DLCDRS DLCDE 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 P03 P05 P87 P86 P85 P84 PJ5 PF5 I/O Output Output Output Output Output Output Output Output Function LED0 output to indicate completion of the RTC initialization LED1 output to indicate E2 DataFlash backup error "Debug LCD Data bit 7" output "Debug LCD Data bit 6" output "Debug LCD Data bit 5" output "Debug LCD Data bit 4" output "Debug LCD Enable" output "Debug LCD Register select" output R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 6 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 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. R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 7 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start Validation Values in the RTC control register match the initial setting values? Not matched Matched When the time-error adjustment function is used: Values in the time error adjustment register match the initial setting values? Not matched Matched The time register has valid values? No Yes When the alarm function is used: The hour alarm register has a valid value? No Yes Warm start? Yes No Difference between the current time and the backup time is within 10 days? No Yes VBATT fully charged? No Yes Continue the count Initialize the RTC return 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. R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 8 of 36 RX63N Group, RX631 Group 5.3 True/False Determination of RTC Time Information on Cold Start 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 No programming // #define performed in the ROM FLASH_API_RX_CFG_ENABLE_ROM_PROGRAMMING Data to be programmed is #define FLASH_API_RX_CFG_FLASH_TO_FLASH stored in the RAM buffer. Settings in the Simple Flash API E2 DataFlash operation is #define FLASH_API_RX_CFG_DATA_FLASH_BGO executed in background. Flash API is not // #define FLASH_API_RX_CFG_COPY_CODE_BY_API transferred to the RAM 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. R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 9 of 36 RX63N Group, RX631 Group 5.4 True/False Determination of RTC Time Information on Cold Start 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 main.c r_init_clock_an1713.c r_init_clock_an1713.h rtc_func.c rtc_func.h flash_write.c Outline Main processing, port setting Clock initialization Header file for r_init_clock_an1713.c RTC register determination, RTC initialization, and periodic interrupt handling Header file for rtc_func.c Processing for backing up the RTC time information to the E2 DataFlash Table 5.3 Standard Include Files File Name stdbool.h stdint.h machine.h Outline Defines macros regarding the boolean type and value. Defines macros declaring the integer type with the specified width. 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 r_init_stop_module.c Function R_INIT_StopModule() r_init_stop_module.h -- r_init_non_existent_port.c r_init_non_existent_port.h r_delay.c r_delay.h R_INIT_NonExistentPort() -- R_DELAY_Us() -- Description -- Module-stop state is canceled for DMAC/DTC, EXDMAC, RAM0, and RAM1. -- 176 pin package is specified. The waiting time is set. -- Table 5.5 Functions and Setting Values in the Sample Code Accompanying the Renesas Starter Kit for RX63N High-performance Embedded Workshop File Name lcd.c lcd.h rskrx63ndef.h Function - Init_LCD() - Display_LCD() -- -- R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Description -- -- -- Page 10 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 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 OFS0 FFFF FF8Fh to FFFF FF8Ch FFFF FFFFh OFS1 FFFF FF8Bh to FFFF FF88h FFFF FFFBh MDES FFFF FF83h to FFFF FF80h FFFF FFFFh R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Contents The IWDT is stopped after a reset. The WDT is stopped after a reset. The voltage monitor 0 reset is enabled after a reset. HOCO oscillation is disabled after a reset. Little endian Page 11 of 36 RX63N Group, RX631 Group 5.6 True/False Determination of RTC Time Information on Cold Start Constants Table 5.8 lists the Constants Used in the Sample Code. Table 5.8 Constants Used in the Sample Code Constant Name RTC_INIT_RES RTC_RUN_RES 1 0 RTC_BACKUP_INIT 2 RTC_BACKUP_ACK 1 RTC_BACKUP_NACK VBATT_FULL_CHARGE VBATT_EMPTY 0 1 0 MASK_DATA_SEC 0x01 MASK_DATA_MIN 0x02 MASK_DATA_HR 0x04 MASK_DATA_WK 0x08 MASK_DATA_DAY 0x10 MASK_DATA_MON 0x20 MASK_DATA_YR 0x40 ALL_DATA_CHECK ADDRESS_BLOCK_DB0 ADDRESS_BLOCK_DB1 0x7F 0x100000 0x100020 BUFF_SIZE 10 WRITE_BUSY ERASE_BUSY WRITE_READY SELECT_SUB 2 1 0 PATTERN_D R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Setting Value Contents Reset with the RTC initialization required Reset with the RTC initialization not required Backup of the RTC time information is requested. (Initialization source, backup request after 1 second) Backup of the RTC time information is requested. (backup request after 15 minutes and every hour) Backup of the RTC time information is not requested. VBATT circuit is fully charged. VBATT circuit is not charged enough. Execution flag of second data verification, data for verifying the flag Execution flag of minute data verification, data for verifying the flag Execution flag of hour data verification, data for verifying the flag Execution flag of day-of-week data verification, data for verifying the flag Execution flag of day data verification, data for verifying the flag Execution flag of month data verification, data for verifying the flag Execution flag of year data verification, data for verifying the flag Execution flag of all data verification Start address of the DB0 block Start address of the DB1 block Sizes for storing the time information and programming Programming mode (programming) Programming mode (erasing) Programming mode (preparing) Selection of the sub-clock setting pattern Page 12 of 36 RX63N Group, RX631 Group 5.7 True/False Determination of RTC Time Information on Cold Start Structure/Union List Figure 5.2 shows the Structure/Union Used in the Sample Code. /* **** Time data **** */ typedef struct { uint8_t second; uint8_t minute; uint8_t hour; uint8_t dayweek; uint8_t day; uint8_t month; uint16_t year; uint8_t charge_VBATT; uint8_t write_cnt; } time_bcd_t; /* Second */ /* Minute */ /* Hour */ /* Day of the week */ /* Day */ /* Month */ /* Year */ /* VBATT charge info */ /* Backup counter */ Figure 5.2 Structure/Union Used in the Sample Code R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 13 of 36 RX63N Group, RX631 Group 5.8 True/False Determination of RTC Time Information on Cold Start 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 uint32_t time_data Buffer to obtain time information uint8_t flash_write Backup request flag for the RTC time information int8_t write_counter Backup counter uint8_t write_mode Programming mode uint8_t lcd_buffer[9] Buffer for Debug LCD uint8_t flash_is_ready Flash processing end flag - main - enable_RTC_an1713 - CGC_subclk_as_RTC_an1713 - check_RTC - flash_check - check_RTC_flash - check_RTC_after10days - enable_RTC_an1713 - Excep_RTC_PRD - time_backup - main - check_RTC - enable_RTC_an1713 - Excep_RTC_PRD - main - check_RTC - flash_check - check_RTC_flash - check_RTC_after10days - Excep_RTC_PRD - Excep_RTC_PRD - flash_check - main - uint32_ToBCDString - time_backup - check_RTC - Excep_RTC_PRD Table 5.10 static Variables Type Variable Name Contents Charge time (minutes) counter for the VBATT circuit static uint8_t charge_min_count static uint8_t check_time_data Time information check required/time information check not required static uint8_t prog_buff Time information for backup Function Used - check_RTC - Excep_RTC_PRD - check_RTC - Set_register_enable - flash_check - check_RTC_clock - time_backup Table 5.11 const Variable Type Variable Name Contents 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 R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Function Used - check_RTC - flash_check - check_RTC_flash - check_RTC_after10days Page 14 of 36 RX63N Group, RX631 Group 5.9 True/False Determination of RTC Time Information on Cold Start Functions Table 5.12 lists the Functions. Table 5.12 Functions Function Name main port_init check_RTC Set_register_enable flash_check check_RTC_clock check_RTC_flash check_RTC_after10days rtc_time_read R_INIT_Clock_an1713 CGC_subclk_as_RTC_ an1713 enable_RTC_an1713 Excep_RTC_PRD time_backup Outline Main processing Port output setting Determination of RTC initialization requirement Setting the validity of the alarm time information Determination of the backup time information for use Verification of the RTC time information value Comparison of the RTC time information with the backup time information Verifying the range of the RTC time information Reading the RTC time information Clock initialization Sub-clock setting (sub-clock is used for the RTC count source and not used for the system clock) RTC initialization RTC periodic interrupt handling Backup processing for the RTC time information R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 File the Function is in main.c main.c rtc_func.c rtc_func.c rtc_func.c rtc_func.c rtc_func.c rtc_func.c rtc_func.c r_init_clock_an1713.c r_init_clock_an1713.c rtc_func.c rtc_func.c flash_write.c Page 15 of 36 RX63N Group, RX631 Group 5.10 True/False Determination of RTC Time Information on Cold Start Function Specifications The following tables list the sample code function specifications. main Outline Header Declaration Description Arguments Return Value Remarks port_init Outline Header Declaration Description Arguments Return Value check_RTC Outline Header Declaration Description Arguments Return Value flash_check Outline Header Declaration Description Arguments Return Value Main processing None void main(void) After initialization, if a backup request of the RTC time information is generated, the backup processing function is called. None None 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 initialization None static void port_init(void) Initializes the ports. None None Determination of RTC initialization requirement rtc_func.h uint8_t check_RTC(void) 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. None RTC_INIT_RES: RTC time information is invalid. RTC_RUN_RES: RTC time information is valid. Determination of the backup time information for use rtc_func.h static uint8_t flash_check(void) 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. None RTC_INIT_RES: RTC time information is invalid. RTC_RUN_RES: RTC time information is valid. R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 16 of 36 RX63N Group, RX631 Group Set_register_enable Outline Header Declaration Description Arguments Return Value check_RTC_clock Outline Header Declaration Description Arguments Return Value check_RTC_flash Outline Header Declaration Description Arguments Return Value True/False Determination of RTC Time Information on Cold Start Setting the validity of the alarm time information rtc_func.h static void Set_register_enable(void) 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. None None Verification of the RTC time information value rtc_func.h static unsigned char check_RTC_clock(void) Verifies that the register value of the RTC time information is correct. None RTC_INIT_RES: RTC time information is invalid. RTC_RUN_RES: RTC time information is valid. Comparison of the RTC time information with the backup time information rtc_func.h static unsigned char check_RTC_flash(void) Compares the RTC time information with the backup time information and verifies the RTC time information is newer than the backup time information. None RTC_INIT_RES: RTC time information is invalid. RTC_RUN_RES: RTC time information is valid. check_RTC_after10days Verifying the range of the RTC time information Outline rtc_func.h Header static unsigned char check_RTC_after10days(void) Declaration Compares the RTC time information with the backup time information and verifies the Description RTC time information is within normal range (10 days after the backup time information). None Arguments RTC_INIT_RES: RTC time information is invalid. Return Value RTC_RUN_RES: RTC time information is valid. rtc_time_read Outline Header Declaration Description Arguments Return Value Reading the RTC time information None static void rtc_time_read(void) Reads the RTC time information and stores it in the RAM area for the RTC time information. None None R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 17 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start R_INIT_Clock_an1713 Clock initialization Outline r_init_clock.h Header void R_INIT_Clock_an1713(void) Declaration Initializes the clock. Description None Arguments None Return Value The sample code selects processing which uses PLL as the system clock and the Remarks 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 Sub-clock setting Outline r_init_clock.h Header void CGC_subclk_as_RTC_an1713(void) Declaration Configures the setting when the sub-clock is used as the RTC count source and not Description used as the system clock. None Arguments None Return Value Refer to pattern D in the RX63N Group, RX631 Group Initial Setting Rev. 1.10 Remarks application note for details on this function. enable_RTC_an1713 Outline Header Declaration Description Arguments Return Value Excep_RTC_PRD Outline Header Declaration Description Arguments Return Value RTC Initialization None static void enable_RTC_an1713(void) Performs the initialization when the RTC is used (setting for clock provision and RTC software reset). None None RTC periodic interrupt handling rtc_func.h static void Excep_RTC_PRD(void) 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. None None R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 18 of 36 RX63N Group, RX631 Group time_backup Outline Header Declaration Description Arguments Return Value Remarks True/False Determination of RTC Time Information on Cold Start Backup processing for the RTC time information None void time_backup(uint32_t time_data, uint8_t write_block) 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. uint32_t time_data: RTC time information data to be backed up uint8_t write_block Data to specify the area used for backup None The program placed in the ROM area is executed even when the CPU is programming/erasing E2 DataFlash. R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 19 of 36 RX63N Group, RX631 Group 5.11 5.11.1 True/False Determination of RTC Time Information on Cold Start Flowcharts Main Processing Figure 5.3 shows the Main Processing. main I flag 0 Disable maskable interrupts 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() True/false determination of RTC time information and RTC initialization Clock initialization R_INIT_Clock_an1713() Debug LCD initialization init_LCD() Debug LCD initialization 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. RSTSR1 register CWSF bit 1: Warm start Set warm start I flag 1 Enable maskable interrupts Backup request for RTC time information is generated? No Verifies whether the RTC time information backup request is generated in the RTC periodic interrupt. 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. Figure 5.3 Main Processing R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 20 of 36 RX63N Group, RX631 Group 5.11.2 True/False Determination of RTC Time Information on Cold Start Port Initialization Figure 5.4 shows the Port Initialization. port_init Set the port output for LED0 and LED1 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 Set the Debug LCD data output 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 Set the Debug LCD reset output and enable 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 return Figure 5.4 Port Initialization R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 21 of 36 RX63N Group, RX631 Group 5.11.3 True/False Determination of RTC Time Information on Cold Start Determination of RTC Initialization Requirement Figure 5.5 and Figure 5.6 show the Determination of RTC Initialization Requirement. check_RTC 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 DFLRE0 register DBRE00 bit 1: Read enabled for block 0000 to 0063 Initialize variables Enable reading of the E2 DataFlash (DB0/DB1) Sub-clock oscillated? No Yes RTC control registers 1 to 4 match initial setting values? Compares the RTC I/O registers with RTC initial setting values and verifies settings. No Yes No Automatic adjustment function being used? Yes Time error adjustment register value matches the initial setting value? No Yes Determination of the backup time information for use flash_check() Determines the backup time information (DB0/DB1) for use. Time information for use determined? No Yes 1/128 second wait R_DELAY_Us() Reading the RTC time information rtc_time_read() Compares the RTC time information (year, month, day, hour, minute, and second) with the backup time information and verifies the information. Verification of the RTC time information value check_RTC_clock() Time information (return value) is valid? No Yes Comparison of the RTC time information with the backup time information check_RTC_flash() Time information (return value) is valid? No Yes A return(RTC_INIT_RES) Figure 5.5 Determination of RTC Initialization Requirement (1/2) R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 22 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start A No Alarm function used? RCR1.AIE: 0: An alarm interrupt request is disabled. 1: An alarm interrupt request is enabled. Yes Read the alarm time registers 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. 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? No Yes Cold start? 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. 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". return(RTC_INIT_RES) flash_write RTC_BACKUP_INIT(2) return(RTC_RUN_RES) Figure 5.6 Determination of RTC Initialization Requirement (2/2) R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 23 of 36 RX63N Group, RX631 Group 5.11.4 True/False Determination of RTC Time Information on Cold Start 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? No RSECAR.ENB: 1: This register value is compared with the RSECCNT value. Yes The second data is to be verified Minute data is valid? No RMINAR.ENB: 1: This register value is compared with the RMINCNT value. No RHRAR.ENB: 1: This register value is compared with the RHRCNT value. No RWKAR.ENB: 1: This register value is compared with the RWKCNT value. Yes The minute data is to be verified Hour data is valid? Yes The hour data is to be verified Day-of-week data is valid? Yes The day-of-week data is to be verified Day data is valid? No RDAYAR.ENB: This register value is compared with the RDAYCNT value. No RMONAR.ENB: This register value is compared with the RMONCNT value. No RYRAREN.ENB: The RYRAR register value is compared with the RYRCNT value. Yes The day data is to be verified Month data is valid? Yes The month data is to be verified Year data is valid? Yes The year data is to be verified return Figure 5.7 Setting the Validity of the Alarm Time Information R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 24 of 36 RX63N Group, RX631 Group 5.11.5 True/False Determination of RTC Time Information on Cold Start Determination of the Backup Time Information for Use Figure 5.8 shows the Determination of the Backup Time Information for Use. flash_check Read the backup counter (DB0) Read the backup counter (DB1) Backup counter (DB0) != backup counter (DB1) + 1? No Set the backup counter (DB0) as the backup counter used Yes return(RTC_RUN_RES) Backup counter (DB0) + 1 != backup counter (DB1)? No Set the backup counter (DB1) as the backup counter used Yes 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? No The read DB0 data is older than DB1 data? Yes Yes The read time information DB0 is invalid? No Set the backup counter (DB0) as the backup counter used Set the backup counter (DB1) as the backup counter used return(RTC_RUN_RES) return(RTC_RUN_RES) No Set the backup counter (DB0) as the backup counter used Yes return(RTC_RUN_RES) The read time information DB1 is invalid? Yes return(RTC_INIT_RES) No Set the backup counter (DB1) as the backup counter used return(RTC_RUN_RES) Figure 5.8 Determination of the Backup Time Information for Use R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 25 of 36 RX63N Group, RX631 Group 5.11.6 True/False Determination of RTC Time Information on Cold Start Verification of the RTC Time Information Value Figure 5.9 shows the Verification of the RTC Time Information Value. check_RTC_clock Second data is to be verified and between 0 to 59? No Yes Minute data is to be verified and between 0 to 59? No Yes Display of the time information is 12-hour clock? No Yes Hour data is to be verified and between 0 to 11? No Hour data is to be verified and between 0 to 23? Yes No Yes return(RTC_INIT_RES) Day-of-week data is to be verified and between 0 to 6? No Yes Year data is to be verified and between 0 to 99? No Yes Month data is to be verified and between 1 to 12? No Yes Day data No is to be verified and appropriate for the month? When the month data is: Yes 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. return(RTC_RUN_RES) return(RTC_INIT_RES) Figure 5.9 Verification of the RTC Time Information Value R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 26 of 36 RX63N Group, RX631 Group 5.11.7 True/False Determination of RTC Time Information on Cold Start 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)? No Yes Backup year data = RTC year data(1)? No Yes Backup month data < RTC month data(1)? No Yes No Backup month data = RTC month data(1)? Yes Backup day data < RTC day data(1)? Yes No return(RTC_RUN_RES) return(RTC_INIT_RES) Note: 1. Data in the RTC time information (in the RAM). Figure 5.10 Comparison of the RTC Time Information with the Backup Time Information R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 27 of 36 RX63N Group, RX631 Group 5.11.8 True/False Determination of RTC Time Information on Cold Start 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? Yes Increment the month data Set the number of days that exceed the range for the month Year data made < RTC year data(1)? No 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. 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. Yes No No Year data made = RTC year data(1)? Yes Month data made < RTC month data(1)? Yes No No Month data made = RTC month data(1)? Yes Day data made < RTC day data(1)? Yes No 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 R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 28 of 36 RX63N Group, RX631 Group 5.11.9 True/False Determination of RTC Time Information on Cold Start Reading the RTC Time Information Figure 5.12 shows the Reading the RTC Time Information. rtc_time_read Enable the CPU interrupt request RCR1 register CIE flag 1 Clear the CPU interrupt request IR062 register IR flag 0 Read the second counter time.second RSECCNT register Read the minute counter time.minute RMINCNT register Read the hour counter Read the day-of-week counter Read the day counter Read the month counter Read the year counter Yes A carry occurred? 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. No Disable the CPU interrupt request RCR1 register CIE flag 0 return Figure 5.12 Reading the RTC Time Information R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 29 of 36 RX63N Group, RX631 Group 5.11.10 True/False Determination of RTC Time Information on Cold Start Clock Initialization Figure 5.13 shows the Clock Initialization. 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() Uses the sub-clock as the RTC count source without using the system clock (pattern D) PLL oscillation setting (2) CGC_oscillation_PLL() Set the division ratio for the internal clock (3) Specify the BCLK pin output setting (3) 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) Switch the system clock (3) Turn off the HOCO power supply (3) Enable write protection HOCOCR register 01h HCSTP bit = 1: HOCO is stopped. HOCOPCR register 01h HOCOPCNT bit = 1: Turns the power supply of the HOCO off. 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 R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 30 of 36 RX63N Group, RX631 Group 5.11.11 True/False Determination of RTC Time Information on Cold Start Sub-Clock Oscillation Setting Figure 5.14 shows the Sub-Clock Oscillation Setting. CGC_subclk_as_RTC_an1713 Yes Sub-clock is used as the RTC count source? rtc_reg_check_result REG_OK_MAIN or REG_NG No Specify the RTC count source No RCR4 register RCKSEL bit 0: The sub-clock is selected. RTC initialization requested? Yes Sub-clock oscillation setting Function: oscillation_subclk Stop the sub-clock oscillator Wait for 5 cycles of the sub-clock using CMT0 cmt0_wait() SOSCCR register 01h SOSTP bit = 1: Sub-clock oscillator is stopped. RCR3 register RTCEN bit 0: Sub-clock oscillator is stopped. Waits for 5 cycles of the sub-clock (approx. 152 s). Set the sub-clock driving ability RCR3 register 0Ch RTCDV[2:0] bits = 110b: Standard driving ability for the clock 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() Waits for the sub-clock oscillation stabilization wait time (2.6 sec.). 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 R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 31 of 36 RX63N Group, RX631 Group 5.11.12 True/False Determination of RTC Time Information on Cold Start RTC Initialization Figure 5.15 shows the RTC Initialization. enable_RTC_an1713 No RTC initialization requested? Yes Set the RCR3 register Stop counters and the prescaler RTC reset completed? RCR3 register RTCEN bit 1: Sub-clock oscillator is operating. RCR2 register RCR2 register & 7Eh START bit = 0: Counters and prescaler are stopped No Yes Reset the RCR3 register Set the date and time to Tuesday, January 1, 2013, 00:00:00 Specify the time error adjustment Set the RTC 1-second periodic interrupt Set the automatic adjustment Turn on LED0 RCR3 register 0Dh RTCDV bit 110b: Standard driving ability for the clock 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. RADJ register ADJ[5:0] bits 000000b: Adjustment value not set PMADJ[1:0] bits 00b: Adjustment is not performed. 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. 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. PORT0.PODR register B3 bit 0: P03(LED0): Low level Initialize the backup information Time information (time_data) 00:00:00: Time information VBATT charge flag (charge_VBATT) Not charged enough: Time information Set the time information backup flash_write RTC_BACKUP_INIT(2) request to 'initialization required' Specify the RTC periodic interrupt settings Start the RTC count operation Read the RTC time information 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. RCR2 register START bit = 1: Year, month, day-of-week, date, hour, minute, second, and 64-Hz counters, and prescaler operate normally. 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 R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 32 of 36 RX63N Group, RX631 Group 5.11.13 True/False Determination of RTC Time Information on Cold Start RTC Periodic Interrupt Handling Figure 5.16 shows the RTC Periodic Interrupt Handling. Excep_RTC_PRD Read previous time information (hour, minute) old_change_minute time_data & 0x00003F00 old_change_hour time_data & 0x003F0000 Read the RTC time information rtc_time_read() Make the current time data (hour and minute) Yes Sets the backup request immediately after the initialization or after an hour elapses. change_minute (time.minute & 0x0000007F) << 8 change_hour (time.hour & 0x0000003F) << 16 Time information backup request is 'initialization required'? No Previous time information = Current time information? Yes No flash_write RTC_BACKUP_ACK (1) Set the time information backup request Yes VBATT circuit is fully charged? No Verifies the charge status of the VBATT circuit and sets the backup request after 15 minutes elapse. VBATT circuit has been charged at least 15 minutes? No Yes Change the VBATT charge flag to 'fully charged' flash_write RTC_BACKUP_ACK (1) Set the time information backup request Confirms that the backup request is set and prepares for backing up. Time information backup request is set? No Yes Update the backup counter (write_counter) Set the programming mode to 'preparing'. Make data and display it on the Debug LCD. Set the current time data (second) in 32-bit integer type time_data (uint32_t)(time.second & 0x0000007F) Set the current time data (minute) in 32-bit integer type time_data time_data | (time.minute & 0x0000007F) << 8 Set the current time data (hour) in 32-bit integer type time_data time_data | change_hour Convert integer into BCD string uint32_ToBCDString() Debug LCD output Display_LCD() return Figure 5.16 RTC Periodic Interrupt Handling R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 33 of 36 RX63N Group, RX631 Group 5.11.14 True/False Determination of RTC Time Information on Cold Start Backup Processing for the RTC Time Information Figure 5.17 and Figure 5.18 show the Backup Processing for the RTC Time Information. time_backup Previous flash processing end flag state is 'completed'? No Yes Clear the previous flash processing end flag state No return Programming mode = Preparing? Yes Processing for E2 data flash access setting R_FlashDataAreaAccess() Clear the previous flash processing end flag state Erasing the DB0/DB1 block R_FlashEraseRange() Command successfully issued? No Yes Change the programming mode to 'erasing' Turn on LED1 return Programming mode = Erasing? No Yes A Transfer the time information (10 bytes) to a buffer for programming Programming E2 DataFlash (DB0,DB1) R_FlashWrite() Command successfully issued? No Yes Change the programming mode to 'programming' Turn on LED1 PORT0.PODR register B5 bit 0: P05 (LED1): Low level return Figure 5.17 Backup Processing for the RTC Time Information (1/2) R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 34 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start A Transfer the time information (10 bytes) to a buffer for reading Obtains 10-byte data for verifying. Compares the programming data with data for verifying. Programming data = Data for verifying? No Yes Turn on LED1 All data verified? PORT0.PODR register B5 bit 0: P05 (LED1): Low level Change the programming mode to 'preparing' Clear the RTC time information backup request flash_write RTC_BACKUP_NACK(0) return Figure 5.18 Backup Processing for the RTC Time Information (2/2) R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 35 of 36 RX63N Group, RX631 Group True/False Determination of RTC Time Information on Cold Start 6. Sample Code Sample code can be downloaded from the Renesas Electronics website. 7. Reference Documents User's Manual: Hardware RX63N Group, RX631 Group User's 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. User's Manual: Development Tools RX Family C/C++ Compiler Package V.1.01 User's 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/ R01AN1713EJ0101 Rev. 1.01 Nov. 6, 2015 Page 36 of 36 REVISION HISTORY Rev. Date 1.00 1.01 Apr. 1, 2014 Nov. 6, 2015 RX63N Group, RX631 Group Application Note True/False Determination of RTC Time Information on Cold Start Page -- 3 27 Program Description Summary First edition issued The specification was corrected. A figure was corrected. 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. A-1 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. 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. Processing at Power-on The state of the product is undefined at the moment when power is supplied. 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 system-evaluation test for the given product. Notice 1. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information. 2. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics does not warrant that such information is error free. Renesas Electronics 3. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein. technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others. 4. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part. Renesas Electronics assumes no responsibility for any losses incurred by you or 5. Renesas Electronics products are classified according to the following two quality grades: "Standard" and "High Quality". The recommended applications for each Renesas Electronics product depends on third parties arising from such alteration, modification, copy or otherwise misappropriation of Renesas Electronics product. the product's quality grade, as indicated below. "Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools; personal electronic equipment; and industrial robots etc. "High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-crime systems; and safety equipment etc. Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury (artificial life support devices or systems, surgical implantations etc.), or may cause serious property damages (nuclear reactor control systems, military equipment etc.). You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas Electronics product for any application for which it is not intended. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas Electronics. 6. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics, especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges. 7. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or systems manufactured by you. 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 products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations. 9. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. You should not use Renesas Electronics products or technology described in this document for any purpose 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 should comply with the applicable export control laws and 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 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. 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 Renesas Electronics products, or if you have any other inquiries. (Note 1) "Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries. (Note 2) "Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics. http://www.renesas.com SALES OFFICES 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 Electronics Europe Limited Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K Tel: +44-1628-585-100, Fax: +44-1628-585-900 Renesas Electronics Europe GmbH Arcadiastrasse 10, 40472 Dusseldorf, Germany Tel: +49-211-6503-0, Fax: +49-211-6503-1327 Renesas Electronics (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 Electronics (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 Electronics 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 Electronics Taiwan 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 Electronics Malaysia Sdn.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 Electronics India 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 (c) 2015 Renesas Electronics Corporation. All rights reserved. Colophon 5.0