Getting Started with Code Composer Studio and MSP430 Launchpad

Getting Started with Code Composer Studio and MSP430 Launchpad

Tutorial

MSP-EXP430G2

The following applies to the MSP-EXP430G2 ONLY. The MSP-EXP430G2 comes per-programmed with a ‘Blink’-LED program. To verify that your board is working correctly, connect it via the Mini-USB cable into a USB port. The two on-board LEDs should alternate blinking red and green.

Installation

  1. Download the most recent version of Code Composer Studio here. (Note: Registration at ti.com will be required for you to download the file.
  2. Run the installation file. Make sure you right-click and select “run as administrator”.
  3. On the “Setup Type” select “Custom” and press “Next”
  4. In the “Processor Support”-tab make sure to select the “MSP430 Ultra Low Power MCUs” and any other processors from TI that you might want to program. Additional processor support requires more disk space and longer download times.
  5. Under “Select Components” tab, check all as follows:
  6. Under “Select Emulators” select “JTAG Emulator Support” and continue clicking next until installation is complete (May take a while).

Code Composer Launch

  1. Run Code Composer
  2. If you are launching it for the first time, you will be asked to Select a workspace. Pick a folder and select Use this as my default and do not ask again to not see this dialogue again. Then select OK.
  3. Under Licensing Options I selected CODE SIZE LIMITED (MSP430) to select a free license that limits the maximum size of files to 16KB
  4. Close the Welcome screen by selecting the X near the ”’TI Resource Explorer”-tab and you will then see a blank slate as follows:

Creating a Flash LED program

  1. To get started, select File->New..->CCS Project
  2. You will get the following dialogue window:
    Give your desired project name (in this case “flashLED”). To select the device information, you will have to look at your MSP430 development board and read the information off the chip:

    You will have to first select the proper family (MSP430), then the Variant (in my case MSP430Gxxx Family) and then the actual chip designation (in my case MSP430G2553).
  3. Press Finish and a default blank code will be created.
  4. Type your code into main.c as follows:
  5. After you are done typing press the debug button to check your code.
  6. If the ULP Advisor comes up, just click Proceed.
  7. You will then see the following window:

    Here you see the Variable Browser, the Debug Controls, your code (main.c) and the Console Window. You will now get the option of going through your code step by step.
  8. The following buttons in the Debug portion give you control over your code execution. From left to right they are:
    1. Resume (F8) run code in real time
    2. Suspend (Alt+F8) Pause code that is running in real time
    3. Terminate (Ctrl + F2) stop code execution
    4. Step Into (F5) step into the function to see code
    5. Step Over (F6) run line of code and move to the next
  9. If you press Resume, your code will run in real time.

There you have it. A blinking LED light using a MSP-430G2 and Code Composer Studio. I would like give a shoutout to Embedded Labs for an MSP tutorial for an older version of CCS.

MMA8451 Accelerometer on the Arduino UNO

MMA8451 Accelerometer on the Arduino UNO

Tutorial

The following procedure will show you how to set up your Arduino UNO with the MMA8451 Accelerometer.

=======

Where to Get Parts

The parts in this tutorial can be acquired:






Advertisement


Hardware

I will be using the Triple-axis 14-bit MMA8451 Accelerometer – from Adafruit.

Breakout-Board Assembly

Assemble the board, by soldering the connector pins:

Circuit

Connect the Arduino and the accelerometer breakout board according to the following diagram:

The accelerometer is powered by the 5 volt line. The A pin is not connected in this tutorial, but can be used to change the I2C address to 0x1D if connected to 3.3 Volt. The SDA and the SCA pins are connected to the analog A4 and A5 pins, respectively.

Software

Arduino Software Installation

  1. Download and install the latest Arduino Development Environment version for your operating system from here.

Accelerometer Library Installation

Adafruit supplies all the necessary libraries for their board. You will have to install the MMA8451 specific library and the Adafruit Sensor library. You can find the location of your Arduino libraries-folder by clicking File->Preferences and then checking the Sketchbook Location.

  1. Download the Adafruit Sensor library from github.
    1. Extract the zip file into your Arduino libraries folder (most likely for windows: <current user>\Documents\Arduino\libraries)
    2. Rename the folder to Adafruit_Sensor
  2. Download the Adafruit MMA8451 library from github.
    1. Extract the zip file into your Arduino libraries folder (most likely for windows: <current user>\Documents\Arduino\libraries\)
    2. Rename the folder to Adafruit_MMA8451_Library
  3. Restart the Arduino software to make sure that the libraries have been loaded. You can check if the libraries are properly installed, by checking the entries in Sketch->Import Library..->.

Sketch Creation

  1. The following example is included with your library and prints the raw accelerometers readings and the readings converted to m/s^2 in the x,y,an z direction.
  2. Load the sketch by clicking File->Examples->Adafruit_MMA8451_Library->MMA8451demo

Uploading Sketch

First select the appropriate board (here Arduino UNO) and the appropriate COM port.
Click upload and the sketch should compile without problems.
The Serial Monitor output can be accessed by pressing [Ctrl]+[Shift]+[M] and should show something like this:

The line readings are:

  • The first line shows the “Range” mode that the accelerometer readings are in +/-2g, +/-4g, or +/-8g.
  • The second line shows the raw readings in the x ,y ,and z direction.
  • The third line shows the readings converted into units of m/s^2.
  • The fourth line describes the orientation of the board.

Conclusion

In this tutorial you were shown how to interface the MMA8451 Accelerometer with the Arduino UNO board. The example shows you how to communicate with the sensor and how to read the acceleration values from the accelerometer.






Advertisement


Internal Pullup Resistors on the Arduino for Digital and Analog Pins

Internal Pullup Resistors on the Arduino for Digital and Analog Pins

The following tutorial will show you how to set up your Arduino to use the internal pull-up resistors with the AnalogRead() function.


Advertisement




Pull-up/pull-down resistors give the pins a reference. If this reference is not provided, then your readings will vary wildly, which is referred to as a floating pin. It is preferable to use external pull-up and pull-down resistors, but you can use the internal pull-up resistors which is simpler.
Note: the Arduino does not have internal pull-down resistors. They will have to be external.

  • A pull-up resistor is connected to the high voltage level, giving for example 5V as reference, which means that the signal coming from a sensor will be inverted.
  • A pull-down resistor is connected to the low voltage level, giving for example GROUND as reference, which means that the signal coming from a sensor will be non-inverted.

Digital Pins Internal Pull-Up Resistor

If you want to use internal pull-up or pull-down resistors on digital pins, you can simply use the following commands:

  • pinMode(2, INPUT_PULLUP);

Analog Pins Internal Pull-Up Resistor

The Arduino also has pull-up resistors, but it was somewhat difficult to find information about that so I made this quick tutorial.

No pull-up resistors, Floating values:

Consider the following code, used with an Arduino, which has nothing connected to analog pin A0:

 
void setup() {                
  Serial.begin(9600);  
}

void loop() {
  int k = analogRead(A0);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  Serial.println(k);
}

The output printed to the serial monitor, will vary at random, because no reference is provided:

Internal Pull-up resistor, Consistent values:

Consider the following code, used with an Arduino, which has nothing connected to analog pin A0:

 
void setup() {
  pinMode(A0, INPUT);
  digitalWrite(A0,HIGH);                
  Serial.begin(9600);  
}

void loop() {
  int k = analogRead(A0);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  Serial.println(k);
}

The output printed to the serial monitor reads roughly 1024 (with the values somewhat lower due to the influence of the resistor). 1024 corresponds to the 5V of the Arduino logic.

Conclusion

In this tutorial you were shown how to access the internal pullup resistors of the Arduino development boards for the digital and analog pins.


Advertisement