Welcome to Lab!
• Feel free to get started until we start talking!
• The lab document is located on the course website: http://users.wpi.edu/~ndemarinis/ece2049/
• You do not need to keep the same partner from last lab
• We will come around checking your prelabs after we introduce the lab
• Let us know if you have any questions!
Lab 2: MSP430 Hero!
The Introduction
Week I: A New Lab
MSP430 Hero!
Basic requirements:
• Play a song on the buzzer and flash the blue LEDs accordingly
• Press buttons at the right times to score points
• This is a two week lab. You will have this lab session and next week’s to work!
• Feel free to add more features than are in the lab document—we may award extra credit!– Show the song on the display (like actual Guitar Hero)
– Multiple songs
– Other ideas?
The Important Parts
• Functions for reading the switches and using the
LEDs
• A data structure to store the song
– Like with Simon, you can decide how to handle this
– Must store a pitch and a duration for each note
• A timer which controls how fast the song plays
– We’ll talk about this in the next few lectures
How to start a new lab
• You should start each lab with a fresh copy of
the template project (Instructions follow)
• If you started with a blank workspace, import the
template again using the menus:
– Project Menu > Importing Existing CCS Project
– Select “Archive File” and then select the template
project
Starting a new project
• 1. Copy your project
1. Right-click on the project(Opens the “Project Menu”)
2. Select “Copy”
Starting a new project (cont’d.)
• 2. Paste! 1. Open the Project Menu again
2. Select “Paste”
3. Enter a new project name
4. Click OK.This will create a
new project called lab 1 for you to use!
Clearing out the demo project
// Don’t remove any #include statements
void main(void) {
WDCTL = WDTPW | WDTHOLD; // Stop watchdog timer
initButtons(); // Configure board hardware
initLeds();
configDisplay();
configKeypad();
// Your setup code goes here!
// (Initialize variables, configure things, etc.)
while(1) {
// Your code goes here!
}
}
You can clear out all of the code from lab 0, except the following code that sets up our boards:
Note: This is the bare minimum. You should refer back to Lab 0 for examples of how to use the display and the buttons.
(Read the comments!)
How to start: Week 1
0. Like last week, start by making copy of the
template project (see instructions in the lab 1
intro)
1. We recommend you start with the small stuff,
like the functions for the LEDs and buttons
– It’s easier to build and debug these functions now
instead of when you’re building the main program!
– Build and test these functions today
• You can do this by writing a simple main() (no welcome
screen, countdown, etc.) that just uses your functions
Example test for LEDs and Buttons
Here’s an example of a way to test your button and
LED functions
• Write a simple main() that does the following:
– When S1 is pressed, turn on the Red User LED
– When S2 is pressed, turn on the Green User LED
– When both S1 and S2 are pressed, turn on both the
on the Red and Green User LEDs
– Otherwise, the LEDs should be off
As you work on this, see here and here for important information on using the buttons
and LEDs!
How to start (cont’d)
2. After you have your LED and button functions
working, try to play some notes using the
buzzer
– See here for more info
3. Since we haven’t covered interrupts yet, try to
create a song using your data structure and play it
in main() with delays between the notes
– If you have trouble with the C syntax for working with the
song structure (using arrays, structs, etc.) see here, or
Google for examples of “initializing” structs or arrays in C
Remember your training…
• Looking back on your last
lab, can you do anything
differently to make your life
easier?
– Simplifying your control flow?
– Not using so many globals?
– Using the debugger? This kitty has developed strong
systems programming skills.
Remember that we are here to help you become better embedded programmers. Feel free to ask us conceptual
questions and we will be happy to teach you! (Please do this before the last day, though!)
Good luck and have fun!
• The rest of these slides contain important info about specific parts of the lab – Skim them over at the beginning of lab
– Look at them when you reach each part or if you have trouble
• Be sure to look at the Frequently Asked Questions, too! – These include helpful tips on C programming and using
CCS efficiently!
Thank you for listening!
Important Stuff: LEDs
• Are LEDs inputs or outputs?
• You are working with the LEDs on the
Launchpad board—this is the small board that
contains the MSP430
• The Launchpad User’s Guide shows the I/O pin
assignments for the User LEDs and buttons
• If you are curious about how configUserLED()
from the prelab should work, ask us!
>>
>>
<<
<<
>>
<<
<<
>>
PWR
GND
GND
GND
470R
470R
GNDGND
LED1_PWR+5V
+3V3
PWR
GND
+5
V
+3
V3
+3
V3
+3
V3
+5V
+5
V
100n100n
100n100n
GNDGND
RTS
CTS
SBW_TST
SBW_RST
TXD
RXD
SBW_NC
GNDGNDGND
40 pin BoosterPack Headers
Connections
1.5
User LEDsUser Buttons
ezFET <<---->> LaunchPad
123
J10
J11 23 45 67 89 10
11 1213 1415 1617 1819 20
J51 23 45 67 89 10
11 1213 1415 1617 1819 20
1 2
S2
1 2
S1
LED1
R29
LED2
R30
1 2
JP8
1 2
JP1
1 2
JP2
123
J3
C20C21
C28C31
1 2
JP6.4
1 2
JP6.3STAND1
STAND2
STAND3
STAND4
1 2
JP4.1
1 2
JP4.2
1 2
JP6.1
1 2
JP6.2
1 2
JP4.3
1 2
JP3
P1.4P1.3
P3.2P1.2
P1.5
P1.7
TEST/SBWTCK
RST/SBWTDIO
RST/SBWTDIO
P1.0P1.1
P6.2
P6.4P6.3
P6.1
P2.0P3.4P3.3
P6.0
P2.1
P2.2P6.5 GND
GND
P3.0P3.1
P4.2
P4.7
EZFET_UARTRTS
EZFET_VBUS
EZFET_VCC
EZFET_UARTCTS
EZFET_UARTRXD
EZFET_UARTTXD
EZFET_SBW_RST
EZFET_SBW_TST
P4.5/UCA1RXD
P6.7
P4.4/UCA1TXD
EZFET_SBW_NC
P6.6
P2.7
P4.1
P2.5P2.4
P1.6
P3.7
P7.4
P2.6P2.3
P7.0 P4.0P4.3
P8.1P3.6P3.5 P8.2
A
B
C
D
1 2 3 4
A
B
C
D
1 2 3 4
www.ti.com Schematics
Figure 41. Schematics (2 of 4)
57SLAU533B–September 2013–Revised June 2014 MSP-EXP430F5529LP LaunchPad™ Development Kit User's GuideSubmit Documentation Feedback
Copyright © 2013–2014, Texas Instruments Incorporated
Important stuff: Buttons
Important questions:
• Are buttons inputs or outputs?
• Do you need pull up/pull down resistors? – Hint: Yes. Which one?
Figure it out using the board schematic!
• Once you can answer these questions, to configure the registers see Table 12-1 on page 408 of the MSP430 User’s Guide
This is the schematic representation of the buttons
What logic level (what voltage) is at P2.1 when S1 is pressed? When it is not pressed?
How does this change if a pull-up resistor is added at P2.1? What about a pull-down?
MSP430I/O Pins
Important Stuff: The Buzzer
• You can modify BuzzerOn() in peripherals.c
to take an argument that represents the
frequency of the note to play
– Don’t forget to also modify the function prototype in
peripherals.h!
• How can you modify it to play a specific frequency?
– Take a look at the comments in BuzzerOn()
– You’ll need a bit of math—try it on paper first!
Important Stuff: The Documentation
• Everything you need is on the Docs page of the
course website
• The tricky part is figuring out which one you need…
Document What’s in it
MSP430 F55xx User’s Guide
• Contains hardware information for MSP430s similar to ours• How peripherals work conceptually• Diagrams and explanations of all registers
MSP430F5529Launchpad User’s
Guide&
Lab Development Board Schematic
• Contains all documentation regarding the board we use in lab, not the MSP430 chip itself
• Includes schematics of our board• Describes all peripherals connected to our MSP430
(buttons, LEDs, display, etc.)
MSP430F5529 Datasheet
• Specific info about our MSP430 chip (package and pin diagrams, electrical specs, etc.)
• Includes memory map for all peripherals
An Introduction
Lab 2: MSP430 Hero!
Week II: The Lab Strikes Back
How to start
• Work on the LED, button, and buzzer functions
from Week 1 if you haven’t already
• Now that you have seen timers in lecture, focus
on configuring your timer today
• After that, work on the logic to play the song
using interrupts and keep score
Make sure your interrupts work before you
leave today! Ask us if you need help!
Starting with interrupts
• Look at the stopwatch
example for help with syntax
– Don’t just copy it
• Make sure you globally
enable interrupts!
– See the lecture notes for
instructions.
• How do you know if your
interrupts work?
Using the debugger, of
course!
1. Put a breakpoint inside your interrupt routine and hit “Run”
2. If you hit the breakpoint, you know that your timer
successfully triggered an interrupt!
A note on interrupts
• As we said in lecture, interrupt routines (ISRs) should be short.– Why?
• For this reason, do NOT do the following in an ISR:– Update the display
– Do float math or call big functions
– Wait in a loop until something happens
– Send a Snapchat
If you can’t think of a way to design your lab without keeping your ISR short, ask us for help!
If you use an ISR improperly, you will lose points!
This kitty will be sad if your ISRs are too long.
Playing the game
• The key point here is figuring out how to use the
timer interrupts to control the song
– This allows you to scan for button presses while the
song is playing
– How does the timer let you play notes for precise
durations?
• After that, how can you determine if the player
pressed the correct button?
Good luck and have fun!
• Feel free to ask us if you have questions—we’re
here to help!
• Be sure to look at the FAQs
• When you are done, make sure you submit your
code online like for lab 1
– See the Lab 1 intro for instructions
Thank you for listening!
Frequently Asked Questions (1/?)
• “My buttons don’t work!”
– Did you configure the buttons to use pull-up resistors?
– Look at table 12-1 on page 408 of the MSP430 User’s
Guide for the register configuration!
• “My interrupts aren’t firing!”
– Did you globally enable interrupts? See the lecture
notes for help!
– Check your timer config and ISR. Make sure you are
using the same components and syntax as the
stopwatch example.
FAQ: Initializing arrays and structs
“How do I set the value of (or ‘initialize’) an array or struct?”
Here are some examples:
Frequently Asked Questions
“My program isn’t working, and when I pause it says “Cannot disassemble address 0xfffe (or similar)”
– This is because your program has jumped to a place in memory that does not contain actual code.
– This is equivalent to a segfault—meaning you are accessing memory you shouldn’t.
• On an MSP430, there’s no OS to clean up after a segfault. Instead, your program will experience Undefined Behavior™
• To fix this, check the following:• Did you configure the display at the start of your program?
• Are you accessing beyond the bounds of an array?
• Are you doing any Bad Things with pointers?
– If you are having trouble, ask the us for help!
Frequently Asked Questions
• “Help! I lost a window in CCS!”
– Reset all of your windows to defaults, go to :
View > Reset Perspective
• I have the warning “Function declared implicitly”
– Make sure you aren’t missing any #include
statements (rand() is in stdlib.h)
– If the warning is for one of your own functions, you
are missing a function prototype. Google “function
prototypes” for help!
Frequently Asked Questions
• I have a vague error saying “Errors exist in
project” or “Errors encountered during linking”
– Look in the Console for the full output during
compilation. If you scroll up a few lines, you may see
some more information about the error.
• See the next slide for more info…
Frequently Asked Questions
• “Why does this variable have a value of ‘.’?”
– This is because CCS is trying to show it as an ASCII
character, but it has a value that isn’t a character. You
can change the format like this:
Right click on the variable here
Pick a format to display it here
Frequently Asked Questions
• Using the graphics library– See lab 0 for examples—especially the comments
– You can draw lines and shapes
– See the “Graphics Library User Guide” on the course website for examples
• You can also draw bitmaps (pixel art)– Some examples are on the local machine at:
C:\ti\ccsv5\ccs_base\msp430\msp430ware_1_40_00_26\examples\grlib\MSP-EXP430F5529_Grlib_Example\images
– We use a black and which screen, so all images should use 1bit/pixel resolution
– This is an advanced topic. If you want to do it, you’re on your own.