This Project brings you with a quick step in blinking an LED on FRDM-KL46ZFRDM-KL46Z board using CodeWarrior.
The Freescale Freedom development platform is a set of software and hardware tools for evaluation and development. It is ideal for rapid prototyping of microcontroller-based applications. The Freescale Freedom KL46Z hardware, FRDM-KL46ZFRDM-KL46Z, is a simple, yet sophisticated design featuring a Kinetis L series microcontroller, built on the ARM Cortex-M0+ core.
FRDM-KL46Z can be used to evaluate the KL46, KL36, KL26 and KL16 Kinetis L series devices. It features a MKL46Z256VLL4MKL46Z256VLL4, this device boasting a max operating frequency of 48MHz, 256KB of flash, 32KB RAM, a full-speed USB controller, segment LCD controller, and loads of analog and digital peripherals. The FRDM-KL46Z hardware is form-factor compatible with the Arduino R3 pin layout, providing a broad range of expansion board options. The on-board interfaces includes a 4 digit segment LCD, a 3-axis digital accelerometer, magnetometer, capacitive touch slider, and ambient light sensor.
The FRDM-KL46Z features the Freescale open standard embedded serial and debug adapter known as OpenSDA. This circuit offers several options for serial communications, flash programming and run-control debugging.
Refer to the link for more details on Freedom board.
The features of the FRDM-KL46ZFRDM-KL46Z include:
- MKL46Z256VLLZ4MKL46Z256VLLZ4 MCU (48 MHz, 256 KB Flash, 32 KB RAM, Low power, 100 LQFP package)
- Dual role USB interface with mini-B USB connector
- Open SDA
- 4 digit segment LCD module
- Capacitive touch slider
- Ambient light sensor
- MMA8451QMMA8451Q accelerometer
- MAG3110MAG3110 Magnetometer
- 2 user LEDs
- 2 user push buttons
- Flexible power supply options – USB, coin cell battery, external source
- Battery-ready, power-measurement access points
- Easy access to MCU I/O via Arduino R3 compatible I/O connectors
- Programmable OpenSDA debug interface with multiple applications available including:
- Mass storage device flash programming interface
- P&E Debug interface provides run-control debugging and compatibility with IDE tools
- CMSIS-DAP interface: new ARM standard for embedded debug interface
- Data logging application
- Arduino R3 compatibility
Before we start on our project make sure the board is in Debug mode (refer to the blog how to load in Debug mode using OpenSDA)
Now that our board is loaded in Debug Let’s start on creating a CodeWarrior project to quickly demonstrate blinking LED on KL46 board.
A free version of Codewarrior can be downloaded following the link below in the Downloads section:
The Evaluation version is a 30 days Limited version and the Special Edition is Code Size Limited version (64KB for Kinetis MCUs with an ARM Cortex-M0+ core and 128KB for the Kinetis MCUs with an ARM Cortex-M4 core)
Follow the below steps for creating the CW project:
Select File->New->Bareboard Project
Provide Project Name “Blink-it using CW” then click Next
Now select the MCU exist on our KL46 board it is “MKL46Z256”
Kinetis L Series-> KL4x Family->KL46Z(48 MHz) Family->MKL46Z256 then Click Next.
Select OpenSDA option to connect for this board for debugging and programming, then click Next
Then click Next to proceed further
proceed further by clicking Next
in Rapid application development do not select Processor Expert then click on finish.
I have created the project by name “Blink-it using CW” as shown below:
Now open “main.c” and add the below code to it.
#include"derivative.h"/* include peripheral declarations */
void delay(int itime);
int main(void)
{
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;
PORTE_PCR29 = PORT_PCR_MUX(1);
GPIOE_PDDR |= (1 << 29);
for(;;) {
GPIOE_PTOR |= (1 << 29);
delay(1000);
}
return 0;
}
void delay(int itime){
int icompTime = 0;
for(icompTime=itime*1000;icompTime!=0;icompTime--){
}
}
The line of code shown below is System Clock Gating Control Register 5 (SIM_SCGC5)and Enable clock for PORT E setting bit field PORTE
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK
Next below line is Pin Control Register n (PORTx_PCRn) setting for PORTE, and Select GPIO as pin functionality on multiplexer setting field MUX=001
PORTE_PCR29 = PORT_PCR_MUX(1);
The below line of code is Port Data Direction Register (GPIOx_PDDR) and Set GPIO direction set bit corresponding bit on the direction register for each port, set the bit means OUTPUT
GPIOE_PDDR |= (1 << 29);
In for() loop we are toggling the output LED connected to PortE29
This can be found from Schematic of KL46Z board (http://www.element14.com/community/docs/DOC-54780/l/element14-presents-the-frdm-kl46z--a-freescale-kinetis-l-based-freedom-development-platform)
LED |
KL46 |
Green (LED1) |
PTD5 |
Red (LED2) |
PTE29 |
Now it’s time to clean and Build the project as shown:
You can then see project starts building as shown
Now Run the project as shown:
Now you can see the blinking of Red LED on KL46 board
Project created folder and Video output of this project execution is attached for reference.
Now we will modify our code to blink Green LED too (both Red and Green)
By referring to schematic we know Green LED is connected to port PTD5
#include"derivative.h"/* include peripheral declarations */
void delay(int itime);
int main(void)
{
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; // PORT E mask Red LED
SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK; // PORT D mask connected to Green LED
PORTE_PCR29 = PORT_PCR_MUX(1); // PORT E MUX
PORTD_PCR5 = PORT_PCR_MUX(1); // PORT D MUX
GPIOE_PDDR |= (1 << 29); // switching on RED LED
GPIOD_PDDR |= (1 << 5); // switching on Green LED
for(;;) {
GPIOE_PTOR |= (1 << 29); // Toggling RED LED after some delay
GPIOD_PTOR |= (1 << 5); // Toggling Green LED after some delay
delay(1000);
}
return 0;
}
void delay(int itime){
int icompTime = 0;
for(icompTime=itime*1000;icompTime!=0;icompTime--){
}
}
we can now see both LED's are blinking
Happy Blinking LED on KL46 board...