c2000 Piccolo Launchpad, Microcontroller, Texas Instruments

c2000 Piccolo F28027 LaunchPad – Tutorial 2

Hey! In this tutorial, we’ll be trying out our first code on the piccolo board. We’ll be doing the proverbial microcontroller “Hello World!” code: Blinking an LED. To do this, we’ll be using one of the four onboard LED’s.

Starting a new project

To start a new project, click on Project –> New CCS Project.

This will open the “Create a New Project” wizard. Here, you can specify the project name.

In device, choose Family as “c2000”, variant as “2802x Piccolo” and “TMS320F28027”. The connection should be “Texas Instruments XDS100v1 USB Emulator”. Finally, make sure that your Output Type is “Executable” and click “Finish“.

Changing Project Properties

To make sure that the Piccolo is able to access the required header files, we have to change the project properties. To do this, click on Projects –> Project Properties.–> c2000 Compiler. Then click on “Include Options” and on the “Add” button besides “Add dir to #include search path”. Here you have to add the linker

C:\ti\controlSUITE\development_kits\C2000_LaunchPad

Similarly on the c2000 Linker, click the “File Search Path” and then on the “Add” button besides “Add <dir> to library search path”. Here you have to add the linker

C:\ti\controlSUITE\development_kits\C2000_LaunchPad\f2802x_common\lib\driverlib.lib

Then click “Finish” and we are ready to start!

Blinking an LED

The code for blinking an LED is as follows

/*
* main.c
*/

#include “DSP28x_Project.h” // DSP28x Headerfile
#include “f2802x_common/include/clk.h” // Header for Clock
#include “f2802x_common/include/gpio.h” // Header for GPIO
#include “f2802x_common/include/pll.h” // Header for PLL
#include “f2802x_common/include/wdog.h” // Header for Watchdog

#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif

void main()
{

WDOG_Handle myWDog;
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
WDOG_disable(myWDog);

CLK_Handle myClk;

PLL_Handle myPll;

myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));

CLK_setOscSrc(myClk, CLK_OscSrc_Internal);

/*
*selecting Internal Oscillator Clock 1 with a base frequency as 10 Mhz
*there is another clock which you can use by replacing this: “CLK_Osc2Src_Internal”
*/

PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
// Selecting 60Mhz InternalClock

GPIO_Handle myGpio;
myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));

GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose);

GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output);

GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_GeneralPurpose);

GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output);

GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_GeneralPurpose);

GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output);

GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_GeneralPurpose);

GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output);

GPIO_setHigh(myGpio, GPIO_Number_0);

//LED 1 is connected to GPIO 1
GPIO_setHigh(myGpio, GPIO_Number_1);
GPIO_setHigh(myGpio, GPIO_Number_2);
GPIO_setHigh(myGpio, GPIO_Number_3);

while(1) //This will run indefinitely
{
GPIO_setLow(myGpio, GPIO_Number_0);

//Setting it to low will turn the LED On
DELAY_US(1000000);

//1000000 us = 1 sec
GPIO_setHigh(myGpio, GPIO_Number_0);
DELAY_US(1000000);
}

}

Debug and Build the project, then hit Play. This will upload the code to the board and the first LED should be blinking every second.

In case you get an error saying that the code cannot upload to the board, then change the Emulator connection to another version.

In the next tutorial, we’ll be changing the brightness of the LED using the ADCIN pins.

Advertisements

1 thought on “c2000 Piccolo F28027 LaunchPad – Tutorial 2”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s