Lib4U

‎"Behind every stack of books there is a flood of knowledge."

TI LaunchPad MSP430 getting started.

Texas

Menu

1. Introduction
2. What you will need
3. The Software
4. Starting a New Project
5. Programming the Chip
6. Line by Line
7. Compiling
8. Debugging
9. Concluding Note 

Introduction

There are so many different ways to get started with micro controllers. With this tutorial I present to you the cheapest possible way to do it. Texas Instruments has created a micro chip testing/development board for $4.30 … jaw dropping, seriously. This board comes with everything you need to get started; the board, a usb cable, and even an extra chip in case you do the ol’ Vcc to ground trick. So as usual, sit back read through this tutorial, I’ll do my best to keep your attention and I hope you learn something.

Back to Top

 

What you will need

See that picture to the left. Yup that’s all you need all $4.30 of it.

Get it here -> http://www.ti.com/tool/msp-exp430g2

If there is too much lead time order it fromwww.digikey.cawww.newark.ca orwww.mouser.ca

So when you open up that perfect sized box for the first time you will notice some random stuff that is included that you may have no idea what it is. Well the little silver canister is an oscillator (you don’t need it). The black rectangle things are female headers (you don’t need those either).

 

Back to Top

 

The Software

When it comes to microcontrollers we are often stuck installing a billion different programs, one for programming, one for coding, one for compiling… sometimes it’s annoying. Well you will be happy to know that this is not the case. We only need one piece of software, it’s called Code Composer Studio and it’s just awesome!

Get it here -> http://processors.wiki.ti.com/index.php/Download_CCS

The only downside is that it takes a while to install… deal with it :)

Back to Top

 

Starting a New project

Open code composer studio, it takes a minute or two to fire up even on an i7 machine. It will ask for a location where you want to save all of your projects, trust me when I say make it somewhere you will remember (My Documents for example).

Time to start the new project! So file -> New -> CCS Project, you should get the following window:

Just some quick notes before you hit finish. Make sure you select the right chip. The name of the chip is most likely “MSP430G2553” but the odd time you will get a different chip depending on what they feel like putting in the package that day. To be sure look at the top of your chip.

Once that is finished you should be rewarded with the project work space. This is the area that we will be entering and editing our code. Remember: DONT BE SCARED OF PROGRAMMING!

 

Back to Top

 

Programming the Chip

The first thing I will let you look at the code, if you are completely lost don’t fret, it will all be explained. The language we are using is called ‘C’ , and as I’m sure many of you may already know, I absolutely love it… and once you know how to use it its can only be described as freedom.

 

1234567891011121314151617181920212223

 

If you want to know more about the language ‘C’ i suggest you take a look at this set of tutorials. And seriously sit down and spend some time trying to figure out how the language works. Trust me when I say its time well spent.

Back to Top

 

Line by Line

If you are like me chances are you have already copy and pasted the code into code composer and tried to compile it. But you still have no idea how it works. Line by line means that i am now going to bore the heck out of you explaining each line of code.

  • include <msp430.h>

This is a file that the compiler includes when it is analysing your code. It gives the computer the information about the chip that you are using.

  • define LED_RED BIT0

Defining which pin we will use can be done with the above statement. It tells the computer that every time we type LED_RED we actually mean BIT0. So where does BIT0 come from anyway. Well if you look at your board you will notice that it has P1.0, P1.1 and so on. These are the individual pins that we can program on the circuit board.

This is how we define the pins in the program so that the computer knows what we are talking about… we have to speak its language. If we were to type “Launchpad I bid you to blink the LED” I don’t think anything would happen. So because the red LED is connected to P1.0 we define it as BIT0.

  • Void Delay_ms(unsigned int ms)

What programmers call a function prototype. All it is a reference to the Delay_ms function we see at the bottom of the code.

  • void main (void)

This defines our main function. The code that the Microcontroller will run before anything else

  • WDTCTL = WDTPW + WDTHOLD;

This probably doesn’t make sense to anyone. All we are doing hear is turning off a function that is called a Watchdog timer. We don’t need it so we turn it off.

  • P1DIR |= LED_RED;

There are two things a pin on a microcontroller can do. It can be an input or it can be an output. What we are doing hear is telling the pin that it is going to output something. We havnt told it what to output yet.

  • While(1){

While(1)… yup sounds weird but what we are asking the controller to do hear is to do everything inside its {} while 1 is equal to 1. You may be thinking “well that just stupid, one is always equal to one”. Actually thats kinda the point. Telling the microcontroller to wait until 1 no longer equals one is the same thing as telling it to run forever.

  • P1OUT ^= RED_LED;

This is where all the action happens the ‘^=” is called XOR. What it does is it looks at what the LED is doing and it tells it to do the opposite. So if the LED is on the XOR will tell it to turn off.

  • Delay_ms(500)

Well if you can’t figure this one out… i won’t say it. Anyway this delays the program for 500 milliseconds. If you want you can change the time that is in the brackets to be any number above 0.

Back to Top

 

Compiling

Compiling is all work that is done by the computer (thank goodness). It takes all of the code that you typed and it turns it into 1s and 0s. To compile your code click the hammer button.

If you did everything right you will get something at the bottom of the window that might scare you “Warnings!” ahhhh. Dont panic! They won’t stop you. If you have an error, that is a different matter. Warning are just the computers way of saying that it thinks you could be doing things better. We are doing things fine so tell the computer to jog on.

Back to Top

 

Debugging the Microcontroller

I was programming for probably about a year before I figured out what debugging actually meant… boy did I feel stupid. Debugging is just a word used to describe the action of finding problems in the code that we wrote. So when we ‘Debug’ our LaunchPad, it simply means that we are loading the program to see if it works. If it doesn’t, then we have to ‘Debug’ it. So click debug already!

Oh yeah make sure the controller is plugged into your computer.

After some loading you will get an new work space that looks something like this:

Press the Play button and watch that LED blink! When you are done click the stop button and the program will return to the original programming window.

Source:

http://roboteurs.com/tutorial-2-ti-launchpad-msp430-getting-started/

Advertisements

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

Virtual Fashion Technology

Virtual Fashion Education

toitocuaanhem

"chúng tôi chỉ là tôi tớ của anh em, vì Đức Kitô" (2Cr 4,5b)

VentureBeat

News About Tech, Money and Innovation

digitalerr0r

Modern art using the GPU

Theme Showcase

Find the perfect theme for your blog.

lsuvietnam

Learn to Learn

Gocomay's Blog

Con tằm đến thác vẫn còn vương tơ

Toán cho Vật lý

Khoa Vật lý, Đại học Sư phạm Tp.HCM - ĐT :(08)-38352020 - 109

Maths 4 Physics & more...

Blog Toán Cao Cấp (M4Ps)

Bucket List Publications

Indulge- Travel, Adventure, & New Experiences

Lib4U

‎"Behind every stack of books there is a flood of knowledge."

The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.

%d bloggers like this: