Welcome to IDI Electronica!!!



Welcome!!! IDI Electronica is a blog for my personal projects and articles to help electronics enthusiasts like me.

Bienvenidos!!! IDI Electronica es un blog con mis proyectos personales y artículos con el fin de ayudar a entusiastas de la electrónica como yo.

Wednesday, April 1, 2015

Blinking an LED Using the Tiva C LaunchPad and Keil µVision 4

One of the most frustrating things for people new to microcontrollers is starting a new project from scratch. The main reason being that, unlike the Arduino platform, you have to install and configure different drivers and configuration files before you can even start your project. Arduino already includes all these files and settings in its platform, which is why it is so appealing to hobbyists.

The purpose of this project is to introduce the Tiva C Series LaunchPad and the Keil µVision embedded development tool to make the on-board LED blink.

This article will show you the steps to install the IDE, create a project and load the code to the LaunchPad board. 

TIVA C SERIES LAUNCHPAD AND KEIL µVISION 4

The Tiva C Series LaunchPad is a family of low-cost microcontroller evaluation boards developed by Texas Instruments. For this project, we will be using the TM4C LaunchPad (EK-TM4C123GXL). This board features an 80-MHz, 32-bit ARM Cortex-M4 CPU with floating point, 256 kBytes of 100,000 write-erase cycles of flash memory, and a wide range of peripherals including motion control PWMs, 1-MSPS ADCs, eight UARTs, four SPIs, four I2Cs, USB, and up to 27 timers. The board includes two general purpose switches, a reset switch, a power LED, and user programmable RGB LEDs for user interface.

For more details about the Tiva C Launchpad, you can visit Texas Instruments’ website 


Fig 1.  Tiva C Series Evaluation Board


µVision v4 is an ARM embedded development platform created by Keil that provides project management, code editing, compilation, debugging, and simulation. Even though µVision v5 has recently been released, we’ll be using v4 because it is more stable, you’ll find more online resources to support this version and more importantly, it’s the one I know how to use better.

For more information about Keil µVision 4.0 you can visit Keil’swebsite 

Fig 2. Opening image for Keil µVision 4


2. INSTALLING THE SOFTWARE (IDE)

a. First, we need to install Keil µVision v4. Go to  https://www.keil.com/demo/eval/armv4.htm. Enter your contact information and then download the file MDK474.exe to install the IDE. The download file size is approximately 590MB.

b. Run the MDK-ARM v4 installer, in the next screens accept the License Agreement, select the installation folder, enter your contact information and wait until the IDE installs. Next, check the box to “Add example projects…” and in the last screen, uncheck the “Launch Driver Installation” box.  

c. After installing Keil, we need to install the drivers to be able to interface the microcontroller with our computer. You will need the LaunchPad board for this step. First, go to http://www.ti.com/tool/stellaris_icdi_drivers to download the drivers for the Tiva C LaunchPad. At the bottom of the page you’ll find a PDF file with instructions on how to install the drivers for different operating systems. You can also access the PDF using this link

3. CREATING A NEW PROJECT

After Keil and the drivers are installed, we can start our new project.

a. Open Keil µVision v4. Click on Project >> New µVision Project and enter a name for the project

b. You’ll be asked to select a target microcontroller. For our board, select Texas Instruments and the device number TM4C123GH6PM


Fig 3. Selecting a microcontroller for new project

c. Accept copying the Startup project file when prompted

Fig 4. System prompt to install project startup file


d. Your Project window should now show the startup file under Target1 >> Source Group

Fig 5. Screenshot of Keil with startup file


e. Next, we need to copy the file system_TM4C123.c to our project folder. This file contains microcontroller specific code to enable the system clocks. The file can be found in the Keil installation folder. In my case, I found it in  C:\Keil\ARM\Startup\TI\TM4C123\system_TM4C123.c

f. After the file has been copied to your project folder, right-click on Source Group 1 in the Project window, click on Add existing files to Group ‘Source Group 1’ and select the file system_TM4C123.c

Fig 6. Adding files to Keil project


g. Finally, right-click on Source Group 1 again and click Add New Item to Group ‘Source Group 1’. Then select C File(.c), enter file name at the bottom and click Add. This will be your main program file.

f. The IDE should show the startup, system and main file that you created under Source Group 1

Fig 7. Screenshot of Keil after project files were added


4. PROGRAMMING

a. Go to https://github.com/sphanlung/TivaC/blob/master/LedBlink.c and copy the code to the C file that you created.  The link will take you to my Github repository.

b. Click on Project and Build Target. This command will compile your code and report any errors or warnings in the Build Output window.

Fig 8. Screenshot of Keil with command to compile code


c. Click on Project and Options for Target ‘Target 1’. Find the Utilities tab and under Configure Flash Menu Command, uncheck the Use Debug Driver box. Then, under Use Target Driver for Flash Programming select the Stellaris ICDI driver and hit OK. This will allow us to program the board through USB.

Fig 9. Configuring drivers to load code into LaunchPad


d. Click on Flash and then Download. This will load the compiled code to the microcontroller. The Build Output window will report the status of the process or any errors.

5. BOARD TEST

a. Once the code is loaded, press the reset button in the LaunchPad to start the program.

b. The blue LED should be on. If you hold SW1, the blue and green LEDs will blink. If you hold SW2, the blue and red LEDs will blink.


Fig 10. Testing the code in the LauchPad 


15 comments:

  1. Perfect my friend keepp the good job!

    ReplyDelete
  2. Nice thanks for the advice.... I was doing this since yesterday ...but without adding system_TM4C123.c but the header file tm4c123gh6pm.h

    I was getting error and my .axf file was not getting generated....thanks it worked now...

    Do you have other projects on tivac controller?

    Please share if can...

    ReplyDelete
  3. Nice article. It helped to solve my problem

    ReplyDelete
  4. iv'e been looking around forever for this please continue the good work.
    cant express my appreciation enough.

    ReplyDelete
  5. i downloaded keil 5 and installed all the packages for the board but i can't find any of the startup .s or .c files. can i find them explicitly somewhere?

    ReplyDelete
    Replies
    1. You don't have to copy the files when using Keil 5. When you create a project and select the microcontroller that you'll be using (i.e. TM4H123GH6PM), the Manage Run Time Environment window will appear. Just click on Device and check the box that says Startup. I'll be posting a video on how to create a project soon.

      Delete
  6. The blink example doesn't work on my lm4f120h5qr board

    ReplyDelete
    Replies
    1. The lm4f120h5qr is the Stellaris Launchpad which uses a different microcontroller. You'd have to use the header files for that specific device provided by TI or download them through Keil. You'll also have to look at the register addresses in the datasheet since the I/O and control addresses may be different.

      Delete
  7. thanks man , i almost lost hope , thanks again

    ReplyDelete
  8. While uploading the code I am getting an error.

    could not find device cortex-M in the device chain.
    Error: Flash Download failed - Target DLL has been cancelled
    how to get rid of this error? Any help is appreciable.
    Thank you

    ReplyDelete
  9. Hello, I got solution for the problem, in my PC required drivers were not installed
    For that i have followed this link:
    http://www.ti.com/tool/stellaris_icdi_drivers

    ReplyDelete
    Replies
    1. Hi, sorry for the late reply. I'm happy you were able to fix your issue. Good luck.

      Delete
  10. hi,could you please tell me how I could modify the code to make the LED blink at first at a steady rate then slow down when SW1 is pressed and make the LED faster when SW2 is pressd and then when both switches are pressed the LED turns red

    ReplyDelete
  11. You could write separate functions for each LED. Notice that they both rely on the delay() function. You could write a function with a smaller delay (fast blinking) and a function with larger delay (slower blinking) and choose which one to use based on the button pressed. Even better, you could use the same delay function and choose the length of the delay based on the button being pressed.

    ReplyDelete