Teaching and Classroom Laboratories Based On The Ez430 and Experimenters Board Msp430 Microcontroller Platforms and Code Composer Essentials 3.1
Teaching and Classroom Laboratories Based On The Ez430 and Experimenters Board Msp430 Microcontroller Platforms and Code Composer Essentials 3.1
Collection Editors:
Pedro Dinis
António Espírito Santo
Teaching and classroom laboratories based
on the “eZ430” and "Experimenter’s board"
MSP430 microcontroller platforms and
Code Composer Essentials
Collection Editors:
Pedro Dinis
António Espírito Santo
Authors:
Pedro Dinis
António Espírito Santo
Bruno Ribeiro
Online:
< http://cnx.org/content/col10706/1.3/ >
CONNEXIONS
4 Timers
4.1 Laboratory Timers: Lab1 - Memory clock with Basic Timer1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.2 Laboratory Timers: Lab2 - Real Time Clock with Basic Timer1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.3 Laboratory Timers: Lab3 - Memory Clock with Timer_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.4 Laboratory Timers: Lab4 - Buzzer tone generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.5 Laboratory Timers: Lab5 - Frequency measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
5 LCD Controller
5.1 Laboratory LCD controller: Lab1 - LCD message display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6 Data Acquisition
6.1 Laboratory Signal Acquisition: Lab1 - SAR ADC10 conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
6.2 Laboratory Signal Acquisition: Lab2 - SAR ADC12 conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6.3 Laboratory Signal Acquisition: Lab3 - SD16_A ADC conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.4 Laboratory Signal Acquisition: Lab4 - Voltage signal comparison with Compara-
tor_A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
9 Hardware Multiplier
9.1 Laboratory Hardware Multiplier: Lab1 - Multiplication without hardware multi-
plier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
9.2 Laboratory Hardware Multiplier: Lab2 - Multiplication with hardware multiplier . . . . . . . . . . . . 136
iv
9.3 Laboratory Hardware Multiplier: Lab3 - RMS and active power calculation . . . . . . . . . . . . . . . . 138
10 Flash Programming
10.1 Laboratory Flash memory: Lab1 - Flash memory programming with the CPU
executing the code from ash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
10.2 Laboratory Flash memory: Lab2 - Flash memory programming with the CPU
executing the code in RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
11 Communication
11.1 Laboratory Communications: Lab1 - Echo test using the UART mode of the
USCI module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
11.2 Laboratory Communications: Lab2 - Echo test using SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
11.3 Laboratory Communications: Lab3 - Echo test using I2C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Attributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
MSP430 Overview
1.1 Introduction1
Introduction
The types of devices such as microprocessor, microcontroller, processor, digital signal processor (DSP),
amongst others, in a certain manner, are related to the same device the ASIC (Application Specic
Integrated Circuit). Each processing device executes instructions, following a determined program applied
to the inputs and shares architectural characteristics developed from the rst microprocessors created in 1971.
In the three decades after the development of the rst microprocessor, huge developments and innovations
have been made in this engineering eld. Any of the terms used at the beginning of this section are correct
to dene a microprocessor, although each one has dierent characteristics and applications.
The denition of a microcontroller is somewhat dicult due to the constantly changing nature of the
silicon industry. What we today consider a microcontroller with medium capabilities is several orders of
magnitude more powerful, than the computer used on the rst space missions. Nevertheless, some gener-
alizations can be made as to what characterizes a microcontroller. Typically, microcontrollers are selected
for embedded systems projects, i.e., control systems with a limited number of inputs and outputs where the
controller is embedded into the system.
The programmable SoC (system-on-chip) concept started in 1972 with the 4-bit TMS1000 microcomputer
developed by Texas Instruments (TI), and in those days it was ideal for applications such as calculators and
ovens. This term was changed to Microcontroller Unit (MCU), which was more descriptive of a typical
application. Nowadays, MCUs are at the heart of many physical systems, with higher levels of integration
and processing power at lower power consumption.
The following list presents several qualities that dene a microcontroller:
- Cost: Usually, the microcontrollers are high-volume, low cost devices;
- Clock frequency: Compared with other devices (microprocessors and DSPs), microcontrollers use a low
clock frequency. Microcontrollers today can run up to 100 MHz/ 100 Million Instructions Per Second (MIPS)
- Power consumption: orders of magnitude lower than their DSP and MPU cousins;
- Bits: 4 bits (older devices) to 32 bits devices;
- Memory: Limited available memory, usually less than 1 MByte;
- Input/Output (I/O): Low to high (8-150) pin-out count.
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
2
1 This content is available online at <http://cnx.org/content/m23492/1.1/>.
2 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
1
2 CHAPTER 1. MSP430 OVERVIEW
Flexibility:
The microcontroller's performance is directly related to the 16-bit data bus, the 7 addressing modes and the
reduced instructions set, which allows a shorter, denser programming code for fast execution. These micro-
controller families share a 16-bit CPU (Central Processing Unit) core, RISC type, intelligent peripherals,
and exible clock system that interconnects using a Von Neumanncommon memory address bus (MAB) and
memory data bus (MDB) architecture.
MSP430 architecture.
Figure 1.1
4 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
5 This content is available online at <http://cnx.org/content/m23495/1.1/>.
ROM devices: Identied by the letter C in the part numbers. They have the advantage of being very
inexpensive because they are shipped pre-programmed, which is the best solution for high-volume designs.
Figure 1.2
Vector Ad- Priority ' 11xx and ' 13x and ' `2xx ' 3xx ' 4xx
dress ' 12xx 14x
0xFFFE 31, Highest Hard Reset/ Hard Reset/ Hard Reset/ Hard Reset/ Hard Reset/
Watchdog Watchdog Watchdog Watchdog Watchdog
15 DMA (241x,
261x only)
14 DAC12
(241x, 261
only)
13 to 0Low- Reserved
est
Table 1.1
1.3.2 Flash/ROM
The start address of Flash/ROM depends on the amount of Flash/ROM present on the device. The start
address varies between 01100h (60k devices) to 0F800h (2k devices) and always runs to the end of the address
space at location 0FFFFh. Flash can be used for both code and data. Word or byte tables can also be stored
and read by the program from Flash/ROM.
All code, tables, and hard-coded constants reside in this memory space.
1.3.5 RAM
RAM always starts at address 0200h. The end address of RAM depends on the amount of RAM present on
the device. RAM is used for both code and data.
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
7 This content is available online at <http://cnx.org/content/m23497/1.1/>.
The MSP430 CPU includes an arithmetic logic unit (ALU) that handles addition, subtraction, comparison
and logical (AND, OR, XOR) operations. ALU operations can aect the overow, zero, negative, and carry
ags in the status register.
The 16-bit Program Counter (PC/R0) points to the next instruction to be read from memory and executed
by the CPU. The Program counter is implemented by the number of bytes used by the instruction (2, 4, or
6 bytes, always even). It is important to remember that the PC is aligned at even addresses, because the
instructions are 16 bits, even though the individual memory addresses contain 8-bit values.
The Status Register (SR/R2) stores the state and control bits. The system ags are changed automatically
by the CPU depending on the result of an operation in a register. The reserved bits of the SR are used to
support the constants generator. See the device-specic data sheets for more details.
SR
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Table 1.2
Bit Description
Table 1.3
R2 00 - Register mode
R3 01 00001h +1
Table 1.4
These general-purpose registers are used to store data values, address pointers, or index values and can be
accessed with byte or word instructions.
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
8
The MSP430X CPU extends the addressing capabilities of the MSP430 family beyond 64 kB to 1 MB. To
achieve this, there are some changes to the addressing modes and two new types of instructions. One type of
new instructions allows access to the entire address space, and the other is designed for address calculations.
The MSP430X CPU address bus is 20 bits, but the data bus is still 16 bits. The CPU supports 8-bit,
16-bit and 20-bit memory accesses. Despite these changes, the MSP430X CPU remains compatible with the
MSP430 CPU, having a similar number of registers. A block diagram of the MSP430X CPU is shown in the
gure below:
8 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
9 This content is available online at <http://cnx.org/content/m23498/1.1/>.
Although the MSP430X CPU structure is similar to that of the MSP430 CPU, there are some dierences
that will now be discussed.
With the exception of the status register SR, all MSP430X registers are 20 bits. The CPU can now
process 20-bit or 16-bit data.
Has the same function as the MSP430 CPU, although now it has 20 bits.
Has the same function as the MSP430 CPU, although now it has 20 bits.
Has the same function as the MSP430 CPU, but still only has 16 bits.
Figure 1.5
Figure 1.6
The registers R2 and R3 can be used to generate six dierent constants commonly used in programming,
without the need to add an extra 16-bit word of code to the instruction. The constants below are chosen
based on the bit (As) of the instruction that selects the addressing mode.
Figure 1.7
Whenever the operand is one of these six constants, the registers are selected automatically. Therefore,
when used in constant mode, registers R2 and R3 cannot be addressed explicitly by acting as source registers.
These registers have the same function as the MSP430 CPU, although they now have 20 bits. They can store
8-bit, 16-bit or 20-bit data. Any byte written to one of these registers clears bits 19:8. Any word written to
one of these registers clears bits 19:16. The exception to this rule is the instruction SXT, which extends the
sign value to ll the 20-bit register.
The following gures illustrate how the operations are conducted for the exchange of information between
memory and registers, for the following formats: byte (8 bits), word (16 bits) and address (20 bits).
The following gure illustrates the handling of a byte (8 bits) using the sux .B.
Figure 1.8
The following gure illustrates the handling of a word (16-bit) using the sux .W.
Figure 1.9
Figure 1.10
The following gure illustrates the manipulation of an address (20 bits) using the sux .A.
Figure 1.11
Figure 1.12
10 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
11 This content is available online at <http://cnx.org/content/m23500/1.1/>.
Table 1.5
Before describing the addressing modes, it is important to mention the clock cycles required by interrupts
and resets.
Interrupt accepted 6 -
Hard reset 4 -
Table 1.6
2 Register Any 1* 1
1 N/A PUSH 3 1
1 N/A CALL 4 1
Table 1.7
2 Register Any 3 2
Table 1.8
2 Register Any 3 2
Table 1.9
2 Register Any 3 2
Table 1.10
2 Register Any 2* 1
Table 1.11
2 Register Any 2* 1
1 N/A PUSH 4 1
1 N/A CALL 5 1
Table 1.12
Length: Two or three words. It is one word less if a constant in CG1 or CG2 can be used.
Comment: Valid only for source operand.
Example 7: Move the immediate constant E2h to the destination (register R5).
Before operation: R4=A002h R5=050Ah
Operation: MOV #E2h, R5
After operation: R4= A002h R5=00E2h
2 Register Any 2* 2
1 N/A PUSH 4 2
1 N/A CALL 5 2
Table 1.13
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Table 1.14
Bit Description
12 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
13 This content is available online at <http://cnx.org/content/m23503/1.1/>.
15-12 opcode
Table 1.15
The next tableshows the double operand instructions that are not emulated.
Arithmetic instructions
DADD(.B or .W) src,dst src+dst+C→dst (dec) Decimal add source and carry to destination
SUBC(.B or .W) src,dst dst+.not.src+C→dst Subtract source and not carry from destination
Data instructions
Table 1.16
Depending on the double operand instruction result, the status bits may be aected. The following gives
the conditions for setting and resetting the status bits.
Status bits
Mnemonic V N Z C
Arithmetic instructions
ADD(.B or .W) =1, Arithmetic =1, negative re- =1, null result=0, =1, carry from re-
src,dst overow=0, other- sult=0, if positive otherwise sult=0, if not
wise
ADDC(.B or .W) =1, Arithmetic =1, negative re- =1, null result=0, =1, carry from
src,dst overow=0, other- sult=0, if positive otherwise MSB result=0, if
wise not
DADD(.B or .W) - =1, MSB=1=0, =1, null result=0, =1, result >
src,dst otherwise otherwise 99(99)
SUB(.B or .W) =1, Arithmetic =1, negative re- =1, null result=0, =1, if no bor-
src,dst overow=0, other- sult=0, if positive otherwise row=0, otherwise
wise
SUBC(.B or .W) =1, Arithmetic =1, negative re- =1, null result=0, =1, if no bor-
src,dst overow=0, other- sult=0, if positive otherwise row=0, otherwise
wise
AND(.B or .W) =0 =1, MSB result =1, null result=0, =1, not zero=0,
src,dst set=0, if not set otherwise otherwise
BIC(.B or .W) - - - -
src,dst
BIS(.B or .W) - - - -
src,dst
BIT(.B or .W) =0 =1, MSB result =1, null result=0, =1, not zero=0,
src,dst set=0, otherwise otherwise otherwise
XOR(.B or .W) =1, both operands =1, MSB result =1, null result,=0, =1, not zero=0,
src,dst negative set=0, otherwise otherwise otherwise
Data instructions
CMP(.B or .W) =1, Arithmetic =1, src>=dst=0, =1, src=dst=0, =1, carry from
src,dst overow=0, other- src<dst otherwise MSB result=0, if
wise not
MOV(.B or .W) - - - -
src,dst
Table 1.17
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Table 1.18
Bit Description
15-7 opcode
Table 1.19
The next table shows the single operand instructions that are not emulated.
Table 1.20
Conditions for status bits, depending on the single operand instruction result.
Status bits
Mnemonic V N Z C
RRA(.B or .W) =0 =1, negative re- =1, null result,=0, Loaded from LSB
dst sult=0, otherwise otherwise
RRC(.B or .W) dst =1, dst positive & =1, negative re- =1, null result,=0, Loaded from LSB
C=1=0, otherwise sult=0, otherwise otherwise
SWPB(.B or .W) - - - -
dst
SXT dst =0 =1, negative re- =1, null result,=0, =1, not zero=0,
sult=0, otherwise otherwise otherwise
PUSH(.B or .W) - - - -
src
Data instructions
CALL(.B or .W) - - -
dst
Table 1.21
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Table 1.22
Bit Description
15-13 opcode
12-10 C
Table 1.23
The following table shows the program ow control (jump) instructions that are not emulated.
Mnemonic Description
Table 1.24
Arithmetic instructions
DADC(.B or .W) dst+C→dst (deci- DADD(.B or .W) #0,dst Decimal add carry
dst mally) to destination
INV(.B or .W) dst .NOT.dst→dst XOR(.B or .W) #0(FF)FFh,dst Invert bits in des-
tination
Data instructions
TST(.B or .W) dst dst + 0FFFFh + CMP(.B or .W) #0,dst Test destination
1dst + 0FFh + 1
Table 1.25
Status bits
Mnemonic V N Z C
Arithmetic instructions
ADC(.B or .W) =1, Arithmetic =1, negative re- =1, null result=0, =1, dst from
dst overow=0, other- sult=0, if positive otherwise 0FFFFh to
wise 0000=0, other-
wise
DADC(.B or .W) - =1, MSB=1=0, =1, dst=0=0, oth- =1, dst from
dst otherwise erwise 99(99) to
00(00)=0, oth-
erwise
DEC(.B or .W) dst =1, Arithmetic =1, negative re- =1, dst contained =1, dst contained
overow=0, other- sult=0, if positive 1=0, otherwise 0=0, otherwise
wise
DECD(.B or .W) =1, Arithmetic =1, negative re- =1, dst contained =1, dst contained
dst overow=0, other- sult=0, if positive 2=0, otherwise 0 or 1=0, other-
wise wise
INC(.B or .W) dst =1, dst contained =1, negative re- =1, dst contained =1, dst contained
07(FF)h=0, other- sult=0, if positive FF(FF)h=0, oth- FF(FF)h=0, oth-
wise erwise erwise
INCD(.B or .W) =1, dst contained =1, negative re- =1, dst contained =1, dst con-
dst 07(FFE)h=0, oth- sult=0, if positive FF(FE)h=0, oth- tained FF(FF)h
erwise erwise or FF(FE)h=0,
otherwise
SBC(.B or .W) dst =1, Arithmetic =1, negative re- =1, null result,=0, =1, if no bor-
overow=0, other- sult=0, if positive otherwise row=0, otherwise
wise
INV(.B or .W) dst =1, negative ini- =1, negative re- =1, dst contained =1, not zero=0,
tial dst=0, other- sult=0, if positive FF(FF)h=0, oth- otherwise
wise erwise
RLA(.B or .W) dst =1, Arithmetic =1, negative re- =1, null result,=0, Loaded from MSB
overow=0, other- sult=0, if positive otherwise
wise
RLC(.B or .W) dst =1, Arithmetic =1, negative re- =1, null result,=0, Loaded from MSB
overow=0, other- sult=0, if positive otherwise
wise
Data instructions
CLRC - - - =0
CLRN - =0 - -
CLRZ - - =0 -
SETC - - - =1
SETN - =1 - -
SETZ - - =1 -
BR dst - - - -
DINT - - - -
EINT - - - -
NOP - - - -
RET - - - -
Table 1.26
14 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
35
36 CHAPTER 2. CODE COMPOSER ESSENTIALS
Most of the installation of CCE is automated. It is only necessary to provide some user indications as to
how the program installation should continue.
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
2
2 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
3 This content is available online at <http://cnx.org/content/m23508/1.1/>.
Assembly instruction
only
Table 2.1
By default, the windows included in the Debug perspective are: Debug (provides information concerning
the debug process); Editor (to edit les); Variables/Expressions (to evaluate variables and expressions
values during debug); Console (console to send messages); Registers/Breakpoints (to evaluate the con-
tents of registers and to dene code breakpoint); and Disassembly/Memory (to evaluate the assembly
code and memory map occupation). The icons associated with the various tasks that can be performed in
this perspective are shown together in Table 2.
Table 2.2
Figure 2.1
After choosing this option, a procedure for the creation of projects for the MSP430 family of microcon-
trollers is provided. The user must answer the rst question concerning the project's name. By default,
all the project les are stored within a folder, with the name of the project in the directory chosen for the
workspace. The New Project window is shown in the Figure 2.
Figure 2.2
Afterwards, some additional settings are made to the project, such as whether there is any dependency of
this project on another. If this condition is true, the dependency should be established through the window
shown in Figure 3.
Figure 2.3
Information indexing functionality is part of the C/C++ Project. It uses a parser to create a database of
the contents of the project les. This feature is used during the information search, the project navigation,
and in the content assistant. The indexing task is performed in the background and reacts to changes in
content such as: C/C++ project creation or deletion; le creation or deletion; le import; content of les
changes.
There are three options for setting up the operation of this functionality:
- Without Project contents indexing (No Indexer);
- Fast C/C++ or;
- Full Indexer C/C++ Indexer).
These two last options dier mainly in the required processing time of the indexing task and results
quality. The conguration window of this feature is displayed in Figure 3.
Figure 2.4
In the nal window displayed during the project's creation procedure (see Figure 4 ), the device with which
the project is being developed must be chosen. By choosing the device, the appropriate linker command le
and supporting libraries are selected automatically.
Figure 2.5
The project's creation can then be nalised by choosing the option Finish. At any time, it is possible
to go back to previous windows by choosing the option Back.
The next step is to add the source code le to the project. Choose File > New > Source File. In this
menu the option to create .C type le should be selected, as shown in Figure 5.
Figure 2.6
The name of the le is then requested in the window as shown in Figure 6. Do not forget to add the le
extension such as myle.c so that it is recognized as a C le.
Figure 2.7
The project is automatically selected as the default project. Although the workspace allows several
projects to be opened simultaneously, it allows only one of them to be active. To select an active project, its
name must be selected with the mouse's right button inC/C++ Project view, in order to show the context
menu. Then the option set as active project must be selected. From here, the expression [Active-Debug]
will appear. In the context menu there are other options to manage the project: add or remove les, import
or export resources, edit the properties and so on.
Figure 2.8
At this point, it is possible to start editing the project's source code. CCE has all the capabilities inherited
from the Eclipse edition. Adding the le lab1.c, which already exists, is done through the option add le
to project. This le can be found in Project > add le to project, as in the context menu of the view
C/C++ Projects. The le lab1.c can be removed from the project by simply selecting it in the view and
selecting the option delete. Note that when the le is removed, it will be cleared from the directory.
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
6
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Figure 2.9
The text editor has a set of features that allow speeding up the code editing process. An overview of the
text editor is shown in Figure 2.
Figure 2.10
Code editing is greatly facilitated using features such as search and replace. To accomplish this task,
the user must select Edit > Find/Replace. In addition to the normal features of search and replace, the
option Search > File allows the use of more elaborate expressions. For example, it provides the global
replacement in all les of a specic directory. The search and replace tasks previously performed can be
found on the drop-list.
CCE can regularly save the opened les for editing in order to prevent losses caused by system crashes.
To use this function, select Window > Preferences > General > Workspace and specify the time
interval at which this task should be performed automatically. The project can also be saved whenever it
goes through project build.
The content wizard is a very eective tool to support the writing of code. It is possible to automatically
insert a code structure model, previously dened, as an alternative to writing it out completely (see an
example in Figure 3 ). To insert a model of a structure, it is only necessary to write the rst letters in the
text editor and then press the Ctrl + Space keys in order to display a list of the corresponding models.
The options in the list can be reduced by continuing writing the structure name. The Arrow Up and Arrow
Down keys can be used to select the desired model and by pressing the Enter key to accept the selection.
At any time the Esc key allows editing to continue without the use of the content wizard.
CCE workbench Content wizard.
Figure 2.11
The behaviour of this feature can be congured in Window > Preferences. In Figure 4 shows the
conguration page of the content wizard.
Figure 2.12
The search range can be restricted to only the edited le and to the les included therein (Search
current le and included les), or alternatively a search can be in the whole project (Search current
project). Automatic model insertion is allowed, as long as it is the only one at the options list (Insert
single proposals automatically). The user may also request that the suggestions list is presented in
alphabetical order (Present proposals in alphabetical order). Another aspect that can be congured is
related to the time (in milliseconds) that the content wizard delays to suggest a list (delay), or the duration
of the validity of the suggestion (Content Assist Parsing timeout).
In addition to the sequence of Ctrl + Space keys, the content wizard can also be set automatically when
the following characters are typed: ".", "->" or "::".
CCE is already provided with a set of models. However, it is possible to create new models by opening
the models editor. Expand the C/C++ perspective in Window > Preferences, and select Editor >
Templates. The option New must be selected to create a new model (see Figure 5 ).
Figure 2.13
A name must be given for the new model. The context in which the model is valid should be selected.
Description eld a brief description of the model can be added. The model itself is described in the
In the
Pattern eld. To insert a variable, use the Insert Variable option.
One way to learn how to create models, or even how to customize existing models, can be achieved using
the model editing feature (see Figure 6 ). To access this feature, the Editor > Templates option must be
chosen, and is visible after expanding the C/C++ perspective in Window > Preferences.
Figure 2.14
The procedures to check on this page are identical to those described earlier for building new models.
The CCE supports the following intrinsic functions for the MSP430 family devices:
- void __no_operation(void);
- void __enable_interrupt(void);
- void __disable_interrupt(void);
- unsigned short __get_interrupt_state(void);
- void __set_interrupt_state(void);
- void __op_code(unsigned short);
- unsigned short __swap_bytes(unsigned short);
- void __bic_SR_register(unsigned short);
- void __bis_SR_register(unsigned short);
- unsigned short __get_SR_register(void);
- void __bic_SR_register_on_exit(unsigned short);
- void __bis_SR_register_on_exit(unsigned short);
- unsigned short __get_SR_register_on_exit(void);
- void __set_SP_register(unsigned short);
- unsigned short __get_SP_register(void);
- unsigned short __bcd_add_short(unsigned short, unsigned short);
- unsigned long __bcd_add_long(unsigned long, unsigned long);
- void __data20_write_char(unsigned long, unsigned char);
- void __data20_write_short(unsigned long, unsigned short);
- void __data20_write_long(unsigned long, unsigned long);
8 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
9 This content is available online at <http://cnx.org/content/m23514/1.1/>.
10 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
11 This content is available online at <http://cnx.org/content/m23518/1.1/>.
Figure 2.15
Figure 2.16
Similar to the import procedure, the resources belonging to a Project can be exported: Archive File;
Export Breakpoints; File System, Preferences, etc. . .
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
12
12 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Figure 2.17
The management of build congurations is found under the option C/C++ Build, accessed via the
Manage button. Through it the management features can be accessed (see Figure 2 ).
Figure 2.18
It is possible to create new build congurations, delete the existing ones or modify their names. The
name of the modied conguration is selected in conguration.
The C/C++ compiler used by the project is controlled by the project's properties. To view the project
properties in the dialog box that appears, the page C/C++ Build allows control of the variety of congu-
rations, including:
Build Options: species the options that aect all project les. This dialog page allows selection of the
appropriate options, including those for compiling and linking. It is also possible to specify whether the
compiler uses Stop On Error or Keep Going On Error. The second option allows the compiler to build
all projects referenced, even if the current project contains errors. The build command species the make
le to use.
The MSP430X devices allow data to be located anywhere in the 20-bit address space. By enabling this
option, the compiler will use instructions that need a larger space for their storage. Hence, the memory
space occupied by the nal program will be greater. The option (- large_memory_model) is valid only
when the project is intended as a MSP430X device dened by the compile option (- vmspx). The programs
for MSP430X processors should be compiled with RTS libraries supplied for that purpose (rts430xl.lib and
rts430xl_eh.lib).
The compilation option (- silicon_version) selects the CPU version using the 4 least signicant processor's
identication digits. If this option is not used, the compiler will construct the default code for the device.
In the process of linking, if all references to the multiplication routines of integers are to be replaced
by the routines versions that use the hardware multiplier option (- use_hw_mpy), the device multiplier's
length must be specied. To use the 16-bit hardware multiplier, present in most devices, choose the option
16. For devices belonging to the F4xx family, which has a 32-bit multiplier module, chose the option 32.
Finally, for the new 5xx family, which also has a 32-bit multiplier, use the F5 option. The default option is
16-bit hardware multiplier module.
The model used for the initialization of static variables in the C program can be specied as: None,
Link using ROM autoinitialization model (- rom_model), or link using RAM autoinitialization model (-
ram_model). The C/C++ compiler produces tables of data for automatic initialization of global variables.
These tables are placed in the section identied by .cinit.
The memory space reserved for the passing of arguments by the C routines is dened in (arg_size). The
space reserved for the dynamic allocation of memory by the program is dened in the option (heap_size).
The system stack size used by the program is set by the option (stack_size). See Figure 3.
Figure 2.19
The device for which the project is intended is congured in the Properties> TI Building Setting.
The window is in every way identical to that presented in the project's creation (Figure 4 ).
Figure 2.20
Figure 2.21
Figure 2.22
Figure 2.23
The rst time that the project is built, theProject > Build All option must be selected. The project
build status can be examined in the Console window. If there is a problem, the Problems window will list
them all. After a successful build of the project, the output le can be automatically loaded into the device.
Alternatively, a project can be built at the beginning of the debug session. The option Debug Active
Project will recompile the project and launch the debugger, using the device information dened in the
project options.
Note that an attempt to update the rmware can occur when the debugger is used for the rst time,
after a software release has been installed or a new USB interface is used.
Finally, the active perspective must be switched to the Debug perspective. This operation can be
carried out with the perspective selection buttons located on upper right corner of the workspace window,
or alternatively, by selecting Window > Open Perspective > Debug.
When the project is debugged, the errors are identied on the right hand side of the editor as red marks
while the problems are identied as white marks. A mark is added on the left hand side of the editor to the
lines that contain an error. When this mark is selected, the compiler provides information about the error.
When the project is made (make option), the resources used can be accessed on Properties > C/C++
Build > MSP430 Linker V3.0 > Linker Output in the option Produce list of input and output
sections.
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
14
14 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
All the MSP430 family of devices have an advanced code debugging module (EEM - Enhanced Emulation
Module). This module allows CCE to monitor the device's operation in a non-intrusive way, and without
using any resources. Thus, it facilitates the development of the application through the verication of its
operation. Depending on the device, the EEM module implementations dier. Generally, the following
features are present:
- Up to 8 hardware breakpoints;
- Operates in all range of frequencies and clock sources;
- Ability to set more complex breakpoints through association of triggers;
- Suspend the execution of the application on the occurrence of a program or data bus access;
- Access protection to protected data and program memory areas;
- All timers and counters can be inhibited (depending on the device);
- Inhibits PWM signals generation on the occurrence of the application's suspension;
- Allows real-time execution of the applications in the modes: single step, step into; run to cursor; step
over;
- Supports all low power modes.
The Figure 1 represents a simplied block diagram of one of the most complete implementations of EEM
module.
Figure 2.24
Events within the device can generate triggers. These triggers can be classied as the event that causes
them to:
- Access to addressing and data buses;
- Access to CPU registers.
Depending on the device, it is possible to associate two or more of these triggers, in order to build
complex event detectors that help the detection of incorrect operation of applications. Generally, a trigger
can be used to control the following functional blocks of the EEM: breakpoints, trace, and sequencer. The
activation of a trigger is conditioned to an access to the data and program busses or access to CPU registers.
A breakpoint is set through one or more triggers. Through these it is possible to establish the following
types of breakpoints:
- Address breakpoint;
- Data breakpoint;
- Register Breakpoint;
- Mask Register;
- Range breakpoint.
A simple breakpoint is dened using a trigger associated with an instruction read operation by the CPU.
It is necessary to specify the instruction address where the trigger should occur.
By combining two triggers, it is possible to establish a Data Breakpoint. While one of the triggers is used
to detect the occurrence of a particular address on the address bus, the other is used to detect the occurrence
of a read or write operation at that address. It is possible to force the suspension of the execution of the
application to only occur when there is a match between the value written or read and the one specied.
When the application is written in assembly language, it is sometimes necessary to analyse the accesses
to some of the microcontroller's registers. A Register Break Point uses a trigger to detect the access to a
register. A Mask Register should be used when the register is composed of several elds, since it can apply
a mask and test specic bits only.
An application in certain operating conditions may occasionally try to access to invalid or protected
memory regions. Using a range breakpoint, it is possible to detect the occurrence of these events. It is thus
possible to suspend the execution of the application on the occurrence of:
- Write to ash;
- Invalid access to memory;
- Access to an instruction in invalid program space;
- Access to data in invalid data space.
The hardware breakpoint properties are established through dierent elds. The action to make when
all triggers are true can be dened in the Action option of the Hardware Conguration eld. One of the
following options can be chosen:
- Halt;
- Trigger storage;
- Halt and trigger storage.
In the trigger eld, specify through various options, the check condition for a true trigger. The trigger
can be:
- Memory Address bus;
- Memory Data bus;
- Register Write.
2.8.1.2 Depending on the type of trigger chosen, the options to specify may be
Location: Address of the program code line or data memory address (e.g.: &a);
Mask: the information introduced in this eld is used in a logic AND operation with the contents;
Operator: Logic operation with the data (==, <=, >=, !=);
Access: Memory access type:
- Instruction fetch;
- Instruction fetch and hold trigger;
- No instruction fetch;
- Don't care;
- No Instruction fetch and read;
- No instruction fetch and write;
- Read;
- Write;
Value: A mask and compare will be applied to the data on the bus and to value added here, to determine
if the trigger is true;
Mask: The information introduced in this eld is used in a logic AND operation with the contents;
Operator: Logic operation with the data (==, <=, >=, !=);
Access: Memory access type (on Memory Address Bus).
2.8.1.2.3 Miscellaneous
- Break in program range: Generates a suspension of the execution of the application in a range of
program memory addresses. It uses two triggers that dene the range of addresses;
- Break in DMA transfer: Generates the suspension of the execution of the application, whenever
a DMA read or write operation at the specied program address occurs. This breakpoint is implemented
using only one trigger;
- Break in DMA transfer range: Generates the suspension of the execution of the application, when-
ever a DMA read or write operation at the specied address range occurs. This breakpoint is implemented
using two triggers;
- Break in stack overow: Generates the suspension of the execution of the application whenever the
SP register value assumes a lower value than the specied one. This breakpoint is implemented using only
one trigger;
- Breakpoint: Generates the suspension of the execution of the application whenever the memory bus
address takes the value specied. This breakpoint is implemented using only one trigger;
- Hardware breakpoint: Generates the suspension of the execution of the application whenever the
memory bus address takes the value specied. This breakpoint is implemented using only one trigger;
- Watch on data address range: Generates a suspension of the execution of the application whenever
the specied data memory addresses range is accessed. It uses two triggers to dene the range of addresses;
- Watchpoint: Generates the suspension of the execution of the application whenever a specied data
memory address is accessed. It uses a trigger to generate the watchpoint;
- Watchpoint with data: Generates the suspension of the execution of the application whenever a
specied data memory address is accessed and the value of the address is equal to specied value. Two
triggers are used to implement this watch.
In order to verify the code execution, it is necessary to use support tools to complete this task. CCE provides
a set of features with this aim.
A breakpoint suspends the execution of the application in order to check the status of the system. The
activation, deactivation and conguration of these breakpoints are possible through CCE.
There are two types of breakpoints: software and hardware. While the rst type of breakpoint is im-
plemented through the insertion of code in the application, in a way invisible to the user, the second type
is implemented internally by the device's hardware. Although the software breakpoints are not limited, the
hardware breakpoints, depending on the device, have a limit of 2 to 4 breakpoints.
The application debugging process often requires access to the actual values of the variables. The Vari-
able view allows the user to monitor the application's local and global variables. In this view, the CCE
automatically displays the name and contents of the local variables of the function that is being executed. It
is also possible to add the name of other local variables or global variables to be monitored in the debugging
process.
The values of the local variables can be modied. The values of the variables that have been changed
during the last instruction execution are displayed in red. However, the variable names cannot be modied.
It is allowed to change the representation format of the variable: Natural, decimal or hexadecimal. The
variables that contain more than one element, such as arrays, structures, or pointers are presented with a
(+) sign immediately after the name. This signal means that the variable has elements that can be seen
through the expansion of the (+) sign, passing this signal (-), which allows the structure to be collapsed.
The local variables cannot be added or removed from the Variables view. However, global variables can
be added or removed. The local variables can be disabled in order to freeze their value as the program is
executed.
The Expressions view accepts the entry of expressions to evaluate them as the program is executed.
These expressions are written in syntax similar to that used by the C programming language.
- Specify the number of elements of the array to be displayed in the Expression view: The command
Display as Array can be used to display the elements of any pointer or array. The command Remove
Array Expansion is used to return an expanded variable back to its original state;
- Change value: Changes the content of the variable;
- Cast to type: Performs a promotion (cast) for a dierent type of variable;
- Restore Original Type: Restores the expression for the original data type.
The Memory window of the Debug perspective allows the user to monitor and modify the device's memory.
Memory Monitors. Each monitor represents a section of memory
The memory is provided with a list of
specied by its named location base address. Each memory monitor may be represented in dierent data
formats (memory renderings). The debugger allows four dierent types of rendering:
- Hex (default);
- Ascii;
- Integer signed;
- Unsigned integer.
The Memory view has two panels:
- Memory Monitors;
- Memory Renderings.
The rst panel displays the memory monitors list added to the debug session. The second panel is
controlled by selection in the rst one and consists of tabs that display the rendering. This panel can be
congured to display both renderings.
Request the MSP430 Teaching ROM Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
16
16 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
71
72 CHAPTER 3. GENERAL PURPOSE INPUT/OUTPUT
The hands-on laboratory consists of conguring the I/O ports, setting up the input lines to read push
buttons and the output lines to feed LEDs. The following exercises have been developed for the three
hardware development tools.
The rst to be discussed is the MSP-EXP430FG4618 Experimenter's board. Modications are later made
to suit the other development boards. The main dierences between the boards are related to the specic
ports in which the buttons and LED are (or can be) connected. For the development of this laboratory,
Code Composer Essentials v3 has been used.
3.1.1.2 Procedure
By analysis of the schematics, determine which I/O port pin is connected to the LED on the board:
- Consult the MSP430FG4618/F2013 Experimenter's Board User's Guide slau213a.pdf
2
- LED1 is connected to Port 2.2
- Consult the eZ430-F2013 Development Tool User's Guide slau176b.pdf
3
- LED1 is connected to Port 1.1
- Consult the eZ430-RF2500 Development Tool User's Guide slau227c.pdf
4
- LED is connected to Port 1.0
Include the standard register and bit denitions for the TI MSP430 microcontroller device (example for
the MSP430FG18/MSP430F2013 Experimenter's board):
#include <msp430xG46x.h>
Dene the main routine:
void main (void){
The watchdog timer must be prevented from generating a PUC. Write 0x5A to the eight MSBs of the
Watchdog timer control register, WDTCTL:
WDTCTL = WDTHOLD | WDTPW;
Port control registers:
- Set the LED port pin as an output;
P2DIR: Port 2.2 is set as an output:
P2DIR |= 0x04; // to force the pin setting. It is uses an OR operation ( | ) with
P2DIR and 0x04
Use an innite loop to modify the state of the port;
Use a software delay loop to generate the pause interval. (a long software delay loop is used here for
simplicity - in real applications, a timer would be used)
- Because no clock is dened, the device will use the 32.768 kHz watch crystal. In order for a rate of
one blinking LED state transition each second, the software delay loop should count to approximately 30000
{30000/32768 = +/- 1 sec};
volatile unsigned int i;
- The programming code for the other hardware kits follows the same sequence as given above, requiring
only conguration the port.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
5
5 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
3.2 Laboratory GPIO: Lab2 - Blinking the LED half the speed6
3.2.1 Laboratory GPIO: Lab2 - Blinking the LED half the speed
3.2.1.1 Introduction
The hands-on laboratory consists of conguring the I/O ports, setting up the input lines to read push
buttons and the output lines to feed LEDs. The following exercises have been developed for the three
hardware development tools.
The rst to be discussed is the MSP-EXP430FG4618 Experimenter's board. Modications are later made
to suit the other development boards. The main dierences between the boards are related to the specic
ports in which the buttons and LED are (or can be) connected. For the development of this laboratory,
Code Composer Essentials v3 has been used.
3.2.1.2 Procedure
Using the Lab1: Blinking the LED example, independently of the hardware development tool, reduce the
value of the software delay to half its previous value.
#include "msp430xG46x.h"
3.3 Laboratory GPIO: Lab3 - Toggle the LED state by pressing the
push button8
3.3.1 Laboratory GPIO: Lab3 - Toggle the LED state by pressing the push button
3.3.1.1 Introduction
The hands-on laboratory consists of conguring the I/O ports, setting up the input lines to read push
buttons and the output lines to feed LEDs. The following exercises have been developed for the three
hardware development tools.
The rst to be discussed is the MSP-EXP430FG4618 Experimenter's board. Modications are later made
to suit the other development boards. The main dierences between the boards are related to the specic
ports in which the buttons and LED are (or can be) connected. For the development of this laboratory,
Code Composer Essentials v3 has been used.
3.3.1.2 Procedure
By analysis of the schematics, determine to which port pin the push button is connected:
- Consult the MSP430FG4618/F2013 Experimenter's Board User's Guide <slau213a.pdf>:
- Button S1 is connected to Port 1.0;
- Consult the eZ430-RF2500 Development Tool User's Guide <slau227a.pdf>:
- Button S1 is connected to Port 1.2;
- The eZ430-RF2500 uses a device in 2xx family, so you need to additionally congure the button as
pull-up or pull-down, in the P1REN register.
Ports control registers:
- Set push button pin port as an input
- P1DIR: Port 1.0 is set as an input:
P1DIR &= ∼0x01 // to force the pin setting to 0. It is uses an AND operation ( & )
between P1DIR and 0xFE
- Enable interrupts to this pin port;
- P1IE: Enable interrupt to port 1.0:
P1IE |= 0x01; // Interrupt Enable in P1.0
- PIIES: Call the port interrupt on a high-to-low transition:
P1IES |= 0x01; // P1.0 Interrupt flag high-to-low transition
- Congure the watchdog timer to prevent a PUC during the program execution;
WDTCTL = WDTPW | WDTHOLD; //Stop Watchdog Timer
- Enable Global Interrupts and congure low power mode 3;
_BIS_SR (LPM3_bits + GIE); //Low Power Mode with interrupts enabled
- Create a interrupt service routine, that includes:
- Toggle LED1 pin port;
- Delay for button debounce;
- Clear interrupt ag.
#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void) {
volatile unsigned int i;
P2OUT ^= 0x04; // Toggle Port P2.2
i=1500; // Delay, button debounce
do (i--);
while (i !=0);
while (! (P1IN & 0x01)); // Wait for the release of the button
8 This content is available online at <http://cnx.org/content/m23547/1.1/>.
9 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
The hands-on laboratory consists of conguring the I/O ports, setting up the input lines to read push
buttons and the output lines to feed LEDs. The following exercises have been developed for the three
hardware development tools.
The rst to be discussed is the MSP-EXP430FG4618 Experimenter's board. Modications are later made
to suit the other development boards. The main dierences between the boards are related to the specic
ports in which the buttons and LED are (or can be) connected. For the development of this laboratory,
Code Composer Essentials v3 has been used.
3.4.1.2 Procedure
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
11
10 This content is available online at <http://cnx.org/content/m23556/1.1/>.
11 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Timers
79
80 CHAPTER 4. TIMERS
Correct system timing is a fundamental requirement for the proper operation of a real-time application. The
timing denition can dictate how the data information processed during the execution of the application
program. The clock implementations vary between devices in the MSP430 family. Each device provides
dierent clock sources, controls and uses. This chapter discusses the clock controls included in the platforms
used. The MSP430 4xx family has two general-purpose 16-bit or 8-bit counters and event timers, named
Timer_A, Timer_B, and a Basic Timer. The Basic Timer module is only implemented in `4xx devices.
The 2xx device family also has Timer_A and Timer_B, but the clock signals are provided by the basic
clock module+. The timers may receive an internal or external clock. Timer_A and Timer_B also include
multiple independent capture and compare blocks, with interrupt capabilities.
4.1.1.2 Overview
This laboratory implements a memory clock using the features provided by Timer1. The clock is updated once
every second by the Basic Timer1 interrupt service routine (ISR). This procedure also performs switching of
LED1. In order to evaluate the execution time of the routine, LED2 is kept active during the execution of
the ISR. When the ISR has completed, the device goes into low power mode, until the new interrupt wakes
it up.
4.1.1.3 Resources
The rst task is to disable the Watchdog Timer. It should be stated that this feature, when used correctly,
makes the application more robust.
The resources needed for the LCD are all congured. This code is given, since its operation will be
analysed in a later laboratory. Once the LCD congured, it is cleared by the execution of the routine
LCD_all_off().
The memory clock consists of setting three global variables: hour, min, and sec, all of the type unsigned
char, used to store the hours, minutes and seconds values elapsed respectively since the beginning of the
execution of the application. These variables are initialized with zero values.
The LCD is refreshed at startup to show the initial clock value.
LED1 is used as an indicator of Basic Timer1 ISR execution. The execution time can be determined
through it. In addition, LED2 state switches whenever the Basic Timer1 ISR is executed.
The Watchdog Timer is disabled with the objective of reducing energy consumption, but giving up the
protection aorded by it. This peripheral is congured by the WDTCTL register. Its access is protected by
a password. The value to disable it:
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
A 32.768 kHz crystal is applied to the oscillator LFXT1. Since it is possible to select the internal capacitors
using software, the value to write to the FLL_CTL0 conguration register to select the 8 pF capacitors is:
FLL_CTL0 |= XCAP18PF; // Set load cap for 32k xtal
Taking into consideration the change mentioned earlier to the FLL+ module, what are the frequencies
of each of the clock signals?
ACLK = _________________;
MCLK = _________________;
SMCLK = ________________;
LED1 and LED2 are connected to ports P2.2 and P2.1 respectively. How should they be congured so that
just the bits related to these ports have digital output functions?
P2DIR |= 0x06; // P2.2 and P2.1 as output
How should the P2OUT register be congured so that the application starts with LED1 on and LED2
o ?
P2OUT |= 0x04; // LED1 on and LED2 off
Basic Timer1 should generate an interrupt once every second. It uses two counters in series, so that the
input of the BTCNT2 counter is the output of the BTCNT1 counter divided by 256. The BTCNT1 counter
input is the ACLK with a 32.768 kHz frequency. If the selected output of the BTCNT2 counter is divided
by 128, what is the time period associated with the Basic Timer1 interrupt? _________
//*********************************************************
// BasicTimer1 Interrupt Service Routine
//*********************************************************
#pragma vector=BASICTIMER_VECTOR
The task simply updates the counters periodically and refreshes the LCD contents. It is possible to congure
the registers for an energy-ecient operation.
Which low power mode should be used? _____________
Which system clocks are activated in the low power mode selected? _________________
BIS_SR(LPM3_bits + GIE); // Enter LPM3 + interrupts enabled
The MCLK, SMCLK and ACLK system clocks are available at ports P1.1, P1.4 and P1.5 respectively. These
ports are located on the SW2, RESET_CC and VREG_EN lines, which are available on the H2 Header
pins 2, 5 and 6. All these resources are available because the Chipcon RF module is not installed and SW2
is not used.
Using the Registers view, set bits 1, 4 and 5 of P1SEL and P1DIR registers, to choose the secondary
function of these ports congured as outputs. By connecting an oscilloscope to those lines, it is possible to
monitor the clock signals.
What are the values measured for each of the system clocks?
ACLK: ________________
SMCLK: _______________
MCLK: ________________
The Basic Timer1 ISR execution time is fundamental to energy conservation, in order to extend the life of
the system battery. The routine execution time can be measured by connecting the oscilloscope to port P2.1,
which controls LED2. This output is available on pin 2 of Header H4.
The execution time of this routine varies with the number of the counter updates and respective updates
to the LCD. What are the times measured for each of these situations and what their frequencies?
Seconds update: ______ with a time period of ______
Seconds and minutes update: ______ with a time period of ______
LCD elds update: ______ with a time period of ______
If the developer chooses to update all the LCD elds at each interrupt, the time required is much
greater than the solution presented. Ecient programming contributes to a reduction in the system power
consumption.
The power consumption was discussed in the previous point. The electrical power required by the system
during operation is measured by replacing the jumper on the Header PWR1 by an ammeter, which indicates
the electric current taken by device during operation.
What is the value read? __________
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
3
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
4.2 Laboratory Timers: Lab2 - Real Time Clock with Basic Timer14
4.2.1 Laboratory Timers: Lab2 - Real Time Clock with Basic Timer1
4.2.1.1 Introduction
Correct system timing is a fundamental requirement for the proper operation of a real-time application. The
timing denition can dictate how the data information processed during the execution of the application
program. The clock implementations vary between devices in the MSP430 family. Each device provides
dierent clock sources, controls and uses. This chapter discusses the clock controls included in the platforms
used. The MSP430 4xx family has two general-purpose 16-bit or 8-bit counters and event timers, named
Timer_A, Timer_B, and a Basic Timer. The Basic Timer module is only implemented in `4xx devices.
The 2xx device family also has Timer_A and Timer_B, but the clock signals are provided by the basic
clock module+. The timers may receive an internal or external clock. Timer_A and Timer_B also include
multiple independent capture and compare blocks, with interrupt capabilities.
4.2.1.2 Overview
The Real Time Clock (RTC) has a 32-bit counter, to automatically control the clock calendar. This peripheral
is present on the MSP430FG461x devices. The application developed in the laboratory Timers: Lab1 -
Memory clock with Basic Timer1 will now be modied to incorporate this module.
4.2.1.3 Resources
The organization of the software is identical to that of laboratory Timers: Lab1 - Memory clock with Basic
Timer1. The Basic Timer1, LCD and LEDs continue to perform the same functions. They are congured
similarly, but with the changes described below.
In routine main(), the congurations for RTC and SW1/SW2 are added.
The memory addresses corresponding to the clock calendar values are initialized with the default values,
that is zero hours, zero minutes and zero seconds, on August 9, 2008. The RTC is then activated in calendar
mode, with the interrupt disabled. This mode aects the Basic Timer1 operation.
The switches SW1 and SW2 are connected to the microcontroller ports P1.0 and P1.1 respectively. Hence,
these ports are congured as inputs and their interrupts activated by a high-to-low transition at the input.
The RTC is congured in calendar mode and enabled. The counting registers provide the values of seconds,
minutes, hours, days, day of the week, day of the month, month and year. The registers are stored in BCD
format to speed up the data writing process to the LCD. The interrupt for this peripheral should be disabled
(disabling the Basic Timer1 interrupt). Given these objectives:
RTCCTL = RTCBCD | RTCHOLD | RTCMODE_3; // BCD mode, RTC and BT disable
The RTC operation in calendar mode automatically congures some of the Basic Timer1 features. The
content of the bits BTSSEL, BTHOLD and BTDIV of BTCNT register are ignored. Thus, the BTCNT1 and
BTCNT2 counters work in cascade. The clock source of the BTCNT1 counter is the ACLK clock signal. The
output of the BTCNT1.Q7 counter is selected as the input of the BTCNT2 counter (frequency: ACLK/256).
The RTC uses the BTCNT2.Q6 output as clock source (frequency: ACLK/32768).
This peripheral is automatically congured with the RTC in calendar mode. To enable the interrupt once
every 0.5 seconds:
The switches SW1 and SW2 are connected to ports P1.0 and P1.1 respectively. How should the following
registers be congured in order to set just the bits that aect the digital inputs, with high-to-low transition
interrupts?
Performing similar procedures to those described in laboratory Timers: Lab1 - Memory clock with Basic
Timer1 measure the ISR execution time. What is the value measured?
LCD refresh: ______
The LCD write routines were changed. Taking advantage of storing the data in the BCD format, the
division operation can be ignored, resulting in the reduction of execution time of the Basic Timer1 ISR. Is
the processing time required to refresh the LCD constant? _____
The power consumption was discussed in the previous point. The electrical power required by the system
during operation is measured by replacing the jumper on the Header PWR1 by an ammeter, which indicates
the electric current taken by device during operation.
What is the value read? __________
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
6
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Correct system timing is a fundamental requirement for the proper operation of a real-time application. The
timing denition can dictate how the data information processed during the execution of the application
program. The clock implementations vary between devices in the MSP430 family. Each device provides
dierent clock sources, controls and uses. This chapter discusses the clock controls included in the platforms
used. The MSP430 4xx family has two general-purpose 16-bit or 8-bit counters and event timers, named
Timer_A, Timer_B, and a Basic Timer. The Basic Timer module is only implemented in `4xx devices.
The 2xx device family also has Timer_A and Timer_B, but the clock signals are provided by the basic
clock module+. The timers may receive an internal or external clock. Timer_A and Timer_B also include
multiple independent capture and compare blocks, with interrupt capabilities.
4.3.1.2 Overview
The objective of this laboratory is to build a memory clock similar to the one that was developed using the
Basic Timer1, in laboratory Timers: Lab1 - Memory clock with Basic Timer1. Timer_A is congured to
generate an interrupt once every 100 msec. The ISR manages the memory clock. LED1 and LED2 are used
to monitor the operation of the system state.
4.3.1.3 Resources
The rst task is to disable the Watchdog Timer. All the resources needed for the LCD are then congured.
Once congured, the LCD is cleared by the execution of the routine LCD_all_off().
The memory clock consists of three global variables: min, sec, msec, of the type unsigned char, to store
the minutes, seconds and milliseconds respectively of the values elapsed since the beginning of the execution
of the application. These variables are initialized with zeros.
The LCD is refreshed at startup to display the initial clock value.
LED2 is used as an indicator of Timer_A ISR execution. The execution time can be monitored using it.
In addition, LED1 switches state whenever Timer_A ISR is executed.
Timer_A is congured to generate an interrupt once every 100 milliseconds.
The routine main() ends with a global interrupt enable and puts the device into a low power mode,
where it waits for the next interrupt.
Timer_A ISR begins by activating LED2, indicating the beginning of execution of the routine and then
switches LED1 state. The counters are updated in cascade and their contents are used to update the LCD,
through the routines LCD_msec(), LCD_sec() and LCD_min(). The routine ends by switching the state of
the clock separation points. Finally, LED2 is turned o.
The Watchdog Timer is disabled with the objective of reducing energy consumption, but giving up the
protection aorded by it. This peripheral is congured by the WDTCTL register. Its access is protected by
a password. The value to disable it:
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
A 32.768 kHz crystal is applied to the oscillator LFXT1. Since it is possible to select the internal capacitors
using software, what is the value to write to the FLL_CTL0 conguration register to select the 8 pF
capacitors?
FLL_CTL0 |= XCAP18PF; // Set load cap for 32k xtal
LED1 and LED2 are connected to ports P2.2 and P2.1 respectively. How should they be congured so that
just the bits related to these ports have digital output functions?
P2DIR |= 0x06; // P2.2 and P2.1 as output
How should the P2OUT register be congured so that the application starts with LED1 on and LED2
o ?
P2OUT |= 0x04; // LED1 on and LED2 off
The Timer_A is congured to count until it reaches the value written in the TACCR0 unit. An interrupt is
generated when it reaches that value. Which is the interrupt vector to use? ____________
Timer_A clock signal is the ACLK without division. What is the value to write in the conguration
register?
TACTL = TASSEL_1 | MC_1 | ID_0; // ACLK, up mode
The TACCR0 capture/compare unit determines the Timer_A counting range. For a 100 msec response,
what is the value to write in the register?
TACCR0 = 3268; // this count corresponds to 100 msec
The interrupt is congured in TACCR0 capture/compare unit. What is the value to write to the following
register?
//*********************************************************
// Timer A ISR
//*********************************************************
#pragma vector=TIMERA0_VECTOR
msec++;
LCD_msec();
if (msec == 10)
{
msec = 0;
sec++;
LCD_sec();
if (sec == 60)
{
sec = 0;
min++;
LCD_min();
if (min == 60)
{
min = 0;
}
}
}
Performing similar procedures to those described in laboratory Timers: Lab1 - Memory clock with Basic
Timer1 measure the ISR execution time. What is the value measured?
The power consumption was discussed in the previous point. The electrical power required by the system
during operation is measured by replacing the jumper on the Header PWR1 by an ammeter, which indicates
the electric current taken by device during operation.
What is the value read? __________
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
9
9 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Correct system timing is a fundamental requirement for the proper operation of a real-time application. The
timing denition can dictate how the data information processed during the execution of the application
program. The clock implementations vary between devices in the MSP430 family. Each device provides
dierent clock sources, controls and uses. This chapter discusses the clock controls included in the platforms
used.
The MSP430 4xx family has two general-purpose 16-bit or 8-bit counters and event timers, named
Timer_A, Timer_B, and a Basic Timer. The Basic Timer module is only implemented in `4xx devices. The
2xx device family also has Timer_A and Timer_B, but the clock signals are provided by the basic clock
module+.
The timers may receive an internal or external clock. Timer_A and Timer_B also include multiple
independent capture and compare blocks, with interrupt capabilities.
4.4.1.2 Overview
The purpose of this laboratory is to build a sound generator using Timer_B. The PWM signal produced by
this peripheral drives the buzzer, producing a sequence of musical notes at regular time intervals. At the
same time, LED1 and LED2 switch state alternately. The volume of sound produced by the buzzer can be
controlled by push buttons SW1 and SW2.
4.4.1.3 Resources
The application consists of the routine main(), which is used to congure all system resources, before entering
into a standby mode, waiting for one of two interrupts.
This routine starts by disabling the watchdog timer and starting the module FLL+ to produce the desired
clock signals of the correct frequency for the SMCLK and MCLK. Then, the Basic Timer1 and Timer_B
are congured in order to perform the desired functions.
The ports connected to the LEDs, buttons and buzzer are then initialized.
Finally, the interrupts are activated, and the application waits for the execution of one of two interrupts.
The Basic Timer1 interrupt executes at a frequency of once every second. When this interrupt is occurs,
it begins by switching the state of LED1 and LED2. Afterwards, it accesses the memory to fetch the next
musical note to be performed. The routine ends with memory pointer management.
The Port 1 ISR begins by evaluating the source of the interrupt. The sound volume is reduced if the
button SW1 is pressed. The sound volume is increased if button SW2 is pressed.
4.4.1.5.1 Timer_B
It is the responsibility of Timer_B to produce the PWM signal that activates the Buzzer. Timer_B counts
until the value contained in the TBCCR0 register is reached. It does not generate an interrupt, and must
be sourced by SMCLK clock signal:
TBCTL = TBSSEL_2 | CNTL_0 | TBCLGRP_0 |MC_1 | ID_0;
Each PWM signal produced by Timer_B corresponds to a musical note. The relationship between the
frequency and the musical note is given in Table 1.
Freq [Hz] 503 524 587 662 701 787 878 1004 1048
Table 4.1
TACCTL1 = CM1 | CCIS_0 | CAP | CCIE;// Capture on rising edge, Cap mode,
// Cap/Com int. enable, TACCR1 input signal selected
//*********************************************************
// Timer A ISR
//*********************************************************
#pragma vector=TIMERA1_VECTOR
__interrupt void TimerA1_ISR (void)
{
switch (TAIV)
{
case TAIV_TACCR1:
if (capture == 0){
T1 = TACCR1;
flag = 1;
capture = 1;
}
else {
if (flag == 1) {
T2 = TACCR1;
if (T2 > T1)
T = T2-T1;
}
else{
TAR = 0;
}
capture = 0;
flag = 0;
}
break;
case TAIV_TACCR2:
break;
case TAIV_TAIFG:
tick++;
if (tick == 60){
LCD_freq();
tick = 0;
}
if (flag == 1)flag = 0;
break;
default:
break;
}
}
The Basic Timer1 generates an interrupt once every second. It uses two counters in series, where the
BTCNT2 counter input uses the BTCNT1 counter output divided by 256. The BTCNT1 counter input is
the ACLK clock signal with a frequency of 32.768 kHz.
If BTCNT2 counter selected output is divided by 128, what is the time period associated with the Basic
Timer1 interrupt? _________
What are the values to write to the conguration registers?
//*********************************************************
// Basic Timer ISR. Run with 1 sec period
//*********************************************************
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer_ISR(void)
{
unsigned int read_data; // read data from file , frequency in kHz
if (counter == 5){
counter = 0;
read_data = 200;
TBCCR0 = 7995392/read_data;
TBCCR4 = TBCCR0/2;
}
}
The MCLK, SMCLK and ACLK system clocks are available at ports P1.1, P1.4 and P1.5 respectively. These
ports are located on the SW2, RESET_CC and VREG_EN lines, which are available on the H2 Header
pins 2, 5 and 6. All these resources are available because the Chipcon RF module is not installed and SW2
is not used.
Using the Registers view, set bits 1, 4 and 5 of P1SEL and P1DIR registers to choose the secondary
function of their ports, that is, congured as outputs. Connect an oscilloscope probe at these positions to
monitor the clock signals.
What are the values measured for each of the system clocks?
ACLK: _____________________
SMCLK: ____________________
MCLK: _____________________
With the help of an oscilloscope, it is possible to evaluate the operation of the application. Alternatively, it
is possible to listen to the sound produced. By removing jumper JP1 and connecting the oscilloscope to this
pin, it is possible to view the PWM signal produced by the microcontroller. The duty-cycle can be reduced
or increased by pressing the push buttons SW1 and SW2.
All Port P1 interrupt lines share the same interrupt vector. The decoding is done through the P1IFG register.
This process can be observed by entering a breakpoint at the rst line of the ISR code.
Execute the application.
The application's execution is suspended at the breakpoint by pressing either button SW1 or SW2. From
this point onwards, run the lines of code step-by-step and observe changes in the register values.
The power consumption was discussed in the previous point. The electrical power required by the system
during operation is measured by replacing the jumper on the Header PWR1 by an ammeter, which indicates
the electric current taken by device during operation.
What is the value read? __________
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
12
12 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Correct system timing is a fundamental requirement for the proper operation of a real-time application. The
timing denition can dictate how the data information processed during the execution of the application
program. The clock implementations vary between devices in the MSP430 family. Each device provides
dierent clock sources, controls and uses. This chapter discusses the clock controls included in the platforms
used.
The MSP430 4xx family has two general-purpose 16-bit or 8-bit counters and event timers, named
Timer_A, Timer_B, and a Basic Timer. The Basic Timer module is only implemented in `4xx devices. The
2xx device family also has Timer_A and Timer_B, but the clock signals are provided by the basic clock
module+.
The timers may receive an internal or external clock. Timer_A and Timer_B also include multiple
independent capture and compare blocks, with interrupt capabilities.
4.5.1.2 Overview
4.5.1.3 Resources
The module FLL+ is congured to a frequency of 7.995392 MHz for the MCLK and SMCLK clock signals.
This application performs the two tasks simultaneously.
On the one hand, it generates a PWM signal with a frequency of 200 Hz and a duty cycle of 50%.
Alternatively, the PWM signal frequency can be read from a le using a breakpoint. This function is
performed by Timer_B, using the compare unit to generate the PWM signal.
The time period between two consecutive PWM signals low-to-high transitions is measured by Timer_A.
The capture unit of this timer is congured to collect the Timer_A counter register's contents when a PWM
signal low-to-high transition is detected at its input.
The Basic Timer1 generates an interrupt once every second. The ISR updates the PWM signal frequency
generated by the Timer_B. If you choose to use this feature, a breakpoint associated with this ISR execution
allows reading a le with the value of the frequency that will be generated.
The microcontroller's ports are congured in order that the PWM signal generated by Timer_B through
the TBCCR4 compare unit available at Port P3.5/TB4 can be connected to the Port P1.2/TA1 of the
Timer_A TACCR1 capture unit. If you plan to use this feature, these pins must be connected together.
Port P3.5 pin is available on Header 7 pin 6, while the Port P1.2 pin is available on Header H2 pin 3.
Ports P2.1 and P2.2 are used to monitor the state of the LED2 and LED1, respectively.
The resources used by the application are:
- Timer_A;
- Timer_B;
- Basic Timer1;
- I/O ports;
- FLL+;
- Interrupts.
The software structure allows various tasks to be performed simultaneously. The routine main() is respon-
sible for conguring all the resources used by the application. Once started, the application enables all the
interrupts and waits for an interrupt request.
There are two routines that separately service the two possible interrupts. The routine TimerA1_ISR()
services interrupts required by the Timer_A overow and by the TACCR1 capture unit. For every interrupt
caused by a TACCR1 capture, the value collected in the TACCR1 register is stored in T1, if it is the rst
low-to-high transition, or stored in T2 if it is the second low-to-high transition. This sequence is controlled
by the variable capture. The variable ag is used to ag the measurement process. This process occurs
between the capture of the rst low-to-high transition and the second transition. The counting of clock
pulses is done by Timer_A, in the time interval between the T1 and T2 acquisition, assigned to the variable
T. The process is synchronized when Timer_A overows, restarting the measurement process. The LCD is
refreshed once every 0.5 seconds with the latest measured frequency value, using the control variable control
tick that corresponds to 0.5 seconds.
The routine basic_timer_ISR() services the interrupt produced by Basic Timer1 once every second.
This routine begins by switching the state of LED1 and LED2. In addition, it updates the Timer_B
counting period. The variable read_data allows the counting period to be changed.
Basic Timer1 generates an interrupt once every second. Use the two counters in series, where the BTCNT2
counter input is selected as the BTCNT1 counter output divided by 256. The BTCNT1 counter input is the
ACLK clock signal with a frequency of 32.768 kHz.
If BTCNT2 counter selected output is divided by 128, what is the time period associated with the Basic
Timer1 interrupt? _________
The values written to the conguration registers are:
4.5.1.5.2 Timer_B
The TBCCR4 compare unit is used to generate the PWM signal. The set/reset compare mode is used.
The values written to the conguration registers are:
The TB4 PWM output signal has a frequency X, with a 50% duty-cycle. The SMCLK clock signal is used
as input of Timer_B.
The values written to the conguration registers are:
4.5.1.5.3 Timer_A
Timer_A is sourced by the SMCLK clock signal. It counts to the value 0xFFFF, in continuous mode. An
interrupt is generated when the TAR counter overows. What is the value to write to its conguration
register?
The capture unit captures the TAR register value to the TACCR1 register when it detects a low-to-high
transition at the TA1 input. What is the value to write to the conguration register?
Determine the maximum and minimum frequency values detected. Note that these values do not take into
account the execution time of the application. The PWM signals should be applied at frequencies well below
the maximum value determined.
Maximum frequency value: ____________
Minimum frequency value: _____________
The TACCR1 capture unit is congured to generate an interrupt when it detects a low-to-high transition.
What is the value to write to the conguration register?
TACCTL1 |= CM1
These ports perform special functions. Thus, the Port P3.5 is congured as an output, selected by the special
function TB4, with the values:
The Port P1.2 is congured as input, with the special function TA1, using the values:
4.5.1.6.1 Run the application using the frequency generator based on Timer_B
Without a frequency generator, the Timer_B generates a PWM signal at the TBCCR4 unit output that
can be fed back to Timer_A TACCR1 capture unit input. These two pins must therefore be connected
together. By default, the PWM signal frequency is 200 Hz. Add a breakpoint at the line of code belonging
to the Basic Timer1 ISR to modify this value.
TBCCR0 = 7995392/read_data;
If the variable read_data has the value 200, it will generate a 200 Hz frequency. The value of this variable
can be changed by associating a breakpoint to that line of code. Before the line of code is executed, the
value of the data le is read and assigned to the variable read_data. The signal will oscillate at the desired
frequency, loading the value in TBCCR0. The breakpoint conguration is as follows:
- Action: read data from le
- File: address of the data le (example in freq.txt)
- Wrap Around: activate this option to restart reading at the beginning
- Start address: &read_data
- Length: 1 in order to read a value from the le each time
The operation of the application can be veried using a frequency generator. The generator should generate
a PWM signal with voltage and frequency values compatible with the device's input (2.5 to 3.3 volts).
The PWM signal applied to the TA1 input can be viewed using an oscilloscope, connected to pin 3 of Header
2. Perform this task and conrm the values present at the LCD.
The power consumption was discussed in the previous point. The electrical power required by the system
during operation is measured by replacing the jumper on the Header PWR1 by an ammeter, which indicates
the electric current taken by device during operation.
What is the value read? __________
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
15
15 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
LCD Controller
99
100 CHAPTER 5. LCD CONTROLLER
This hands-on laboratory consists of conguring the LCD_A controller of the MSP430FG4618 device of the
Experimenter's board to display a message on the LCD display. This laboratory has been developed for
Code Composer Essentials version 3 software development tool only.
5.1.1.2 Overview
This laboratory will explore the LCD_A controller of the MSP430FG4618 device included on the Experi-
menter's board. This application ( Lab1_LCD.c
2 ) demonstrates the activation of various LCD segments.
5.1.1.3 Resources
The Experimenter's board uses a LCD, which does not have its own controller. The operation is controlled
by MSP430FG4618.
The interface between these two components is described in the Experimenter's Board datasheet
slau213a.pdf
3
It is also recommended that the LCD datasheet be read.
Based on this information, it is possible to dene the values to write to each of the memory registers to
turn on the desired segments, or to set several of them, as is the case with numbers. The denitions are
listed in LCD_defs.h
4 .
From analysis of the Experimenter's Board schematics, it can be seen that there is a 10 µF between the
LCDCAP pin and ground, which means it is possible to use the charge pump.
The segments shared by the I/O function are not used by the LCD, being connected to the segments S4
to S25. The four lines COM0, COM1, COM2, and COM3 are used. The last three lines are shared by ports
P5.2, P5.3 and P5.4, respectively. The LCD is operated in 4-mux mode.
The pins R03, R13, R23 and LCDCAP\R33 are used to provide the V5, V4, V3, V2 and V1 (V LCD )
voltages, using an external resistor network. They are available at Header H5.
In the current Experimenter's Board conguration, it is possible to select the AV ss or charge pump to
provide the V1 (V LCD ), V2, V3, V4 and V5 voltages. These voltages are only generated when LCD_A
module and the ACLK clock are active. This allows the use of low power mode 3 (LPM3).
Timer_A, together with the TACCR0 unit are used to generate an interrupt once every second. LED1
and LED2 are switched at each Timer_A interrupt.
The push button SW1 is used to change the value of voltage generated by the charge pump. The push
button SW2 is used to change the LCD frequency.
The application starts by conguring the Ports P5.2, P5.3, P5.4 to special function COM1, COM2 and
COM3, respectively. The function of COM0 is not shared with the digital I/O functions.
Then, the pins with multiplexed functions are selected to perform the functions necessary to control the
LCD segments.
The LCD_A control register and the voltage conguration register are also congured.
There then follows the execution of the LCD clear routine LCD_all_off(), which ensures that all segments
of the LCD are o.
1 This content is available online at <http://cnx.org/content/m23558/1.3/>.
2 http://cnx.org/content/m23558/latest/Lab1_LCD.c
3 http://cnx.org/content/m23558/latest/SBLCDA4_Specication.pdf
4 http://cnx.org/content/m23558/latest/LCD_defs.h
Timer_A is congured with its TACCRO unit to generate an interrupt once every second. The ISR
generates the memory clock with msec, sec and min, and also connects/disconnects the remaining LCD
symbols.
The port pins P2.1 and P2.2 drive LED2 and LED1, respectively. Hence, these ports are congured as
digital outputs.
Push buttons SW1 and SW2 have the capacity to generate an interrupt through a change at ports P1.0
and P1.2 respectively. The interrupt ISR, after decoding its source, modies the LCD operation frequency
or modies the VLCD voltage.
Finally, all the interrupts are activated and the system enters low power mode LPM3.
Select the function COM1, COM2 and COM3. What is the value to write to these registers?
The LCD segments are controlled by the S4 to S25 LCD memory segments. Activate these segments by
writing to correct value to the following register:
LCDAPCTL0 = LCDAPCTL0 = LCDS24 | LCDS20 | LCDS16 | LCDS12 | LCDS8 | LCDS4; // Enable S4 to S25
The LCD is to operate in 4-mux mode, with a 30 Hz to 100 Hz refresh frequency. It uses the following
equation to determine the LCD operation frequency, f LCD :
fLCD = 2 x mux x fframe
Choose the frequency that provides greatest energy savings.
The LCD_A module is to be activated in 4-mux mode from a 32768 Hz clock. What value should be written
to the following register?
Use the charge pump to internally generate all the voltages necessary for the operation of the LCD, using a
bias 1/3. What is the value to write to the register?
LCDAVCTL0 = LCDCPEN; // Charge pump enable
The charge pump generates a LCD voltage of 3.44 volts. Congure the following register:
LCDAVCTL1 = VLCD_3_44; // VLCD = 3.44 V
The Timer_A generates an interrupt once every second. It uses the TACCR0 unit. Congure the following
registers:
Congure the ports connected to LED1 and LED2 in order to make one of them active and the other inactive
at system start up:
The push buttons SW1 and SW2 generate an interrupt on a low-to-high transition. Congure the necessary
registers:
Compile the project, load it into microcontroller's memory and execute the application. For each value of the
operating frequency and voltage generated by the charge pump, measure the electrical current consumption.
Draw a graph of these results and draw conclusions concerning the energy consumption.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
5
5 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Data Acquisition
103
104 CHAPTER 6. DATA ACQUISITION
This laboratory gives examples of the uses of the ADC types available in the hardware development kits. A
dierent laboratory is developed for each kit, taking into account that both the ADC10 and the SD16_A
laboratories implement a temperature data logger. The ADC12 laboratory also uses operational ampliers
to perform the analogue signal conditioning.
6.1.1.2 Overview
6.1.1.3 Resources
Flash memory pointers and interrupt counters are initialized. The Timer_A ISR increments the variable
counter and when this variable reaches the value 60 (1 minute), the software start of conversion is requested.
At the end of this ISR, the system returns to low power mode.
When the ADC10 ends the conversion, an interrupt is requested. While variable min is lower than 60,
the temperature is written to ash memory. The memory pointer is increased by two (word). When min =
60, the system stops operation.
Adjust the DCO frequency to 1 MHz by software using the calibrated DCOCTL and BCSCTL1 register
settings stored in information memory segment A.
Set MCLK and SMCLK to 1 MHz. Use the internal very low power VLOCLK source clock to ACLK/8 clock
signal as low frequency oscillator (12 kHz):
The ADC10's input channel is the integrated temperature sensor (A10) and it uses the signal V REF+ (1.5
V) as reference voltage. The ADC10 clock source is ADC10OSC, the clock signal being ADC10CLK/4.
Congure the ADC10 sample-and-hold time: 64xADC10CLKs, to perform a single-channel single-conversion
and enable its interrupts. What are the values to write to the conguration registers?
//*********************************************************
// ADC10 Interrupt Service Routine
//*********************************************************
#pragma vector=ADC10_VECTOR
__interrupt void ADC10ISR(void)
{
unsigned int temperature;
Congure Timer_A register to enable an interrupt once every second. Use the ACLK clock signal as the
clock source. This timer is congured in up counter mode in order to count until the TAR value reaches the
TACCR0 value.
//**********************************************************
// Timer_A Interrupt Service Routine
//**********************************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0_ISR (void)
{
counter++;
P1OUT ^= 0x01; // LED toogle
if (counter == 60)
{
min++;
counter = 0;
ADC10CTL0 |= ENC + ADC10SC; // Sampling/Conversion start
}
}
After compiling the project, start the debug session and before running the application, put a breakpoint
_NOP() instruction. Go to breakpoint properties and set action to Write data
at the line of code with the
to le. Name the le as Temp.dat and dene the data format as integer. The data starts at address
0x01040, with a length of 3C. Run the application and let the temperature data logger acquire the values
for 1 hour. Use a heater or a fan to force temperature variations during the measurement period. When
execution reaches the breakpoint, the le will be available in your le system. Construct a graph in Excel
or a similar tool, in order to plot the temperature variation obtained by the data logger.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
3
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
This laboratory gives examples of the uses of the ADC types available in the hardware development kits. A
dierent laboratory is developed for each kit, taking into account that both the ADC10 and the SD16_A
laboratories implement a temperature data logger. The ADC12 laboratory also uses operational ampliers
to perform the analogue signal conditioning.
6.2.1.2 Overview
6.2.1.3 Resources
The DAC12 module uses the same internal reference voltage as the ADC12 module (V REF+ = 2.5 V).
The OA module is congured as Non-inverting PGA with unity gain. The Non-inverting input is the
DAC0 internal while the output is connected to internal/external A1 of the ADC12. The ADC12 sample-
and-hold time is congured to be 64 ADC12CLK cycles. It performs a single-channel, single-conversion using
ADC12OSC/1 as the clock source.
The resources used by the application (following the signal modication steps) are:
- DAC12;
- OA;
- ADC12;
- Timer_A;
- Interrupts.
The Timer_A is congured to use the ACLK as the clock source. It will count in continuous mode
(TACCR0 counts up to 0FFFFh) and generate an interrupt to update the ADC12MEM. When the interrupt
is serviced, the MSP430 enters into LPM3.
ADC12CTL0 |= SHT02|REF2_5V|REFON|ADC12ON|ENC|ADC12SC;
//SHT1x (Sample-and-hold time) = 0000b -> N/A
//SHT0x (Sample-and-hold time) = 0010b -> 64 ADC12CLK
//MSC (Multiple sample and conversion) = 0b -> N/A
//REF2_5V (Reference generator voltage) = 1b -> 2.5 V
//REFON (Reference generator on) = 1b -> Reference on
//ADC12ON (ADC12 on) = 1b -> ADC12 on
//ADC12OVIE (overflow-int. enable) = 0b -> disabled
//ADC12TOVIE (conversion-time-overflow int enable) = 0b
// -> disabled
//ENC (Enable conversion) = 0b -> enable configuration
//ADC12SC (Start conversion) = 1b -> Start conversion
The OA module of the MSP430FG4168 has three operational ampliers with wide utilization exibility. For
this laboratory it is set up using the OA0 in non-Inverting PGA mode with the following conguration:
- The inverting input is connected to the DAC12 channel 0;
- The amplier gain is congured as unity;
- The input is congured in rail-to-rail mode;
- The output is connected to the channel A1.
#pragma vector=ADC12_VECTOR
__interrupt void ADC_ISR(void)
{
int x;
x = ADC12MEM0; // Reads data
ADC12CTL0 |= ADC12SC; // Start new conversion
}
#pragma vector=TIMERA1_VECTOR
__interrupt void TimerA_ISR (void)
{
ADC12CTL0 &= ∼ADC12SC; //start new conversion
TACTL &= ∼TAIFG;
}
This laboratory uses the previous modules to construct an analogue signal chain as shown in Figure 1.
Figure 6.1
The input voltage V IN is in the range 0 V and 2.5 V, with a resolution of:
∆VIN = ( 2.5 x V REF ) / 212 = 0.6 mV
The V IN value is controlled by the value in the DAC12_0DATA register.
The output voltage V o has the same characteristics as the input voltage, but scaled by a multiplication
factor (gain), attributed by the OA. The OA gain is selectable through the OAFBR eld in the OA0CTL1
register.
The V o conversion result is stored in the ADC12MEM0 register.
Once the signal chain modules are congured in accordance with the previous steps, initiate the exper-
iment by completing the le, compiling it and running it on the Experimenter's board. For the evaluation
of the peripherals discussed during this laboratory, set a breakpoint on the ADC12_ISR and perform the
following operations:
- Congure the DAC12_0DATA register with the value 0xFF. With the aid of a voltmeter, measure the
analogue input voltage A6 (DAC12 channel 0 output). The value should be in the region of 0.15 V;
- Measure the input voltage A1 (OA0's output). The voltage value should be the same;
- Execute the code. Verify the ADC12's conversion result. The value should be similar to the one of the
DAC12_0DATA register;
- Double the amplier gain (2x). Verify the voltage at A0. It should be the double of the input voltage
A1 (OA0's output) given in step 2;
- Execute the code. Verify the ADC12's conversion result. The value should be two times the value of
the DAC12_0DATA register;
- Execute further modications in order to evaluate the digital-to-analogue and analogue-to-digital con-
version. Do not exceed the Vo maximum value (2.5 V).
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
6
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
This laboratory gives examples of the uses of the ADC types available in the hardware development kits. A
dierent laboratory is developed for each kit, taking into account that both the ADC10 and the SD16_A
laboratories implement a temperature data logger. The ADC12 laboratory also uses operational ampliers
to perform the analogue signal conditioning.
6.3.1.2 Overview
6.3.1.3 Resources
The Timer_A is congured to generate an interrupt once every second. ACLK/8 is selected as the clock
signal using VLOCLK as clock source and will count until it reaches the TACCR0 value (up mode). The
system enters into low power mode and waits for an interrupt.
Flash memory pointers and interrupt counters are initialized. The Timer_A ISR increments variable
counter and when this variable reaches the value 60 (1 minute), the software start of conversion is requested.
At the end of this ISR, the system returns to low power mode.
When the SD16_A ends the conversion, an interrupt is requested. While variable min is lower than 60,
the temperature is written in ash memory. The memory pointer is increased by two (word). When min =
60, the system stops operation.
Adjust the DCO frequency to 1 MHz by software using the calibrated DCOCTL and BCSCTL1 register
settings stored in information memory segment A.
Set MCLK and SMCLK to 1 MHz. Use the internal very low power VLOCLK source clock to ACLK/8 clock
signal as low frequency oscillator (12 kHz):
The SD16_A's input channel is the integrated temperature sensor (A6) and it uses the signal V REF+ (1.2
V) as reference voltage. The SD16_A clock source is SMCLK. Congure the SD16_A to perform a single
conversion and enable its interrupts. What are the values to write to the conguration registers?
//*********************************************************
// SD16_A Interrupt Service Routine
//*********************************************************
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
unsigned int temperature;
Congure Timer_A register to enable an interrupt once every second. Use the ACLK clock signal as the
clock source. This timer is congured in up mode in order to count until the TAR value reaches the TACCR0
value.
//*********************************************************
// Timer_A Interrupt Service Routine
//*********************************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0_ISR (void)
{
counter++;
P1OUT ^= 0x01; // LED toogle
if (counter == 60)
{
min++;
counter = 0;
SD16CCTL0 |= SD16SC; // Start SD16 conversion
}
}
After compiling the project and starting the debug session, before running the application, put a breakpoint
at line of code with the _NOP() instruction. Go to breakpoint properties and set action to Write data to le.
Name the le as Temp.dat and dene the data format as integer. The data starts at address 0x01040 with
a length of 3C. Run the application and let the temperature data logger acquire the values over 1 hour. Use
a heater or a fan to force temperature variations during the measurement period. When execution reaches
the breakpoint, the le will be available in your le system. Construct a graph using Excel or a similar tool,
to plot the temperature variation obtained by the data logger.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
9
9 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
This laboratory gives examples of the uses of the ADC types available in the hardware development kits. A
dierent laboratory is developed for each kit, taking into account that both the ADC10 and the SD16_A
laboratories implement a temperature data logger. The ADC12 laboratory also uses operational ampliers
to perform the analogue signal conditioning.
6.4.1.2 Overview
6.4.1.3 Resources
Congure the registers in order to receive the external signal at the CA0 input and compare it with the
internal reference 0.5 V cc . Enable the comparator with an interrupt triggered on a low-to-high transition of
the comparator output.
//*********************************************************
// Comp_A interrupt service routine -- toggles LED
//*********************************************************
#pragma vector=COMPARATORA_VECTOR
__interrupt void Comp_A_ISR (void)
{
CACTL1 ^= CAIES; // Toggles interrupt edge
P2OUT ^= 0x02; // Toggle P2.1
}
// Compare mode
TAR = 0; // TAR reset
TACCR0 = 13600; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt
TACTL = TACLR + MC_1 + TASSEL_2; // up mode, SMCLK
// Interrupt enable
TAR = 0; // TAR reset
TACCTL0 = CCIE; // CCR0 interrupt enabled
TACCR0 = 32; // 1 msec counting period
TACTL = TASSEL_1 | MC_1 | ID_0; // ACLK, up mode
//*********************************************************
// ISR to TACCRO from Timer A
//*********************************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0_ISR (void)
{
DAC12_0DAT++;
if (DAC12_0DAT == 0xFFF)
DAC12_0DAT = 0;
The experimental verication of this laboratory can be accomplished by connecting the DAC12's output,
available on Header 8 pin 7, to the Comparator_A's input CA0, available on Header 4 pin 7.
Observe the signals wave form at the Comparator_A's input and output using an oscilloscope. The
LED1 switches state whenever the input's voltage value is lower than the compare value.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
12
12 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
121
122 CHAPTER 7. DIGITAL-TO-ANALOG CONVERTER (DAC)
This laboratory gives an example of the use of the DAC available in the MSP-EXP430FG4618 Development
Tool. The DAC module reference is obtained from the ADC module. The DAC is congured with 12 bits
resolution in straight binary format. The DAC's output value is updated every 1 msec by a Timer_A ISR.
The buttons SW1 and SW2 are used to manually modify the DAC's output.
7.1.1.2 Overview
7.1.1.3 Resources
The DAC12_0 module uses V REF+ as reference voltage. It is therefore necessary to activate this reference
voltage in the ADC12 module.
The DAC12_0 is connected to Port P6.6 on the Header 8 pin 7. Connect the oscilloscope probe to this
port pin.
The output of the DAC is updated whenever Timer_A generates an interrupt. This peripheral is con-
gured to generate an interrupt with a 1 msec time period.
After refreshing the output of the DAC, the system returns to low power mode LPM3.
The push buttons SW1 and SW2 allow the output of the DAC value to be changed manually.
The resources used by the application are:
- Timer_A;
- DAC12;
- I/O ports;
- FLL+;
- Interrupts.
The DAC12_0 uses the signal V REF+ as reference voltage. What is the value to write to the conguration
register in order to obtain the internally available reference?
ADC12CTL0 = REF2_5V | REFON; // Internal 2.5V ref on
The DAC12_0 is congured with 12-bit resolution. The output is updated immediately when a new DAC12
data value is written in straight binary data format to the DAC12_0DAT register.
The full-scale output must be equal to the V REF+ 2.5 V internal reference voltage. Choose a compromise
solution between the settling time and current consumption, by selecting a medium frequency and current
for both input and output buers. Congure the following register in order to meet these specications:
Congure Timer_A register to enable an interrupt once every 1 msec. Use the ACLK clock signal as the
clock source. This timer is congured in count up mode in order to count until the TAR value reaches the
TACCR0 value.
// Timer_A ISR:
TAR = 0; // TAR reset
TACCR0 = 13600; // Delay to allow Ref to settle
//*********************************************************
// ISR to TACCRO from Timer A
//*********************************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void TimerA0_ISR (void)
{
DAC12_0DAT++; // Increase DAC's output
if (DAC12_0DAT == 0xfff)
DAC12_0DAT = 0; // reset DAC's output
if (flag == 1) // if flag active exite LPM0
{
flag = 0;
LPM0_EXIT;
}
}
Port P1 uses the bits P1.0 and P1.2 to activate the ISR whenever the push buttons SW1 and SW2 are
activated (low-to-high transition).
//*********************************************************
// Port1 Interrupt Service Rotine
//*********************************************************
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR (void)
{
if (P1IFG & 0x01) // SW1 generate interrupt
DAC12_0DAT += 400; // DAC's output increases
After compiling the project and starting the debug session, monitor the operation of the application using
an oscilloscope probe connected to pin 7 of Header 8 (P6.6).
Assign dierent values to the bits set in DAC12AMP0. Suspend the execution of the application then directly
change the registers. Do not forget that this change requires suspending the operation of the DAC12 by
disabling the bit DAC12ENC. Afterwards, this bit must be enabled.
Please note the special cases relating to:
- DAC12 o;
- High impedance output and DAC12 o;
- Output: 0 V.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
3
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
127
128 CHAPTER 8. DIRECT MEMORY ACCESS (DMA)
This laboratory gives an example of the use of the DMA peripheral available in the MSP-EXP430FG4618
Development Tool. It requires the conguration of the DMA Source and Destination Addresses Registers,
DMA Size Address Register; DMA Control Registers and DMA Channel 0 Control Register in order to
transfer data between two regions of memory.
8.1.1.2 Overview
8.1.1.3 Resources
The software begins by disabling the watchdog timer. Port P2.1 is set as an output with a logic low level.
The memory addresses of the data vectors are passed to the source data address DMA0SA and destination
address DMA0DA registers.
The number of words to be transferred is loaded in the DMA0SZ (size) register.
The DMA channel 0 is congured so that the data transfer trigger is controlled by software, in order that
after each transfer, the source and destination addresses are correctly incremented.
The application enters an innite loop, where port P2.1 state is switched just before initiating the data
transfer.
The source address and destination address of the data must be loaded into their respective registers:
To move a total of 32 words, what is the value to write to the data size register?
DMA0SZ = 0x0020; // Block size
The DMA channel must be congured to transfer the word under software control. The source and
destination addresses should be incremented immediately after each of the transfers.
// Enable DMA0
In the Memory window, the addresses of data vector Tab_1 and Tab_2 addresses are displayed. The contents
of these blocks must be identied in memory.
Add a breakpoint at line of code that performs the switching of port P2.1 state.
Execute the application, and whenever the breakpoint is reached, the execution of the application will
be suspended. Observe the data being gradually transferred from source to destination.
The data transfer is suspended once the 32 elements of the source data vector have been transferred.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
3
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
This laboratory gives an example of the use of the DMA peripheral available in the MSP-EXP430FG4618
Development Tool. It requires the conguration of the DMA Source and Destination Addresses Registers,
DMA Size Address Register; DMA Control Registers, DMA Channel 0 Control Register, DAC12 control
register and Timer_A control register in order to generate a sinusoidal waveform.
8.2.1.2 Overview
8.2.1.3 Resources
The successive samples needed to produce the sinusoidal waveform using the DAC are stored in the data
vector Sin_tab, which contains 32 points:
//---------------------------------------------------------
// 12-bit Sine Lookup table with 32 steps
//---------------------------------------------------------
int Sin_tab[32] = {2048, 2447, 2831, 3185, 3495, 3750, 3939, 4056,
4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447,
2048, 1648, 1264, 910, 600, 345, 156, 39,
0, 39, 156, 345, 600, 910, 1264, 1648};
The software begins by disabling the watchdog timer, followed by activating the internal reference voltage
VREF+ . The source and destination registers of the data vector to be transferred by the DMA channel
are loaded into the data vector Sin_tab (source) address and with the DAC12 data register (destination)
address. There are 32 data values to be transferred.
The data transfer is initiated whenever the DAC12IFG ag is enabled. In this application, the DAC
interrupt should be disabled.
The DMA controller is congured to operate in repeat mode, to transfer a word whenever the previous
event occurs. The data source address is set to increment after each transfer, while the destination address
must remain constant.
The timer is set to generate the PWM signal through the capture/compare unit TACCR1. SMCLK is
the clock signal that counts up to the value in the TACCR0 register.
Finally, the settings and interrupts are enabled and the device enters into low power mode LPM0.
The DAC12 requires a reference voltage. One of the options is to use the internal voltage V REF+ . Set the
ADC12CTLO register to activate this voltage:
ADC12CTL0 = REFON; // Internal reference
Congure the registers DMA0SA (source), DMA0DA (destination) and DMA0SZ (size) to transfer 32 words
between the source vector Sin_tab and the DAC12_0DAT data destination register:
Congure the register DMACTL0 to provide a data transfer whenever the DAC12IFG ag is set:
DMACTL0 = DMA0TSEL_5; // DAC12IFG trigger
Congure the register DMA0CTL to carry out a repeated simple data transfer, increasing the data source
address:
The DAC12 will update its output whenever there is the activation of the signal TA1. The DAC full-scale
should be 1x reference voltage. Choose a medium relationship between the DAC's current and average
conversion speed:
Timer_A is responsible for synchronizing data transfers between memory and the DAC12. The Timer_A
input receives as the SMCLK signal (1.048576 MHz) and must have a 30 msec counting period. What value
needs to be written to TACCR0, in order to achieve this counting period:
The capture/compare unit TACCR1 should generate a PWM signal in set/reset mode. Congure the unit
appropriately:
The verication of this laboratory is achieved by using an oscilloscope probe to monitor the output of the
DAC12 Channel 0, available on header 8 pin 6.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
6
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Hardware Multiplier
133
134 CHAPTER 9. HARDWARE MULTIPLIER
This laboratory explores the hardware multiplier peripheral. It is composed of three dierent tasks, each of
which evaluates a dierent characteristic of the hardware multiplier peripheral:
- Multiplication operation execution time, with and without the hardware multiplier.
-Dierences between the use of the operator * and direct write to the hardware multiplier registers.
- Task operational analysis, in which the active power and the RMS value of an electrical system are
calculated.
9.1.1.2 Overview
This laboratory explores and analyses the MSP430's performance when it performs multiply operations
without the hardware multiplier. The execution time is measured using an oscilloscope.
9.1.1.3 Resources
This laboratory only uses Port P2.1 connected to LED2 in order to measure the execution time of the
multiply operation when it is performed by a software routine.
The default conguration of the FLL+ is used. All the clock signals required for the operation of the
components of this device take their default values.
Go to Properties > TI Debug Settings and select the Target tab. Uncheck the automatically step
over functions without debug information when source stepping in order to allow stepping into the
multiply routine;
Go to Properties > C/C++ Build > Linker MSP430 Linker v3.0 > General options and choose
the option None at the Link in hardware version of RTS mpy routine. With this linker option, the
application ( Lab1_HM.c
2 ) will be built without the hardware multiplier and all multiplication operations
will be performed by the software routine.
Rebuild the project and download it to the target.
Run to line;
- Put the cursor at line of code 51 {c = a*b} and
- Go to Disassembly view and switch to mixed disassembly view in order to show both C and
Assembly code;
- Observe that the variables a and b are passed by registers and the #__mpyi routine is called;
- Run the code step-by-step with the Disassembly view active. This action will lead to the software
multiply routine;
- As the software multiply routine source code is not available, switch to Assembly view only;
- Run the application step-by-step until the RETA instruction;
- This multiplication is a time-consuming CPU operation.
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
This laboratory explores the hardware multiplier peripheral. It is composed of three dierent tasks, each of
which evaluates a dierent characteristic of the hardware multiplier peripheral:
- Multiplication operation execution time, with and without the hardware multiplier.
-Dierences between the use of the operator * and direct write to the hardware multiplier registers.
- Task operational analysis, in which the active power and the RMS value of an electrical system are
calculated.
9.2.1.2 Overview
This laboratory explores and analyses the MSP430's performance when it performs multiply operations using
the hardware multiplier peripheral. Two dierent variants are analysed:
- Using the * operator;
-Accessing the hardware multiplier registers directly.
The execution times are measured with an oscilloscope.
9.2.1.3 Resources
This laboratory only uses Port P2.1 connected to LED2 in order to measure the execution time of the
multiplication operation, when it is performed by the hardware multiplier.
The default conguration of the FLL+ is used. All the clock signals required for the operation of the
components of the device take their default values.
Go to Properties > TI Debug Settings and select the Target tab. Uncheck the automatically step
over functions without debug information when source stepping in order to allow stepping into the
multiply routine;
Go to Properties > C/C++ Build > Linker MSP430 Linker v3.0 > General options and
choose the option 16 (default) at the Link in hardware version of RTS mpy routine. With this
4 This content is available online at <http://cnx.org/content/m23584/1.2/>.
- Connect the oscilloscope probe to port P2.1, which is connected to Header 4 pin 2;
- Put the cursor at line of code 55 {c
= a*b} and Run to line;
- Go to Disassembly view and switch to mixed disassembly view in order to show both C and
Assembly code;
- Observe that the variables a and b are passed to registers and #__mpyi_hw routine is called;
- Run the code step-by-step with the Disassembly view active. This action will lead to the multiply
operation being performed by the hardware multiplier;
- As the hardware multiply routine source code is not available, switch to Assembly view only;
- The routine starts by pushing the Status Register onto the system stack (PUSH instruction) and disabling
the interrupts (this always occurs when using the hardware multiplier peripheral);
- The next line of code exchanges data with the hardware multiplier;
- Then the SR is popped (POP instruction) from the system stack, restoring the system environment (data
interrupt state restored);
- The routine nishes with a RETA instruction.
5 http://cnx.org/content/m23584/latest/Lab2_HM.c
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
This laboratory explores the hardware multiplier peripheral. It is composed of three dierent tasks, each of
which evaluates a dierent characteristic of the hardware multiplier peripheral:
- Multiplication operation execution time, with and without the hardware multiplier.
-Dierences between the use of the operator * and direct write to the hardware multiplier registers.
- Task operational analysis, in which the active power and the RMS value of an electrical system are
calculated.
9.3.1.2 Overview
This laboratory explores and analyses the MSP430 performance when it makes multiply operations using
the hardware multiplier peripheral. In this laboratory, the active power and the RMS value of an electrical
signal are calculated.
The execution times are measured using an oscilloscope.
9.3.1.3 Resources
This laboratory only uses Port P2.1 connected to LED2, in order to measure the execution time of the
multiply operation when it is performed by the hardware multiplier.
The application uses the default conguration of the FLL+. All the clock signals required for the
operation of the components of the device take their default values.
N
1 X
P = uk ik (9.1)
N
k=1
- A signed multiply operation is performed by writing the rst sample of current to MPYS and the rst
sample of voltage to OP2;
- The result of the multiplication is stored in the RESHI and RESLO registers;
- A loop is performed with a signed multiply and accumulate (MACS) operation;
- The nal result is transferred from the RESHI and RESLO registers to the long variable result;
- The power is computed by dividing the variable result by the number of samples (N);
- Port P2.1 is active between MACS operations;
- The RMS current and voltage values are calculated from the following expressions:
v
u
u1 XN
IRMS =t ik ik (9.2)
N
k=1
v
u
u1 XN
URMS =t uk uk (9.3)
N
k=1
- The two procedures are similar, with the exception of the square root (sqrt) operations;
- P2.1 is active during for all the RMS current calculation;
- The computation times of the sqrt and division operations are determined when the RMS voltage value
is calculated;
- This application ends by putting the device into low power mode LPM4.
Go to Properties > TI Debug Settings and select the Target tab. Uncheck the automatically step
over functions without debug information when source stepping in order to allow stepping into the
multiply routine;
Go to Properties > C/C++ Build > Linker MSP430 Linker v3.0 > General options and
choose the option 16 (default) at the Link in hardware version of RTS mpy routine. With this
linker option, the application ( Lab3_HM.c
8 ) will be built with the 16-bit hardware multiplier peripheral
contained in the Experimenter's board.
Rebuild the project and download to the target.
- Connect the oscilloscope probe to port P2.1, which is available at Header 4 pin 2;
- Put the cursor at the line of code 88 and Run to line;
- In the Variables view, add the global variable P and format it to decimal;
- The active power is in the region of 1204 W;
- The pulse width, as viewed on the oscilloscope, corresponds to the time to perform the 200 signed
multiply and accumulate operations and is 5.4 msec.
8 http://cnx.org/content/m23582/latest/Lab3_HM.c
- Starting at the last step of the previous task, put the cursor at line of code 105 {MPYS = u[0]} and Run
to line;
- Add the global variable I (RMS voltage);
- Set the value to 10;
- The pulse width, as viewed on the oscilloscope, corresponds to the time required to perform the 200
signed multiply and accumulate operations, 1 division operation and 1 square root operation, and is 12.6
msec;
- Starting at the last step of the previous task, put the cursor at line of code 121 {_BIS_SR(LPM4)} and Run
to line;
- Add the global variable U (RMS voltage);
- Set the value to 240;
- The pulse width, as viewed on the oscilloscope, corresponds to the time to perform the 200 signed
multiply and accumulate operations, and is 6.8 msec;
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
9
9 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Flash Programming
141
142 CHAPTER 10. FLASH PROGRAMMING
The TI MSP430 has an internal ash memory that can be used for data storage. Two dierent methods of
writing to the ash memory are studied in this laboratory. The rst method requires the CPU execution of
the code resident in ash memory. The consequences of this procedure are discussed. In the second part of
the laboratory, the ash write and erase operations are conducted with the CPU executing the code resident
in RAM. The important details are highlighted.
10.1.1.2 Overview
This laboratory programs the internal ash memory with the CPU executing the code resident in ash
memory. It requires to congure: - Flash memory controller; - Segment erase routine; and the - Flash write
routine. The execution time of the dierent operations can be obtained with an oscilloscope connected on
pin 2 of the Header 4 or analyzing the state of the LED (digital output P2.1).
10.1.1.3 Resources
This laboratory uses the ash memory controller. The operation of this device is monitored using a digital
output port (P2.1).
The project must be compiled using the les ( Lab1_Flash.c
2 )and the command le
lnk_msp430fg4618.cmd.
The code is resident in the ash memory, so whenever a ash write or erase operation occurs, the CPU
access to this memory is automatically inhibited.
The software begins by disabling the Watchdog Timer. Then, port P2.1 is set as an output with a logic low
level.
The ash memory controller is congured with the clock MCLK divided by 3. Thus the fFTG operating
frequency lies within the specied limits of 257 kHz to 476 kHz.
A set of routines are provided to erase, write and copy the contents of a segment. The main tasks related
to the ash memory handling are presented using this set of routines.
The information Segments A and B are erased rst. Then, bytes are written to SegmentA and words
are written to SegmentB. The contents of the information memory SegmentA are copied to the information
SegmentB, overwriting the previous contents.
Congure the register FCTL2 to use clock MCLK divided by 3. Do not forget to enter the password to
access the register.
FCTL2 = FWKEY | FSSEL0 | FN1; // MCLK/3 for Flash Timing Generator
1 This content is available online at <http://cnx.org/content/m23580/1.2/>.
2 http://cnx.org/content/m23580/latest/Lab1_Flash.c
Congure the registers FCTL1 and FCTL3 in order to initiate the ash segment erase process by writing an
address belonging to the segment to be erased. Be sure to include the password to access the register.
Block ash write and erase operations are carried out after erasing the segment:
//Flash block write and erase operations after erasing the segment:
FCTL3 = FWKEY | LOCK; // Set LOCK bit
Congure the registers in order to start writing to the ash memory. Be sure to include the password to
access the register.
Congure ash block write and erase operations and disable the write bit:
// Flash block write and erase operations and disable the write bit
// after the writing process to the segment:
FCTL3 = FWKEY | LOCK; // Set LOCK bit
Put the cursor at line of code 124, located just after the second port P2.1 switching state. Execute the
software until the cursor position is reached. The erase operation timing can be seen on an oscilloscope with
the probe connected to pin 2 of the Header 4.
The routine write_char_flash allows writing a byte to ash memory. It receives the memory address where
the byte should be stored.
Open the memory window, and add the address of the information memory A. The content of this
rendering. As we are writing a byte to ash, we must change the
address becomes visible after ordering its
presentation of the memory contents. Choose the option Column Size 1, from the context menu of the
memory window, through the option Format.
Now, during the execution of the for loop, the ash contents is written sequentially.
This routine is similar to the previous one. Note that now the ash write address is increased by two because
a word occupies two bytes of memory.
The information is more readily observed when the memory contents display mode is restored to its initial
state. Reset the default conditions in the option Format of the context menu.
The output port P2.1 is enabled before the copy process begins. The copy routine receives the start ad-
dress of the source information segment and the start address of the destination information segment. The
information is then successively read and written from one segment to another.
Port P2.1 is disabled at the end of the copy process. Thus, the task execution time can be measured
using an oscilloscope.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
3
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
The TI MSP430 has an internal ash memory that can be used for data storage. Two dierent methods of
writing to the ash memory are studied in this laboratory. The rst method requires the CPU execution of
the code resident in ash memory. The consequences of this procedure are discussed. In the second part of
the laboratory, the ash write and erase operations are conducted with the CPU executing the code resident
in RAM. The important details are highlighted.
10.2.1.2 Overview
This laboratory programs the internal ash memory with the CPU executing the code in RAM. It requires to
congure: - Several ash storage management routines; - Check the state of the ag Wait; an the - Flash write
routine. This procedure requires special attention during the project construction. The application begins
copying the routines from ash to RAM. Directive MEMORY: Device's memory conguration. Identies the
memory ranges that are physically present on the device Directive SECTIONS: controls how the sections
are built and reserved.
The execution time of the dierent operations can be obtained with an oscilloscope connected on pin 2
of the Header 4 or analyzing the state of the LED (digital output P2.1).
10.2.1.3 Resources
The tasks developed in the Lab1: Flash memory programming with the CPU executing the code from ash
memory are executed again during this laboratory. The dierence this time is that the software runs from
RAM.
This process requires special procedures. The routines to run from RAM must be identied. The
application must begin by copying the routines from ash to RAM.
The directive MEMORY determines the device's memory conguration. The memory can be organized
in accordance with the system needs. This directive identies the memory ranges that are physically present
on the device. Each of these ranges has a set of features, such as:
- Name;
- Initial address;
- Length;
- Optional attributes set;
- Optional lling specications.
The directive Memory is organized as described below.
MEMORY
{
name 1 [(attr)] : origin = constant, length = constant [, fill = constant]
The directive SECTIONS controls how the sections are built and reserved. The directive performs the
following:
- Describes how the input sections are related to the output sections;
- Denes the output sections in the executable program;
- Denes where the output sections are placed in memory;
- Allows changing the name of the output sections;
The directive SECTIONS is organized as described below.
SECTIONS
{
name : [property [, property] [, property] . . . ]
name : [property [, property] [, property] . . . ]
name : [property [, property] [, property] . . . ]
}
// Define the memory space where the code belonging to the section will run:
Syntax: run = allocation or
run > allocation
In this project, we intend to write the code to the ash memory, but we want it to be executed from RAM.
The Linker oers a very simple way to accomplish this task. A memory space where the code is stored is
associated with another memory space where it will run. The application transfers the code to the memory
space, where it will be executed.
The memory spaces needed to store the routines are dened in the lnk_msp430fg4618_RAM.cmd le.
The software for this laboratory has the same structure as the Lab1: Flash memory programming with the
CPU executing the code from ash memory.
The directive #pragma CODE_SECTION (symbol, "section name") reserves space for the "symbol" in
a section called "section name". Thus, the routines are stored in the section ".FLASHCODE".
The routine copy_flash_to_RAM runs from the beginning of the program. It is responsible for transferring
the ash contents to RAM.
The les ( Lab2_Flash.c
5 ) and lnk_msp430fg4618_RAM.cmd must be included during the compilation.
Now, the code is executed from RAM. Check, whenever appropriate, the Wait bit state of the register
FCTL3.
5 http://cnx.org/content/m23578/latest/Lab2_Flash.c
To store the ash management routines in the section ".FLASHCODE" complete the empty spaces:
#pragma CODE_SECTION(erase_segment,".FLASHCODE")
void erase_segment(int address)
#pragma CODE_SECTION(write_char_flash,".FLASHCODE")
void write_char_flash(int address, char value)
#pragma CODE_SECTION(write_int_flash,".FLASHCODE")
void write_int_flash(int address, int value)
#pragma CODE_SECTION(copy_seg_flash,".FLASHCODE")
void copy_seg_flash(int address_source, int address_destination)
At software key points, and whenever writing or erasing the ash memory, perform a delay before proceeding
with the data writes. Complete the following line of code in order to suspend the program ow while the
busy ag is not active.
Analyse the dierences between the dierent versions of the routines. Note that successive delays are placed
in the versions to be executed from RAM.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
6
6 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Communication
149
150 CHAPTER 11. COMMUNICATION
The MSP430 contains built-in features for both parallel and serial data communication. This chapter de-
scribes the operation of these peripherals, and discusses the protocols, data formats and specic techniques
for each type of data communication.
The communication modules available for the MSP430 family of microcontrollers are USART (Universal
Synchronous/Asynchronous Receiver/Transmitter), USCI (Universal Serial Communication Interface) and
USI (Universal Serial Interface). These provide asynchronous data transmission between the MSP430 and
other peripheral devices when congured in UART mode. They also support data transmission synchronized
to a clock signal through a serial I/O port in Serial Peripheral Interface (SPI) and Inter Integrated Circuit
(I2C) modes.
11.1.1.2 Overview
This laboratory explores the USCI module in UART mode that will be connected to a Code Composer
Essentials (CCE) IO console. When the connection is established, the character sequence written on the
keyboard to the console will be displayed again on the console.
11.1.1.3 Resources
This laboratory uses the USCI module in asynchronous mode. The RX interrupt activates the service routine
that reads the incoming character and sends it out again to the PC (computer), allowing the instantaneous
display (echo) of the written character.
The resources used are:
- USCI module;
- Interrupts;
- IO ports:
- System clock.
With the objective of allowing the generation of two dierent baud rates, a function has been added that
congures the FLL+ and selects the base frequency for the UART. In this example it will be 8 MHz.
Figure 11.1
UCA0CTL0 = 0x00;
// UCA0CTL0 =
//UCPEN|UCPAR|UCMSB|UC7BIT|UCSPB|UCMODEx|UCSYNC|
//UCPEN (Parity) = 0b -> Parity disabled
//UCPAR (Parity select) = 0b -> Odd parity
//UCMSB (MSB first select) = 0b -> LSB first
//UC7BIT (Character length) = 0b -> 8-bit data
//UCSPB (Stop bit select) = 0b -> One stop bit
//UCMODEx (USCI mode) = 00b -> UART Mode
//UCSYNC = 0b -> Asynchronous mode
UCA0CTL1 = 0x81;
// UCA0CTL1 =
//UCSSELx|UCRXEIE|UCBRKIE|UCDORM|UCTXADDR|UCTXBRK|UCSWRST|
//UCSSELx (USCI clock source select) = 10b -> SMCLK
//UCRXEIE = 0b -> Erroneous characters rejected
//UCBRKIE = 0b -> Received break characters set
//UCDORM = 0b -> Not dormant
//UCTXADDR = 0b -> Next frame transmitted is data
//UCTXBRK = 0b -> Next frame transmitted is no break
//UCSWRST = 1b -> normally Set by a PUC
The module has an 8 MHz clock source and the objective is to establish a connection at 9600 Baud. It is
necessary to select the baud rate generation in oversampling mode:
UCA0BR0 = 0x34;
UCA0BR1 = 0x00;
//Prescaler = 8MHz/(16 x 9600) = 52 = 0x34
//9600 from 8MHz -> SMCLK
UCA0MCTL = 0x11;
// UCA0MCTL = UCBRFx | UCBRSx | UCOS16
//UCBRFx (1st modulation stage) = 0001b -> Table 19-4
//UCBRSx (2nd modulation stage) = 000b -> Table 19-4
//UCOS16 (Oversampling mode) = 1b -> Enabled
In order to set the external interfaces at the USCI module, it is necessary to congure the I/O ports. Select
the USCI peripheral in UART mode following the connections provided on the Experimenter's board:
P2SEL |= 0x30; // P2.4,P2.5 = USCI_A0 TXD,RXD
Once the USCI module is congured in accordance with the previous steps, compile it and run it on the
Experimenter's board.
For the correct operation, there must be a connection between the Experimenter's board and the PC. If
the CCE console is disabled, go to Window > Show View > Console to enable it. If necessary, congure
the CCE console options in accordance to the connection details.
Once the program code is running, any character key pressed in the PC keyboard will be displayed on
the CCE console.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
3
3 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
The MSP430 contains built-in features for both parallel and serial data communication. This chapter de-
scribes the operation of these peripherals, and discusses the protocols, data formats and specic techniques
for each type of data communication.
The communication modules available for the MSP430 family of microcontrollers are USART (Universal
Synchronous/Asynchronous Receiver/Transmitter), USCI (Universal Serial Communication Interface) and
USI (Universal Serial Interface). These provide asynchronous data transmission between the MSP430 and
other peripheral devices when congured in UART mode. They also support data transmission synchronized
to a clock signal through a serial I/O port in Serial Peripheral Interface (SPI) and Inter Integrated Circuit
(I2C) modes.
11.2.1.2 Overview
This laboratory explores the USCI and USI communication interfaces in SPI mode. The MSP430 de-
vices included on the Experimenter's board will exchange messages between themselves, one being the
MSP430FG4618 (master) that will control operation of the other MSP430F2013 device (slave). The master,
by reading the current state of the slave, will drive the slave to the new desired state, controlling its activity.
In this particular case, switching the state of LED3 will be implemented.
11.2.1.3 Resources
This laboratory uses the USCI module of the MSP430FG4618 device and the USI module included on the
MSP430F2013. Both units operate in SPI mode.
The Basic Timer1 of the master device is programmed to switch the status of the slave device once every
2 seconds.
The slave is notied of the arrival of information through the counting end interrupt of the USI module.
The resources used are:
- USCI module;
- USI module;
- Basic Timer1;
- Interrupts;
- I/O ports.
Figure 11.2
UCB0CTL0 = 0x29;
//UCB0CTL0 =
// UCCKPH|UCCKPL|UCMSB|UC7BIT|UCMST|UCMODEx|UCSYNC|
//UCCKPH (Clock phase) = 0b -> Data is changed on the
// first UCLK edge and captured on the following edge.
//UCCKPL (Clock polarity) = 0b -> Inactive state is low
//UCMSB (MSB first select) = 1b -> MSB first
//UC7BIT (Character length) = 0b -> 8-bit data
//UCMST (Master mode) = 1b -> Master mode
//UCMODEx (USCI mode) = 00b -> 3-Pin SPI
//UCSYNC (Synch. mode enable) = 1b -> Synchronous mode
UCB0CTL1 = 0x81;
//UCB0CTL1 =
// UCSSELx | Unused |UCSWRST|
//UCSSELx (USCI clock source select)= 10b -> SMCLK
//UCSWRST (Software reset) = 1b -> normally set by a PUC
The system clock is congured to operate with a frequency of ∼ 1048 kHz from the DCO. This frequency
will be the working base frequency of the USCI module. The connection operates at a clock frequency of ∼
500 kHz. Congure the following registers:
UCB0BR0 = 0x02;
UCB0BR1 = 0x00;
// DATA RATE
// Data rate = SMCLK/2 ∼= 500kHz
// UCB0BR1 = 0x00 & UCB0BR0 = 0x02
In order to set the external interfaces at the USCI module, it is necessary to congure the I/O ports. Select
the USCI peripheral in SPI mode, matching the connections provided at the Experimenter's board:
P3SEL |= 0x0E; // P3.3, P3.2, P3.1 option select
USICTL0 = 0xE3;
//USICTL0 =
//USIPE7|USIPE6|USIPE5|USILSB|USIMST|USIGE|USIOE|USISWRST
//USIPE7 (USI SDI/SDA port enable) = 1b -> USI enabled
//USIPE6 (USI SDO/SCL port enable) = 1b -> USI enabled
//USIPE5 (USI SCLK port enable) = 1b -> USI enabled
//USILSB (LSB first) = 0b -> MSB first
//USIMST (Master) = 0b -> Slave mode
//USIGE (Output latch control) = 0b -> Output latch
// enable depends on shift clock
//USIOE (Serial data output enable) = 1b-> Output enable
//USISWRST (USI software reset) = 1b -> Software reset
USICTL1 = 0x10;
//USICTL1 =
//USICKPH|USII2C|USISTTIE|USIIE|USIAL|USISTP|USISTTIFG|USIIFG
//USICKPH (Clock phase select) = 0b -> Data is changed
// on the first SCLK edge and captured on the following edge
//USII2C (I2C mode enable) = 0b -> I2C mode disabled
//USISTTIE (START condition interrupt) = 0b -> Not used
//USIIE (USI counter) = 1b -> Interrupt enabled
//USIAL (Arbitration lost) = 0b -> Not used
//USISTP (STOP condition received) = 0b -> Not used
//USISTTIFG (START condition int. flag) = 0b -> Not used
Once the USCI module is congured in accordance with the previous steps, initiate the experiment with the
les Lab2_Comm_1.c (master MSP430FG4618) and Lab2_Comm_2.c (slave MSP430F2013), compiling
them and running them on the Experimenter's board.
For this laboratory, it is necessary to set the following jumper settings:
- PWR1/2, BATT, LCL1/2, JP2;
- SPI: H1- 1&2, 3&4, 5&6, 7&8.
Once the program code is running in the two microcontrollers, monitor LED3 on the Experimenter's
board. It will blink with a period of 4 seconds.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
7
7 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
The MSP430 contains built-in features for both parallel and serial data communication. This chapter de-
scribes the operation of these peripherals, and discusses the protocols, data formats and specic techniques
for each type of data communication.
The communication modules available for the MSP430 family of microcontrollers are USART (Universal
Synchronous/Asynchronous Receiver/Transmitter), USCI (Universal Serial Communication Interface) and
USI (Universal Serial Interface). These provide asynchronous data transmission between the MSP430 and
other peripheral devices when congured in UART mode. They also support data transmission synchronized
to a clock signal through a serial I/O port in Serial Peripheral Interface (SPI) and Inter Integrated Circuit
(I2C) modes.
11.3.1.2 Overview
2
This laboratory explores the USCI and USI communication interfaces in I C mode. It uses the two MSP430
devices included on the Experimenter's board: MSP430FG4618 as the master and the MSP430F2013 as the
slave. The master receives a single byte from the slave as soon as a button connected to P1.0 is pressed.
11.3.1.3 Resources
This laboratory uses the USCI module of the MSP430FG4618 device and the USI module included in the
MSP430F2013. Both units operate in I2C mode.
The interrupts on the slave unit are generated exclusively by the USI module. They are:
- START condition in the I2C bus;
- Data reception and transmission.
The interrupts on the master unit are provided by the USCI module. They are:
- Data reception;
- Interrupt on Port1.
The resources used are:
- USCI module;
- USI module;
- Interrupts;
- I/O ports.
Figure 11.3
For the operational capability of the slave unit based on the USI module, it is necessary to implement a
state machine as shown in Figure 2. It is important to note that the states RX Address and RX (N)ACK"
are transient states that ensure the USI module is prepared for the next activity.
Slave state machine.
Figure 11.4
UCB0CTL0 = 0x0F;
//UCB0CTL0 = UCA10 | UCSLA10 | UCMM | Unused | UCMST | UCMODEx | UCSYNC
//UCA10 (Own address) = 0b -> Own address (7-bit)
//UCSLA10 (Slave address) = 0b -> 7-bit slave address
//UCMM (Multi-master) = 0b -> Single master
//Unused
//UCMST (Master mode) = 1b -> Master mode
//UCMODEx (USCI mode) = 11b -> I2C Mode
//UCSYNC (Synchronous mode enable) = 1b -> Synchronous
UCB0CTL1 = 0x81;
The system clock is congured to operate with a frequency of ∼ 1048 kHz from the DCO. This frequency
will be the working base frequency of the USCI module. The connection operates at a clock frequency of ∼
95.3 kHz:
// DATA RATE
// data rate -> fSCL = SMCLK/11 = 95.3kHz
UCB0BR0 = 0x0B; // fSCL = SMCLK/11 = 95.3kHz
UCB0BR1 = 0x00;
In order to set the external interfaces at the USCI module, it is necessary to congure the I/O ports. Select
2
the USCI peripheral in I C mode matching the connections provided at the Experimenter's board:
P3SEL |=0x06; // Assign I2C pins to USCI_B0
USICTL0 = 0XC1;
USICTL1 = 0x70;
The slave unit interrupt service routine is not complete. The portion related to the I2C_TX state needs
to be completed:
- Congure the USI module as output;
- Insert the information to transmit using the transmission register;
- Congure the bit counter.
Once the USCI module is congured in accordance with the previous steps, initiate the experiment with the
les ( Lab3_Comm_1.c
10 ) (master MSP430FG4618) and ( Lab3_Comm_2.c11 ) (slave MSP430F2013),
compiling them and running them on the Experimenter's board.
For this laboratory, the following jumper settings are required:
- PWR1/2, BATT, LCL1/2, JP2;
- SPI: H1- 1&2, 3&4.
The slave data is sent and increments from 0x00 with each transmitted byte, which is veried by the
Master. The LED is o for address or data Acknowledge and the LED turns on for address or data Not
Acknowledge. LED3 blinks at each data request. It is turned on with a START condition and it is turned
2
o by the data transmit acknowledge by the slave (Note: the I C bus is not released by the master since the
successive START conditions are interpreted as repeated START).
Verify the value received setting a breakpoint in the line of code RxBuffer = UCB0RXBUF; of the USCI
interrupt.
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here https://www-
a.ti.com/apps/dspuniv/teaching_rom_request.asp
12
10 http://cnx.org/content/m23569/latest/Lab3_Comm_1.c
11 http://cnx.org/content/m23569/latest/Lab3_Comm_2.c
12 https://www-a.ti.com/apps/dspuniv/teaching_rom_request.asp
Attributions
Collection: Teaching and classroom laboratories based on the eZ430 and "Experimenter's board" MSP430
microcontroller platforms and Code Composer Essentials
Edited by: Pedro Dinis, António Espírito Santo
URL: http://cnx.org/content/col10706/1.3/
License: http://creativecommons.org/licenses/by/3.0/
Module: "Introduction"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23492/1.1/
Page: 1
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory GPIO: Lab2 - Blinking the LED half the speed"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23540/1.2/
Page: 74
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory GPIO: Lab3 - Toggle the LED state by pressing the push button"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23547/1.1/
Pages: 75-76
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory GPIO: Lab4 - Enable/disable LED blinking by push button press"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23556/1.1/
Page: 77
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory Timers: Lab2 - Real Time Clock with Basic Timer1"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23531/1.2/
Pages: 84-85
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory Signal Acquisition: Lab4 - Voltage signal comparison with Comparator_A"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23543/1.2/
Pages: 117-119
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory Hardware Multiplier: Lab3 - RMS and active power calculation"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23582/1.2/
Pages: 138-140
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory Flash memory: Lab1 - Flash memory programming with the CPU executing the code
from ash memory"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23580/1.2/
Pages: 142-144
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory Flash memory: Lab2 - Flash memory programming with the CPU executing the code
in RAM"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23578/1.2/
Pages: 145-147
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
Module: "Laboratory Communications: Lab1 - Echo test using the UART mode of the USCI module"
By: Pedro Dinis, António Espírito Santo, Bruno Ribeiro
URL: http://cnx.org/content/m23567/1.2/
Pages: 150-153
Copyright: Pedro Dinis, António Espírito Santo, Bruno Ribeiro, Cathy Wicks
License: http://creativecommons.org/licenses/by/3.0/
About Connexions
Since 1999, Connexions has been pioneering a global system where anyone can create course materials and
make them fully accessible and easily reusable free of charge. We are a Web-based authoring, teaching and
learning environment open to anyone interested in education, including students, teachers, professors and
lifelong learners. We connect ideas and facilitate educational communities.
Connexions's modular, interactive courses are in use worldwide by universities, community colleges, K-12
schools, distance learners, and lifelong learners. Connexions materials are in many languages, including
English, Spanish, Chinese, Japanese, Italian, Vietnamese, French, Portuguese, and Thai. Connexions is part
of an exciting new information distribution system that allows for Print on Demand Books. Connexions
has partnered with innovative on-demand publisher QOOP to accelerate the delivery of printed course
materials and textbooks into classrooms worldwide at lower prices than traditional academic publishers.