The basics of application development on a MSP430 16-bit MCU – Part 1

Editor’s Note: In this first of a two part tutorial excerpted from MSP430 Microcontroller Basics , by John H. Davies, the author provides a basic introduction to application development on the Texas Instruments MSP430 16- bit MCU using IAR’s free Embedded Workbench Kickstart integrated development environment.

An enormous number of microcontrollers are available. They ?ll many pages of the distributor catalogs with a tiny typeface. Where does the MSP430 ?t into this spectrum?

The MSP430 was introduced in the late 1990s by Texas Instruments, although its ancestry goes back to the 4-bit TSS400. In summary, it is a particularly straightforward 16-bit processor with a von Neumann architecture, designed for low-power applications. Both the address and data buses are 16 bits wide. The registers in the CPU are also all 16 bits wide and can be used interchangeably for either data or addresses. This makes the MSP430 simpler than an 8-bit processor with 16-bit addresses. Such a processor must use its general-purpose registers in pairs for addresses or provide separate, wider registers.

In many ways, the MSP430 ?ts between traditional 8- and 16-bit processors. The 16-bit data bus and registers clearly de?ne it as a 16-bit processor. On the other hand, it can address only 216 = 64 KB of memory. This is the same as the Freescale HCS08, an 8-bit family that also uses von Neumann memory and whose architecture goes back to the 6800 in the very early days of microprocessors. The corresponding 16-bit family is the HCS12, which uses paging to address up to 8 MB of memory. The absence of pages or banks in the memory makes the MSP430 very simple to use. (The picture is a little different with the MSP430X, which has extended registers and a wider address bus that can handle up to 1 MB of memory.)

Another feature of the MSP430 that stems from its relatively recent introduction is that it is designed with compilers in mind. Most small microcontrollers are now programmed in C, and it is important that a compiler can produce compact, ef?cient code. The MSP430 has 16 registers in its CPU, which enhances ef?ciency because they can be used for local variables, parameters passed to subroutines, and either addresses or data. This is a typical feature of a RISC, but unlike a “pure” RISC, it can perform arithmetic directly on values in main memory. Microcontrollers typically spend much of their time on such operations.

The MSP430 is the simplest microcontroller in TI’s current portfolio. Its more powerful siblings include the TMS470, which is based on the 32/16-bit ARM7, and the C2000, which incorporates a digital signal processor. Several features make the MSP430 suitable for low-power and portable applications:

  • The CPU is small and ef?cient, with a large number of registers.
  • It is extremely easy to put the device into a low-power mode. No special instruction is needed: The mode is controlled by bits in the status register. The MSP430 is awakened by an interrupt and returns automatically to its low-power mode after handling the interrupt.
  • There are several low-power modes, depending on how much of the device should remain active and how quickly it should return to full-speed operation.
  • There is a wide choice of clocks. Typically, a low-frequency watch crystal runs continuously at 32 KHz and is used to wake the device periodically. The CPU is clocked by an internal, digitally controlled oscillator (DCO), which restarts in less than 1 µs in the latest devices. Therefore the MSP430 can wake from a standby mode rapidly, perform its tasks, and return to a low-power mode.
  • A wide range of peripherals are available, many of which can run autonomously without the CPU for most of the time.
  • Many portable devices include liquid crystal displays, which the MSP430 can drive directly.
  • Some MSP430 devices are classed as application-speci?c standard products (ASSPs) and contain specialized analog hardware for various types of measurement.

It is impossible to pick a single number to demonstrate the low-power consumption and great caution is needed when comparing different manufacturers’ claims. For example, the F2013 draws around 4.5 mA when operating at its top speed of 16 MHz. This also needs its maximum supply voltage of 3.5 V. However, the supply can be reduced to 1.8 V and the current falls to 0.2 mA if a speed of 1 MHz is acceptable.

In many applications, the microcontroller spends most of its time in standby mode, when a typical current is below 1 µA. Many batteries have a larger self-discharge current than this. The MSP430 can restart quickly because of its DCO, which may be an important factor in the overall power budget.

As of this writing four families of MSP430 are available. The letter after MSP430 shows the type of memory. Most part numbers include F for ?ash memory but some have C for ROM. There is a second letter for ASSPs to show the type of measurement for which they are intended: E for electricity, W for water, and G for signals that require a gain stage, provided by operational ampli?ers. The next digit shows the family and the ?nal two or three digits identify the speci?c device.

MSP430x1xx: Provides a wide range of general-purpose devices from simple versions to complete systems for processing signals. There is a broad selection of peripherals and some include a hardware multiplier, which can be used as a rudimentary digital signal processor. Packages have 20–64 pins.

MSP430F2xx: A newer, general-purpose family introduced in 2005. Its CPU can run at 16 MHz, double the speed of earlier devices, while consuming only half the current at the same speed. Some come in 14-pin packages, including a traditional plastic dual-in-line (PDIP) option, which is attractive for anybody who has to build circuits by hand. They do not require a crystal for their low-frequency clock. Pull-up or pull-down resistors are provided on the inputs to reduce the number of external components needed. There are many options for analog inputs. Even the smallest, 14-pin devices offer a 16-bit sigma–delta ADC. This family is intended to supersede the MSP430x1xx over the next few years. Devices with the same pin-out and related model numbers are intended as drop-in replacements. For example, the F24x can replace the F14x.

MSP430x3xx: The original family, which includes drivers for LCDs. It is now obsolescent.

MSP430x4xx: Can drive LCDs with up to 160 segments. Many of them are ASSPs, but there are general-purpose devices as well. Their packages have 48–113 pins, many of which are needed for the LCD.

MSP430X: The original MSP430 architecture, extended to give the MSP430X in 2006, mainly so that it can address extra memory but with other improvements as well. Curiously, this is not marketed as a separate family: The devices are included in the MSP430F2xx and MSP430F4xx families with nothing in their part number to distinguish them. The CPU is a MSP430x if there is more than 64 KB of memory.

The letters MSP stand for mixed signal processor , which is a reminder that many practical applications require analog inputs. There is a selection of analog-to-digital converters with a resolution of up to 16 bits. An example of a system where this choice is important is the weighing machine shown in Figure 2 , which is another project formerly used in my department. It includes the following functional blocks:

  • The sensor has four resistive elements arranged as a Wheatstone bridge. Ideally, this is balanced when there is no load, giving V+ = V-. Two of the resistances increase and two decrease when a weight is placed on the scale pan, driving the bridge out of balance.
  • A differential ampli?er magni?es the difference in voltage between its input terminals, giving Vout = A(V+ – V-), where A is the gain.
  • The analog output of the ampli?er is converted to a binary value in an analog-to-digital converter.
  • The microcontroller multiplies the input by an appropriate factor so that the display gives the weight in grams or ounces and subtracts an offset so that the display reads zero when no weight is present. It also reads the buttons and supervises the complete system.
  • There is a serial interface between the microcontroller and the liquid crystal display, which has a built-in controller.

Figure 1: Weighing machine with a liquid crystal display, broken down into individual functions.

This system clearly needs a lot of components, including several integrated circuits. The project was designed this way for pedagogical reasons, to pull together functions that had been covered in other courses that students had taken on analog electronics, embedded systems, digital electronics, circuits, and so on. It was not intended as a practical product, although weighing machines would have been designed this way in the past.

In contrast, the whole system can be constructed from a sensor, an MSP430, a simple LCD without a controller, and a couple of decoupling capacitors. The MSP430x4xx family drives segmented LCDs directly, which eliminates the need for a controller. Several devices contain ADCs with high-resolution, differential inputs, which would work directly from the sensor without the need for an amplifier. The microcontroller can also manage the power drawn by the circuit so that the processor would be switched off when it was not needed and the whole system shut down after a period of inactivity. This is an ideal application for the MSP430—so well suited, in fact, that it is described in the application note MSP430F42x Single-Chip Weight Scale (slaa220) .Kickstarting the MSP430
The IAR Embedded Workbench Kickstart for MSP430 ,or EW430 for short, is a free integrated development environment (IDE)but is limited to 4 KB of C code. (That is more than enough for theexamples in this book.) EW430 is produced by IAR Systems , which also sells unrestricted versions, but Kickstart is distributed and supported by TI.

IAREmbedded Workbench is available for a wide range of processors and I?nd it to be straightforward to use, predictable, and reasonablyreliable if not the most powerful IDE that I encountered. It seems toget better with each release, which is less common than it ought to be.The only problem that I experienced at all frequently is that theemulator loses contact with the device when it enters a low-power modeand it is not hard to see why this might create dif?culties.

TI itself developed another IDE, Code Composer Essentials . (Editor’s Note: ComposerEssentials (CCE) has merged with Code Composer Studio v4 to bringdevelopment for all TI's embedded processors, including MSP430 under asingle IDE .) The environment is based on the Eclipse open-sourceplatform, with a distinctive look and feel. Some aspects, such as thedirectives in assembly language, are entirely different from EW430.

Plentyof documents support EW430. These include a user guide and referenceguides for the assembler and the C/C++ compiler. The user guide includesa tutorial but it is of a general nature and not speci?c to the MSP430.Further information is in the MSP-FET430 Flash Emulation Tool (FET) User’s Guide (slau138) ,which is updated for each release of EW430. The “Frequently AskedQuestions” are particularly valuable and will solve many of yourproblems. The ?rst step is to install the software from a CD or afteryou have downloaded it. I’ve never had any problems with this.

Figure 2 showsa screenshot of EW430 in use for editing a program. I took this andother images from a screen with a width of only 800 pixels so that thetext is legible when reduced to ?t on the page. You almost certainlyhave a larger screen and are able to ?t more into the windows. There isthe usual menu bar along the top and a toolbar underneath. I describehow to perform actions using the menus and leave you to exploreshortcuts. The main part of the screen is divided into three windows.

Workspace window: Has individual tabs for each project in the current workspace with anOverview in the leftmost tab. Make a project active by selecting itstab.

A project   shows the relations between all the ?lesneeded to produce an application. This obviously includes your sourcecode, C or assembly language (or both). The project also shows theheader (.h) ?les that you include and ?les that provide otherinformation needed to make the application, such as linker scripts(.xcl). Other ?les are added to the project after the IDE has compiledand linked the code. I show all of these in Figure 2 but most of the tree is collapsed by default.

Figure 2: EW430 while editing a C program. It shows the ?le main.c in the project first.

Thereare two columns after the name of each ?le. The ?rst shows that optionshave been set for this ?le. Normally there is a checkmark only againstthe project itself but sometimes a ?le needs its own, special settings.The third column contains a red blob if errors were detected when the?le was last compiled or if the ?le has been modi?ed and not yetrecompiled.

The layout of ?les in the workspace window showstheir logical hierarchy within the project and bears little relationshipto the directory structure on the hard disk.

Each project canhave several con?gurations, shown in the drop-down list at the top ofthe Workspace window. There are two by default, Debug and Release.Typically the Release con?guration omits debugging information and ismore highly optimized. I use only the Debug con?guration but this wouldnot be a good idea for a version to be released commercially.

Aworkspace contains a set of related projects. For large-scaledevelopment the projects might be slightly different versions of thesoftware, which share many ?les. I simply used a workspace for theprograms in each chapter of this book. Figure 3, shown in Part 2 of thisarticle, shows a workspace window that contains several projects withthe Overview tab on the left, which shows a list of all the projects inthe workspace.

Editor window: Where you type and edit yoursource code, as you might expect. Several ?les can be edited or viewedby using tabs or multiple windows. It is convenient to see both thesource code and header ?les, for instance. There are the usual featuresfor editing code including syntax coloring and so on, which can beadjusted with the menu item Tools > Options.

Messages window: Shows text output from the tools, such as error messages from the compiler.

Read Part 2 of this article.

John M. Davies is head of the Aerospace Engineering Teaching Discipline in the Schoolof Engineering at the University of Glagow, United Kingdom. Hepreviously taught at Cambridge University and Ohio State University. Inaddition to microprocessor development, his research interests andpublications cover a wide range, including physics, elasticity andelectronics, mainly centered around semiconducting heterostructures.

Used with permission from Newnes, a division of Elsevier, Copyright 2010, this article was excerpted from MSP430 Microcontroller Basics , by John H. Davies.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.