element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Documents [FRDM-KE02Z - PE - CW] Tutorial: Make it blink RGB
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 21 May 2014 5:15 AM Date Created
  • Last Updated Last Updated: 31 Jul 2014 4:21 AM
  • Views 3113 views
  • Likes 1 like
  • Comments 4 comments
Related
Recommended

[FRDM-KE02Z - PE - CW] Tutorial: Make it blink RGB

This Project brings you a detailed steps involved in creating and demonstrating a RGB LED peripheral present on KE02 Freedom demo board (FRDM-KE02ZFRDM-KE02Z).

 

The Freescale KE02Z Freedom Board is a simple, yet sophisticated design featuring the Kinetis E Series microcontroller KE02Z64VQH2KE02Z64VQH2, the industry’s first 5 V microcontroller built on the ARMRegistered CortexRegistered-M0+ core.

The Kinetis E series is the most scalable portfolio of low-power, high-robustness, mixed signal 32-bit ARM Cortex-M0+ MCUs running up to 20 MHz in the industry. It supports power supply voltage range from 2.7–5.5 V, ambient operating temperature range from –40 °C to 105 °C and includes up to 64 KB flash memory


The FRDM-KE02ZFRDM-KE02Z hardware is a Freescale Freedom Development Platform microcontroller board assembled with the following features

  • Kinetis E Series KE02 family MCU in an 64 QFP package
  • Onboard Serial and Debug Adapter (OpenSDA)
  • I/O headers for easy access to MCU I/O pins
  • Freescale inertial sensor, MMA8451QMMA8451Q
  • Capacitive touch slider
  • Reset pushbutton
  • RGB LED
  • Infrared communication
  • One thermistor
  • Motor control function interface for simple BLDC motor control

 

  The block diagram of the board is as shown below:

 

image

Before we proceed with actual project creation let’s have a bit knowledge on Kinetis GPIO concept.

The most basic interface of a microcontroller is the General Purpose Input/Outputs (GPIOs). These modules allow the programmer to get input from devices such as switches, and outputting the values to display a status or result, for example, on LEDs.

 

Figure 1 shows the block diagram of the GPIO modules used in the Kinetis Family of microcontrollers. In general, most microcontrollers separate individual GPIO pins into groups, called ports.

 

In the Kinetis microcontrollers, each port has 32 pins [31:0] as shown in the next diagram. Each of these ports are connected to the microcontroller via the peripheral bridge, which is a bus that allows slower components to talk to the microcontroller on a shared bus. This design is very common and helps to save on space within the chip. Since GPIO pins are not a high speed interface, they are normally either multiplexed or connected in a bus. Later on, we will see how each of these ports is organized.



image

Figure 1: GPIO Port block diagram from Freescale Kinetis Microcontroller


In the Kinetis microcontrollers, the GPIO are connected into ports of 32 pins each. Each of these ports have a separate set of registers to control the pins. To control whether the GPIO pin is used as an input or an output, the user can set a bit in the Port Data Direction Register (GPIOx_PDDR) shown below in Figure 2.

image

Figure 2: GPIO Port Data Direction Register (GPIOx_PDDR)

 

If the pin is setup as an output there are four registers that can be modified to set the output value. The Port Data Output Register (GPIOx_PDOR) sets the value of a pin to logic level 0 when a 0 is written, and a logic level 1 when a 1 is written.

 

The Port Set Output Register (GPIOx_PSOR) allows the user to write a 1 to it in order to set the logic level at 1. The PortClear Output Register (GPIOx_PCOR) allows the user to write a 1 to it in order to clear the pin, thus setting it to logic level 0.

 

This may seem like overkill, to have two extra registers, when you can do the same with 1. However, it really makes it easier to always set a bit to change the value of a output pin. The Port Toggle Output Register (GPIOx_PTOR) allows the user to write a 1 to it in order to toggle the current logic state.

 

For example, if the current value is 1 then writing a 1 to the register will flip the output logic level to 0. Also, writing a 1 to the register when the current level is 0, flips the output logic level to 1. If the pin is setup as an input, then reading the value in the Port Data Input Register (GPIOx_PDIR) will give the current logic level on the pin. Through the use of these register, the user can read and write data onto the pin with ease.

 

The Kinetis microcontrollers were designed for very low power operation. One of the ways to reduce the power on a chip is to turn off the clocks to particular areas that are not in use. The default setting for the microcontroller is to have the clock disabled. In order to use a particular peripheral or resource the user needs to enable this clock to each item individually. This is a great feature, and builds upon the latest research in preventing wasted power by reducing the dynamic power required for a chip.

image

Figure 3: System Clock Gating Control Register 5 (SIM_SCGC5)


Functional Description:

 

Each GPIO pin has 6 registers that are used to modify and evaluate the state of the pin. The block diagram for the GPIO pin operations used in the Kinetis microcontrollers is shown below in Figure 4.

image

Figure 4: A GPIO Pin Block Diagram


The actual GPIO pin is buffered into and out of the microcontroller so that the voltage levels do not short out the delicate chips circuits. These buffers are actually tri-state buffers since they can be set to a low logic level, a high logic level, and a high impedance value. These buffers are controlled via the data direction register.

 

As is shown in the diagram, there is an inverter between this register and the input buffer, so in order to use the pin as an input a ‘0’ must be written to the register. This also would turn off the output buffer so that the user doesn’t accidentally drive the value on the pin and read it at the same time.

The four output registers are multiplexed to the output buffer and this is controlled by logic that enables the register that was written to last. This way the user can write to any register at any time and update the value. The input buffer connects directly to the input register that can then be read by the user to determine the logic level on the pin.

 

A Short note on OpenSDA:

 

  OpenSDA is a low-cost debug/programming interface embedded in certain Freescale evaluation boards. It handles debug communications between the PC and target via USB. Evaluation boards that feature OpenSDA are great for the beginning phases of development.

 

image


OpenSDA is managed by a Kinetis K20 MCU built on the ARMRegistered CortexTm-M4 core. The Kinetis K20 includes an integrated USB controller that can operate at clock rates up to 50MHz. The OpenSDA circuit includes, at a minimum, a status LED and a pushbutton. The pushbutton asserts the Reset signal to the target processor, which could be a microcontroller, digital signal controller, or a microprocessor. It can also be used to place the OpenSDA circuit into Bootloader mode. The OpenSDA circuit receives power when plugged into a USB Host.


OpenSDA software includes a flash-resident USB MSD Bootloader and a collection of OpenSDA Applications. The MSD Bootloader is consistent across all implementations of OpenSDA, but the available OpenSDA Applications may vary from one hardware system to another. The OpenSDA MSD Bootloader provides a simple interface for loading an OpenSDA Application into the OpenSDA processor’s non-volatile memory. Only one OpenSDA Application may be resident at a time, and this application will be automatically run at startup unless Bootloader mode is selected by holding down the Reset button while plugging in a USB cable.


The P&E Debug Application is an OpenSDA Application that provides debugging and a virtual serial port all in one application. It provides a run-control debug interface that controls the JTAG or SWD debug interface to the target processor. It also provides a USB communications device class (CDC) interface that bridges serial communications between the USB Host and a UART serial interface on the target processor. The P&E Debug Application is designed to debug the resident target processor in the OpenSDA system with limited support for off-board devices within the same processor family as the resident target processor.     

 

Steps to be followed to load OpenSDA Debug file:

 

Before we start we need to download KE02 board quick start package from below link: ‘FRDM-KE02ZFRDM-KE02Z’ Quick Start Package containing Quick Start Guide, precompiled examples and OpenSDA Applications.

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-KE02Z&fpsp=1&tab=Design_Tools_Tab#

 

Plug in a USB cable from a USB host to the OpenSDA mini-B USB connector. The FRDM-KE02Z will be powered by this USB connection.

It comes with the mass-storage device (MSD) Flash Programmer OpenSDA Application preinstalled. It will appear as a removable storage drive with a volume label of 'FRDM-KE02Z'.

Now the board has to be in P&E Debug mode before we create a project in Processor Expert so that we can “Run” and “Debug” our example project,


P&E Debug Application


The P&E Debug Application is a run-control debug interface that controls the JTAG or SWD debug interface to the target controller/processor. It also provides a virtual serial port bridging a USB CDC device to a UART serial interface on the target device. Thus, it provides debugging and a serial port all in one application. Host drivers for this application are provided with several IDE toolchains such as CodeWarrior for Microcontrollers, IAR Embedded Workbench, and Keil MDK. Drivers are also available for download from P&E Microcomputer Systems at http://www.pemicro.com/opensda.


image

To do so the board should be in OpenSDA Bootloader mode so that the file “DEBUG-APP_Pemicro_v106.SDA” can be loaded.

 

To Enter into OpenSDA Bootloader Mode follow the below steps:


1. Unplug the USB cable if attached.

2. Press and hold the Reset button (SW1).

3. Plug in a USB cable between a USB host and the OpenSDA USB connector (labeled ―OPENSDA).

4. Release the Reset button.

 

A removable drive should now be visible in the host file system with a volume label of “BOOTLOADER” as shown below; you are now in OpenSDA Bootloader mode.


image

Now Locate the OpenSDA Applications folder in the FRDM-KE02Z Quick Start Package as shown here:

 

Inside the folder  \FRDM-KE02Z_QSP\OpenSDA Applications you can find three files as shown below:


image

  • CMSIS-DAP interface new ARM standard for embedded debug interface
  • P&E Debug interface provides run-control debugging and compatibility with IDE tools
  • Mass storage device flash programming interface (default) – no tool installation required to evaluate demo apps

 

Copy & paste or drag & drop the MSD Flash Programmer Application “DEBUG-APP_Pemicro_v106.SDA“to the BOOTLOADER drive.

Unplug the USB cable and plug it in again. The new OpenSDA Application (Debug Mode) should now be ready.

 

 

Now that our board is loaded in Debug Let’s start on creating a Processor expert project to demonstrate RGB LED interfaced to GPIO on KE02 board.

 

(Refer to my earlier blog for creating PE project:

http://www.element14.com/community/docs/DOC-67175/l/creating-processor-expert-project-for-ke02-kinetis-freedom-board-frdm-ke02z)

 

Open Codewarrior and select the workspace as shown below:

image

Click on File -> New -> Bareboard Project as shown below:


image

Provide Project Name, here in my case i have given project name as “RGB Demo-KE02” as shown below:

image

Next select Kinetis-E series and KE02Z (20MHz) device MKE02Z64MKE02Z64


image

Select OpenSDA as connection to target board to be used for this project as shown below

image

Select Default Language and build tools option as shown


image

Next, Select ‘Processor Expert’ check box option for Rapid Application Development as shown below:


image

Now we can see the project wizard is gathering and creating project for given settings


image

After creating project we can see the above project window ready for next step as shown below:


image

Now, Select the component ‘BitIO’ from component library and add to project, we need three 'BitIO' for connecting three LED’s RGB.


image

We need three ‘BitIO’ for connecting three LED’s RGB, so add three components as shown here:


image

Rename the 3 components as ‘Red’, ‘Green’ and ‘Blue’ for our ease of recognize and readability convention as shown here:


image

Next refer to the schematic of the board as shown in order to identify the port pin connected to RGB LED (you will get this from “FRDM-KE02Z User’s Manual“)


image

As we can see the LED’s are having ‘common Anode’ connection which is connected to 3.3V and we need to send ‘0’ signal to port pin to glow the LED and send ‘1’ signal to port pin to switch off the LED.


Now we need to assign to the particular port pin number as shown here


LED Red is connected to PTH1

LED Green is connected to PTH2

LED Blue is connected to PTE7


image

Select direction as ‘output’ and initial value as ‘1’ so that the LED will be ‘switched off’ initially.


image

Perform the same settings to other two LED’s as shown below:


image

Next click on ‘Generate Processor Expert’ Code button as shown here to generate all its library contents to be used in our project


image

After clicking Generate code you can see progress of generating files, it can be seen even at right hand below side of CW which is running at background


image

After generating the code you can see ‘ProcessorExpert.c’ file is generated under ‘Source’ folder with the entire required header files linked and generated, we need to add our code in this file as shown here.


image

As shown here we have written piece of code to glow all the three LED sequentially one after the other by giving some delay


image

              unsigned int i;

                  for(;;){

                        Blue_ClrVal();                                   // passing '0' to Blue LED port

                        for(i=0;i<=1000000;i++); //software delay

                        Blue_SetVal();                      // passing '1' to Blue LED port

                        for(i=0;i<=1000000;i++); //software delay

                   

                                    Green_ClrVal();        // passing '0' to Green LED port

                                    for(i=0;i<=1000000;i++); //software delay

                                    Green_SetVal();                   // passing '1' to Green LED port

                                    for(i=0;i<=1000000;i++);     //software delay

                     

                          Red_ClrVal();          // passing '0' to Red LED port

                          for(i=0;i<=1000000;i++);   //software delay

                          Red_SetVal();                     // passing '1' to Red LED port

                          for(i=0;i<=1000000;i++);   //software delay

                }

 

Next we need to ‘Clean’ and ‘Build’ the project as shown here

image

 

You can see the build process progress, and the steps involved can be seen in ‘console’ sub-window as shown here and if any error exists it prompts here.

Now build process is completed.

It is ready for ‘debugging’ or ‘Run’ the project.

 

image

 

Now connect KE02 board to computer through USB cable to openSDA port as shown below below.

 

image

 

To Run the project right click on project folder ‘RGB Demo-KE02’ -> Run As -> and click Codewarrior option as shown here:

 

image

 

Click on ‘open Perspective’ then select ‘Debug’ then click on ‘ok’ button

 

image

Now click on “Run” menu then select ‘Run’

 

image

Here you can see the progress happening in the console window, after everything is finished it displays “Target has been RESET and is active”

 

image

Now the board starts working i.e you can see all the three LED blinks sequentially for some interval (software delay).

(Note: you can watch this execution in video attached)


image

                    Blue LED blinking

 

     image

                    Green LED blinking

image

                    Red LED blinking


Here is a video output of RGB LED execution:


You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image


Now we will execute this program in “Debug” mode which is explained here:


image

Next proceed by clicking “Run”->”Debug”, you can see the debugging progress bar at below right side of the CW window.


image


Now Debug window is ready for debug process, you can see all associated resources available like Breakpoints, Memory menu, Register menu, Disassembly menu, and ProcessorExpert.c program menu for debugging. This is show below.


image


Now click on ‘step over’ icon as shown below, CW runs our program in single stepping mode and you can see corresponding registers value changes and while single stepping you can see output LED glowing accordingly.


image


Happy Glowing and Debugging RGB on KE-02 board image image


Attachments:
RGB Demo-KE02.rar
You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image
  • cortex-m0+
  • freescale
  • kinetis
  • freedom
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
  • bheemarao
    bheemarao over 10 years ago

    Yes i will do it sometime later, added to my list.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago

    Thanks for an excellent Tutorial. Can you do one using Kinetis Design Studio? Perhaps using the touch slider to alter the delay time and control the blinking speed?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bheemarao
    bheemarao over 11 years ago in reply to mcb1

    Hi Mark,

     

    Thanks for the compliments!

    I'm glad you found it useful.


    Regards

    Bheema Rao

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago

    Thanks for that very clear explanation.

    I've bookmarked it for later.

     

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube