Using Code Composer to Create and Debug Code Application Notes

Brandon Briegel | 1 Using Code Composer™ to Create and Debug Code Application Notes 11/8/2013 Brandon Briegel Executive Summary: Code composer Studi...
Author: Donald Ellis
36 downloads 3 Views 573KB Size
Brandon Briegel | 1

Using Code Composer™ to Create and Debug Code Application Notes

11/8/2013 Brandon Briegel Executive Summary: Code composer Studio is a software development tool that is used to create, compile, debug, and flash code to a microcontroller. In this application notes, we will go over how to utilize Code Composer’s tools to implement and debug code.

Keywords: Code Composer Studio, Integrated Development Environment, code, compile, debug, debug menu, breakpoints

Brandon Briegel | 2

Contents Introduction ......................................................................................................................... 3 Objective ............................................................................................................................. 3 Issues ................................................................................................................................... 3 Creating a new project ........................................................................................................ 3 Header Files ........................................................................................................................ 5 Debug Mode........................................................................................................................ 6 Conclusions ......................................................................................................................... 8 References ........................................................................................................................... 9

Brandon Briegel | 3

Introduction Code Composer is an Integrated Development Environment (IDE) created by Texas Instruments. It is a software application that provides tools for programming TI microcontrollers, writing, modifying, compiling, and debugging code. Code Composer is a good development tool because it has an accessible user interface that presents projects in a single, all-inclusive program. The microcontroller demonstrated is the MSP430 which is a low cost, low power microcontroller designed for battery powered applications. The MSP430 incorporates a 16-bit RISC CPU that is optimized for modern high-level programming because it enables new applications at a fraction of the code size. These notes will explain how to use Code Composer, start a project, and debug basic code.

Objective The main use of Code Composer is to write and flash code to a microcontroller. With the flexibility of the MSP430, applications of code include capacitive touch sensing, energy metering, battery-less temperature sensor, or digital signal filtering. The example code in Step 14 demonstrates a simplified application using the built-in LED functionality of the MSP430 with the goal of learning the process of using Code Composer and its built-in tools.

Issues Issues discussed will involve starting a project, setting up source code, debugging, and running the completed code.

Creating a new project A project is the central hub for all the files, libraries, and codes. 1.) Before creating a new project, open Code Composer (Start →All Programs →Texas Instruments →Code Composer Studio →Code Composer Studio). 2.) There will be a prompt to choose a workspace. Browse for the file location to which you wish to save the project. 3.) Make a new Project by clicking (File →New →CCS Project)

Brandon Briegel | 4

4.) Name your project file, and select the appropriate Device Family. For this example, select MSP430 and the project is named Application Notes. 5.) Select the variant MSP430G2553 and keep the Connection as USB1 [Default] 6.) Select Empty Project, then click Finish and a new empty project will appear.

Figure 2 New CSS Project Wizard

Brandon Briegel | 5

7.) To create a source code file, click (File  New Source File) 8.) Here, name the source file, be sure to add the suffix .c, and click Finish. For this example the source is named ApplicationNotes.c 9.) Now we have an empty body where we can edit our code. Notice that in the top right corner there are two prospective modes, CCS Edit & CCS Debug. We’ll discuss the debug mode in Step 15. Also notice all of the project files are seen in the Project Explorer in the left pane of the source code. This window provides easy access to switch between different code in the same project, or completely change projects.

Header Files 10.) To start coding, library files, functions, and core variables need to be set. Also, the MSP430G2553’s pins, registers, and memory need to be defined using the header file. Think of a header as reusable code that contains forward declarations of classes, subroutines, variables, and other identifiers. To add the header using Code Composer, type the following in the body of your source code: #include

Brandon Briegel | 6

11.) Next, the code needs a main code to run. The Void is a C++ type that requires no arguments and ends the function either by reaching the end of the function or by executing a return statement with no return value. The function called at program startup is called main. Executing the main code starts and runs the code until the end of the main code is reached. Calling functions to perform computations reside in the main code, but the functions themselves do not have to be written in the body of the source code. 12.) Variables used in the main code have to be defined outside of said main code. For this example, an integer delay is initialized under the header, outside the main code. Variables are local to the specific source code and are not passed between codes. Their values can be passed between functions and source codes, but that is beyond the scope of this example. 13.) Now that we understand the primary components of our code, let’s debug the sample code below. #include // accesses the microcontroller so we can program it unsigned int delay; // initializes the variable 'delay' as an integer void main(void) // creates a main function { WDTCTL = WDTPW + WDTHOLD; // Turns off the Watchdog timer P1DIR = 0x40; // Sets P1.6 directory as an output while(1) { P1OUT ^= 0x40; //Turns on P1.6 LED for(delay=0; delay

Suggest Documents