MSP430G2 launchPad Features
When you purchase MSP430G2 launchPad, it comes with two microcontrollers , MSP430G2553 microcontroller and MSP430G2452 microcontroller. Technical specifications of both microcontrollers are shown in table below:
As you can see in above table, MSP430G2553 microcontroller has better features than MSP430G2452 microcontroller. So we will be using MSP430G2553 microcontroller in this tutorial. For more details about MSP430G2 launchPad check this video:
PINS MAPPING OF MSP430G2553 microcontroller in MSP43052 Launch pad
Now, I will show you the pin map of MSP430G2553 microcontroller with Launch pad so you that you can know which pin of microcontroller you are actually using. Energia supports pin number of MSP430G2 LaunchPad instead of actual GPIO or port name like p1.0. So it is good to understand pin mapping. I encourage you to use the physical pin numbers of header pins as identifiers in their software. Because these numbers are consistent between all Launchpads, this help to ensure the portability of the user’s software. The table below shows the complete pin map for the MSP430G2553 LaunchPad in Energia. Pin maps are used to access microcontroller pins in energia ide. For example if you want to access pin number p1.0 of microcontroller you will use number 2 and similarly if you want to access p2.0 you will use number 8. For example if you want to declare pin p1.0 as a output you will use Pin mode function like this
Pinmode( 2, OUTPUT) ;
It will declare pin p1.0 as a digital output. You can simply use pin numbers written on board instead of using name of pins like p1.0 or p2.1. Function of all pins will become clearer as you progress in this course. So from now onwards in course I will talk about pin number of headers instead of ports of microcontroller. Because you know about Pin mapping.
How to download Energia IDE
We will be using Energia IDE in this tutorial for programming and uploading code to MSP430G2 launchpad. The reason for using energia IDE is that it is very easy to use for beginners and those who are just getting started with MSP430 microcontrollers programming and there are other IDE’s available which are used to program MSP430 microcontroller like code composer studio and Keil micro vision. But if you are using these IDE’s you have to work with register level programming of microcontrollers. But if you want to use many built in libraries for MSP430 peripherals like input output ports, communications modules, timers and PWM, energia is best IDE available for you. The best thing about Energia is that it is exactly similar to Arduino IDE. If you know how to use Arduino IDE, you can learn to program MSP430 microcontroller quickly. So now lets see how to download and install Energia IDE.
Following these step to download and install energia IDE
- To download Energia IDE go to this link http://energia.nu/download/
- Now go to the download options and choose file according to your operating system, energia supports mac, windows and Linux operating system
- I am using windows, so I will download Energia IDE from second link and just click on second link
- After that it will start downloading Energia IDE and it will be compressed file and copy the download folder to location which is easily accessible for you.
- After that unzip the file and you will get all these files inside the folder
- Now click right click on energia IDE icon and create its shortcut on desktop or wherever you want.
- Now double click on energia IDE icon and open it.
- Here you go you have successfully, downloaded and installed energia IDE.
- In tnext video I will show you how to use energia IDE and how to program MSP430 launch pad with energia IDE by using any code.
- If you still have issues you can check this video
How to upload code to MSP430G2 launchPad using Energia IDE
Now , you will learn how to connect MSP430G2 LaunchPad with Energia IDE and how to upload your code to LaunchPad with Energia IDE. First of all you need to install drivers for Launch Pad. To install drivers connect you board with computer USB port using USB cable as shown in video. As soon as you connect Launchpad with your computer, it will automatically start installing drivers. After sometime drivers will be installed successfully. If drivers are not installed automatically, you can download drivers manually and install them.
Now you have successfully installed drivers for Launch pad and we are ready to use Energia IDE to program Launch Pad. Now double click on Energia IDE and open it.
- Now select the serial port to which Lanuch pad is connected
- After that select the board which we are using MSP430G2-MSP430G2553
- Now lets open and example of led blinking and upload this to board
- LaunchPad has on board two LEDs we can use these LEDs to test our code. I will explain it in more detail in next section. For now just understand how to upload code to LauchPad with Energia
- Now open the example of Led blinking and click on compile button to check if code is correct or not
- After that click on upload button and code has been uploaded successfully and you can see LED is blinking with a delay of one second.
- Don’t worry about the code and its working right now. Because we will be learning all these things in later section of this article
- Till now, I have only shown you how to connect the LaunchPad and how to program it using Energia IDE.
- In next section, we will start with basics of how to write code with energia IDE.
- Check this video to know how to upload code to MSP430G2 launchPad using Energia IDE :
Getting started with MSP430G2 launchpad
For this example all we’ll need is the msp430g2 launchpad now. Let’s get started first plug your Launchpad to your computer over USB for our hardware setup. you will want to check on a few things, you can refer to the msp430g2 hardware guide on the Energia website for the most complete details on hardware setup. There are several versions of this board with minor differences. So make sure you’re handling your version correctly. The first thing you want to make sure is the jumpers match the default factory positions. Wrong jumper placement can cause unexpected results for revision 1.5 with this launch pad. You can choose hardware or software you are so please make sure they are oriented appropriately for Hardware you are using.
you also want to make sure the board is receiving power over the USB cable. This is indicated by the green power indicator LED at the top of the launchpad. Now we’re ready to move on to the software make sure you’ve downloaded and installed the drivers. So your computer can communicate with the launchpad over USB. you can find the drivers and instructions for your operating system on the energia website. Msp430g2 hardware guide in some cases drivers are not required next. Let’s open up energia IDE make sure we select our board and com port by going to tools board msp430g2553, 16 megahertz crystal and tools serial port. Note there are several msp430g2 devices supported so if you’re using one different from the MSP4302553 microcontroller, you can select the appropriate one. If you don’t see a serial port option available there is likely a problem with your driver installation go back through the setup instructions to correct the error. Now go ahead and run a blink example to ensure the hardware is functioning properly.
LED blinking using MSP430G2 launchPad
We will import an existing code example by going to file examples basics link. Click the download button and make sure your red LED is blinking if the LED is successfully blinking your hardware is correctly set up and you are ready to move on to your project. Code for LED blinking is shown below:
How to use Push Button with MSP430G2 launchPad
Let’s try out the push button on our launchpad, we will import an existing code example by going to file examples basics digital read serial. This is a good example because it teaches us how to use the onboard push-button and how to use the enter key up in maps to identify pin locations and how to use the serial monitor in energia. The first thing we want to do is change the push-button variable to the correct pin. Code for push button interfacing is shown below:
For a launchpad, we can find this information by going to the pin map of our launchpad. Picture of pin map is shown above. we see that the bottom-left button is called push button 2. we can also call the pin number directly using p1 underscore 3 or analog pin a3 or the energia pin number 5. Note even though the pins have a period separator on the board silkscreen and data sheet in energia. We use underscore for the variables because the period character is reserved for special functions in C. We can see all the pins are labeled in the map and color coded by function use. These pin names in your inner gear code to interact with peripherals attached to the pins.
Explanation of code
- In the setup function, we start our serial communication with serial begin. In this function, we indicated the baud rate that we want our communication to have make sure this baud rate matches the baud rate of your serial monitor otherwise you will not receive the data properly.
- It is important to note that on the msp430g2553 microcontroller, the maximum baud rate supported is 9600
- we also want to use pin mode to set our push-button as input pull up in the loop function. We use digital read to get the state of the push-button and then we print that over serial and that’s it.
- Make sure, we change the pin for the push button press the verify and download button.
- Then open up the serial monitor by clicking the magnifying glass in the upper right corner of energia.
- The data will display that is sent over the USB cable from your MSP430G2 Launchpad to your computer. This is excellent for debugging
- What is happening in your code again make sure your baud rate in the serial monitor matches what is in your sketch so you can properly receive data
- if you still don’t see any data make sure you select the com port for UART. You can verify the COM port in your computer’s device manager
- you will see a stream of data that indicates the state of the push-button.
when we press the button it should change the value between 1 and 0 now. You’re ready to move on to the energia IDE tutorials or begin working on your next project using MSP430G2 launchPad. So it was a step by step guide on making your first small project using MSP430G2 microcontroller. We have learnt how to use Energia IDE to upload code to MSP430G2 launchPad and How to use input output ports of MSP430G2 launchPad. This is all for this getting started tutorial.
How to declare variables in Energia IDE
How to use functions in Energia IDE