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 buttonsand 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 statementsvoid main(void) {
WDCTL = WDTPW | WDTHOLD; // Stop watchdog timer
initButtons(); // Configure board hardwareinitLeds();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!
1
1
2
2
3
3
4
4
D D
C C
B B
A A
Title
Number RevisionSize
A
Date: 1/26/2016 Sheet ofFile: R:\ece_mdrive\..\mep430_exp_main.SchDocDrawn By:
1 23 45 67 89 1011 1213 1415 1617 1819 20
P1
Launchpad Header (Left)
1 23 45 67 89 1011 1213 1415 1617 1819 20
P2
Launchpad Header (Right)
+3.3V +5V
P6.5/A5P3.4P3.3P1.6P6.6P3.2P2.7P4.2/UCB1SCLP4.1/UCB1SDA
P6.0/A0P6.1/A1P6.2/A2P6.3/A3P6.4/A4P7.0/A12P3.6P3.5
GND
P2.5P2.4P1.5P1.4P1.3P1.2P4.3P4.0P3.7P8.2
P2.0P2.2P7.4RSTP3.0/UCB0SIMOP3.1/UCB0SOMIP2.6P2.3P8.1
GND
LS1
Buzzer
P8
Jumper
D1
Red LED
S1
GND
S2
S3
S4
P7.0/A12
P3.6
P2.2
P7.4
GND
P3.5
50
R1
Res1P6.2/A2
P9
Jumper
D2
Green LED50
R2
Res1P6.1/A1
P10
Jumper
D3
Blue LED50
R3
Res1P6.3/A3
D4
Yellow LED50
R4
Res1
P6.4/A4 123
P11
Jumper
GND
Xout
1234567
P6
Keypad
P2.5P2.4P1.5P1.4P1.3P1.2P4.3
10K
RPotPotentiometer
+3.3V
GND
P6.0/A0
MSP430F5529 Launchpad Headers
MSP430 Expansion Board
Main - Buttons a LEDs HW Rev 2.0Schematic Rev A
1 2N. DeMarinis
PID101 PID102
COD1
PID201 PID202
COD2
PID301 PID302
COD3
PID401 PID402
COD4
PILS101PILS101A
PILS102PILS102A
COLS1
PIP101 PIP102PIP103 PIP104PIP105 PIP106
PIP107 PIP108PIP109 PIP1010PIP1011 PIP1012
PIP1013 PIP1014PIP1015 PIP1016PIP1017 PIP1018
PIP1019 PIP1020
COP1PIP201 PIP202PIP203 PIP204PIP205 PIP206
PIP207 PIP208PIP209 PIP2010PIP2011 PIP2012
PIP2013 PIP2014PIP2015 PIP2016PIP2017 PIP2018
PIP2019 PIP2020
COP2
PIP601
PIP602
PIP603PIP604
PIP605
PIP606PIP607
COP6
PIP801 PIP802
COP8
PIP901 PIP902
COP9
PIP1001 PIP1002
COP10
PIP1101PIP1102PIP1103
COP11
PIR101 PIR102COR1
PIR201 PIR202COR2
PIR301 PIR302COR3
PIR401 PIR402COR4
PIRPot01
PIRPot02PIRPot03
CORPot
PIS101 PIS102
COS1
PIS201 PIS202
COS2
PIS301 PIS302
COS3
PIS401 PIS402
COS4
PIP101
PIRPot02
PIP102
PID102
PID202
PID302
PID402
PILS102PILS102A
PIP104PIP202
PIRPot01
PIS102
PIS202
PIS302
PIS402
PID101PIR102
PID201PIR202
PID301PIR302
PID401PIR402
PIP802 PIR101
PIP902 PIR201
PIP1002 PIR301
PIP1102
PIR401
PIP1103POXout
PIP2011
PIP606NLP102
PIP209
PIP605NLP103
PIP207
PIP604NLP104
PIP205
PIP603NLP105
PIP109NLP106
PIP204NLP200
PIP206
PIS301NLP202
PIP2018NLP203
PIP203
PIP602NLP204
PIP201
PIP601NLP205
PIP2016 NLP206PIP1015NLP207PIP2012
NLP3000UCB0SIMOPIP2014 NLP3010UCB0SOMIPIP1013NLP302
PIP107NLP303 PIP105NLP304
PILS101PILS101A
PIP1020
NLP305
PIP1018
PIS201NLP306
PIP2017NLP307 PIP2015NLP400
PIP1019NLP4010UCB1SDAPIP1017NLP4020UCB1SCL
PIP2013
PIP607NLP403
PIP106
PIRPot03
NLP6000A0PIP108
PIP901
NLP6010A1PIP1010
PIP801
NLP6020A2PIP1012
PIP1001
NLP6030A3PIP1014
PIP1101
NLP6040A4
PIP103NLP6050A5
PIP1011NLP606
PIP1016
PIS101NLP7000A12
PIP208
PIS401NLP704
PIP2020NLP801
PIP2019NLP802
PIP2010 NLRST
POXOUT
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 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.cto 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 itMSP430 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 SnapchatIf 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.