Texas Instruments MSP430 Student Manual
Hide thumbs Also See for MSP430:
Table of Contents

Advertisement

MSP430 Workshop
STUDENT GUIDE
MSP430 Workshop
Revision 3.02a
January 2014

Advertisement

Table of Contents
loading

Summary of Contents for Texas Instruments MSP430

  • Page 1 MSP430 Workshop STUDENT GUIDE MSP430 Workshop Revision 3.02a January 2014...
  • Page 2 Important Notice Important Notice Texas Instruments and its subsidiaries (TI) reserve the right to make changes to their products or to discontinue any product or service without notice, and advise customers to obtain the latest version of relevant information to verify, before placing orders, that information being relied on is current and complete.
  • Page 3 MSP430ware™. Whether you are a fan of the MSP430 for its low-power DNA, appreciate its simple RISC-like approach to processing, or are just trying to keep your system’s cost to a minimum … we hope you’ll enjoy working through this material as you learn how to use this nifty little MCU.
  • Page 4: Table Of Contents

    Communications (Serial ports, USB, Radio) ............... 1-26 Hardware Accelerators ......................1-27 Summary ..........................1-28 ULP ............................1-29 Profile Your Activities ......................1-30 Launchpad’s ..........................1-34 Lab 1 – Out-of-Box User Experience Lab ................1-35 1 - 2 MSP430 Workshop - Introduction to MSP430...
  • Page 5: Administrative Topics

    Administrative Topics Administrative Topics A few important details, if you’re taking the class live. If not, we hope you already know where your own bathroom is located. MSP430 Workshop - Introduction to MSP430 1 - 3...
  • Page 6: Workshop Agenda

    “Clocks” This chapter starts at reset – in fact, all three resets found on the MSP430. We then progress to examining the rich and robust clocking options provided in the MSP430. This is followed by the power management features found on many of the ‘430 devices. The chapter finishes up by reviewing the other required system initialization tasks …...
  • Page 7 This chapter focuses on Timer_A – the primary timer module found in the MSP430. Chapter 7: –...
  • Page 8: Ti Products

    … so much more – you’ll find them at TI. Before taking a closer look at embedded processors, we’ll glance at one of the hottest growing product categories … TI’s extensive portfolio of wireless connectivity. 1 - 6 MSP430 Workshop - Introduction to MSP430...
  • Page 9: Wireless Products

    Drop a CC3000 module into your design and you’ve enabled it to join the Internet of Things revolution. Check out TI’s inexpensive, low-power and innovative wireless lineup! MSP430 Workshop - Introduction to MSP430 1 - 7...
  • Page 10: Ti's Embedded Processors

    TI's Embedded Processors TI's Embedded Processors Whether you are looking for the MSP430, which is the lowest power microcontroller (MCU) in the world today … or the some of the highest performance single-chip microprocessors (MPU) ever designed (check out Multicore) … or something in between … TI has your needs covered.
  • Page 11 Driving to the lowest-power dissipation is one of those areas. In the end, the venerable MSP430 is not to be outdone on the low end. As the MSP430 teams says, Ultra Low-Power (ULP) is “in our DNA”. You know you’re doing something right when the 10-year shelf-life of the battery ends up self-dissipating before you run it dry with your MSP430 design.
  • Page 12: Msp430 Family

    MSP430 Family MSP430 Family As stated, low-power is ‘in our DNA’. That said, it’s not all the MSP430 is known for. One vector of new products has continued to integrate a wide range of low-power peripherals into the MSP430 platform. Look for the products in the MSP430 F5xx, F6xx and FR5xxx families.
  • Page 13 – giving you a new choice versus those old 8-bit micros. And finally, the new MSP430 Wolverine series of devices is once again setting new standards for low-power processing. Sure, we’re only topping our own products, but who else is better suited to enable your lowest power processing needs? Utilizing the FRAM memory technology, the FR5xxx Wolverine devices combine the lowest power dissipation with a rich integration of peripherals.
  • Page 14 F5xx series of devices and is found on the new ‘F5529 USB Launchpad. This is one of TI’s line-up of MSP430 devices featuring highly integrated set of peripherals. We will be exploring quite a bit more about this device as we progress through the workshop.
  • Page 15: Msp430 Cpu

    64K of memory – and that really isn’t acceptable in many of today’s applications. As early as the second generation of MSP430 devices, the CPU was expanded to provide full 20- bits of addressing space – which provides 1M of address reach. The new CPU cores that support these enhancements were called CPUX (for eXtended addressing).
  • Page 16 MSP430 CPU There are many touches to the MSP430 CPU which make it idea for low-power and microcontroller applications, such as the ability to manage bytes, as well as 16-bit words. Note: If you see a ‘gray’ slide like the one above and below were placed into the workbook, but has been hidden in the slide set, so the instructor may not present it during class.
  • Page 17 ‘atomic’ addressing are critical for real-world embedded processing. The little bit of genius that is the Constant Generator minimizes code size and runtime cycle count. These ideas save you money while helping to reduce power dissipation. MSP430 Workshop - Introduction to MSP430 1 - 15...
  • Page 18 MSP430 CPU A low number of instructions are at the heart of Reduced Instruction Set Computers (RISC). RISC lowers complexity, cost and power … while, surprisingly, maintaining performance. 1 - 16 MSP430 Workshop - Introduction to MSP430...
  • Page 19: Msp430 Memory

    Like most MCU’s nowadays, the processor is dominated by non-volatile memory. In this case, Flash technology provides us with the means to store information into the device – which retains its contents, even when power is removed. (As we’ll see next, some of the latest MSP430 devices use FRAM technology rather than Flash.)
  • Page 20: Ram

    Main flash. Please be aware that the BSL is handled differently amongst the various generations of MSP430. In some cases, as with the ‘F5529, it is stored in its own region of flash memory. On other devices, it may be hard-coded into the device.
  • Page 21: Fram

    MSP430 Memory FRAM Some of the latest MSP430 devices from TI now use FRAM in place of Flash for their non-volatile memory storage. For example, you will find the Wolverine (FR58xx, FR59xx) devices utilize this new technology. Actually, FRAM is not a brand new technology. It has been available in stand-alone memory chips for nearly a decade.
  • Page 22 The other two caveats to FRAM are that reads are a bit slower than Flash and their density is not as great as we can build using flash technology. On the other hand, the benefits are an outstanding fit for many MSP430 types of applications. 1 - 20...
  • Page 23 RAM. The flexibility of FRAM allows your programs to use the non-volatile storage for things like variables and buffers. This flexibility often ends up lowering your overall system costs. MSP430 Workshop - Introduction to MSP430 1 - 21...
  • Page 24: Msp430 Peripherals

    Like most current day microcontrollers, the pins on our devices are heavily multiplexed. That is, you often have one of several choices of signals that can be output to a given pin. The MSP430 makes each signal independently programmable, which affords maximum flexibility.
  • Page 25: Timers

    MSP430 Peripherals Timers As stated earlier, timers are often thought of as the heartbeat of an embedded system. The MSP430 contains a number of different timers that can assist you with different system needs. Timer _A (covered in detail in Chapter 6) is the original timer found across all MSP430 generations.
  • Page 26: Clocking And Power Management

    Power is one of those features that every system needs but doesn't often get highlighted. All of the MSP430 devices provide some level of Power Management. On the most cost-sensitive, it might only be a Brown-Out Reset (BOR) peripheral - which makes sure there is enough power going to the device to assure proper, stable operation.
  • Page 27: Analog

    The 'F5529 also contains a sophisticated power supervisor to warn (i.e. interrupt) your system when the power is getting close to out-of-spec. Power gating is another feature found on most of the MSP430 devices. The basic idea is that we want to power-down anything that is not needed.
  • Page 28: Communications (Serial Ports, Usb, Radio)

    The additional of radios to some MSP430 devices makes them quite unique in the industry. Beyond that, TI has created wireless chips and modules that can be used from any MSP430 device. It's really telling when the cheapest Value Line MSP430 device can actually talk Wi-Fi using TI's CC3000 module.
  • Page 29: Hardware Accelerators

    DMA might save you time and power. It also should be utilized in your peripheral driver software whenever and wherever it's available. MSP430 Workshop - Introduction to MSP430 1 - 27...
  • Page 30 Many of the peripherals we've just outlined are covered - in detail - within their own chapters. Over time, we'll be adding more chapters to the course to cover additional peripherals. 1 - 28 MSP430 Workshop - Introduction to MSP430...
  • Page 31: Ulp

    "Why consume power if you don't have to?" In fact, the MSP430 has found many new applications in the last couple of years where end-users are demanding the reduction of 'phantom load', also known as 'vampire power'. This can be defined as the dissipation of power when electronic products are in standby mode (or even when switched off completely).
  • Page 32: Profile Your Activities

    RTC. Then, as needed, the system wakes up, performs one or more tasks, then goes back into low-power mode. 1 - 30 MSP430 Workshop - Introduction to MSP430...
  • Page 33 The MSP430 supports this sleep/wake/sleep profile quite well, by providing a variety of low-power modes (LPM). The following chart is an example of the LPM's found on various MSP430 devices, showing which resources are powered down by LP mode. It also broadly indicates what it takes to wake up from a given LPM.
  • Page 34 Please, keep in mind that you should always design your system by referencing the datasheet, but this slide does give us a good comparison between the various MSP430 generations. Much of designing for low-power is common sense; e.g. turn it off when you're not using it. The following slide provides a good set of guidelines (or principles) to use when developing our application.
  • Page 35 Many of these guidelines have been distilled into a static code analysis tool that is part of the TI (and IAR) compiler. This tool can help us learn what techniques to apply - or for the more experienced, help us not overlook something we already know. MSP430 Workshop - Introduction to MSP430 1 - 33...
  • Page 36: Launchpad's

    As the diagram shows, the board is really divided into two halves. The top portion (above the ------ - line) is an open-source emulator (called eZ-FET lite). This connects our 'target' MSP430 to a PC running a debugging tool, such as Code Composer Studio. You can isolate the emulator from the 'target' processor by pulling the appropriate jumpers (that straddle the dashed line).
  • Page 37 HID (Human Interface device): an emulated keyboard • MSC (Mass Storage class): an emulated hard drive with FAT volume The contents of the hard drive can be viewed with a file browser such as Windows Explorer. MSP430 Workshop - Introduction to the MSP430 1 - 35...
  • Page 38 Button2.txt – the contents of this file are "typed out" to the PC, using the emulated keyboard when you press button S2 − MSP430 USB LaunchPad.url – when you double-click, your browser launches the MSP- EXP430F5529LP home page − README.txt – a text file that describes this example 5.
  • Page 39 Even if you have some experience with CCS, we hope that you will find exercise to be a good review – and in fact, that you might even learn a few new things about CCS that you didn’t already know. Learning Objectives MSP430 Workshop - Programming C with CCS 2 - 1...
  • Page 40 Optimize Options (aka Release Options) ..............2-21 Build Configurations ....................2-22 Data Types .......................... 2-23 Device Specific Files (.h and .cmd) ..................2-24 MSP430 Compiler Intrinsic Functions ................. 2-26 Lab 2 – CCSv5 Projects ......................2-27 2 - 2 MSP430 Workshop - Programming C with CCS...
  • Page 41: Programming C With Ccs

    We’ll take a brief look at all three parts of the Ecosystem: • Run-Time Software • Development Tools • Support and Community MSP430 Workshop - Programming C with CCS 2 - 3...
  • Page 42: Run-Time Software

    Low-level C Header Files Working our way up from the bottom, the MSP430 family provides a custom C language header file (and linker command file) for each device. These header files provide symbols that define all the various registers, pointers and bitfields found on ‘your’...
  • Page 43: Energia

    Arduino community and put it to good use on TI’s MSP430 Launchpads. In other words, it puts the word “rapid” in rapid-prototyping. In fact, Energia isn’t just for prototyping anymore. There are many customers using this in small to midsize production systems.
  • Page 44: Development Tools

    Energia, you can write C code using the open-source version of the Gnu Compiler (GCC). It doesn’t matter which tool suite you choose, in any case, you’ll still have all the other MSP430 ecosystem components at your disposal. For example, MSP430ware DriverLib works in all of these environments.
  • Page 45: Other Msp430 Tools

    TI Support Ecosystem Other MSP430 Tools The MSP430 team has created a number of additional tools to support development of MSP430 applications. For example, since low-power designs are a major consideration for MSP430 users, the ULP Advisor tool provides static analysis of your code – from a power perspective – every time you compile.
  • Page 46: Support & Community

    The TI Embedded Processor’s wiki provides a wealth of information. Highlighted below you’ll find the MSP430 and TTO (Technical Training Organization) links found on the main TI wiki page. Of course, most anything else you might be looking for can be easily found from the Google search box, right under the “Main Page”...
  • Page 47: Forums

    Forums There are a wide ranging set of user-to-user forums. Check them out, when you have a ??? MSP430 Workshop - Programming C with CCS 2 - 9...
  • Page 48: Examining Ccsv5

    Any object library you want to reference in your code. By default, TI’s compiler ships with a run-time support library (RTS) that provides standard C functions. See the compiler user’s guide for more information. (slau132.pdf) 2 - 10 MSP430 Workshop - Programming C with CCS...
  • Page 49 .cmd Linker command files tells the linker how to allocate memory and stitch your code and libraries together. TI provides a default linker command file specific to each MSP430 device; it is automatically added to your project when you create a new project. You can edit it, if needed, though most users get by without ever touching it.
  • Page 50: Debugging

    CCS needs to connect and talk to your target (be it a board or a software simulator). For the MSP430, the CCXML file is automatically created when you create a new project. This file is based on your telling CCS which CPU variant you’ve chosen (i.e. MSP430F5529); as well as which “Connection”...
  • Page 51: Perspectives

    CCS Debug are the two perspectives that are used most often. Notice how the perspectives differ for each of the modes shown below. Eclipse even varies the toolbars and menus between perspectives. MSP430 Workshop - Programming C with CCS 2 - 13...
  • Page 52: Workspaces & Projects

    CCS, they are not stored in the Windows registry. This makes the Linux version of the tools possible; but it also means it’s easier to keep multiple versions of CCS on your computer (if you should need to do so). 2 - 14 MSP430 Workshop - Programming C with CCS...
  • Page 53: Some Final Notes About Ccs/Eclipse

    Windows explorer, it will be “in the project”. Note, though, that CCS does provide a way to “exclude a file from build” – but this is not the default. • You can export and import projects directly to/from archive (zip) files. Very nice! MSP430 Workshop - Programming C with CCS 2 - 15...
  • Page 54: Creating A Project

    “Empty”. But some of the others may come in handy. For example, if you are creating a TI-RTOS based project, you will want to choose one of their project templates. 2 - 16 MSP430 Workshop - Programming C with CCS...
  • Page 55: Adding Files To A Project

    Portable Projects This is not an issue for this workshop because the MSP430 team recommends that you add a copy of DriverLib to each project. That said, you will likely run into this issue in the future, so we wanted to bring it to your attention.
  • Page 56: Licensing/Pricing

    For example, there is no charge when using CCS with most of the available TI development boards – with the MSP430, they allow you to use it for free (with any tool), as long as your program is less than 16KB.
  • Page 57: Changing A Ccs User Licence

    As shown, choose Code Composer Studio Licensing Information from the Help menu. When that dialog appears, choose the Upgrade tab, then click the Launch License Setup… button. In this workshop, we can use the free 16K Code Size Limited (MSP430) option. MSP430 Workshop - Programming C with CCS...
  • Page 58: Writing Msp430 C Code

    You should find the table below broken into three sets of options: Processor Options • Early MSP430 CPU’s were 16-bit only processors and could only address 64K bytes. Most of the MSP430 devices from the F2xx series onward utilize the MSP430X CPU which contains eXtended 20-bit addressing (up to 1MB).
  • Page 59: Debug Options

    C code. Bottom Line: When optimizing your code, replace the –ss option with the –k option! MSP430 Workshop - Programming C with CCS 2 - 21...
  • Page 60: Build Configurations

    (manually) change them both at the same time … or be prepared to tweak the Release build options the first time you use it. 2 - 22 MSP430 Workshop - Programming C with CCS...
  • Page 61: Data Types

    The following data types are specified in the C Compiler Users Guide. We’ve circled the types that best describe this processor. With the MSP430’s ability to perform byte-wide addressing, it follows that char’s are 8-bits. As one might expect, though, being a 16-bit CPU, both the short and int data types are 16-bits wide.
  • Page 62: Device Specific Files (.H And .Cmd)

    TI has created a device-specific header file (.h) and linker command file (.cmd) for each specific MSP430 device. With the MSP430F5529 device as an example, if you look through the files installed with the MSP430 compiler, you’ll find: msp430f5529.h and msp430f5529.cmd Example: Device Specific ‘Header’...
  • Page 63 Structs/union’s also defined for bit fields, if you prefer  You shouldn’t have to use hard-coded bit locations, etc.  Your code should #include msp430.h, this points to the device specific .h file  Device linker command file msp430f5529.cmd Device specific addresses defined in dev specific .cmd file ...
  • Page 64: Msp430 Compiler Intrinsic Functions

    _delay_cycles(); We’ve circled some of the intrinsic functions we’ll use in this class. From setting and/or clearing bits in the Status Register (SR) to putting the processor into low-power modes. 2 - 26 MSP430 Workshop - Programming C with CCS...
  • Page 65: Lab 2 - Ccsv5 Projects

    Lab 2 – CCSv5 Projects The objective of this lab is to learn the basic features of Code Composer Studio. In this exercise you will create a new project, build the code, and program the on-chip flash on the MSP430 device.
  • Page 66 Lab 2c – Putting the OOB back into your device ..............2-47 (Optional) Lab 2d – MSP430Flasher .................. 2-48 Programming the UE OOB demo using MSP430Flasher ........... 2-48 Programming Blinky with MSP430Flasher ..............2-51 Cleanup ........................2-52 2 - 28 MSP430 Workshop - Programming C with CCS...
  • Page 67: Lab 2 - Ccsv5 Projects

    “hand holding” instructions. Hint: In a real-world MSP430 program, you would NOT want to call printf(). This function is slow, requires a great deal of program and data memory, and sucks power – all bad things for any embedded application.
  • Page 68: Start Code Composer Studio And Open A Workspace

    Once you close this window, you can always reopen it via: Help  Welcome to CCS Go ahead and close the TI Resource Explorer tab 2 - 30 MSP430 Workshop - Programming C with CCS...
  • Page 69: 00430

    If you are attending another workshop in conjunction with this one, like the Tiva-C ARM Cortex-M4F LaunchPad workshop, you can return here and change this to the FREE LICENSE option. MSP430 Workshop - Programming C with CCS 2 - 31...
  • Page 70: Ccs Edit" Perspective

    You can customize the perspectives and save as many as you like. Most of us find the Window  Reset Perspective… handy for those times when Hint: we’ve messed our windows up a bit too much. 2 - 32 MSP430 Workshop - Programming C with CCS...
  • Page 71: Create A New Project

    7. Select New CCSP Project from the menu. A project contains all the files you will need to develop an executable output file (.out) which can be run on the MSP430 hardware. To create a new project click: File  New  CCS Project 8.
  • Page 72 If you want a file in the project folder, but not in your program, you can exclude files from build: Right-click on the file  Exclude from Build 2 - 34 MSP430 Workshop - Programming C with CCS...
  • Page 73 As the comment indicates, this turns off the watchdog timer (WDT peripheral). As we’ll learn in Chapter 4, the WDT peripheral is always turned on (by default) in MSP430 devices. If we don’t turn it off, it will reset the system – which is not what we usually want during development (especiall during ‘hello world’).
  • Page 74: Build The Code (Ignore Advice)

    As the dialog above indicates, you can always go into your project’s properties and enable or disable this advice. We will do this in a later chapter, when we’re ready to focus on driving our every last nanoamp. 2 - 36 MSP430 Workshop - Programming C with CCS...
  • Page 75: Debug The Code

    This occurs when CCS finds that the FET firmware – that is, the firmware in your Launchpad’s debugger – is out-of-date. We recommend that you choose to update the firmware. Once complete, CCS should finish launching the debugger. MSP430 Workshop - Programming C with CCS 2 - 37...
  • Page 76 Open Windows Device Manager and verify the board exists and there are no warnings or errors with its driver.  If all else fails, ask your neighbor (or instructor) for assistance. 2 - 38 MSP430 Workshop - Programming C with CCS...
  • Page 77 Your program will now download to the target board and the PC will automatically run until it reaches main(), then stop as shown: MSP430 Workshop - Programming C with CCS 2 - 39...
  • Page 78 This closes the debug session (and Debug Perspective). CCS will switch back to the Edit perspective. You are now completely disconnected from the target. 20. Also, if the Target Configurations window is still open, please close it. 2 - 40 MSP430 Workshop - Programming C with CCS...
  • Page 79: Fix Your Project

    Lab 2 – CCSv5 Projects Fix Your Project 21. What is wrong? We searched the internet for: “msp430 printf” and found a wiki page that demonstrated how to get printf() to work: http://processors.wiki.ti.com/index.php/Printf_support_for_MSP430_CCSTUDIO_compiler Since you may not have internet access in the classroom, here’s the relavent bit: 22.
  • Page 80: Build, Load, Connect And Run

    – only to find you were editing a file with the same name, but from a different project. Doh!) You can quickly reopen the project, when and if you need to. 2 - 42 MSP430 Workshop - Programming C with CCS...
  • Page 81: Lab 2B - My First Blinky

    At that time, we will also introduce the MSP430ware DriverLib library to help you program GPIO, as well as all the other peripherals on the MSP430. In the lab exercise, we want to teach you a few additional debugging basics – and need some code to work with.
  • Page 82: Build, Load, Run

    (In this case, it appears the author didn’t really care if his LED started in the on or off position; just that it changed each time thru the loop.) Hint: As we mentioned earlier, we will provide more details about the MSP430 GPIO features, registers, and programming in the next chapter. Build, Load, Run 3.
  • Page 83: Restart, Single-Step, Run To Line

    Click on the line of code that toggles the LED. Click on the line: P1OUT ^= 0x01; Then Right-click and select Run To Line (or hit Ctrl-R) Single-step once more to toggle the LED MSP430 Workshop - Programming C with CCS 2 - 45...
  • Page 84 You should see the LED toggling on or off each time you run the code. 12. Terminate your debug session. When you’re done having fun, terminate your debug session. 13. Close the project. 2 - 46 MSP430 Workshop - Programming C with CCS...
  • Page 85: Lab 2C - Putting The Oob Back Into Your Device

    This runs the original demo that was just re-programmed into Flash. (We unplugged from Windows to get Windows to recognize the memory-stick (MSC) feature of the demo program. (You can refer back to lab_01_oob if you have questions.) MSP430 Workshop - Programming C with CCS 2 - 47...
  • Page 86: (Optional) Lab 2D - Msp430Flasher

    -v tells the tool to verify the image We used the default locations for MSP430Flasher and our lab exercises. You will have to change them if you installed these items to other locations on your hard drive. 2 - 48 MSP430 Workshop - Programming C with CCS...
  • Page 87 4. Navigate to your lab_02d_flasher folder. The DOS command for changing directories is: “cd” cd C:\msp430_workshop\<target>\lab_02d_flasher\ Once there, you should be able to list the directories contents using the dir command. MSP430 Workshop - Programming C with CCS 2 - 49...
  • Page 88 Below is what the command window should look like right before you hit any key, which should end the batch program. 7. Once again, verify the Launchpad program works. 2 - 50 MSP430 Workshop - Programming C with CCS...
  • Page 89: Programming Blinky With Msp430Flasher

    Clean the project Build the project 12. Verify that lab_02b_blink.txt was created in the /Debug directory. 13. Open blink.bat with a text editor and verify all the paths are correct. C:\msp430_workshop\<target>\lab_02d_flasher\blink.bat MSP430 Workshop - Programming C with CCS 2 - 51...
  • Page 90: Cleanup

    14. Run blink.bat from the DOS command window. When done programming, you should see the LED start blinking. Cleanup 15. Close your lab_02b_blink project. 16. You can also close the DOS command window, if it’s still open. 2 - 52 MSP430 Workshop - Programming C with CCS...
  • Page 91 Using GPIO with MSP430ware Introduction In the previous lab exercise, we blinked an LED on the MSP430 Launchpad, but we didn’t write the code – we were able to import a generic ‘blink’ template that ships with CCSv5. This chapter explores the GPIO (general purpose bit input/output) features of the MSP430 family.
  • Page 92 GPIO Input Worksheet ....................3-29 File Management ......................3-30 Add Setup Code (to reference push button) ............... 3-32 Modify Loop ......................... 3-33 Verify Code........................3-34 Optional Exercises ......................3-34 Chapter 3 Appendix ........................ 3-35 3 - 2 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 93: Using Gpio With Msp430Ware

    (.exe) file. Installing MSP430ware When installing Code Composer Studio, if you choose to include MSP430 support (or choose to install everything), MSP430ware will be installed by the CCS installer. In this case, you will find MSP430ware along the path: C:\ti\ccsv5\ccs_base\msp430\msp430ware_1_40_01_44\ The path above assumes that you installed CCS to “C:\ti”.
  • Page 94: Driverlib

    The Texas Instruments® MSP430® Peripheral Driver Library is a set of drivers for accessing the peripherals found on the MSP430 5xx/6xx family of microcontrollers. While they are not drivers in the pure operating system sense (that is, they do not have a common interface and do not connect into a global device driver infrastructure), they do provide a mechanism that makes it easy to use the device’s peripherals.
  • Page 95: Driverlib Modules

    Programming Methods – Summary Over the past two chapters we have introduced four ways to program the MSP430. They are listed below along with the chapters (and courses) they are discussed in. Summary Name 4 ways to program GPIO: Using device specific header &...
  • Page 96: Msp430 Gpio

    This is the most basic service provided by processors. The MSP430 provides one or more 8-bit I/O ports. The number of ports is often correlated to the number of pins on the device – more pins, more I/O. The I/O port bits (and their related pins) are enumerated with a Port number, along with the bit/pin number;...
  • Page 97: Input Or Output

    With the direction configured you will either use the respective IN or OUT register to view or set the pin value (as we’ll see on the next couple pages). MSP430 Workshop - Using GPIO with MSP430ware 3 - 7...
  • Page 98: Gpio Output

    PxOUT registers. You can set multiple pins/bits by or’ing (+) them together (similar to the P1DIR example on the previous page). 3 - 8 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 99: Gpio Input

    To minimize system cost and power, most MSP430 I/O ports provide internal pull-up and pull- down resistors. You can enable these resistors via the PxREN (Resistor ENable) register bits.
  • Page 100: Drive Strength

    MSP430 GPIO Drive Strength The F5xx/6xx series of MSP430 devices allow the designer to select whether they want outputs to be driven with lower or higher drive strength. The benefit of this extra feature is that it allows you to tune or power dissipation of your system. You can minimize the extra power usage of outputs when and where it is not needed.
  • Page 101: Flexible Pin Useage (Muxing)

    If you have done microcontroller system design in the past, this is probably an obvious statement, but it’s a mistake we’ve seen a number of times in the past. MSP430 Workshop - Using GPIO with MSP430ware 3 - 11...
  • Page 102: Pin Selection

    Peripheral “PxSEL = 1” (e.g. Timer) GPIO_setAsPeripheralModuleFunctionOutputPin( port, pin ); GPIO_setAsPeripheralModuleFunctionInputPin( port, pin ); In some devices, you’ll actually find two select registers – which provides more pin mux options. 3 - 12 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 103: Port Mapping

    The signals that can be mapped to the port mapping pins are highlighted with a PM_ prefix. On the device shown above, only Port 4 has been designed with the Port Mapping (PM) feature. MSP430 Workshop - Using GPIO with MSP430ware 3 - 13...
  • Page 104: Summary

    Most of these registers were described in the preceding discussion. • All three devices (and most all MSP430 devices) contain two 8-bit I/O ports (P1, P2) which provide the GPIO functionality – including interrupt inputs. We demonstrated this above by using the ‘black’...
  • Page 105 GPIO_ setAsInputPinWithPullUpresistor FR5969 GPIO_setAsInputPin PxDIR (only) GPIO_setAsOutputPin Three PxSEL GPIO_setAsPeripheral ModuleFunctionInputPin Devices PxDS GPIO_setAsPeripheral ModuleFunctionOutputPin support PxIV Ports 1 GPIO_setDriveStrength PxIES GPIO_interruptEdgeSelect FR5969 (only) GPIO_disableInterrupt PxIE GPIO_enableInterrupt PxIFG GPIO_getInterruptStatus GPIO_clearInterruptFlag MSP430 Workshop - Using GPIO with MSP430ware 3 - 15...
  • Page 106: Before We Get Started Coding

    If you’ve programmed in C for very long, you have probably become accustomed to using Include files. As described in the last chapter, every MSP430 device has a specific .h file created to define its various registers and symbols. When using the “Register” model of programming, you would need to include this header file.
  • Page 107: Disable Watchdog Timer

    Before We Get Started Coding 2. Disable Watchdog Timer The MSP430 watchdog timer is always enabled. If you’re just trying to get your first program to run, you won’t need this feature, thus you can stop this timer with the DriverLib function shown below.
  • Page 108: Pin Unlocking (Wolverine Only)

    GPIO control registers. As shown above, it is suggested that you setup your GPIO registers and then unlock the registers using the PMM_unlockLPM5() function. 3 - 18 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 109: Lab 3

    Lab 3 Lab 3 We begin with a short Worksheet to prepare ourselves for coding GPIO using MSP430 DriverLib. Next you’ll implement the blinking LED example using DriverLib, finally adding a test of the push button in the final part of the lab exercise.
  • Page 110 - Single-step code to observe behavior - Run, to watch it work! Note: "Polling" the button is very inefficient! We'll improve on this in both the Interrupts and Timers chapters and exercises. 3 - 20 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 111: Lab 3 Worksheet

    //Set pin to “1” (hint, see question 4) ______________________________________________________________ ; _delay_cycles( ONE_SECOND ); // Set pin to “0” _______________________________________________________________ ; _delay_cycles( ONE_SECOND ); Check your answers against ours … see the Chapter 3 Appendix. MSP430 Workshop - Using GPIO with MSP430ware 3 - 21...
  • Page 112: Lab 3A - Blinking An Led

    2. Also, if the Target Configurations window is open, please close it. 3. Create a new project. Note: If you’re working with the ‘FR5969, please replace the ‘F5529 references shown above with those required for your platform. 3 - 22 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 113 Hint: The default main.c created by the new project wizard already has #included <msp430.h>. You can replace this with the DriverLib #include. It’s OK to have both of them, but the DriverLib header file already references msp430.h. 6. Do you see question marks next to #include statement? What does this mean?
  • Page 114: Add Msp430Ware Driverlib

    Note: The version of MSP430ware you have may vary slightly from what is shown above. If the version is lower (i.e. older), you should update it. If it is later, hopefully it will work without any problems. 3 - 24 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 115 Along with adding the library, we also need to tell the compiler where to find it. Open the Include Options and add the directory to #include search path: Right-click project → Properties Then select: Build → MSP430 Compiler → Include Options and add the appropriate path to the #include search path: ${PROJECT_ROOT}\driverlib\MSP430F5xx_6xx or ${PROJECT_ROOT}\driverlib\MSP430FR5xx_6xx With this step done, you should notice the ??? gone from the #include statements.
  • Page 116: Add The Code To Main.c

    If it doesn’t, let’s hope following debug steps help you to track down your error. If it does, hooray! We still think you should perform the following debug steps, if only to better understand some additional features of CCS. 14. Suspend the debugger. Alt-F8 3 - 26 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 117: Debug

    17. Single-step until you reach the _delay_cycles() function. You should see the P1OUT register change as you step over the appropriate function. Unfortunately, the “Step Over” command doesn’t step over _delay_cycles(). MSP430 Workshop - Using GPIO with MSP430ware 3 - 27...
  • Page 118 A cut and paste error left us with two lines of code in our loop that both turned off the LED. Oops! While basic debugging techniques, these steps are powerful tools for finding and fixing errors in your code. 3 - 28 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 119: Lab 3B - Reading A Push Button

    Lab 3b – Reading a Push Button GPIO Input Worksheet 1. What three DriverLib functions can setup a GPIO pin for input? Hint, one place to look would be the MSP430 DriverLib Users Guide found in the MSP430ware folder: \MSP430ware_1_60_01_11\driverlib\doc\MSP430F5xx_6xx\ _________________________________________________________________________...
  • Page 120: File Management

    We’re going to try another – easier – method of creating a new DriverLib project from scratch. Import the Empty driverlib example project 1. Import the emptyProject from the MSP430 DriverLib examples. There are a couple different ways to import the example projects, but in this lab we’ll utilize the TI Resource Explorer as it provides convenient access to examples from within CCS.
  • Page 121 (Believe us, this happens a lot.). Right-click on the project and select “Close Project”. 6. Build the new lab, just to make sure everything was copied correctly. MSP430 Workshop - Using GPIO with MSP430ware 3 - 31...
  • Page 122: Add Setup Code (To Reference Push Button)

    Launchpad board. It’s very hard to see which button is SW1 – and the pin it is connected to. It may easier to reference the Quick Start sheet that came with your Launchpad. 3 - 32 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 123: Modify Loop

    Copying from PDF will usually mess up the code’s indentation. You can fix this by selecting the code inside CCSv5 and telling it to clean-up indentation: Right-click → Source → Correct Indentation (Ctrl+I) MSP430 Workshop - Using GPIO with MSP430ware 3 - 33...
  • Page 124: Verify Code

    Try this lab without pull-up (or pull-down) resistor. (yes / no) Without the resistor, is the pushbutton’s value always consistent? _______________ • Try using the other LED on the board … • … or the other pushbutton. 3 - 34 MSP430 Workshop - Using GPIO with MSP430ware...
  • Page 125: Chapter 3 Appendix

    (1) { //Set pin to “1” (hint, see question 4) GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0) _________________________________________________ ; _delay_cycles( ONE_SECOND ); // Set pin to “0” GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0) _________________________________________________ ; _delay_cycles( ONE_SECOND ); MSP430 Workshop - Using GPIO with MSP430ware 3 - 35...
  • Page 126 Chapter 3 Appendix Lab3b – Worksheet 1. What three functions choices are there for setting up a pin for GPIO input? Hint, one place to look would be the MSP430 Driverlib Users Guide found in the MSP430ware folder: \MSP430ware_1_60_01_11\driverlib\doc\MSP430F5xx_6xx\ GPIO_setAsInputPin()
  • Page 127 It becomes even more important in applications that depend upon precise, or very low-power, timing. The MSP430 provides a wealth of clock sources; from ultra-low-power, low-cost, on-chip clock sources to high-speed external crystal inputs. All of these can be brought to bear through the use of 3 internal clock signals, which drive the CPU along as well as fast and slow peripherals.
  • Page 128 Other Initialization (WDT, PMM) ..................... 4-32 Watchdog Timer ........................4-33 PMM with LDO, SVM, SVS, and BOR ................4-34 Operating Voltages ......................4-36 Summary ..........................4-37 Initialization Summary (template) ..................4-40 Lab Exercise ........................... 4-41 4 - 2 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 129: Operating Modes (Reset → Active)

    Operating Modes (Reset → Active) Operating Modes (Reset → Active) The MSP430 has a number of operating modes. In this chapter we explore the modes that take the processor from startup to active. In a future chapter, the low-power modes will be explored.
  • Page 130: Bor → Por → Puc → Active (Am)

    The previous page contained a list of actions that occur in the MSP430 hardware when a BOR event occurs. To find these details for all of the reset modes, please refer to the datasheet and users guides;...
  • Page 131 Here’s the full diagram showing the Reset and Active modes for the ‘F5529 . This shows all the various events that direct the MSP430 CPU into its different Reset states. You can find a similar diagram for each series of MSP430 processors.
  • Page 132: Clocking

    Clocking What Clocks Do You Need? MSP430 provides a wide range of clocking options. Before choosing and configuring the clocks, though, you need to determine which clock features are most important for your system: Fast, low-power, accurate, etc. At times, choosing these various options may force you to make tradeoffs;...
  • Page 133 Clocking MSP430's rich clock ecosystem provides three internal clocks from a variety of clock sources. Let's start on the right-side of the following diagram; there are 3 internal clocks which provide a variety of high and/or low speed options. On the left-hand side, there are internal and external oscillators which provide both high and slow speed clock sources.
  • Page 134: Mclk, Smclk, Aclk

    The preceding graphic shows how one might use these various clocks on the MSP430. Please refer to the datasheet, though, since these vary slightly by device. For example, some devices allow all three clocks (MCLK, SMCLK, ACLK) to drive all of the peripherals while others only allow SMCLK and ACLK.
  • Page 135: Oscillators (Clock Sources)

    Clocking Oscillators (Clock Sources) The typical MSP430 device provides a wide range of clock oscillator sources: internal/external, fast/slow, higher precision vs lower cost. Looking at the diagram, we can see that the typical sources are listed in the order from lower to higher frequency. Two slides from now, we'll compare the essential differences between the oscillator clock sources.
  • Page 136 • 5 MHz / 128 or ADC VLO: most MSP430 devices provide a Very Low-frequency Oscillator (VLO). While not a highly accurate clock, this source is extremely low-power. Also, as it is internal to the chip, it ends up being very inexpensive. If you need to wake up the processor every couple seconds to perform a task (i.e.
  • Page 137: Clock Details (By Device Family)

    What differs between them are exactly which sources are provided for a given family, how the DCO frequency is configured and tuned, as well as a number of other miscellaneous clock features. Many of these similarities and differences are described over the next few pages. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 11...
  • Page 138 Also, the DCO had to be tuned in software if the temperature or voltage changed significantly during operation. (Later devices moved this chore into hardware.) F1xx Basic Clock System (BCS) Reserved SCG1 SCG0 R2/SR 4 - 12 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 139 0-to-16MHz  load capacitance of 6pF. If LFXT1 fails, ACLK defaults to VLO. + 3% tolerance   Factory calibration in Flash * Not on all devices. Check the datasheet. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 13...
  • Page 140 Clocking F5xx/F6xx Clocks (UCS) The Unified Clock System is most flexible MSP430 clock peripheral to date. It provides an orthogonal set of clock options – any source can drive any internal clock signal. Additionally, it provides the hardware required to dynamically tune the DCO as needed under varying conditions.
  • Page 141 LF and HF ranges for XT1  Defaults:  DCO = 1MHz  ACLK = Only LF sources  Failsafe's:  XT1LF: LFMODCLK (~42kHz)  XT1HF  or XT2: MODCLK (5MHz) MSP430 Workshop - MSP430 Clocks & Initialization 4 - 15...
  • Page 142: Using Msp430Ware To Configure Clocking

    1. Conveniently, the DriverLib API provides an enumeration for each possible field value, including all the various clock divider options. (DriverLib, with these enumerations, makes the code very easy to read.) 4 - 16 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 143 Conveniently, DriverLib provides UCS functions for putting the interfaces into bypass mode. The optional lab exercise for this chapter provides a crystal oscillator example for you to explore. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 17...
  • Page 144: Additional Clock Features

    What happens if the external crystal breaks or falls off your board? The MSP430 clocks will default to an internal clock. While this may not be the rate/precision you were expecting to run at, it’s better than having the system fail outright. There are clock fault events that indicate if the external clock is not working correctly.
  • Page 145 Must be very conscious of  the clocks required in the system. Note: While this feature is a handy failsafe, it can also prevent your system from reaching its lowest power state. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 19...
  • Page 146 LFXTOFF bit can be cleared prior to entering the low-power mode which causes LFXT to remain enabled. Similarly, the HFXTOFF bit can be cleared prior to entering the low-  power mode. This causes HFXT to remain enabled. 4 - 20 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 147: Dco Setup And Calibration

    As you can see from our earlier table, the DCO (digitally controlled oscillator) can be calibrated in a variety of different ways, depending upon which generation MSP430 processor you're using. Before discussing these various calibration options, let's first look at how the DCO works.
  • Page 148: How The Dco Works

    Any of the first three would work, but range "1" puts our desired frequency close to the middle of the range. Notice that the DCORSEL (DCO Range SELect) register field provides a means of selecting which DCO range you want to use. 4 - 22 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 149 DCO field? In other words, what happens if the granularity of the DCO field is not enough to specify our frequency of interest? (I.E. our frequency falls between a value of DCO and DCO+1.) MSP430 Workshop - MSP430 Clocks & Initialization 4 - 23...
  • Page 150 DCO Setup and Calibration This is where the final field, called MOD, comes into play. MOD lets you tell the MSP430 clock to modulate between two frequency levels: DCO and DCO+1. By mixing these two frequencies you can obtain a very close approximation to your chosen clock frequency.
  • Page 151 DCO Clock Summary 1. Select Range 2. Select Tap within Range 3. Choose Modulation to effect greater precision MSP430 Workshop - MSP430 Clocks & Initialization 4 - 25...
  • Page 152: Factory Callibration (G2Xx, Fr5Xx)

    // Set DCO to 8MHz CS_setDCOFreq(CS_BASE, CS_DCORSEL_1, CS_DCOFSEL_3); Configuration of the ‘FR5xxx devices is the easiest of all the MSP430 devices. Looking at the table in the datasheet (which has been replicated above), you just need to choose the value of the DCORSEL and DCOFSEL fields to match the frequency you want to run at.
  • Page 153 INFOA memory by the tester. You can then copy the appropriate calibration constant from Flash into your DCO control register to run the clock at a specified frequency. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 27...
  • Page 154: Runtime Calibration

    Hardware FLL circuitry In earlier MSP430 processors, this needed to be handled in software. Using the FLL, the Modulation (MOD) parameter (i.e. field of the DCO control register) is adjusted up or down based upon the count of DCO cycles versus an accurate reference clock (most commonly, a 32KHz watch crystal).
  • Page 155 As long as you know the desired value of DCOCLK and the FLL Reference Clock, it’s a simple matter of choosing values for the 3 divider/multiplier fields (n, FLLD, FLLN) to solve the equation. DCOCLK = (FLLREFCLK/n) * FLLD (FLLN + 1) MSP430 Workshop - MSP430 Clocks & Initialization 4 - 29...
  • Page 156 SMCLK was running at the same speed as MCLK. One last note, the initFLL functions will set MCLK and SMCLK to DCOCLK if the frequency is greater than 16MHz, otherwise it will use the divided down DCOCLKDIV. 4 - 30 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 157: Vlo 'Calibration

     Timer_A clocked at calibrated 1MHz (from DCO)   Capture with rising edge of ACLK/8 from VLO  = 8MHz/Counts  Code library on the web (search for “SLAA340”) MSP430 Workshop - MSP430 Clocks & Initialization 4 - 31...
  • Page 158: Other Initialization (Wdt, Pmm)

    “ON”, it must be configured. During development and debugging we usually turn it off. The next section discusses the Watchdog in further detail. Some of the more feature-rich series of the MSP430 devices contain an on-chip along with Power Manager Supervisor circuitry.
  • Page 159: Watchdog Timer

    The goal here is to prevent your system from locking-up due to some unexpected fault. As mentioned frequently in this class, the MSP430 watchdog timer is “on” by default. You should always disable the watchdog or configure it as needed.
  • Page 160: Pmm With Ldo, Svm, Svs, And Bor

    The BOR (brown-out reset) circuitry is found on every MSP430 device. You might remember us talking about this hardware at the beginning of the chapter. In a sense, it is redundant to the SVS circuitry, although it is always on –...
  • Page 161 (check it after reset) High side is the voltage input to  the device (prior to PMM’s LDO) Low side is the core voltage  (after LDO) MSP430 Workshop - MSP430 Clocks & Initialization 4 - 35...
  • Page 162: Operating Voltages

    Other Initialization (WDT, PMM) Operating Voltages For many of the MSP430 devices, their capabilities can vary based upon the input voltage supply. For example, most of the devices do not support in-system Flash programming when running below 2.2V. Another example is that many devices require higher voltages to run at their faster speeds.
  • Page 163 Other Initialization (WDT, PMM) Summary We have summarized three MSP430 devices in the table below. They demonstrate some of the differences between the various series of MSP430: Value-Line, F5xx, and Wolverine FR5xxx. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 37...
  • Page 164 If CE line is not in use the domain is powered down  Domain 1: Always ON CPU, Interrupt logic Domain 2: Always OFF, AES, HW MPY Domain 3/4: Peripheral Domain for e.g. timers 4 - 38 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 165 • 5 us wakeup from LPM2,3,4 consumption • +4 uA active & LPM2,3,4 current 0 nA LPM2,3,4 current  consumption consumption • Automatic high-side protection when CPU is active 150 us wakeup from LPMx MSP430 Workshop - MSP430 Clocks & Initialization 4 - 39...
  • Page 166: Initialization Summary (Template)

    Other Initialization (WDT, PMM) Initialization Summary (template) To some of you the following template may seem obvious, but we thought it might be handy to provide a template, of sorts, for a main() function in an MSP430 program. Summary: Initializing MSP430 #include <driverlib.h>...
  • Page 167 Lab 4a – Program MSP430 Clocks We explore the default clock rates for each of MSP430’s three internal clocks; then, set them up with a set of specified clock rates.
  • Page 168 MSP430 Clocks & Initialization ....................4-40 Lab 4 - Abstract ........................4-41 Lab 4 Worksheet ........................4-43 Lab 4a – Program the MSP430 Clocks ................... 4-47 File Management ......................4-47 Do Clock Code ........................ 4-47 Initialization Code - Three more simple changes ............4-50 Debugging the Clocks .....................
  • Page 169 Lab 4 Worksheet Lab 4 Worksheet MSP430 Workshop - MSP430 Clocks & Initialization 4 - 43...
  • Page 170: Lab 4 Worksheet

    Lab 4 Worksheet 4 - 44 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 171 Lab 4 Worksheet MSP430 Workshop - MSP430 Clocks & Initialization 4 - 45...
  • Page 172 Lab 4 Worksheet Check your answers against ours … see the Chapter 4 Appendix 4 - 46 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 173: Lab 4A - Program The Msp430 Clocks

    Lab 4a – Program the MSP430 Clocks Lab 4a – Program the MSP430 Clocks File Management 1. Import previous lab_03a_gpio solution. Project → Import Existing CCS Eclipse Project 2. Rename the project to: lab_04a_clock Right-Click on Project → Rename 3. Build it, just to make sure the import went without errors.
  • Page 174 Lab 4a – Program the MSP430 Clocks 5. Update myclocks.c – adding answers from the worksheet Fill in the with code you wrote on the worksheet. blanks //***** Header Files ************************************************ //#include <stdbool.h> #include <driverlib.h> #include "myClocks.h" Worksheet //***** Defines *****************************************************...
  • Page 175 Lab 4a – Program the MSP430 Clocks 6. Try building to see if there are any errors. Hopefully you don’t have any typographic or syntax errors, but you should see this error: fatal error #1965: cannot open source file "myClocks.h"...
  • Page 176: Initialization Code - Three More Simple Changes

    Lab 4a – Program the MSP430 Clocks Initialization Code - Three more simple changes 11. Use the simple initialization “template” to organize your setup code. We’ve outlined the 3 areas you will need to adapt to create a little better code organization.
  • Page 177: Debugging The Clocks

    Lab 4a – Program the MSP430 Clocks 12. Build the code and fix any errors. When no errors exist, launch the debugger. Debugging the Clocks Before running the code, let’s set some breakpoints and watch expressions. 13. Open myClocks.c in the debugger.
  • Page 178 Lab 4a – Program the MSP430 Clocks Note: Before you run the code to the first breakpoint, you may see an error in the Expressions window similar to “Error: identifier not found”. This happens when the variable in the expression is out-of-scope. For example, this can happen if you defined the variable as a local, but you were currently executing code in another function.
  • Page 179: Extra Credit (I.e. Optional Step) - Change The Rate Of Blinking

    Lab 4a – Program the MSP430 Clocks Extra Credit (i.e. Optional Step) – Change the Rate of Blinking 20. Halt the processor and terminate the debugger session. 21. Add a function call to initClocks() to force MCLK to use the REFO oscillator.
  • Page 180: (Optional) Lab 4B - Exploring The Watchdog Timer

    (Ours wasn’t blinking at all, after we left the WDT_A running. It must keep resetting the processor before we even get to the while{} loop.) 7. Close the lab_04a_clock project. 4 - 54 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 181: File Management

    This new code will initialize the watchdog timer using the clock and divisor of our choice; then start the watchdog timer running. (See question in step #1 on page 4-54.) MSP430 Workshop - MSP430 Clocks & Initialization 4 - 55...
  • Page 182 17. Include driverlib.h in your hello.c file. Yep, when we added the driverlib code, we needed to add the driverlib header file, too. Actually, you can replace the msp430.h file with driverlib.h because the latter references the former. When complete, your code should look similar to this: #include <stdio.h>...
  • Page 183: Keep It Running

    Notice how they utilize the GPIO pin. Every time the program re-starts it toggles the GPIO pin. If you look in the User Guide for your MSP430 device, you can see that while the PDIR (pin direction) register is reset after a Power-Up Clear (PUC), the POUT value is left alone. This is the trick used to make the pin toggle after every watchdog reset.
  • Page 184: (Optional) Lab 4C - Using Crystal Oscillators

    // XT2OUT on P5.3 GPIO_PIN2 // XT2IN on P5.2 By default – on some MSP430 devices, such as the F5529 – these pins default to GPIO mode. Thus, we have to connect them by reprogramming the GPIO. 4 - 58...
  • Page 185 _________________________________________________________________________ Hint: Read the comments on the code itself. We hope that’ll explain what caused this. 12. When done experimenting with this code, terminate the debugger and close the project. MSP430 Workshop - MSP430 Clocks & Initialization 4 - 59...
  • Page 186: Chapter 04 Appendix

    Chapter 04 Appendix Chapter 04 Appendix Chapter 4 Worksheet Hints: The MSP430 DriverLib Users Guide will be useful in helping to answer these  workshop questions. Find it in your MSP430ware DriverLib doc folder: e.g. \MSP430ware_1_60_01_11\driverlib\doc\ Maybe even more helpful is to reference the actual DriverLib source code –...
  • Page 187: Define Lf_Crystal_Frequency_In_Hz

    7. What function specifies these crystal frequencies to the DriverLib? Hint: Look in the MSP430ware DriverLib User’s Guide – “UCS chapter”. UCS_setExternalClockSource _______________________( UCS_BASE, (for FR5969: CS_setExternalClock Source) LF_CRYSTAL_FREQUENCY_IN_HZ ___________________________, HF_CRYSTAL_FREQUENCY_IN_HZ ___________________________); MSP430 Workshop - MSP430 Clocks & Initialization 4 - 61...
  • Page 188: Define Mclk_Fllref_Ratio

    _____________________, // Clock Source UCS_CLOCK_DIVIDER_1 ); Config the FLL's freq, let it settle, and set MCLK & SMCLK to use DCO+FLL as clk source UCS_initFLLSettle _________________________( UCS_BASE, MCLK_DESIRED_FREQUENCY_IN_KHZ, MCLK_FLLREF_RATIO _____________________________); 4 - 62 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 189 WDT_A_CLOCKDIVIDER_64 ); //Two other divisor options //WDT_A_CLOCKDIVIDER_512 ); //WDT_A_CLOCKDIVIDER_32K ); // Start the watchdog WDT_A_start __________________________________( WDT_A_BASE ); 2. Write the code to ‘kick the dog’? WDT_A_resetTimer __________________________________( WDT_A_BASE ); MSP430 Workshop - MSP430 Clocks & Initialization 4 - 63...
  • Page 190 Chapter 04 Appendix Page left almost entirely empty… 4 - 64 MSP430 Workshop - MSP430 Clocks & Initialization...
  • Page 191 … and so on. This chapter discusses how interrupts work; how they are implemented on the MSP430 MCU, and what code we need to write in order to harness their functionality. The lab exercises provided are relatively simple (using a pushbutton to generate an interrupt), but the skills we learn here will apply to all the remaining chapters of this workshop.
  • Page 192 GPIO Interrupt Summary ....................5-30 Interrupt Processing Flow ....................5-30 Interrupts and TI-RTOS Scheduling ..................5-31 Threads – Foreground and Background ................5-31 TI-RTOS Thread Types ....................... 5-33 Summary: TI-RTOS Kernel ....................5-36 Lab Exercise ........................... 5-37 5 - 2 MSP430 Workshop - Interrupts...
  • Page 193: Interrupts

    Both methods signal that we have arrived at our destination. In most cases, though, the use of Interrupts tends to be much more efficient. For example, in the case of the MSP430, we often want to sleep the processor while waiting for an event. When the event happens and signals us with an interrupt, we can wake up, handle the event and then return to sleep waiting for the next event.
  • Page 194 • The #pragma sets up the interrupt vector. The MSP430 has a handy pragma which makes it easy to configure this item. (Note: we’ll cover the details of all these items later in this chapter.)
  • Page 195: Processor States And Interrupts

    In a previous chapter we covered many of the MSP430’s processor states. To summarize, the MSP430 CPU can reside in: Reset, Active, or one of many Low-Power Modes (LPM). In many cases, interrupts cause the CPU to change states. For example, when sitting in Low Power Mode, an interrupt can “wake-up”...
  • Page 196: Threads: Foreground And Background

    ‘forever’ in the background In this case, ‘Background’ implies that it runs at a  while(1){ lower priority than ‘Foreground’ background In MSP430 systems, the background loop often  or LPMx contains a Low Power Mode (LPM) command – this sleeps the CPU/System until an interrupt...
  • Page 197: How Interrupts Work

    Slide left intentionally blank… If you’ve been reading this chapter, you might notice that we’ve already covered these four items. Over the next few pages we enumerate these steps again, filling-in additional details. MSP430 Workshop - Interrupts 5 - 7...
  • Page 198 Notes:...
  • Page 199: Interrupt Must Occur

    1. Interrupt Must Occur For the processor to respond to an interrupt, it must have occurred. There are many possible sources of interrupts. Later in this chapter we will delve into the MSP430 datasheet which lists all of the interrupt sources.
  • Page 200: Interrupt Is Flagged (And Must Be Enabled)

    The distributed nature of the interrupts provides a number of benefits in terms of device flexibility and future feature expansion; further, it fits nicely with the low-power nature of the MSP430. The only ‘negative’ of distributed interrupts might be that it’s different — it’s just that many of us older engineers are used to seeing all the interrupts grouped together.
  • Page 201 Finally, there’s a “master” switch that turns all interrupts off. This lets you turn off interrupts without having to modify all of the individual IE bits. The MSP430 calls this the global interrupt enable (GIE). It is found in the MSP430 Status Register (SR).
  • Page 202: Cpu's Hardware Response

    We hope the first 3 items are self-explanatory; the current instruction is completed while the Program Counter (PC) and Status Register (SR) are written to the system stack. (You might remember, the stack was setup for the MSP430 by the compiler’s initialization routine. Please refer to the compiler user’s guide for more information.) After saving the context of SR, the interrupt hardware in the CPU clears most of the SR bits.
  • Page 203 The MSP430 Vector Table is similar and dissimilar to other microcontrollers: • The MSP430, like most microcontrollers, uses an Interrupt Vector Table. This is an area of memory that specifies a vector (i.e. ISR address) for each interrupt source. •...
  • Page 204: Your Software Isr

    The other bullets listed under “4. ISR” are related to saving and restoring the context of the system. This is required so that the condition mentioned earlier can be met: “without adversely affecting the code threads already running in the system.” 5 - 14 MSP430 Workshop - Interrupts...
  • Page 205 We show the interrupt flow in a slightly different fashion in the following diagram. As you can see, when an enabled interrupt occurs, the processor will look up the ISR’s branch-to address from a specific address in memory (called the interrupt vector). For the MSP430, this address is defined using the vector pragma.
  • Page 206 How Interrupts Work Nesting Interrupts (not recommended) Finally, while the MSP430 allows nesting of interrupts, it is not recommended. • Nesting interrupts means one interrupt can interrupt another interrupt. • You must manually configure nesting. That is, before running your interrupt handling code you must: −...
  • Page 207: Interrupts: Priorities & Vectors

    In the previous paragraph we used the phrase “pending priority” deliberately. As you might remember from the last topic in this chapter, interrupts on the MSP430 do not nest within each other by default. This is because the global interrupt (GIE) bit is disabled when the CPU acknowledges and processes an interrupt.
  • Page 208: Interrupt Vector (Iv) Registers

    As has been mentioned a couple of times in this chapter, to make responding to grouped interrupts easier to handle, the MSP430 team created the concept of Interrupt Vector (IV) Registers. Reading an IV register will return the highest-priority, pending interrupt in that group; it will also clear that interrupts associated flag (IFG) bit.
  • Page 209: Interrupt Vector Table

    ISR into location “57”. As we saw in a previous topic, this can easily be done using the vector pragma. The MSP430 devices reserve the range 0xFFFF to 0xFF80 for the interrupt vectors. This means that for the ‘F5529, the address for the System Reset interrupt service routine will sit at addresses 0xFFFE –...
  • Page 210 Notes:...
  • Page 211 The preceding interrupt tables were re-drawn to make them easier to view when projected during a workshop. The following slide was captured from ‘F5529 datasheet. This is what you will see if you examine the MSP430 documentation. ‘F5529 Vector Table (From Datasheet) Each device’s datasheet provides a similar vector table listing.
  • Page 212: Dedicated Isr (Interrupt Service Routine)

    1. Put the ISR address into the vector table (using the vector #pragma) 2. Save/Restore the CPU context (using the __interrupt keyword) 3. Write your interrupt handler code (in other words, “Do what needs doing”) 5 - 22 MSP430 Workshop - Interrupts...
  • Page 213 In this example, the output of a GPIO pin is toggled every time the watchdog timer interrupt event occurs. Not all ISR’s will be this short, but we hope this gives you a good starting example to work from. MSP430 Workshop - Interrupts 5 - 23...
  • Page 214: Grouped Isr (Interrupt Service Routine)

    If the first interrupt (TA0CCR0) occurs, it will cause the code at vector address 53 (TIMER_A0_VECTOR) to be executed. • Similarly, the remaining Timer0 interrupts are associated with vector 52. • Finally, the GPIO port (P1) was assigned (by the chip designer) to vector 47. 5 - 24 MSP430 Workshop - Interrupts...
  • Page 215 F5xx device Users Guide and the F5xx DriverLib User’s Guide. You will find similar documentation for all MSP430 devices..) If our program was using Pin 2 on Port 1, you should see the code for case 0x06 executed if the GPIO interrupt occurs.
  • Page 216: Enabling Interrupts

    IFG before setting IE when you want to ignore any prior interrupt event; in other words, clear the flag first if you only care about interrupts that will occur now – or in the future. 5 - 26 MSP430 Workshop - Interrupts...
  • Page 217 What makes the MSP430 such a good fit for this application is: (1) it’s inexpensive; and (2) when a load is not present and nothing needs to be charged, it can turn off the external charging components and put itself to sleep –...
  • Page 218 Handling Unused Interrupts While you are not required to provide interrupt vectors – or ISR’s – for every CPU interrupt, it’s considered good programming practice to do so. To this end, the MSP430 compiler issues a warning whenever there are “unhandled” interrupts.
  • Page 219: Miscellaneous Topics

    So, we stated this humorously, but it is very true. We recommend that: • You shouldn’t nest interrupts • If you do, verify the code in your ISR is reentrant • Never call malloc() – or similar functions - from inside an ISR MSP430 Workshop - Interrupts 5 - 29...
  • Page 220: Gpio Interrupt Summary

    P1IFG: Interrupt Flag register for Port 1  There are other devices in the MSP430 family that support interrupts on more than 2 ports, but of the three example processors we use throughout this course, only the FR5969 (Wolverine) devices support interrupt inputs on additional ports (P3 and P4).
  • Page 221: Interrupts And Ti-Rtos Scheduling

    – using a Real-Time Operating System (RTOS) can greatly increase your system’s reliability … while decreasing your time-to-market, frustration and costs. The Texas Instruments RTOS (TI-RTOS) – also known as SYS/BIOS – provides many functions that you can use within your program; for example, the TI-RTOS kernel includes: Scheduling, Instrumentation, and Memory Management.
  • Page 222 TI-RTOS has you add them to Idle. (TI-RTOS includes a GUI configuration tool that makes this very easy to do.) Since interrupts are part of the MSP430’s hardware, they essentially work the same way when using TI-RTOS. What changes when using RTOS are: •...
  • Page 223: Ti-Rtos Thread Types

    If all of this sounds complicated, it really isn’t. While outside the scope of this course, the TI- RTOS course will have you up-and-running in no time. Once you experience the effective organization provided by an RTOS, you may never build another system without one. MSP430 Workshop - Interrupts 5 - 33...
  • Page 224 While you can construct a time-slicing system using TI-RTOS, this is not commonly done. While time-slicing can be a very effective technique in host operating systems (like Windows or Linux), it is not a common method for scheduling threads in an embedded system. 5 - 34 MSP430 Workshop - Interrupts...
  • Page 225 We won’t go through the remaining details in this course, though we suspect that you can all follow the diagram. For this slide, and a lot more information, please refer to the TI-RTOS Kernel Workshop. MSP430 Workshop - Interrupts 5 - 35...
  • Page 226: Summary: Ti-Rtos Kernel

    Remember, we make our money selling you devices. Our code and tools are there to help you get your programs put together – and your systems to market – more quickly. * That is, it’s free for use on all Texas Instruments processors. 5 - 36...
  • Page 227 Lab 5 – Interrupts Lab 5 – Interrupts This lab introduces you to programming MSP430 interrupts. Using interrupts is generally one of the core skills required when buiding embedded systems. If nothing else, it will be used extensively in later chapters and lab exercises.
  • Page 228 (Optional) Lab 5b – Can You Make a Watchdog Blink? ............. 5-51 Import and Explore the WDT_A Interval Timer Example ..........5-51 Run the code ........................5-53 Change the LED blink rate ....................5-53 Appendix ..........................5-54 5 - 38 MSP430 Workshop - Interrupts...
  • Page 229: Interrupts

    2. Why keep ISR’s short (i.e. Why shouldn’t you do a lot of processing in them)? _________________________________________________________________________ __________________________________________________________________________ 3. What causes the MSP430 to exit a Low Power Mode (LPMx)? _________________________________________________________________________ 4. Why are interrupts generally preferred over polling? __________________________________________________________________________...
  • Page 230: Interrupt Priorities & Vectors

    // Toggle the LED on/off GPIO_toggleOutputOnPin( GPIO_PORT_P1, GPIO_PIN0 ); What is wrong with this GPIO port ISR? __________________________________________________________________________ __________________________________________________________________________ 12. How do you pass a value into (or out from) and interrupt service routine (ISR)? __________________________________________________________________________ 5 - 40 MSP430 Workshop - Interrupts...
  • Page 231 Lab 5 – Interrupts ISR’s for Group Interrupts As we learned earlier, most MSP430 interrupts are grouped. For example, the GPIO port interrupts are all grouped together. 13. For dedicated interrupts (such as WDT interval timer) the CPU clears the IFG flag when responding to the interrupt.
  • Page 232: Lab 5A - Push Your Button

    1. Close all previous projects. Also, close any remaining open files. 2. Import the solution for Lab 4a from: lab_04a_clock_solution Select import previous CCS project from the Project menu: Project → Import Existing CCS Eclipse Project 5 - 42 MSP430 Workshop - Interrupts...
  • Page 233 – since, at this point, all of the interrupts are unused. As you add each interrupt to the project, you will need to modify this file. MSP430 Workshop - Interrupts 5 - 43...
  • Page 234 (Fix any error that pops up.) Hint: If you are commenting out the code, it’s easiest to select all the code and hit the Ctrl-/ keys: This toggles the line comments on/off. 5 - 44 MSP430 Workshop - Interrupts...
  • Page 235: Configure/Enable Gpio Interrupt

    10. Launch the debugger. 11. Set a breakpoint on the “enable GIE” line of code in main.c. 12. Next, set a breakpoint inside the ISR in the unused_interrupts.c file. MSP430 Workshop - Interrupts 5 - 45...
  • Page 236 You can find it under the Core Registers at the top of the Registers window. You should notice that the GIE bit equals 0, since we haven’t executed the line of code enabling interrupts globally, yet. 5 - 46 MSP430 Workshop - Interrupts...
  • Page 237 Did that cause the program to stop at the breakpoint we set in the ISR? If you hit Suspend in the previous step, did you remember to hit Resume afterwards? (If it didn’t stop, and you cannot figure out why, ask a neighbor/instructor for help.) MSP430 Workshop - Interrupts 5 - 47...
  • Page 238: Add A Simple Interrupt Service Routine (Isr)

    Location (sometimes it’s also called Interrupt Priority) in the Interrupt Vector table. You can find this in the chapter discussion or the datasheet. Once you’ve done so, you should see the correlation with the PORT1_VECTOR. 5 - 48 MSP430 Workshop - Interrupts...
  • Page 239 We didn’t see the light toggle-off – and we didn’t stop at the breakpoint inside the ISR. Some of you may have already known this was going to happen. If you’re still unsure, go back to Step 13 from our worksheet (page 5-41). We discussed it there. MSP430 Workshop - Interrupts 5 - 49...
  • Page 240 If the breakpoint in the ISR is still set, you should see the processor stop for each button press (and you’ll need to click Resume). You’re welcome to explore the code further by single-stepping thru code, using breakpoints, syspending (halting) the processor and exploring the various registers. 5 - 50 MSP430 Workshop - Interrupts...
  • Page 241: (Optional) Lab 5B - Can You Make A Watchdog Blink

    (Whereas the GPIO Port interrupt had 8 interrupts that shared one vector.) Import and Explore the WDT_A Interval Timer Example 1. Import the wdt_a_ex2_intervalACLK project from the MSP430 DriverLib examples. We’re going to “cheat” and use the example provided with MSP430ware to get the WDT_A timer up and running.
  • Page 242 Since WDT has a dedicated interrupt vector, the code inside the ISR is simple. We do not have to manually clear the IFG bit, or use the IV vector to determine the interrupt source. 5 - 52 MSP430 Workshop - Interrupts...
  • Page 243: Run The Code

    5. Modify the example to blink the LED at 2 second intervals. (Hint: choose clock divide by 32K.) 6. Build and run the example again. If you want, you can experiment with other clock divider rates to see their affect on the LED. MSP430 Workshop - Interrupts 5 - 53...
  • Page 244: Appendix

    INEFFICIENT. Do interrupt follow-up processing in while{} loop … or use TI-RTOS kernel. ______________________________________________________ 3. What causes the MSP430 to exit a Low Power Mode (LPMx)? ______________________________________________________ Interrupts 4. Why are interrupts generally preferred over polling? ______________________________________________________ They are a lot more efficient.
  • Page 245 WDT interval timer interrupt? If so, is there anything you could do to your code in order to allow this to happen? ______________________________________________________ No, by default, MSP430 interrupts are disabled when running an ISR. To ______________________________________________________ enable this you could settup interrupt nesting (though this isn’t recommended)
  • Page 246 Interrupts cannot pass arguments, we need to use global variables ______________________________________________________ ISR’s for Group Interrupts As we learned earlier, most MSP430 interrupts are grouped. For example, the GPIO port interrupts are all grouped together. 13. For dedicated interrupts (such as WDT interval timer) the CPU clears the IFG flag when responding to the interrupt.
  • Page 247 Timers are the solution. This chapter begins with a brief summary of the MSP430 Timers. Most of the chapter, though, is spent digging into the details of the MSP430’s TIMER_A module. Not only does it provide rudimentary counting/timing features, but provides sophisticated capture and compare features that allow a variety of complex waveforms –...
  • Page 248 Prerequisites and Tools To get full entitlement from this chapter, we expect that you are already familiar with MSP430ware’s DriverLib as well as MSP430 clocking and interrupts. The “extra” piece of hardware required for this chapter is a single jumper wire.
  • Page 249: Overview Of Msp430 Timers

    Overview of MSP430 Timers Overview of MSP430 Timers The MSP430F5529 timers are highlighted in the following block diagram. • Yellow marks the three instances of the TIMER_A module. • Pink was used for TIMER_B. • Dark brown highlights the real-time clock (RTC_A).
  • Page 250: Timer_A/B Nomenclature

    (What happened to _C? Even I don’t know that. <ed>) The use of a suffix is the generic naming convention found on the MSP430. With the timers, though, there are a couple more naming variations to be discussed. As we will cover in great detail during this chapter, these timers contain one or more Capture and Compare Registers (CCR);...
  • Page 251: Timer Summary

    Overview of MSP430 Timers Timer Summary The ‘F5529 contains most of the different types of timers found across the MSP430 family; in fact, the only type of timer not present on this device is the high-resolution TIMER_D. The following summary provides a snapshot of what timers are found on various MSP430 devices.
  • Page 252: Timer Basics: How Timers Work

    TIMER_A, the interrupt flag bit for this event is called TAIFG (TIMER_A Interrupt Flag). The clock input signal for TIMER_A (named TACLK) can be one of the internal MSP430 clocks or a signal coming from a GPIO pin.
  • Page 253: Frequency, Time-Period, Resolution

    CPU get to reading the counter … and how consistent can this be each time it occurs There is a better way to implement this in your system … turn the page and let’s examine the timer’s Capture feature. MSP430 Workshop - Timers 6 - 7...
  • Page 254: Capture

    A few notes about the capture feature: • As we discussed earlier, the MSP430 timers (TIMER_A, TIMER_B, and TIMER_D) have multiple CCR registers; check your datasheet to determine how many are available per timer peripheral. Each CCR, though, has its own capture input signal.
  • Page 255: Compare

    The “modify pin” action is a very powerful capability. Using the timer’s compare feature, we can create sophisticated PWM waveforms. (Don’t worry, there’s more about this later in the chapter.) MSP430 Workshop - Timers 6 - 9...
  • Page 256 The clock input can be further divided down by a 5-bit scalar. • The TA0IE interrupt enable can be used to allow (or prevent) an interrupt (TA0IFG) from reaching the CPU whenever the counter (TA0R) rolls over. 6 - 10 MSP430 Workshop - Timers...
  • Page 257 As we go through the rest of this chapter, we’ll examine further details of the CCR registers as well as the various “actions” that the timer generates. In the next section, we’ll begin examining how to configure the timer using the MSP430ware DriverLib API. MSP430 Workshop - Timers 6 - 11...
  • Page 258: Timer Details: Configuring Timer_A

    (While interrupts were covered in the last chapter, we briefly summarize this again in context of the Timer_A.) We will intermix how to write code for the timer with further examination of the timer’s features. 6 - 12 MSP430 Workshop - Timers...
  • Page 259: Counter: Timer_A_Configure

    TA0IE bit. TA0R: Name for count register • Finally, do you want to have the timer counter register (TA0R) reset when referring to instance “0” when the other parameters are configured? (i.e. Timer0_A) MSP430 Workshop - Timers 6 - 13...
  • Page 260: Timer Counting Modes

    There are three different ways that the timer counter (TAR) can be incremented. These correlate to the three configuration functions listed on the previous page. This page provides a single-slide summary of the different modes – but we’ll examine each one over the following three pages. 6 - 14 MSP430 Workshop - Timers...
  • Page 261 As you can see, every time the counter rolls back to zero, the TAIFG bit gets set; which, if input clocks. (Since our previous example was for enabled, interrupts the processor every 2 Timer0_A, the diagram shows TA0IFG getting set.) MSP430 Workshop - Timers 6 - 15...
  • Page 262 The other special feature of CCR0 is that it provides a dedicated interrupt (CC0IFG). In other words, there is an Interrupt Vector location dedicated to CC0IFG. All the other Timer_A interrupts share a common vector location (i.e. they make up a grouped interrupt). 6 - 16 MSP430 Workshop - Timers...
  • Page 263 The two interrupts are spaced at ½ the time period from each other. − When using multiple CCR registers, you can get two compare interrupts per cycle. (We’ll see more on this later.) − MSP430 Workshop - Timers 6 - 17...
  • Page 264 Clock Pre-scaler TIMER_A_CLOCKSOURCE_DIVDER_xx Timer Period Not applicable Used to set the CCR0 value Enable the TAIE interrupt? TIMER_A_TAIE_INTERRUPT_xxxxxx Enable the CCR0 interrupt? Not applicable Used to set TA0CC0IFG Clear the counter (TAR) ? TIMER_A_DO_CLEAR 6 - 18 MSP430 Workshop - Timers...
  • Page 265: 2A. Capture: Timer_A_Initcapture()

    Use one for capture and the rest for compare. Or, use all for capture. You get to decide how they are used. Warning: If you are using Up or UpDown count modes, you should not configure CCR0. Just remember that the TIMER_A_configureUpMode() TIMER_A_configureUpDownMode() configuration functions handle this for you. MSP430 Workshop - Timers 6 - 19...
  • Page 266 CCR6’s Output signal. The output signal can be used by other peripherals or routed to the TA0.6 pin. Note: With regards to OutputMode, this is just the tip-of-the-iceberg. There are actually 8 possible output mode settings. We will take you through them later in the chapter. 6 - 20 MSP430 Workshop - Timers...
  • Page 267: 2B. Compare: Timer_A_Initcompare()

    (in this case, TA0.2). − Again, similar to the Capture mode, there are a variety of possible output modes for the OUT2 signal (which will be discussed shortly). MSP430 Workshop - Timers 6 - 21...
  • Page 268 The OutputMode setting will be configured using the “Set/Reset” mode (which correlates to the value 0x3). Once again, with so many different output mode choices, we’ll defer the full explanation of this until the next topic. 6 - 22 MSP430 Workshop - Timers...
  • Page 269: Summary Of Timer Setup Code - Part 2

    CCR registers – in which case, our initTimerA0() function would become a lot longer. Before we move onto Part 3 of our timer configuration code, let’s spend a few pages explaining the 8 different output mode options available when configuring Capture/Compare Registers. MSP430 Workshop - Timers 6 - 23...
  • Page 270: Output Modes

    The exact details for this are TA0.1 = TA0CCTL1.OUT. (Sometimes you’ll just see this OUT bit abbreviated as OUT1.) Besides routing the CCR OUT signal to a pin, it can also be used by other MSP430 peripherals. For example, on some devices the A/D converter could be triggered by the timer directly.
  • Page 271 Timer Details: Configuring TIMER_A Before we examine OutputMode 2, let’s consider the nomenclature used in the MSP430 User’s Guide. Apparently, there is an EQU (equate) signal inside the timer for each CCR. For example, the equate signal for CCR1 would be called EQU1. While these EQU values cannot be read directly from any of the timer control registers, the documentation makes use of them to describe when a comparison becomes true.
  • Page 272 (i.e. width) is proportional to the difference between CCR0 and CCR1. By showing both OUTMOD=1 and OUTMOD=2 in the same diagram, you can see how the value of OUT can be very different depending upon the OutputMode selected. 6 - 26 MSP430 Workshop - Timers...
  • Page 273 Routing the OUT signal to a pin, as shown here, lets us drive external hardware directly from the output of the timer. (In fact, we’ll use this feature to let the timer directly drive an LED during one of the upcoming lab exercises.) MSP430 Workshop - Timers 6 - 27...
  • Page 274 In this case, though, CCRn = CCR0. That means these modes could be trying to change OUT0 in two different ways at the same time. Bottom Line: When using CCR0, only set OUTMOD to 0, 1, 4, or 5. 6 - 28 MSP430 Workshop - Timers...
  • Page 275: Pwm Anyone

    In this example, CCR0 – CCR1 = amount of time Signal is High  In the case of the MSP430, any timer can generate a PWM waveform by configuring the CCR registers appropriately. In fact, if you are using a Timer_A5, you could output 4 or 5 different PWM waveforms.
  • Page 276: Clear Interrupt Flags And Timer_A_Starttimer()

    Why, because we thought it had already been specified by using the TIMER_A_configureUpMode() function. Well, we found out the hard way that you need to do both. Use the correct function AND specify the correct count mode in the start function. 6 - 30 MSP430 Workshop - Timers...
  • Page 277: Interrupt Code (Vector & Isr)

    The last part of our timer code is actually a review since interrupts were covered, in detail, in a previous workshop chapter. Remember, TIMER_A has two interrupt vectors: one dedicated to CCR0; another shared by TAIFG and all the other CCR’s. Below, we provide a simple example of handling both. MSP430 Workshop - Timers 6 - 31...
  • Page 278 TIMER_A_getOutputForOutputModeOutBitValue() TIMER_A_getCaptureCompareInterruptStatus() TIMER_A_setOutputForOutputModeOutBitValue() TIMER_A_clearCaptureCompareInterruptFlag() TIMER_A_clearTimerInterruptFlag() The bottom of the slide contains two boxes: one summarizes the Interrupt related functions while the other contains three functions that read/write the input and output bit values. 6 - 32 MSP430 Workshop - Timers...
  • Page 279: Differences Between Timer's A And B

    Hint: For a more complete understanding of these differences, we highly recommend that you refer to MSP430 Microcontroller Basics. John Davies does a great job of describing the differences between these timers. Furthermore, his discussion of generating PWM waveforms using these timers is extremely good. If you’ve never heard of the differences between edge-aligned and centered PWM waveforms, check out his MSP430 book.
  • Page 280 Notes:...
  • Page 281 Lab 6 – Using Timer_A Note: The solutions exist for all of these exercises, but the instructions for Lab 6d are not yet included. These will appear in a future version of the course. MSP430 Workshop - Timers 6 - 35...
  • Page 282 (Extra Credit) Lab 6c – Timer using Up Mode ................ 6-51 Lab 6c Worksheet ....................... 6-51 File Management ........................ 6-54 Change the GPIO Setup ..................... 6-54 Change the Timer Setup Code ................... 6-55 Debug/Run .......................... 6-56 Chapter 6 Appendix ........................ 6-59 6 - 36 MSP430 Workshop - Timers...
  • Page 283: Timers

    Hint: Since we are interested in 2 seconds, a slow clock might work best. Another Hint: Look up the arguments for the TIMER_A_configureContinuousMode( ) function in the MSP430® Peripheral Driver Library User’s Guide. MSP430 Workshop - Timers 6 - 37...
  • Page 284 (timer_a.h). TIMER_A_configureContinuousMode( // Setup Timer A0 TIMER_A0_BASE, // Timer clock source _______________________________________, // Timer clock divider _______________________________________, // Enable interrupt on TAR counter rollover _______________________________________, // Clear TAR & previous divider state TIMER_A_DO_CLEAR 6 - 38 MSP430 Workshop - Timers...
  • Page 285 // Pin 6 case 16: break; // Pin 7 default: _never_executed(); Hint: On your Launchpad, what Port/Pin number does the Green LED use? ______________ Please verify your answers before moving onto the lab exercise. MSP430 Workshop - Timers 6 - 39...
  • Page 286 Notes:...
  • Page 287: File Management

    Verify that both LED GPIO outputs are properly configured – adding the code, if necessary. That means, on the F5229 Launchpad, setting up both P1.0 and P4.7. Also, we recommend initializing LEDs by turning them off. 6. Build the project to verify no errors were introduced. MSP430 Workshop - Timers 6 - 41...
  • Page 288: Setup The Timer

    Failing to do this will generate a build error. (Most of us saw this error back during the lab exercise for the Interrupts chapter.) 11. Build the code. Verify there are no syntax errors. 6 - 42 MSP430 Workshop - Timers...
  • Page 289: Debug/Run

    Make sure your program is executing the GPIO instruction. A common error, in this case, is accidentally putting the “do something” code (in our case, the GPIO toggle function) into the wrong ‘case’ statement. MSP430 Workshop - Timers 6 - 43...
  • Page 290: (Extra Credit) Lab 6B - Timer Using Up Mode

    What value do we need to set CCR0 to get a ½ second interval? 32 KHz 32 KHz ÷ Timer Frequency clock frequency timer clock divider 32 KHz ½ second ÷ Timer Output timer frequency timer period (i.e. CCRO value) 6 - 44 MSP430 Workshop - Timers...
  • Page 291 // Timer clock divider TIMER_A_CLOCKSOURCE_DIVIDER_1, (calculated in previous question) // Period _______________________________________, // Enable interrupt on TAR counter rollover TIMER_A_TAIE_INTERRUPT_ENABLE, // Enable CCR0 compare interrupt _______________________________________, // Clear TAR & previous divider state TIMER_A_DO_CLEAR MSP430 Workshop - Timers 6 - 45...
  • Page 292 Here we’ve given you a bit of code to get you started: #pragma vector= _________________________________ __interrupt void ccr0_ISR (void) // Toggle the Red LED on/off _______________________________________________________________ Please verify your answers before moving onto the lab exercise. 6 - 46 MSP430 Workshop - Timers...
  • Page 293: File Management

    Failing to do this will generate a build error. (Most of us saw this error back during the lab exercise for the Interrupts chapter.) 10. Build the code to verify that there are no syntax errors; fix any as needed. MSP430 Workshop - Timers 6 - 47...
  • Page 294: Debug/Run

    Once you reach the first breakpoint, resume running your code and you should reach the other ISR. Which ISR was reached first? _________________________________________________ Why? ____________________________________________________________________ 13. Remove the breakpoints and let the code run. Do both LED’s toggle? 6 - 48 MSP430 Workshop - Timers...
  • Page 295: Archive And Close The Project

    Select ‘Archive File’ for export, then click Next − Fill out the dialog as shown below, choosing: the ‘upTimer’ lab; “Save in zip format”, “Compress the contents of the file”; and the following destination: C:\msp430_workshop\<target>\lab_06b_upTimer\my_lab_06b_upTimer.zip MSP430 Workshop - Timers 6 - 49...
  • Page 296 Notes:...
  • Page 297: (Extra Credit) Lab 6C - Timer Using Up Mode

    2. Write the function to set this Pin/Port to be used as a timer pin (as opposed to an output pin) GPIO_setAs________________________________( ___________, ___________ ); 3. Which Port/Pin drives the Red LED? Port ______ Pin _______ MSP430 Workshop - Timers 6 - 51...
  • Page 298 // Clear TAR & previous divider state TIMER_A_DO_CLEAR 5. What ‘compare’ value does CCR2 need to equal in order to toggle the output signal at ¼ second? ½ Second CCR0=0x8000 CCR2 = __________________ CCR2 ¼ Second 6 - 52 MSP430 Workshop - Timers...
  • Page 299 GPIO_toggleOutputOnPin( GPIO_PORT_P4, GPIO_PIN7 ); break; default: _never_executed(); During debug, we will ask you to set a breakpoint on ‘case 4’. Why should case 4 be skipped, and thus, the breakpoint never reached? _________________________________________________________________________ _________________________________________________________________________ MSP430 Workshop - Timers 6 - 53...
  • Page 300: File Management

    Similar to the earlier parts of the lab, we will make the changes discussed in the worksheets. 5. Modify the initGPIO function, defining the appropriate pin to be configured for peripheral (i.e. timer) functionality. Please refer to the Lab6c Worksheet for assistance. (Step 2, Page 6-51). 6 - 54 MSP430 Workshop - Timers...
  • Page 301: Change The Timer Setup Code

    9. Make the minor modification to the timer0_isr() as shown in the worksheet. Please refer to the Lab Worksheet for assistance. (Step 7, Page 6-53). 10. Build the code verifying there are no syntax errors; fix any as needed. MSP430 Workshop - Timers 6 - 55...
  • Page 302 We left the timer configured to break whenever TAR rolled-over to zero. (That is, whenever TA0IFG is set.) 12. Remove the breakpoints and let the code run. Do both LED’s toggle? Why doesn’t the LED toggle? _____________________________________________ 6 - 56 MSP430 Workshop - Timers...
  • Page 303 On the ‘F5529 Launchpad, connect P1.3 (fifth pin down, right-side of board, inside row of pins) to the bottom of the LED jumper (JP8) using the jumper wire. Ask your instructor for a jumper wire, when you need one. MSP430 Workshop - Timers 6 - 57...
  • Page 304 Hint, if you haven’t already tried this trick, delete the last part of the parameter and hit Ctrl_Space: TIMER_A_OUTPUTMODE_ then hit Control-Space Eclipse will provide the possible variations. Double-click on one (or select one and hit return) to enter it into your code. 6 - 58 MSP430 Workshop - Timers...
  • Page 305 ______________________________________________________________________ ______________________________________________________________________ You may want to experiment with a few other output mode settings. It can be fun to see them in action. 18. When done experimenting, close the project. Chapter 6 Appendix MSP430 Workshop - Timers 6 - 59...
  • Page 306 Chapter 6 Appendix 6 - 60 MSP430 Workshop - Timers...
  • Page 307 Chapter 6 Appendix MSP430 Workshop - Timers 6 - 61...
  • Page 308 Chapter 6 Appendix 6 - 62 MSP430 Workshop - Timers...
  • Page 309 Chapter 6 Appendix MSP430 Workshop - Timers 6 - 63...
  • Page 310 Chapter 6 Appendix 6 - 64 MSP430 Workshop - Timers...
  • Page 311 Chapter 6 Appendix MSP430 Workshop - Timers 6 - 65...
  • Page 312 Chapter 6 Appendix 6 - 66 MSP430 Workshop - Timers...
  • Page 313 USB Devices Introduction The MSP430 makes an ideal USB device: ultra-low power, rich integration of peripherals and it’s inexpensive. Do you want to make a Human Interface Device product? Maybe a sensor, such as a barcode reader, that needs to be both low-power (when collecting data), but also capable of ‘dumping’...
  • Page 314 MSP430's USB Support ......................7-5 How USB Works ........................7-11 Descriptions and Classes ......................7-14 Quick Overview of MSP430’s USB Stack ................7-19 ABC’s of USB .......................... 7-21 A. Plan Your System ......................7-21 B. Connect & Enumerate ....................7-22 C.
  • Page 315: Usb Devices

    What is USB? What is USB? MSP430 Workshop - USB Devices 7 - 3...
  • Page 316 • Power mgmt features MSP430 USB Peripheral Supports USB 2.0 standard  Full speed USB device (12Mbps)  Device only  Note: Look at TI’s TivaC processors if you need host, device or OTG support 7 - 4 MSP430 Workshop - USB Devices...
  • Page 317 8 - 32 Portfolio of devices with more (or less) peripheral/memory integration;  this provides basis for different price points USB Launchpad uses the ‘F5529 … found in the middle of the pack  MSP430 Workshop - USB Devices 7 - 5...
  • Page 318: Msp430'S Usb Support

    MSP430's USB Support 7 - 6 MSP430 Workshop - USB Devices...
  • Page 319 MSP430's USB Support MSP430 Workshop - USB Devices 7 - 7...
  • Page 320 – Simply turn the DMA feature ‘on’ and select the channel 4. Limited resource usage – Only uses the USB module, some memory, & a DMA ch; no other resources 5. RTOS-friendly – TI will soon provides using it with TI-RTOS 7 - 8 MSP430 Workshop - USB Devices...
  • Page 321 MSP430's USB Support MSP430 USB API Features, cont. 6. Responsiveness – No risky blocking calls stuck waiting for the host – Data can be transferred “in the background”, for increased system responsiveness and efficiency, even with a busy host/bus 7. Easy data interface (CDC and HID-Datapipe) –...
  • Page 322 MSP430's USB Support Suggested Reading “Starting a USB Design Using MSP430™ MCUs” App Note by Keith Quiring  (Sept 2013) (Search ti.com for SLAA457.pdf) “Programmers_Guide_MSP430_USB_API” by Texas Instruments (Aug 2013)  Found in the MSP430 USB Developers Package “USB Complete: The Developer's Guide”...
  • Page 323: How Usb Works

    Endpoint 0 is special case – all USB  devices must have EP0, which is used for setup and control Device MSP430 Endpoints:  16 endpoints (8 in, 8 out)  Each has 64 byte buffer  MSP430 Workshop - USB Devices 7 - 11...
  • Page 324 Large size allowed  No time guarantees Isochronous Guar. time, Periodic  No error handling … Endpoints Not supported on ‘430 Contrary to the name, ‘interrupt’  transfers are not initiated by device Device 7 - 12 MSP430 Workshop - USB Devices...
  • Page 325 How USB Works MSP430 Workshop - USB Devices 7 - 13...
  • Page 326: Descriptions And Classes

    Memory devices also require 1-in/1-out  USB devices must describe their themselves using device descriptors  Host must match descriptors (at run time) with host-side device drivers  MSP430 supports a single configuration with  Device Descriptors one or more interfaces Configuration ...
  • Page 327 Descriptors take form of:  Etc. Device: data-structures   Host: .INF file  “CDC” “HID” “HID” Virtual Setup & Mouse Keyboard COM Port Control … EP0 EP0 EP1 EP1 EP6 EP6 EP7 EP7 Device MSP430 Workshop - USB Devices 7 - 15...
  • Page 328 Descriptions and Classes 7 - 16 MSP430 Workshop - USB Devices...
  • Page 329 Descriptions and Classes MSP430 Workshop - USB Devices 7 - 17...
  • Page 330 Bulk (BOT)  Familiar to user  Silent loading  Familiar to user Advantages  Bulk transport  Interrupt xfers  Allows storage of  Common host apps  Mouse/Keybd data using filesys 7 - 18 MSP430 Workshop - USB Devices...
  • Page 331: Quick Overview Of Msp430'S Usb Stack

    Quick Overview of MSP430’s USB Stack Quick Overview of MSP430’s USB Stack MSP430 Workshop - USB Devices 7 - 19...
  • Page 332 Quick Overview of MSP430’s USB Stack 7 - 20 MSP430 Workshop - USB Devices...
  • Page 333: Abc's Of Usb

    Run Descriptor Tool Provides help & feedback in creating device description  Generates device descriptor files & INF files  If you followed step 3, it automatically drops generated  files into the project MSP430 Workshop - USB Devices 7 - 21...
  • Page 334: Connect & Enumerate

     PROGRESS NOENUM_SUSP → Enumeration succeeds 4. Device is enumerated, bus active ST_ENUM_   handleEnumCompleteEvent() ACTIVE → Host Suspends device/bus ST_ENUM_ 5. Device is enum, but suspended  SUSPENDED  handleSuspendEvent() 7 - 22 MSP430 Workshop - USB Devices...
  • Page 335 ABC’s of USB MSP430 Workshop - USB Devices 7 - 23...
  • Page 336: Managing My App & Transferring Data

    IF{} stmt case ST_ERROR: Most common non-RTOS solution – break;  it’s used in many of the USB default:; examples provided with the API 7 - 24 MSP430 Workshop - USB Devices...
  • Page 337 ABC’s of USB MSP430 Workshop - USB Devices 7 - 25...
  • Page 338 ABC’s of USB 7 - 26 MSP430 Workshop - USB Devices...
  • Page 339 Final Thoughts Final Thoughts MSP430 Workshop - USB Devices 7 - 27...
  • Page 340 Final Thoughts 7 - 28 MSP430 Workshop - USB Devices...
  • Page 341 Starts by importing the Empty USB Example  You add code to read the state of the  pushbutton and send it to the host ( CDC) Read data on host with serial terminal  MSP430 Workshop - USB Devices 7 - 29...
  • Page 342 Lab 7c – CDC ‘Simple Send’ Example ................... 7-39 Lab 7d – Creating a CDC Push Button App................7-41 Import Empty USB Project Steps ..................7-41 Use the Descriptor Tool ...................... 7-42 Add ‘Custom’ Code to Project ..................... 7-44 7 - 30 MSP430 Workshop - USB Devices...
  • Page 343: Lab 7A - Led On/Off Hid Example

    Lab 7a – LED On/Off HID Example Lab 7a – LED On/Off HID Example The MSP430 USB Developers Package contains an example which changes the state of an LED based on string commands sent from the USB host. 1. Import the following example into your workspace using TI Resource Explorer.
  • Page 344 With the USB program running on the Launchpad, let’s connect to it and send it commands. 6. Connect to the USB application. Click the button that tells the HID app to find the USB device with the provided Vendor/Product IDs. 7 - 32 MSP430 Workshop - USB Devices...
  • Page 345 8. In the HID USB application, disconnect from the the command repeated back to the log. USB device; then close the application. 9. Switch back to CCS and Terminate the debugger and close the project. MSP430 Workshop - USB Devices 7 - 33...
  • Page 346: Lab 7B - Led On/Off Cdc Example

    Lab 7b – LED On/Off CDC Example Our next program is another example from the MSP430 USB Developers Package. This program is a near duplicate of the previous lab – that is, it changes the state of an LED based on string commands sent from the USB host.
  • Page 347 Device Manager: devmgmt.msc On Windows XP, you can quickly run the command line from the Start Menu: Start Menu → Run You should find the a USB driver with a problem: MSP430 Workshop - USB Devices 7 - 35...
  • Page 348 Lab 7b – LED On/Off CDC Example 14. Update the MSP430-USB Example driver. For Windows 7, the steps include: Right-click on the driver → Update Driver Software… Click Browse my computer for driver software Select the following (or wherever you installed the USB Developers Package)
  • Page 349: Play With The Demo

    Before we can communicate with the device, though, we also need to open a serial terminal. 16. Open your favorite serial terminal and connect to the MSP430. Putty and Tera Term are common favorites, but we’ll provide directions for using the Terminal built into CCS.
  • Page 350 OK. The Terminal should then show as “CONNECTED”. If the terminal does not connect, then check: − Is the MSP430 USB app running? − Does the USB device show up in the Device Manager? −...
  • Page 351: Lab 7C - Cdc 'Simple Send' Example

    Let’s try one more simple application example before we build our own. This next example simply sends the time (from MSP430’s Real Time Clock) to a serial terminal. 19. Similar to our previous two examples, import the “Simple Sending of Data” project.
  • Page 352 = hourStr[0]; str[1] = hourStr[1]; str[2] = ':'; str[3] = minStr[0]; str[4] = minStr[1]; str[5] = ':'; str[6] = secStr[0]; str[7] = secStr[1]; str[8] = '\n'; 7 - 40 MSP430 Workshop - USB Devices...
  • Page 353: Lab 7D - Creating A Cdc Push Button App

    Finally, we’re going to start by following the first 3 steps provided in TI Resource Explorer for the Empty USB Example. Import Empty USB Project Steps 1. Import the Empty USB Project. As it states in the Resource Explorer, DO NOT RENAME the project (yet). MSP430 Workshop - USB Devices 7 - 41...
  • Page 354: Use The Descriptor Tool

    We will take a quick look at the organization levels in the tool. In most cases, we will use the tools defaults. a) MSP430 level … use the defaults. b) USB Device We suggest changing the Product String – easier to see that it is different than other examples.
  • Page 355 Click the button to generate the descriptor files. Notice they get written to your empty project. (This is the reason we were asked not to change the name until after we had used the Descriptor Tool.) MSP430 Workshop - USB Devices 7 - 43...
  • Page 356: Add 'Custom' Code To Project

    Right-click the project → Add Files… Choose the three files from the location: C:\msp430_workshop\ \lab_07d_usb\ <target> 7. Open main.c and add a #include for the myTimer.h. We suggest doing this somewhere below #include “driverlib.h”. 7 - 44 MSP430 Workshop - USB Devices...
  • Page 357 11. Add #include "USB_app/usbConstructs.h". We need to use this header file since it supports the cdcSendDataInBackground() function we are using to send data via USB. 12. Build and launch debugger. Then run the program. MSP430 Workshop - USB Devices 7 - 45...
  • Page 358 Windows to register the device is missing; then reinserting the device and helping Windows load the driver again. (While that usually works, every once-in-a-while we’ve needed to reboot our computer, as well.) 7 - 46 MSP430 Workshop - USB Devices...
  • Page 359 Basic understanding of using a C library and header files  This chapter doesn’t explain clock, interrupt, and GPIO features in detail,  this is left to the other chapters in the MSP430 workshop Requirements - Tools and Software  Hardware ...
  • Page 360 Lab 8e – Using TIMER_A ....................8-31 Appendix – Looking ‘Under the Hood’ ..................8-32 Where, oh where, is Main ....................8-32 Two ways to change the MSP430 clock source ............. 8-34 Sidebar – initClocks() ...................... 8-35 Sidebar Cont’d - Where is F_CPU defined? ..............8-36 Lab Debrief ..........................
  • Page 361: What Is Arduino

    In the end, Arudino is basically an ecosystem for easy, hardware-oriented, real-world programming. It combines the Tools, Software and Hardware for talking to the world. http://www.wired.com/gadgetlab/2008/04/just-what-is-an/ http://en.wikipedia.org/wiki/Wiring_%28development_platform%29 MSP430 Workshop - Using Energia (Arduino) 8 - 3...
  • Page 362: Energia

     Energia is a rapid electronics prototyping platform for the Texas Instruments msp430 LaunchPad. Energia is based on Wiring and Arduino and uses the Processing IDE. It is a fork of the Arduino ecosystem, but centered around the popular TI microntrollers: MSP430 and ARM Cortex-M4F.
  • Page 363 C++ program. http://en.wikipedia.org/wiki/Design_By_Numbers_%28programming_language%29 http://en.wikipedia.org/wiki/Processing_(programming_language) http://en.wikipedia.org/wiki/Wiring_%28development_platform%29 MSP430 Workshop - Using Energia (Arduino) 8 - 5...
  • Page 364 Processing-based integrated development environment. Energia (2012) – As explained in the previous section of this chapter, Energia is a fork of Arduino which utilizes the Texas Instruments microcontroller Launchpad development boards. Fritzing (2009) - An open-source initiative to support designers, artists, researchers and hobbyists to take the step from physical prototyping to actual product.
  • Page 365: Programming Energia (And Arduino)

    For example, in one of the later lab exercises, you will see how you can change the clock source for the TI MSP430 microcontroller. Changing clocks is often done on the MSP430 so that you can balance processing speed against long battery life.
  • Page 366: Wiring Language/Library Reference

    Arduino provides a language reference on their website. This defines the operators, controls, and functions needed for programming in Arduino (and Energia). You will also find a similar HTML reference available in the Energia installation zip file. Wiring Library Reference http://arduino.cc/en/Reference/HomePage 8 - 8 MSP430 Workshop - Using Energia (Arduino)
  • Page 367: How Does 'Wiring' Compare

    Arduino over to Energia for the TI microcontrollers. MSP430 Workshop - Using Energia (Arduino) 8 - 9...
  • Page 368 Pins can also be address by there alternative names, such as P1_0. These correlate to the GPIO port (P1) and pin (0) names (P1.0) as defined by the MSP430. (In fact, the Launchpads conveniently show which I/O pins are mapped to the Boosterpack header connectors.) Using these symbols, we can write to pins using the following: pinMode(P1_0, OUTPUT);...
  • Page 369 Should you do Pullups or Not? To reduce power consumption, MSP430 Value-Line Launchpads (version V1.5 and later) are shipped without pull-up resistors on PUSH2 (S2 or P1_3 or pin 5). This saves (77uA) if port P1_3 is driven LOW. (On your LaunchPad just below the "M" in the text "MSP-EXP430G2" see if R34 is missing.) For these newer launchpads, sketches using PUSH2 should enable the internal pull-up...
  • Page 370 GPIO pins to evaluate the runtime state of your program sketches. (We explore using LED’s and serial communications in the upcoming lab exercises.) 8 - 12 MSP430 Workshop - Using Energia (Arduino)
  • Page 371: Examples, Lots Of Examples

    Blink is the ‘hello  world’ of micro’s BareMinimum is just  setup() and loop() Selecting example…  Opens sketch in  debugger window Click download to  compile, download and run MSP430 Workshop - Using Energia (Arduino) 8 - 13...
  • Page 372: Energia/Arduino References

    Home: http://energia.nu/  Download: http://energia.nu/download/  Wiki: https://github.com/energia/Energia/wiki  Supported Boards: https://github.com/energia/Energia/wiki/Hardware (H/W pin mapping)  Getting Started: https://github.com/energia/Energia/wiki/Getting-Started  Support Forum: http://forum.43oh.com/forum/28-energia/ Arduino  Site: http://www.arduino.cc/  Comic book: http://www.jodyculkin.com/.../arduino-comic-latest3.pdf 8 - 14 MSP430 Workshop - Using Energia (Arduino)
  • Page 373: Lab 8

    – including trying some of our own. Lab Exercises Installing Energia Blinking the LED Pushing the Button Serial Communication & Debugging PushButton Interrupt Timer Interrupt (Uses Non-Energia Code) Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 15...
  • Page 374: Installing The Launchpad Drivers

    1. To use Energia you will need to have the LaunchPad drivers installed. For Windows Users If TI's Code Composer Studio 5.x with MSP430 suport is already installed on your computer then the drivers are already installed. Skip to the next step.
  • Page 375: Starting And Configuring Energia

    Lab 8 Starting and Configuring Energia 3. Double click Energia.exe (Windows users). Energia will start and an empty Sketch window will appear. Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 17...
  • Page 376 It makes it easier to save and open files if Energia defaults to the folder where you want to put your sketches. The easiest way to set this locations is via Energia’s preferences dialog: File  Preferences Then set the Sketchbook location to: C:\msp430_workshop\<target>\energia Which opens: 8 - 18 Gettings Started with the MSP430 - Using Energia (Arduino)
  • Page 377 6. Select the board you are using – most likely the msp430f5529 (16MHz). To select the board or rather the msp430 in your LaunchPad, select Board from the Tools menu and choose the board that matched the msp430 in the LaunchPad.
  • Page 378: Lab 8A - Blink

    Your First Sketch 1. Open the Blink sketch (i.e. program). Load the Blinky example into the editor; select Blink from the Examples menu. File  Examples  1.Basics  Blink 8 - 20 Gettings Started with the MSP430 - Using Energia (Arduino)
  • Page 379 () { digitalWrite (RED_LED, HIGH); // turn on LED delay (1000); // wait one second (1000ms) digitalWrite (RED_LED, LOW); // turn off LED delay (1000); // wait one second Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 21...
  • Page 380 We recommend you check out the Hardware Pin Mapping to answer this last question. There’s a copy of it in the presentation. Of course, the original is on the Energia wiki. 8 - 22 Gettings Started with the MSP430 - Using Energia (Arduino)
  • Page 381 Flash memory; and, run the program sketch. Did it work? _______________________________________________________________ (We hope so. Please ask for help if you cannot get it to work.) Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 23...
  • Page 382: Lab 8B - Pushing Your Button

    How is the pushbutton created/used differently from the LED? ________________________ _________________________________________________________________________ What “Energia” pin is the button connected to? ___________________________________ What is the difference between INPUT and INPUT_PULLUP? ________________________ _________________________________________________________________________ 8 - 24 Gettings Started with the MSP430 - Using Energia (Arduino)
  • Page 383: Reverse Button/Led Action

    The changes required are similar to what you would do in C, they are not unique to Energia/Arduino. 8. When your changes are finished, upload it to your Launchpad. Did it work? _______________________________________________________________ Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 25...
  • Page 384: Lab 8C - Serial Communication (And Debugging)

    Note: Why are we limited to 9600 baud (roughly, 9600 bits per second)? The G2553 Launchpad’s onboard emulation (USB to serial bridge) is limited to 9600 baud. It is not a hardware limitation of the MSP430 device. Please refer to the wiki for more info: https://github.com/energia/Energia/wiki/Serial-Communication.
  • Page 385: What If The Serial Monitor Is Blank

    J3 jumpers need to be configured differently than how the board is configured out-of-the-box. (This fooled us, too.) Refer to these diagrams for correct operation. (This does not affect other Launchpads.) Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 27...
  • Page 386: Blink With Serial Communication

    12. Examine the sketch, download and run it. How is this sketch different? What makes it more efficient? __________________________ ________________________________________________________________________ How is this (and all our sketches, up to this point) inefficient? ________________________ ________________________________________________________________________ 8 - 28 Gettings Started with the MSP430 - Using Energia (Arduino)
  • Page 387: Lab 8D - Using Interrupts

    In this part of the lab exercise, you will setup two different interrupts. The first one will be triggered by the pushbutton; the second, by one of the MSP430 timers. 1. Once again, let’s start with the Blink code.
  • Page 388 Missing the INPUT_PULLUP is especially common since most Arduino examples – like the one shown on the attachInterrupt() reference page only show INPUT. This is because many boards include an external pullup resistor, Since the MSP430 contains an internal pullup, you can save money by using it instead.
  • Page 389: Lab 8E - Using Timer_A

    In this case, we are not using the attachInterrupt() function to setup the interrupt. If you double-check the Energia reference, it states the function is used for ‘external’ interrupts. In this case, the MSP430’s Timer_A is an internal interrupt. In essense, though, the same three steps are required: a) The interrupt source must be setup.
  • Page 390: Appendix - Looking 'Under The Hood

    Where, oh where, is Main How does Energia setup the system clock? Before jumping into how to change the MSP430 system clock rate, let’s explore how Energia sets up the clock in the first place. Thinking about this, our first question might be…...
  • Page 391 C:\TI\energia-0101E0010\hardware\msp430\cores\msp430\wiring.c The init() function implements the essential code required to get the MSP430 up and running. If you have already completed Chapter 4 – Clocking and Initialization, then you should recognize most of these activities. At reset, you need to perform two essential activies: ...
  • Page 392: Two Ways To Change The Msp430 Clock Source

    Appendix – Looking ‘Under the Hood’ Two ways to change the MSP430 clock source There are two ways you can change your MSP430 clock source:  Modify the initClocks() function defined in wiring.c  Add the necessary code to your Setup() function to modify the clock sources Advantages ...
  • Page 393: Sidebar - Initclocks()

    Clock System) control registers being set to configure the clock sources and speeds. Once again, there are more details on this in Clocking chapter and its lab exercise. Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 35...
  • Page 394: Sidebar Cont'd - Where Is F_Cpu Defined

    Energia forum, we found that it is specified in boards.txt. This is the file used by the debugger to specifiy which board (i.e. target) you want to work with. You can see the list from the ToolsBoard menu. C:\TI\energia-0101E0010\hardware\msp430\boards.txt 8 - 36 Gettings Started with the MSP430 - Using Energia (Arduino)
  • Page 395: Lab Debrief

    Change from P1_0 to P4_7, for the green LED to blink Please describe it here: _________________________________________________ (Easier yet, just use the pre-defined symbol: GREEN_LED) _____________________________________________________________________ 6. Make the other LED blink. Did it work? ____________________________________ Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 37...
  • Page 396 What would be a more efficient way to handle responding to a pushbutton? (And why would this be important to many of us MSP430 users?) It would be more efficient to let the button ‘interrupt’ the processor, as opposed to _____________________________________________________________________ reading the button over and over again.
  • Page 397 ____________________________________________________________________ Similarly, many folks hook up an oscilloscope or logic analyzer to a pin, similar to using an LED. (Since our boards have more pins than LEDs.) ____________________________________________________________________ Gettings Started with the MSP430 - Using Energia (Arduino) 8 - 39...
  • Page 398 When you push the button, does the GREEN_LED light? _____________________ Notes: Use reset button to start program again and clear GREEN_LED  Most common error, not configuring PUSH2 with INPUT_PULLUP.  8 - 40 Gettings Started with the MSP430 - Using Energia (Arduino)

Table of Contents