MATLAB Examples

Getting Started with MSP-EXP430G2 LaunchPad

This example shows how to use Embedded Coder Support Package to run a Simulink® model on MSP-EXP430G2 LaunchPad using Energia Toolchain.


Supported Hardware:

MSP-EXP430G2 LaunchPad.

Available versions of this example:

MSP-EXP430G2 LaunchPad: MSP430G2553_gettingstarted.

The provided model is pre-configured for MSP-EXP430G2 LaunchPad and can be run on any of the boards listed in the "Supported Hardware" section, by changing the "Hardware board" parameter in the Hardware implementation configuration parameters of the model as described in Task 3 of this example.


Embedded Coder Support Package for MSP-EXP430G2 LaunchPad enables you to create and run Simulink models on for MSP-EXP430G2 LaunchPad. The target includes a library of Simulink blocks for configuring and accessing sensors, actuators and communication interfaces. Library of Simulink blocks uses source and include files provided by Energia IDE.

In this example you will learn how to create and run a simple Simulink model on MSP-EXP430G2 LaunchPad.


If you are new to Simulink, we recommend completing Interactive Simulink Tutorial, reading the Getting Started section of the Simulink documentation and running Simulink Getting Started example.

Required Hardware

To run this example you will need the following hardware:

  • MSP-EXP430G2 LaunchPad
  • USB cable


The following figure shows the example model:


Task 1 - Review MSP-EXP430G2 LAUNCHPAD Block Library supported by Energia

Embedded Coder Support Package for MSP-EXP430G2 LaunchPad provides an easy way to create algorithms that use sensors and actuators by using the blocks that can be added to your Simulink model. The blocks are used to configure the associated sensors and actuators, as well as to read and write data to them.

1. Enter simulink at the MATLAB® prompt. This opens the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Embedded Coder Support Package for Energia Hardware.

3. Double-click the Digital Output block. Review the block mask, which contains a description of the block and parameters for configuring the associated MSP-EXP430G2 LAUNCHPAD digital output pin.

Task 2 - Create a Model for MSP-EXP430G2 LAUNCHPAD Hardware

In this task, you will create a simple Simulink model where blocks are supported by Energia third party library that changes the state of the MSP-EXP430G2 LAUNCHPAD digital output pin.

1. In MATLAB, select HOME > New > Simulink Model.

2. Drag Pulse Generator block from the Simulink Sources library to your model.

3. Double-click the Pulse Generator block. Set the Pulse type to parameter to Sample based and set the Sample time parameter to 0.1 seconds.

4. Drag the Digital Output block to the model. Use the default block settings.

5. Connect the Pulse Generator block to the Digital Output block.

Note:- Maximum baserate allowed in Simulink for this Launchpad is 0.05 second. You can drag the another Digital Output block from library in the same Simulink model, and set the sample time greater than 0.05 second. Essentially, baserate is used to schedule sample time of other blocks in integer multiple of baserate.

Task 3 - Configure and Run the Model on MSP-EXP430G2 LAUNCHPAD Hardware

In this task, you will configure and run your model on the MSP-EXP430G2 LaunchPad.

1. Connect the MSP-EXP430G2 LaunchPad to your computer with a USB cable.

2. Open the Configuration Parameters in the model. Click the Code Generation and select ert.tlc as the System target file under Target selection. Set the Hardware implementation->Hardware board parameter to MSP-EXP430G2 LaunchPad that is connected to your computer. Observe that Energia MSP430 is selected as a Toolchain in Code Generation pane. Do not make any other settings.

3. Click Apply and OK.

4. In your Simulink model, click the Deploy to Hardware button on the toolbar. The model will now be deployed to the connected MSP-EXP430G2 LAUNCHPAD hardware.

5. Look at the on board LED attached to digital pin 14. The LED blinks once for every second.

6. You can change the pin number as 2 for Red LED.

7. Save your model.

A pre-configured model "MSP430G2553_gettingstarted" is included for your convenience.

Other Things to Try

Experiment with other blocks in the MSP-EXP430G2 LAUNCHPAD block library. For example:

* Create and run a model that turns the LED on if a signal is applied to a digital input pin.

* Create and run a model that repeatedly brightens and dims an LED. Hint: use the PWM block.


This example introduced the workflow for creating an algorithm from a Simulink model and then running it on the MSP-EXP430G2 LaunchPad. In this example you learned that:

* Embedded Coder Support Package for MSP-EXP430G2 LaunchPad provides blocks for configuring, reading from and writing to sensors and actuators.

* You can use the Deploy to Hardware button to configure and run the model on MSP-EXP430G2 LaunchPad.