rl78 ultra low power lab – cl07i - renesas electronics · pdf filerl78 ultra low power...

27
LAB PROCEDURE Using Applilet to Create IAR RL78 Project Page 1 of 27 RL78 Ultra Low Power LAB – CL07I Description: This lab will demonstrate low power modes of the RL78 and show how important pin setups are to achieve the best power performance. The lab will also demonstrate how the Applilet code generator simplifies getting started with the RL78 Lab Sections 1 Running the Pre-Programmed Application: .......................................................................................... 2 2 Generate IAR Project using Applilet ..................................................................................................... 4 3 Edit/Build IAR Project ........................................................................................................................... 8 4 Download and Debug IAR Project.................................................................................................... 183 5 .................................................................................................................... Configuring Unused Pins 15 6 Flash Programming and Low Power .................................................................................................. 17 Lab Objectives 1. Demonstrate the low power modes of the RL78 2. Generate IAR project using Applilet 3. Edit/Compile/build/debug the project in IAR IDE Skill Level 1. New to RL78/ IAR Tools Time to Complete Lab 1 hour Lab Materials Please verify you have the following materials at your lab station. Laptop PC with IAR/Applilet tools pre-installed IAR Kickstart V1.20.1 KS Applilet3 for RL78/G14 V1.01.01 Renesas Flash Programmer V1.03 YRPBRL78G14 target board USB cable Multimeter

Upload: truongthuy

Post on 06-Mar-2018

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 1 of 27

RL78 Ultra Low Power LAB – CL07I Description: This lab will demonstrate low power modes of the RL78 and show how important pin setups are to achieve the best power performance. The lab will also demonstrate how the Applilet code generator simplifies getting started with the RL78 Lab Sections 1 Running the Pre-Programmed Application: .......................................................................................... 22 Generate IAR Project using Applilet..................................................................................................... 4 3 Edit/Build IAR Project ........................................................................................................................... 8 4 Download and Debug IAR Project .................................................................................................... 183 5 .................................................................................................................... Configuring Unused Pins 15 6 Flash Programming and Low Power ................................................................................................ .. 17

Lab Objectives 1. Demonstrate the low power modes of the

RL78 2. Generate IAR project using Applilet 3. Edit/Compile/build/debug the project in

IAR IDE

Skill Level 1. New to RL78/ IAR Tools

Time to Complete Lab 1 hour

Lab Materials Please verify you have the following materials at your lab station. • Laptop PC with IAR/Applilet tools pre-installed • IAR Kickstart V1.20.1 KS • Applilet3 for RL78/G14 V1.01.01 • Renesas Flash Programmer V1.03 • YRPBRL78G14 target board • USB cable • Multimeter

Page 2: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 2 of 27

1 Running the Pre-Programmed Application: This lab section is designed to highlight the features which come as the default program with the RL78 demo board. This is a quick overview, there is much more information in the Quickstart Guide for the kit

Step 1.1 Remove the jumper on CN4 on the Demo Board and place a multimeter configured to measure milliamps across those terminals. Set the multimeter to 20 mA range.

Step 1.2 Make sure that jumpers are placed on CN6, CN7, CN8 and CN11, positions 2-3, labeled “Virtual UART”.

Step 1.3 To start the demonstrations ensure that the USB stick is connected to the laptop PC via USB cable.

Step 1.4 The Demonstrations are controlled by the YRPBRL78G14 GUI which can be started from the “Start -> All Programs -> Renesas Electronics Tools -> YRPBRL78G14 -> YRPBRL78G14-Demo” menu or from the icon on the desktop.

Page 3: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 3 of 27

Step 1.5 The GUI should now be connected and running. Diode D2 should now be blinking and the graphs and data values on the GUI start page should now be updating with the USB stick parameters as shown below

The demo allows you to investigate many of the unique features of the RL78. These include:

a. Real Time Clock configuration and settings - Note that this tab allows you to synch the RTC to the PC clock and set alarms and interval interrupts using the RTC

b. Memory demo including RAM and Data Flash (EEPROM) c. Self Test – Highlights the self-test features of the RL78 and memory protection

features

You can click the various tabs and you will see the demos that are available.

Step 1.6 We will concentrate on the Low Power demo. Select this tab.

Step 1.7 With the program running in normal 32 MHz mode record the current on the multimeter.

____________________________ mA

Page 4: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 4 of 27

Step 1.8 Now select the “Halt” button and record the multimeter current. ____________________________ mA

Step 1.9 Select “Release” for the Halt mode, the current should go back to the original reading.

Step 1.10 Select the “Stop” button and record the multimeter current. ____________________________ mA

Step 1.11 Select “Release” for the stop mode, the current should go back to the original reading. Now that you have seen the impressive low power numbers for the RL78 we will show how to recreate those numbers with your code.

2 Generate IAR Project using Applilet: This lab section will show how to use Applilet to quickly create a project. Then we will place the MCU into various low power operating modes. The project uses RL78G14 Family device, R5F104LE. We will create a simple project that blinks LED (D2) every 1s with RTC interrupt. Procedural Steps

Step 2.1 Close the demo program and disconnect the USB cable.

Step 2.2 Move the four jumpers (CN6, CN7, CN8, CN11) in the middle of the board to position 1-2 which enables the OCD .

Step 2.3 Open Applilet by clicking the desktop shortcut or from the menu : Start -> All Programs -> Applilet -> Applilet3 for RL78G14 -> V1.01.01-> Applilet3 for RL78G14 V1.01.01.

Step 2.4 From Applilet, select “File>new”. This will open “New Project” window.

Step 2.5 Enter the options below to configure project environment for R5F104LE device. The device in the RL78 Stick is the R5F104LE: Ensure that ‘Kind of project’ “Project for RL78/78K0R”

Halt mode stops the clock to the CPU core but maintains clocks to the peripherals which are enabled

Stop mode stops the clocks to the CPU and peripherals but can allow the WDT and RTC to be functional. Low Voltage Detect (LVD) is also enabled

Page 5: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 5 of 27

Scroll down the “Using microcontroller” device list to find the 64k Flash version Click on RL78/G14(ROM:64KB),select device :“R5F100LE(64pin)”.

Specify “Using Build Tools ‘IAR Compiler’ Specify ‘Project name’ ‘MyRL78G14Project’ Specify ‘Place’ ‘C:\RL78_Projects’

Step 2.6 Click OK to create the new project

Step 2.7 The next screen shows the Applilet Code Generator. You may recognize this from CubeSuite or from previous Applilet versions. Note: If this is not what your screen looks like, then you are using a different version of Applilet.

Page 6: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 6 of 27

Step 2.8 For this project, leave the boxes unchecked and click on “Fix Settings.” Other settings are handy for projects that need enhanced serial or timer functionalities.

The project opens for you to begin at the System Settings. The first thing to decide is how the pin assignment is set. This setting can only be done once per project. The default is PIOR = 0x00, where PIOR = Port IO Re-direction register.

Page 7: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 7 of 27

Step 2.9 Select the “Clock setting” tab. Select the settings as shown in the below picture (all are default except we check the SubClock Operation box):

Operation Mode Setting High speed main mode 2.7≤VDD≤5.5

EVDD setting 4.0V-5.5V Main system clock (fMAIN) setting High-speed OCO

High Speed OCO clock setting: 64MHz (TAU timer is 64MHZ, CPU is 32MHZ) High-Speed System Clock setting Unchecked

Subsystem clock (fSUB setting) Operation checked XT1 Oscillation: Checked Frequency: 32.768kHz XT1 oscillator Oscillation mode setting: Ultra Low power consumption Subsytem Clock in Stop Mode Stops supply (except real-time counter and interval timer) RTC operation clock: 32.768 (fSub) CPU and peripheral clock : 32000 (flH).

Page 8: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 8 of 27

Step 2.10 Select the On-Chip Debug Tab. Select these settings: On-Chip Debug: “Used” RRM function setting ‘Used’ (default) or ‘Unused’ – either setting is OK Use Security ID Checked Security ID 0x00000000000000000000 Erase Flash Memory Data Checked Security ID Authentication Erase flash memory data

Step 2.11 Reset Source and Safety functions can be left as default.

Step 2.12 Select the Port tab from project tree, select Port7, and set bit 7 as output, with level at 1. This is for driving the on-board LED (other pins should be left as unused):

Note: “Unused” just means the Port pin is not yet reserved for General Purpose Input/Output use, so alternate peripheral function can be can be specified. However, all Unused pins will default to INPUT mode on MCU Power-On RESET, except for P130 which is output only. If a peripheral input or output function is utilized, the Port pin will show a RED circle with Exclamation point next to the “In” and “Out” buttons, but the “Unused” button is still selected.

Page 9: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 9 of 27

Step 2.13 The Interrupt, Serial, A/D and Timer tabs are not used in this example, so we will skip those.

Step 2.14 Select the WDT (Watch Dog Timer) tab, and set the WDT as UNUSED.

Step 2.15 Select the RTC (Real Time Clock) tab. Set it as USED, enable the Interrupt setting, and set the Constant Period Interrupt function (INTRTC), set at “Once per 1 s” for a once-per-second interrupt, priority at low.

Step 2.16 Save this project.

Step 2.17 Click the Generate Code button on the toolbar or using the menu File>>Generate Source Code. It should report that the project was created successfully:

Step 2.18 Minimize Applilet; you do not have to close it.

Page 10: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 10 of 27

3 Edit/Build IAR Project This section explains how to open an IAR project, edit/modify the source code for the target application and IAR tools setting for the target board. Procedural Steps

Step 3.1 Launch IAR from the desktop icon or Start -> All Programs -> IAR Systems->IAR Embedded Workbench for Renesas RL78 1.20.3 Kickstart-> IAR Embedded Workbench. You should be using V1.20.3, which can be installed from the RL78G14 RDK install disk.

Step 3.2 Click File>Open>Workspace and browse to the directory where you created the IAR project using Applilet . (C:\RL78_Projects\MyRL78G14Project)

Step 3.3 Click on “MyRL78G14Project.eww” file. This will load the IAR project file generated by Applilet.

Step 3.4 If IAR displays a message stating that the project file is an old format, click “Yes” to convert it into the new format.

Step 3.5 Your screen should look like this:

Page 11: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 11 of 27

Step 3.6 Expand the applilet_src folder by clicking on the “+” symbol to the left of the folder. Your screen should now show the files below

Step 3.7 Open the r_cg_port.c file by double-clicking on it. You can see that the R_PORT_Create function contains the following code which sets up port 7 as an output with a logic level 1 which we selected using Applilet

Notice that there is a red asterisk next to each of the source files that we have added – this indicates that the code will be compiled at the next build either because the source is new or has changed since the last build. After compilation, the asterisks will disappear until we make a change to the code.

Notice that there is r_cg_port.c and a r_cg_port_user.c . The r_cg_port.c is the setup code for the ports based on selections made using Applilet and the r_cg_port_user.c is a framework file for the user to input their own code. Notice a similar structure exists for each peripheral which was setup using Applilet

void R_PORT_Create(void) { P7 = _80_Pn7_OUTPUT_1; PM7 = _01_PMn0_NOT_USE | _02_PMn1_NOT_USE | _04_PMn2_NOT_USE | _08_PMn3_NOT_USE | _10_PMn4_NOT_USE | _20_PMn5_NOT_USE | _40_PMn6_NOT_USE | _00_PMn7_MODE_OUTPUT; }

Page 12: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 12 of 27

The first thing we will do is modify the program to blink the LED using the RTC ISR.

Step 3.8 Open the r_cg_rtc.c file. Click the “f( )” in the lower left corner of the editor window to see the functions in the file. We will need to enable the counter in our program and we will also need to provide an ISR.

Step 3.9 Double-click “r_main.c” to open it in the editor window

Step 3.10 Add the code below that is shown with the comment “//add this line” to main() void main(void) { /* Start user code. Do not edit comment generated here */

R_RTC_Start(); // add this line while (1U) { ; } /* End user code. Do not edit comment generated here */

Step 3.11 Now we will add the code to the ISR. The interrupt is already setup with a callback function. Open the r_cg_rtc_user.c file.

Page 13: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 13 of 27

Step 3.12 In the “r_rtc_callback_constperiod” function add the code shown in the lines with // add this line

void r_rtc_callback_constperiod(void)

{

/* Start user code. Do not edit comment generated here */

volatile unsigned int i; // add this line

P7_bit.no7 = 0; // add this line

for (i=0;i<0xffff;i++); // add this line

P7_bit.no7 = 1; // add this line

/* End user code. Do not edit comment generated here */

}

Step 3.13 Make the project by clicking the Make icon on the toolbar or pressing F7. The project should build with no error

Step 3.14 Right click on project name and select “Option.” You will see a window like the one shown below.

Page 14: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 14 of 27

Step 3.15 Under Category, select “Debugger”. On this screen you will notice that the default debug target is the simulator

Step 3.16 Now select Category as “Debugger”. Select “Driver” as “TK”.

Step 3.17 Click OK to save all the changes we have made to the Project Options.

4 Download and Debug IAR Project Overview: In this section of the lab, we will download our project into the target board and run it as well as explore some of the different low power options. Procedural Steps

Step 4.1 Re-connect the USB cable to the YRPBRL78G14 board.

Step 4.2 Click the Download/Debug button on the toolbar . If a window appears that indicates the TK tool must be setup click OK to go to the emulator setup. You do not need to change any information on that window just click OK.

Step 4.3 Click “Debug-> Go” or press F5 to RUN the program. You will see the LED D2 on the demo board will blink briefly every second

Congratulations! You have a working project running on the RL78 MCU.

Page 15: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 15 of 27

Step 4.4 With the program running in normal 32 MHz mode record the current on the multimeter

____________________________ mA

This current should be very close to the current that was measured when using the demo. We will now place the device into Halt mode.

Step 4.5 Click “Debug-> Break” or use the icon on the toolbar to stop executing the code.

Step 4.6 Click “Debug-> Stop Debugging”

Step 4.7 Open r_main.c and add the following line of code (notice there are two underscores before halt).

void main(void) { /* Start user code. Do not edit comment generated here */

R_RTC_Start(); while (1U) { __halt(); // add this line } /* End user code. Do not edit comment generated here */

Step 4.8 Click the Download/Debug button on the toolbar to rebuild the program and download it.

Step 4.9 Click “Debug-> Go” or press F5 to RUN the program and record the current. ____________________________ mA

Side Note: You may observe the Multimeter current drain measurement jumping around a bit as the MCU is alternating between the 2 different modes at a 1 second rate. (between Halt and RUN mode, with the LED flashing). The exact mA value is not important, as we will look for a trend. You just may want to be consistent in your measurement method; either use the lowest current seen, or the average between lowest/highest readings, or the most frequently seen value. Whatever measurement method you use, try to stick with it - to see lowered current drain trends -

Notice the decrease in current required though the LED is still blinking. Rather than wasting energy “spinning” in a “while(1) loop the MCU is placed in Halt mode until the RTC interrupt wakes it up. The task is then completed and the MCU is placed back in a low power state.

Page 16: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 16 of 27

with the goal of achieving the lowest MCU power consumption while still performing the desired function (blinking the LED!).

We will now place the device into Stop mode.

Step 4.10 Click “Debug-> Break” or use the icon on the toolbar to Stop executing the code.

Step 4.11 Click “Debug-> Stop Debugging”

Step 4.12 Open r_main.c and add the following line of code (notice there are two underscores before stop( ) ).

void main(void) { /* Start user code. Do not edit comment generated here */

R_RTC_Start(); while (1U) { __stop(); // add this line } /* End user code. Do not edit comment generated here */

Step 4.13 Click the Download/Debug button on the toolbar this will rebuild the program and download it

Step 4.14 Click “Debug-> Go” or press F5 to RUN the program and record the current ____________________________ mA

Step 4.15 Click “Debug -> Stop Debugging” to discontinue debugging. Remove the USB cable.

Notice the current is lower, however, it is not nearly as low as we showed in the demo. One reason for this is the wasted current from floating pins. We will modify the starting configuration to improve this. If you look at the schematic for the RPB demo board in the Appendix you will notice most of the pins are not connected. We are going to configure these as output pins so they will not “float”.

Page 17: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 17 of 27

5 Configuring Unused Pins One nice feature of Applilet is you can modify a project and update the code. Applilet will not change any code you added that is within the line shown below /* Start user code. Do not edit comment generated here */ /* End user code. Do not edit comment generated here */ There are also options to allow Applilet to overwrite or merge code

Step 5.1 Minimize your IAR project and return to the Applilet project that should still be open.

Step 5.2 Under OPTIONS>>Generate Type make sure “Merge file” is selected.

Step 5.3 Select the “Port” tabs to configure the following ports

Port 0 – all pins as outputs Port 1 – Pins 0, 1, 2, 3, 5, 6 and 7 as outputs.

P1-4 input

Port 2 – Pins 0, 1, 3-7 as outputs P2-2 input (R5 potentiometer)

Port 3 – Pin 0 as output

Pin 1 as input (SW2 Pushbutton) Port 4 – Pins 1, 2 and 3 as outputs

Pin 0 not used (notice Applilet warns there would be a conflict on Pin 0) Ports 5, 6, and 14 - all output Port 7 – Pins 0, 1, 2, 3, 4, 5, 7 as outputs Pin 6 as input (SW1 Pushbutton) Port 12 - Pin 0 as output

Pin 1,2 as input Pins 3, 4: Not used

Port 13 - Pin 0 as output

Pin 7: not used

Page 18: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 18 of 27

Step 5.4 Now select “Generate Source Code.”

Step 5.5 Return to your IAR project and you will see a dialog window like the one below indicating the project has changed.

Step 5.6 Click “Yes” to allow the new files to be loaded.

Step 5.7 Now build and connect to the debugger. Run the program and note the stop current. ____________________________ mA

Step 5.8 Change the __stop(); command to a __halt(); command and compare the currents. ____________________________ mA

Step 5.9 Comment out the _halt(); to see the 32 MHz current when the port pins are configured for a low power state.

____________________________ mA

Notice that the currents are somewhat lower but still the lowest power Stop mode current is not <1 uA. There are a few reasons for this

1. The debugger block in the RL78 MCU is enabled. This block consumes a few hundred uAmps so we will need to disable it

2. We setup the unused pins but did not configure all the pins. There are a few that still need to be configured.

6 Flash Programming and Low Power This section explains how to program the code to the target board using Renesas Flash Programmer (RFP) which allows running in the standalone mode. We will also configure the remaining port pins and disable the debugging function to achieve the lowest power numbers for the configuration

Page 19: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 19 of 27

Procedural Steps

Step 6.1 Set your IAR project to be for Release session (and not Debug, as it has been). You can change it at the pull-down menu just above the project name (this will terminate the debug session)

Step 6.2 Select, Project -> Options, and go the Linker settings.

Step 6.3 Select the “Output” tab and set the Output to have a name that is overridden from the default <filename>.a87 file name. We use “hex” extension so that RFP (Renesas Flash Programmer) will find it easily. Set the “output format” to be “intel-extended”, as shown below and click OK

Page 20: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 20 of 27

Step 6.4 Near the top of the r_main.c file is the code shown below, Change the opbyte3 value to 0x04U, this will disable the debug block

/*********************************************************************************************************************** Global variables and functions ***********************************************************************************************************************/ /* Set option bytes */ #pragma location = "OPTBYTE" __root const uint8_t opbyte0 = 0xEFU; #pragma location = "OPTBYTE" __root const uint8_t opbyte1 = 0xFFU; #pragma location = "OPTBYTE" __root const uint8_t opbyte2 = 0xF8U; #pragma location = "OPTBYTE" __root const uint8_t opbyte3 = 0x84U; // change this value to 0x04U

This portion of the code sets up the RL78 option bytes. These are configuration values that are stored in RAM which set default clock speed, WDT and LVD configuration settings. It also controls whether the debug block is enabled. We also need to modify some ports; we could use Applilet but we will instead just change them in code. This is done in the next step

Page 21: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 21 of 27

Step 6.5 Make the following changes to r_main.c. This will configure the two remaining lines that were not configured with Pull-up resistors on inputs. We could also use Applilet to configure the Pull-up resistors.

Make sure you change the // __halt to __stop not commented out /* Start user code. Do not edit comment generated here */

// add the lines below PU3_bit.no1 = 1; // pull-up for port 3 bit 1 on (pushbutton SW2 input) PU7_bit.no6 = 1; // pull-up for port 7 bit 6 on (pushbutton SW1 input) R_RTC_Start(); // add this line R_RTC_Set_ConstPeriodInterruptOff(); while (1U) { __stop(); } /* End user code. Do not edit comment generated here */

Step 6.6 Make the project to be sure the hex file is made. You should see the file appear on the list of output files in the main IDE window.

Step 6.7 Build the program but do not download it.

Step 6.8 Open the Renesas Flash Programmer from: Start -> All Programs -> Renesas Electronics Utilities -> Programming Tools -> Renesas Flash Programmer V2.00 -> Renesas Flash Programmer V2.00

Step 6.9 Select Create New Workspace. Choose “Basic Mode”

Step 6.10 In the “Create a new workspace” window select: Group: RL78/G14 Device Name: R5F104LE Workspace Name: MyRL78G14ProjectRFP Project Name: MyRL78G14ProjectRFP Folder C:\RL78_Projects\MyRL78G14Project

The above SW enables the 32KHZ/RTC operation but disables the RTC interrupt that blinks the LED. To enable LED blinking, just comment out the R_RTC_Set_ConstPeriodInterruptOff(); line. Most ultra low power MCU designs in battery-operated applications need the 32KHZ/RTC running for time/date function, with either periodic wakeup or random wakeup by the user. This exercise demonstrates a 32KHZ/RTC STOP mode current well less than 1uA.

Page 22: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 22 of 27

Click on “Next”.

Page 23: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 23 of 27

Step 6.11 In the “Communication Interface” window under Tool, select the highest COM port available. Click Next and click Next again on the “Setting Power Supply” window.

Step 6.12 Click Complete in the “Project Settings” window.

Page 24: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 24 of 27

Now you are ready to program the flash memory. Load the intel-hex file by clicking on Browse next to “User/Data area.” It is located under the C:\RL78_Projects\MyRL78G14Project\Release\Exe folder.

Page 25: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 25 of 27

Step 6.13 The Command should be set to Autoprocedure (E.P.). This will perform an Erase, Program and Verify operation in a single step. You can also perform these operations one step at a time. When you are done, close the program and unplug the USB cable from your board.

Step 6.14 To run the program you just programmed, remove the four option jumpers and plug it back into the USB port. This will power it without forcing it to talk to the PC. You should now see the low power current that was shown in the demo.

____________________________ uA

Note: since the R5 Potentiometer is tied to the port P22 digital input, the pot should be placed at full clock-wise or full counter-clock-wise position. Otherwise, the STOP/standby mode current will increase as port P22 starts to look like a floating input when not at logic “0” or “1”. You can experiment with the pot setting in a middle position to see the standby current drain rise dramatically, simulating effects of a single floating MCU input pin! However, if we had configured P22 as an ADC input pin, the Digital input buffer would be disabled, thus eliminating the potential problems of a floating input pin.

Page 26: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 26 of 27

As a last step we will restore your board to the initial configuration used to show the demo.

Step 6.15 Unplug the USB cable and install the four jumpers (CN6, CN7, CN8, CN11) between pins 1-2 (OCD).

Step 6.16 Reconnect the USB cable.

Step 6.17 Open Renesas Flash Programmer again and Open Latest Workspace. This time select the hex file YRPBRL78G14_Stick_Demo_SW.mot, located here: “C:\Workspace\RPB\RL78G14\Sample Projects\GUI Demo Source Code\YRPBRL78G14_Stick_Demo_SW\HardwareDebug.”

Step 6.18 Program the device.

Step 6.19 Unplug the USB cables and move the jumpers (CN6, CN7, CN8, CN11) to between positions 2-3 (Virtual UART).

Step 6.20 Plug in the USB cable and launch the demo app from the desktop.

You can now shut all programs down and disconnect the board. The lab is complete.

This workspace is installed as part of the install that comes with the RL78/G14 RPB .

Page 27: RL78 Ultra Low Power LAB – CL07I - Renesas Electronics · PDF fileRL78 Ultra Low Power LAB ... settings are handy for projects that need enhanced serial or timer ... Step 3.7 Open

LAB PROCEDURE

Using Applilet to Create IAR RL78 Project Page 27 of 27