MSP430 DriverLib For MSP430F5xx_6xx Devices MSP430F5xx 6xx Driver Lib Users Guide 2 91 10 06

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 631 [warning: Documents this large are best viewed by clicking the View PDF Link!]

Copyright © 2019 Texas Instruments Incorporated.DOCNUM-2.91.10.06
User’s Guide
MSP430 DriverLib for MSP430F5xx 6xx Devices
1
Copyright
Copyright © 2019 Texas Instruments Incorporated. All rights reserved. MSP430 and MSP430Ware are trademarks of Texas Instruments Instruments.
ARM and Thumb are registered trademarks and Cortex is a trademark of ARM Limited. Other names and brands may be claimed as the property of
others.
Please be aware that an important notice concerning availability, standard warranty, and use in critical applications of Texas Instruments semi-
conductor products and disclaimers thereto appears at the end of this document.
Texas Instruments
13532 N. Central Expressway MS3810
Dallas, TX 75243
www.ti.com/
Revision Information
This is version 2.91.10.06 of this document, last updated on Wed Jan 23 2019 17:54:26.
Table of Contents 2
Table of Contents
Copyright ..................................................... 1
Revision Information ............................................... 1
1 Introduction ................................................. 7
2 Navigating to driverlib through CCS Resource Explorer ....................... 9
2.1 Introduction .................................................. 9
3 How to create a new CCS project that uses Driverlib ......................... 21
3.1 Introduction .................................................. 21
4 How to include driverlib into your existing CCS project ....................... 23
4.1 Introduction .................................................. 23
5 How to create a new IAR project that uses Driverlib ......................... 25
5.1 Introduction .................................................. 25
6 How to include driverlib into your existing IAR project ........................ 28
6.1 Introduction .................................................. 28
7 10-Bit Analog-to-Digital Converter (ADC10 A) ............................. 31
7.1 Introduction .................................................. 31
7.2 API Functions ................................................ 31
7.3 Programming Example ........................................... 49
8 12-Bit Analog-to-Digital Converter (ADC12 A) ............................. 51
8.1 Introduction .................................................. 51
8.2 API Functions ................................................ 51
8.3 Programming Example ........................................... 70
9 Advanced Encryption Standard (AES) ................................. 72
9.1 Introduction .................................................. 72
9.2 API Functions ................................................ 72
9.3 Programming Example ........................................... 82
10 Battery Backup System .......................................... 83
10.1 Introduction .................................................. 83
10.2 API Functions ................................................ 83
11 Comparator (COMP B) ........................................... 84
11.1 Introduction .................................................. 84
11.2 API Functions ................................................ 84
11.3 Programming Example ........................................... 95
12 Cyclical Redundancy Check (CRC) ................................... 97
12.1 Introduction .................................................. 97
12.2 API Functions ................................................ 97
12.3 Programming Example ........................................... 101
13 16-Bit Sigma Delta Converter (CTSD16) ................................ 102
13.1 Introduction .................................................. 102
13.2 API Functions ................................................ 102
13.3 Programming Example ........................................... 103
14 12-bit Digital-to-Analog Converter (DAC12 A) ............................. 104
14.1 Introduction .................................................. 104
14.2 API Functions ................................................ 104
14.3 Programming Example ........................................... 116
Table of Contents 3
15 Direct Memory Access (DMA) ...................................... 117
15.1 Introduction .................................................. 117
15.2 API Functions ................................................ 117
15.3 Programming Example ........................................... 130
16 EUSCI Universal Asynchronous Receiver/Transmitter (EUSCI A UART) ............. 131
16.1 Introduction .................................................. 131
16.2 API Functions ................................................ 131
16.3 Programming Example ........................................... 142
17 EUSCI Synchronous Peripheral Interface (EUSCI A SPI) ...................... 143
17.1 Introduction .................................................. 143
17.2 Functions ................................................... 143
17.3 Programming Example ........................................... 152
18 EUSCI Synchronous Peripheral Interface (EUSCI B SPI) ...................... 153
18.1 Introduction .................................................. 153
18.2 Functions ................................................... 153
18.3 Programming Example ........................................... 162
19 EUSCI Inter-Integrated Circuit (EUSCI B I2C) ............................. 163
19.1 Introduction .................................................. 163
19.2 Master Operations .............................................. 163
19.3 Slave Operations .............................................. 164
19.4 API Functions ................................................ 165
19.5 Programming Example ........................................... 186
20 FlashCtl - Flash Memory Controller ................................... 187
20.1 Introduction .................................................. 187
20.2 API Functions ................................................ 187
20.3 Programming Example ........................................... 193
21 GPIO ..................................................... 194
21.1 Introduction .................................................. 194
21.2 API Functions ................................................ 195
21.3 Programming Example ........................................... 228
22 LCDBController ............................................... 230
22.1 Introduction .................................................. 230
22.2 API Functions ................................................ 230
22.3 Programming Example ........................................... 231
23 LDO-PWR .................................................. 232
23.1 Introduction .................................................. 232
23.2 API Functions ................................................ 232
23.3 Programming Example ........................................... 243
24 32-Bit Hardware Multiplier (MPY32) ................................... 245
24.1 Introduction .................................................. 245
24.2 API Functions ................................................ 245
24.3 Programming Example ........................................... 254
25 Operational Amplifier (OA) ........................................ 255
25.1 Introduction .................................................. 255
25.2 API Functions ................................................ 255
25.3 Programming Example ........................................... 256
26 Port Mapping Controller .......................................... 257
26.1 Introduction .................................................. 257
26.2 API Functions ................................................ 257
Table of Contents 4
26.3 Programming Example ........................................... 258
27 Power Management Module (PMM) ................................... 259
27.1 Introduction .................................................. 259
27.2 API Functions ................................................ 261
27.3 Programming Example ........................................... 273
28 RAM Controller ............................................... 275
28.1 Introduction .................................................. 275
28.2 API Functions ................................................ 275
28.3 Programming Example ........................................... 277
29 Internal Reference (REF) ......................................... 279
29.1 Introduction .................................................. 279
29.2 API Functions ................................................ 279
29.3 Programming Example ........................................... 285
30 Real-Time Clock (RTC A) ......................................... 287
30.1 Introduction .................................................. 287
30.2 API Functions ................................................ 287
30.3 Programming Example ........................................... 302
31 Real-Time Clock (RTC B) ......................................... 304
31.1 Introduction .................................................. 304
31.2 API Functions ................................................ 304
31.3 Programming Example ........................................... 316
32 Real-Time Clock (RTC C) ......................................... 317
32.1 Introduction .................................................. 317
32.2 API Functions ................................................ 317
32.3 Programming Example ........................................... 334
33 24-Bit Sigma Delta Converter (SD24 B) ................................. 336
33.1 Introduction .................................................. 336
33.2 API Functions ................................................ 336
33.3 Programming Example ........................................... 352
34 SFR Module ................................................. 353
34.1 Introduction .................................................. 353
34.2 API Functions ................................................ 353
34.3 Programming Example ........................................... 359
35 System Control Module .......................................... 360
35.1 Introduction .................................................. 360
35.2 API Functions ................................................ 360
35.3 Programming Example ........................................... 368
36 Timer Event Control (TEC) ........................................ 369
36.1 Introduction .................................................. 369
36.2 API Functions ................................................ 369
36.3 Programming Example ........................................... 379
37 16-Bit Timer A (TIMER A) ......................................... 380
37.1 Introduction .................................................. 380
37.2 API Functions ................................................ 381
37.3 Programming Example ........................................... 396
38 16-Bit Timer B (TIMER B) ......................................... 398
38.1 Introduction .................................................. 398
38.2 API Functions ................................................ 399
Table of Contents 5
38.3 Programming Example ........................................... 417
39 TIMER D ................................................... 418
39.1 Introduction .................................................. 418
39.2 API Functions ................................................ 419
39.3 Programming Example ........................................... 446
40 Tag Length Value .............................................. 448
40.1 Introduction .................................................. 448
40.2 API Functions ................................................ 448
40.3 Programming Example ........................................... 455
41 Unified Clock System (UCS) ....................................... 456
41.1 Introduction .................................................. 456
41.2 API Functions ................................................ 457
41.3 Programming Example ........................................... 473
42 USCI Universal Asynchronous Receiver/Transmitter (USCI A UART) ............... 474
42.1 Introduction .................................................. 474
42.2 API Functions ................................................ 474
42.3 Programming Example ........................................... 484
43 USCI Synchronous Peripheral Interface (USCI A SPI) ........................ 486
43.1 Introduction .................................................. 486
43.2 API Functions ................................................ 486
43.3 Programming Example ........................................... 495
44 USCI Synchronous Peripheral Interface (USCI B SPI) ........................ 497
44.1 Introduction .................................................. 497
44.2 API Functions ................................................ 497
44.3 Programming Example ........................................... 506
45 USCI Inter-Integrated Circuit (USCI B I2C) ............................... 508
45.1 Introduction .................................................. 508
45.2 Master Operations .............................................. 508
45.3 Slave Operations .............................................. 509
45.4 API Functions ................................................ 510
45.5 Programming Example ........................................... 529
46 WatchDog Timer (WDT A) ......................................... 531
46.1 Introduction .................................................. 531
46.2 API Functions ................................................ 531
46.3 Programming Example ........................................... 535
47 Data Structure Documentation ...................................... 536
47.1 Data Structures ............................................... 536
47.2 Timer D initCompareModeParam Struct Reference ........................... 538
47.3 Timer B initContinuousModeParam Struct Reference .......................... 539
47.4 Timer D outputPWMParam Struct Reference ............................... 541
47.5 SD24 B initParam Struct Reference .................................... 544
47.6 USCI B SPI changeMasterClockParam Struct Reference ........................ 546
47.7 Timer A initUpModeParam Struct Reference ............................... 547
47.8 USCI B I2C initMasterParam Struct Reference .............................. 549
47.9 EUSCI B SPI initSlaveParam Struct Reference .............................. 550
47.10Timer A initCompareModeParam Struct Reference ........................... 552
47.11EUSCI B SPI changeMasterClockParam Struct Reference ....................... 553
47.12Timer B initUpDownModeParam Struct Reference ............................ 554
47.13Timer D initUpModeParam Struct Reference ............................... 556
Table of Contents 6
47.14Timer A initContinuousModeParam Struct Reference .......................... 559
47.15EUSCI B I2C initSlaveParam Struct Reference .............................. 561
47.16Comp B configureReferenceVoltageParam Struct Reference ...................... 562
47.17Timer A initCaptureModeParam Struct Reference ............................ 563
47.18USCI A UART initParam Struct Reference ................................ 565
47.19RTC C configureCalendarAlarmParam Struct Reference ........................ 568
47.20USCI A SPI initMasterParam Struct Reference .............................. 569
47.21USCI B SPI initMasterParam Struct Reference .............................. 571
47.22TEC initExternalFaultInputParam Struct Reference ............................ 572
47.23USCI A SPI changeMasterClockParam Struct Reference ........................ 574
47.24SD24 B initConverterParam Struct Reference .............................. 574
47.25EUSCI A UART initParam Struct Reference ............................... 576
47.26Timer B outputPWMParam Struct Reference ............................... 579
47.27EUSCI B I2C initMasterParam Struct Reference ............................. 581
47.28EUSCI A SPI changeMasterClockParam Struct Reference ....................... 582
47.29Timer B initUpModeParam Struct Reference ............................... 583
47.30Timer B initCompareModeParam Struct Reference ........................... 585
47.31EUSCI A SPI initMasterParam Struct Reference ............................. 587
47.32DAC12 A initParam Struct Reference ................................... 589
47.33Timer D initCaptureModeParam Struct Reference ............................ 591
47.34Timer B initCaptureModeParam Struct Reference ............................ 594
47.35EUSCI B SPI initMasterParam Struct Reference ............................. 596
47.36SD24 B initConverterAdvancedParam Struct Reference ......................... 598
47.37Timer D combineTDCCRToOutputPWMParam Struct Reference .................... 601
47.38Timer D initContinuousModeParam Struct Reference .......................... 604
47.39DMA initParam Struct Reference ...................................... 606
47.40ADC12 A configureMemoryParam Struct Reference ........................... 609
47.41Timer D initHighResGeneratorInRegulatedModeParam Struct Reference ............... 612
47.42Calendar Struct Reference ......................................... 614
47.43Timer A initUpDownModeParam Struct Reference ............................ 615
47.44Comp B initParam Struct Reference .................................... 617
47.45RTC A configureCalendarAlarmParam Struct Reference ........................ 620
47.46EUSCI A SPI initSlaveParam Struct Reference .............................. 621
47.47Timer D initUpDownModeParam Struct Reference ............................ 622
47.48PMAP initPortsParam Struct Reference .................................. 625
47.49RTC B configureCalendarAlarmParam Struct Reference ........................ 626
47.50Timer A outputPWMParam Struct Reference ............................... 627
IMPORTANT NOTICE ............................................... 630
CHAPTER 1. INTRODUCTION 7
1 Introduction
The Texas Instruments® MSP430® Peripheral Driver Library is a set of drivers for accessing the
peripherals found on the MSP430 5xx/6xx family of microcontrollers. While they are not drivers in
the pure operating system sense (that is, they do not have a common interface and do not connect
into a global device driver infrastructure), they do provide a mechanism that makes it easy to use
the device's peripherals.
The capabilities and organization of the drivers are governed by the following design goals:
They are written entirely in C except where absolutely not possible.
They demonstrate how to use the peripheral in its common mode of operation.
They are easy to understand.
They are reasonably efficient in terms of memory and processor usage.
They are as self-contained as possible.
Where possible, computations that can be performed at compile time are done there instead
of at run time.
They can be built with more than one tool chain.
Some consequences of these design goals are:
The drivers are not necessarily as efficient as they could be (from a code size and/or
execution speed point of view). While the most efficient piece of code for operating a
peripheral would be written in assembly and custom tailored to the specific requirements of
the application, further size optimizations of the drivers would make them more difficult to
understand.
The drivers do not support the full capabilities of the hardware. Some of the peripherals
provide complex capabilities which cannot be utilized by the drivers in this library, though the
existing code can be used as a reference upon which to add support for the additional
capabilities.
The APIs have a means of removing all error checking code. Because the error checking is
usually only useful during initial program development, it can be removed to improve code
size and speed.
For many applications, the drivers can be used as is. But in some cases, the drivers will have to be
enhanced or rewritten in order to meet the functionality, memory, or processing requirements of the
application. If so, the existing driver can be used as a reference on how to operate the peripheral.
Each MSP430ware driverlib API takes in the base address of the corresponding peripheral as the
first parameter. This base address is obtained from the msp430 device specific header files (or
from the device datasheet). The example code for the various peripherals show how base address
is used. When using CCS, the eclipse shortcut ”Ctrl + Space” helps. Type MSP430 and ”Ctrl +
Space”, and the list of base addresses from the included device specific header files is listed.
The following tool chains are supported:
IAR Embedded Workbench®
Texas Instruments Code Composer Studio™
Using assert statements to debug
CHAPTER 1. INTRODUCTION 8
Assert statements are disabled by default. To enable the assert statement edit the hw regaccess.h
file in the inc folder. Comment out the statement #define NDEBUG ->//#define NDEBUG Asserts
in CCS work only if the project is optimized for size.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 9
2 Navigating to driverlib through CCS
Resource Explorer
2.1 Introduction
In CCS, click View->TI Resource Explorer
In Resource Explorer View, click on MSP430ware
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 10
Clicking MSP430ware takes you to the introductory page. The version of the latest MSP430ware
installed is available in this page. In this screenshot the version is 1.30.00.15 The various
software, collateral, code examples, datasheets and user guides can be navigated by clicking the
different topics under MSP430ware. To proceed to driverlib, click on Libraries->Driverlib as shown
in the next two screenshots.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 11
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 12
Driverlib is designed per Family. If a common device family user's guide exists for a group of
devices, these devices belong to the same 'family'. Currently driverlib is available for the following
family of devices. MSP430F5xx 6xx MSP430FR57xx MSP430FR2xx 4xx MSP430FR5xx 6xx
MSP430i2xx
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 13
Click on the MSP430F5xx 6xx to navigate to the driverlib based example code for that family.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 14
The various peripherals are listed in alphabetical order. The names of peripherals are as in device
family user's guide. Clicking on a peripheral name lists the driverlib example code for that
peripheral. The screenshot below shows an example when the user clicks on GPIO peripheral.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 15
Now click on the specific example you are interested in. On the right side there are options to
Import/Build/Download and Debug. Import the project by clicking on the ”Import the example
project into CCS”
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 16
The imported project can be viewed on the left in the Project Explorer. All required driverlib source
and header files are included inside the driverlib folder. All driverlib source and header files are
linked to the example projects. So if the user modifies any of these source or header files, the
original copy of the installed MSP430ware driverlib source and header files get modified.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 17
Now click on Build the imported project on the right to build the example project.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 18
Now click on Build the imported project on the right to build the example project.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 19
The COM port to download to can be changed using the Debugger Configuration option on the
right if required.
To get started on a new project we recommend getting started on an empty project we provide.
This project has all the driverlib source files, header files, project paths are set by default.
CHAPTER 2. NAVIGATING TO DRIVERLIB THROUGH CCS RESOURCE EXPLORER 20
The main.c included with the empty project can be modified to include user code.
CHAPTER 3. HOW TO CREATE A NEW CCS PROJECT THAT USES DRIVERLIB 21
3 How to create a new CCS project that uses
Driverlib
3.1 Introduction
To get started on a new project we recommend using the new project wizard. For driver library to
work with the new project wizard CCS must have discovered the driver library RTSC product. For
more information refer to the installation steps of the release notes. The new project wizard adds
the needed driver library source files and adds the driver library include path.
To open the new project wizard go to File ->New ->CCS Project as seen in the screenshot below.
Once the new project wizard has been opened name your project and choose the device you
would like to create a Driver Library project for. The device must be supported by driver library.
Then under ”Project templates and examples” choose ”Empty Project with DriverLib Source” as
seen below.
CHAPTER 3. HOW TO CREATE A NEW CCS PROJECT THAT USES DRIVERLIB 22
Finally click ”Finish” and begin developing with your Driver Library enabled project.
We recommend -O4 compiler settings for more efficient optimizations for projects using driverlib
CHAPTER 4. HOW TO INCLUDE DRIVERLIB INTO YOUR EXISTING CCS PROJECT 23
4 How to include driverlib into your existing
CCS project
4.1 Introduction
To add driver library to an existing project we recommend using CCS project templates. For driver
library to work with project templates CCS must have discovered the driver library RTSC product.
For more information refer to the installation steps of the release notes. CCS project templates
adds the needed driver library source files and adds the driver library include path.
To apply a project template right click on an existing project then go to Source ->Apply Project
Template as seen in the screenshot below.
In the ”Apply Project Template” dialog box under ”MSP430 DriverLib Additions” choose either ”Add
Local Copy” or ”Point to Installed DriverLib” as seen in the screenshot below. Most users will want
to add a local copy which copies the DriverLib source into the project and sets the compiler
settings needed.
Pointing to an installed DriverLib is for advandced users who are including a static library in their
project and want to add the DriverLib header files to their include path.
CHAPTER 4. HOW TO INCLUDE DRIVERLIB INTO YOUR EXISTING CCS PROJECT 24
Click ”Finish” and start developing with driver library in your project.
CHAPTER 5. HOW TO CREATE A NEW IAR PROJECT THAT USES DRIVERLIB 25
5 How to create a new IAR project that uses
Driverlib
5.1 Introduction
It is recommended to get started with an Empty Driverlib Project. Browse to the empty project in
your device's family. This is available in the driverlib instal folder\00 emptyProject
CHAPTER 5. HOW TO CREATE A NEW IAR PROJECT THAT USES DRIVERLIB 26
CHAPTER 5. HOW TO CREATE A NEW IAR PROJECT THAT USES DRIVERLIB 27
CHAPTER 6. HOW TO INCLUDE DRIVERLIB INTO YOUR EXISTING IAR PROJECT 28
6 How to include driverlib into your existing
IAR project
6.1 Introduction
To add driver library to an existing project, right click project click on Add Group - ”driverlib”
Now click Add files and browse through driverlib folder and add all source files of the family the
device belongs to.
CHAPTER 6. HOW TO INCLUDE DRIVERLIB INTO YOUR EXISTING IAR PROJECT 29
Add another group via ”Add Group” and add inc folder. Add all files in the same driverlib family inc
folder
CHAPTER 6. HOW TO INCLUDE DRIVERLIB INTO YOUR EXISTING IAR PROJECT 30
Right click on the project, select ”Options...”, add
”$PROJ DIR$\..\..\..\..\driverlib\MSP430FR5xx 6xx” under ”General Options->C/C++
Compiler->Additional include directories: (one per line)”. Click ”OK” and start developing with
driver library in your project.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 31
7 10-Bit Analog-to-Digital Converter
(ADC10 A)
Introduction ..............................................................................................31
API Functions ............................................................................................31
Programming Example ...................................................................................49
7.1 Introduction
The 10-Bit Analog-to-Digital (ADC10 A) API provides a set of functions for using the MSP430Ware
ADC10 A modules. Functions are provided to initialize the ADC10 A modules, setup signal
sources and reference voltages, and manage interrupts for the ADC10 A modules.
The ADC10 A module provides the ability to convert analog signals into a digital value in respect
to given reference voltages. The ADC10 A can generate digital values from 0 to Vcc with an 8- or
10-bit resolution. It operates in 2 different sampling modes, and 4 different conversion modes. The
sampling modes are extended sampling and pulse sampling, in extended sampling the
sample/hold signal must stay high for the duration of sampling, while in pulse mode a sampling
timer is setup to start on a rising edge of the sample/hold signal and sample for a specified
amount of clock cycles. The 4 conversion modes are single-channel single conversion, sequence
of channels single-conversion, repeated single channel conversions, and repeated sequence of
channels conversions.
The ADC10 A module can generate multiple interrupts. An interrupt can be asserted when a
conversion is complete, when a conversion is about to overwrite the converted data in the memory
buffer before it has been read out, and/or when a conversion is about to start before the last
conversion is complete. The ADC10 A also has a window comparator feature which asserts
interrupts when the input signal is above a high threshold, below a low threshold, or between the
two at any given moment.
7.2 API Functions
Functions
bool ADC10 A init (uint16 t baseAddress, uint16 t sampleHoldSignalSourceSelect, uint8 t
clockSourceSelect, uint16 t clockSourceDivider)
Initializes the ADC10 A Module.
void ADC10 A enable (uint16 t baseAddress)
Enables the ADC10 A block.
void ADC10 A disable (uint16 t baseAddress)
Disables the ADC10 A block.
void ADC10 A setupSamplingTimer (uint16 t baseAddress, uint16 t clockCycleHoldCount,
uint16 t multipleSamplesEnabled)
Sets up and enables the Sampling Timer Pulse Mode.
void ADC10 A disableSamplingTimer (uint16 t baseAddress)
Disables Sampling Timer Pulse Mode.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 32
void ADC10 A configureMemory (uint16 t baseAddress, uint8 t inputSourceSelect, uint8 t
positiveRefVoltageSourceSelect, uint8 t negativeRefVoltageSourceSelect)
Configures the controls of the selected memory buffer.
void ADC10 A enableInterrupt (uint16 t baseAddress, uint8 t interruptMask)
Enables selected ADC10 A interrupt sources.
void ADC10 A disableInterrupt (uint16 t baseAddress, uint8 t interruptMask)
Disables selected ADC10 A interrupt sources.
void ADC10 A clearInterrupt (uint16 t baseAddress, uint8 t interruptFlagMask)
Clears ADC10 A selected interrupt flags.
uint16 t ADC10 A getInterruptStatus (uint16 t baseAddress, uint8 t interruptFlagMask)
Returns the status of the selected memory interrupt flags.
void ADC10 A startConversion (uint16 t baseAddress, uint8 t
conversionSequenceModeSelect)
Enables/Starts an Analog-to-Digital Conversion.
void ADC10 A disableConversions (uint16 t baseAddress, bool preempt)
Disables the ADC from converting any more signals.
int16 t ADC10 A getResults (uint16 t baseAddress)
Returns the raw contents of the specified memory buffer.
void ADC10 A setResolution (uint16 t baseAddress, uint8 t resolutionSelect)
Use to change the resolution of the converted data.
void ADC10 A setSampleHoldSignalInversion (uint16 t baseAddress, uint16 t invertedSignal)
Use to invert or un-invert the sample/hold signal.
void ADC10 A setDataReadBackFormat (uint16 t baseAddress, uint16 t readBackFormat)
Use to set the read-back format of the converted data.
void ADC10 A enableReferenceBurst (uint16 t baseAddress)
Enables the reference buffer's burst ability.
void ADC10 A disableReferenceBurst (uint16 t baseAddress)
Disables the reference buffer's burst ability.
void ADC10 A setReferenceBufferSamplingRate (uint16 t baseAddress, uint16 t
samplingRateSelect)
Use to set the reference buffer's sampling rate.
void ADC10 A setWindowComp (uint16 t baseAddress, uint16 t highThreshold, uint16 t
lowThreshold)
Sets the high and low threshold for the window comparator feature.
uint32 t ADC10 A getMemoryAddressForDMA (uint16 t baseAddress)
Returns the address of the memory buffer for the DMA module.
uint16 t ADC10 A isBusy (uint16 t baseAddress)
Returns the busy status of the ADC10 A core.
7.2.1 Detailed Description
The ADC10 A API is broken into three groups of functions: those that deal with initialization and
conversions, those that handle interrupts, and those that handle auxiliary features of the ADC10 A.
The ADC10 A initialization and conversion functions are
ADC10 A init()
ADC10 A configureMemory()
ADC10 A setupSamplingTimer()
ADC10 A disableSamplingTimer()
ADC10 A setWindowComp()
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 33
ADC10 A startConversion()
ADC10 A disableConversions()
ADC10 A getResults()
ADC10 A isBusy()
The ADC10 A interrupts are handled by
ADC10 A enableInterrupt()
ADC10 A disableInterrupt()
ADC10 A clearInterrupt()
ADC10 A getInterruptStatus()
Auxiliary features of the ADC10 A are handled by
ADC10 A setResolution()
ADC10 A setSampleHoldSignalInversion()
ADC10 A setDataReadBackFormat()
ADC10 A enableReferenceBurst()
ADC10 A disableReferenceBurst()
ADC10 A setReferenceBufferSamplingRate()
ADC10 A getMemoryAddressForDMA()
ADC10 A enable()
ADC10 A disable()
7.2.2 Function Documentation
ADC10 A clearInterrupt()
void ADC10 A clearInterrupt (
uint16 t baseAddress,
uint8 t interruptFlagMask )
Clears ADC10 A selected interrupt flags.
The selected ADC10 A interrupt flags are cleared, so that it no longer asserts. The memory buffer
interrupt flags are only cleared when the memory buffer is accessed.
Parameters
baseAddress is the base address of the ADC10 A module.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 34
Parameters
interruptFlagMask is a bit mask of the interrupt flags to be cleared. Mask value is the logical
OR of any of the following:
ADC10 A TIMEOVERFLOW INTFLAG - Interrupts flag when a new
conversion is starting before the previous one has finished
ADC10 A OVERFLOW INTFLAG - Interrupts flag when a new
conversion is about to overwrite the previous one
ADC10 A ABOVETHRESHOLD INTFLAG - Interrupts flag when the
input signal has gone above the high threshold of the window
comparator
ADC10 A BELOWTHRESHOLD INTFLAG - Interrupts flag when the
input signal has gone below the low threshold of the low window
comparator
ADC10 A INSIDEWINDOW INTFLAG - Interrupts flag when the
input signal is in between the high and low thresholds of the window
comparator
ADC10 A COMPLETED INTFLAG - Interrupt flag for new
conversion data in the memory buffer
Modified bits of ADC10IFG register.
Returns
None
ADC10 A configureMemory()
void ADC10 A configureMemory (
uint16 t baseAddress,
uint8 t inputSourceSelect,
uint8 t positiveRefVoltageSourceSelect,
uint8 t negativeRefVoltageSourceSelect )
Configures the controls of the selected memory buffer.
Maps an input signal conversion into the memory buffer, as well as the positive and negative
reference voltages for each conversion being stored into the memory buffer. If the internal
reference is used for the positive reference voltage, the internal REF module has to control the
voltage level. Note that if a conversion has been started with the startConversion() function, then a
call to disableConversions() is required before this function may be called. If conversion is not
disabled, this function does nothing.
Parameters
baseAddress is the base address of the ADC10 A module.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 35
Parameters
inputSourceSelect is the input that will store the converted data into the
specified memory buffer. Valid values are:
ADC10 A INPUT A0 [Default]
ADC10 A INPUT A1
ADC10 A INPUT A2
ADC10 A INPUT A3
ADC10 A INPUT A4
ADC10 A INPUT A5
ADC10 A INPUT A6
ADC10 A INPUT A7
ADC10 A INPUT A8
ADC10 A INPUT A9
ADC10 A INPUT TEMPSENSOR
ADC10 A INPUT BATTERYMONITOR
ADC10 A INPUT A12
ADC10 A INPUT A13
ADC10 A INPUT A14
ADC10 A INPUT A15
Modified bits are ADC10INCHx of ADC10MCTL0
register.
positiveRefVoltageSourceSelect is the reference voltage source to set as the upper limit for
the conversion that is to be stored in the specified memory
buffer. Valid values are:
ADC10 A VREFPOS AVCC [Default]
ADC10 A VREFPOS EXT
ADC10 A VREFPOS INT
Modified bits are ADC10SREF of ADC10MCTL0
register.
negativeRefVoltageSourceSelect is the reference voltage source to set as the lower limit for
the conversion that is to be stored in the specified memory
buffer. Valid values are:
ADC10 A VREFNEG AVSS
ADC10 A VREFNEG EXT
Modified bits are ADC10SREF of ADC10CTL0
register.
Returns
None
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 36
ADC10 A disable()
void ADC10 A disable (
uint16 t baseAddress )
Disables the ADC10 A block.
This will disable operation of the ADC10 A block.
Parameters
baseAddress is the base address of the ADC10 A module.
Modified bits are ADC10ON of ADC10CTL0 register.
Returns
None
ADC10 A disableConversions()
void ADC10 A disableConversions (
uint16 t baseAddress,
bool preempt )
Disables the ADC from converting any more signals.
Disables the ADC from converting any more signals. If there is a conversion in progress, this
function can stop it immediately if the preempt parameter is set as
ADC10 A PREEMPTCONVERSION, by changing the conversion mode to single-channel,
single-conversion and disabling conversions. If the conversion mode is set as single-channel,
single-conversion and this function is called without preemption, then the ADC core conversion
status is polled until the conversion is complete before disabling conversions to prevent
unpredictable data. If the ADC10 A startConversion() has been called, then this function has to be
called to re-initialize the ADC, reconfigure a memory buffer control, enable/disable the sampling
pulse mode, or change the internal reference voltage.
Parameters
baseAddress is the base address of the ADC10 A module.
preempt specifies if the current conversion should be pre-empted before the end of the
conversion Valid values are:
ADC10 A COMPLETECONVERSION - Allows the ADC10 A to end the
current conversion before disabling conversions.
ADC10 A PREEMPTCONVERSION - Stops the ADC10 A immediately,
with unpredictable results of the current conversion. Cannot be used with
repeated conversion.
Modified bits of ADC10CTL1 register and bits of ADC10CTL0 register.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 37
Returns
None
ADC10 A disableInterrupt()
void ADC10 A disableInterrupt (
uint16 t baseAddress,
uint8 t interruptMask )
Disables selected ADC10 A interrupt sources.
Disables the indicated ADC10 A interrupt sources. Only the sources that are enabled can be
reflected to the processor interrupt; disabled sources have no effect on the processor.
Parameters
baseAddress is the base address of the ADC10 A module.
interruptMask is the bit mask of the memory buffer interrupt sources to be disabled. Mask
value is the logical OR of any of the following:
ADC10 A TIMEOVERFLOW INT - Interrupts when a new conversion is
starting before the previous one has finished
ADC10 A OVERFLOW INT - Interrupts when a new conversion is about
to overwrite the previous one
ADC10 A ABOVETHRESHOLD INT - Interrupts when the input signal
has gone above the high threshold of the window comparator
ADC10 A BELOWTHRESHOLD INT - Interrupts when the input signal
has gone below the low threshold of the low window comparator
ADC10 A INSIDEWINDOW INT - Interrupts when the input signal is in
between the high and low thresholds of the window comparator
ADC10 A COMPLETED INT - Interrupt for new conversion data in the
memory buffer
Modified bits of ADC10IE register.
Returns
None
ADC10 A disableReferenceBurst()
void ADC10 A disableReferenceBurst (
uint16 t baseAddress )
Disables the reference buffer's burst ability.
Disables the reference buffer's burst ability, forcing the reference buffer to remain on continuously.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 38
Parameters
baseAddress is the base address of the ADC10 A module.
Returns
None
ADC10 A disableSamplingTimer()
void ADC10 A disableSamplingTimer (
uint16 t baseAddress )
Disables Sampling Timer Pulse Mode.
Disables the Sampling Timer Pulse Mode. Note that if a conversion has been started with the
startConversion() function, then a call to disableConversions() is required before this function may
be called.
Parameters
baseAddress is the base address of the ADC10 A module.
Returns
None
ADC10 A enable()
void ADC10 A enable (
uint16 t baseAddress )
Enables the ADC10 A block.
This will enable operation of the ADC10 A block.
Parameters
baseAddress is the base address of the ADC10 A module.
Modified bits are ADC10ON of ADC10CTL0 register.
Returns
None
ADC10 A enableInterrupt()
void ADC10 A enableInterrupt (
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 39
uint16 t baseAddress,
uint8 t interruptMask )
Enables selected ADC10 A interrupt sources.
Enables the indicated ADC10 A interrupt sources. Only the sources that are enabled can be
reflected to the processor interrupt; disabled sources have no effect on the processor. Does not
clear interrupt flags.
Parameters
baseAddress is the base address of the ADC10 A module.
interruptMask is the bit mask of the memory buffer interrupt sources to be enabled. Mask
value is the logical OR of any of the following:
ADC10 A TIMEOVERFLOW INT - Interrupts when a new conversion is
starting before the previous one has finished
ADC10 A OVERFLOW INT - Interrupts when a new conversion is about
to overwrite the previous one
ADC10 A ABOVETHRESHOLD INT - Interrupts when the input signal
has gone above the high threshold of the window comparator
ADC10 A BELOWTHRESHOLD INT - Interrupts when the input signal
has gone below the low threshold of the low window comparator
ADC10 A INSIDEWINDOW INT - Interrupts when the input signal is in
between the high and low thresholds of the window comparator
ADC10 A COMPLETED INT - Interrupt for new conversion data in the
memory buffer
Modified bits of ADC10IE register.
Returns
None
ADC10 A enableReferenceBurst()
void ADC10 A enableReferenceBurst (
uint16 t baseAddress )
Enables the reference buffer's burst ability.
Enables the reference buffer's burst ability, allowing the reference buffer to turn off while the ADC
is not converting, and automatically turning on when the ADC needs the generated reference
voltage for a conversion.
Parameters
baseAddress is the base address of the ADC10 A module.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 40
Returns
None
ADC10 A getInterruptStatus()
uint16 t ADC10 A getInterruptStatus (
uint16 t baseAddress,
uint8 t interruptFlagMask )
Returns the status of the selected memory interrupt flags.
Returns the status of the selected interrupt flags.
Parameters
baseAddress is the base address of the ADC10 A module.
interruptFlagMask is a bit mask of the interrupt flags status to be returned. Mask value is the
logical OR of any of the following:
ADC10 A TIMEOVERFLOW INTFLAG - Interrupts flag when a new
conversion is starting before the previous one has finished
ADC10 A OVERFLOW INTFLAG - Interrupts flag when a new
conversion is about to overwrite the previous one
ADC10 A ABOVETHRESHOLD INTFLAG - Interrupts flag when the
input signal has gone above the high threshold of the window
comparator
ADC10 A BELOWTHRESHOLD INTFLAG - Interrupts flag when the
input signal has gone below the low threshold of the low window
comparator
ADC10 A INSIDEWINDOW INTFLAG - Interrupts flag when the
input signal is in between the high and low thresholds of the window
comparator
ADC10 A COMPLETED INTFLAG - Interrupt flag for new
conversion data in the memory buffer
Returns
The current interrupt flag status for the corresponding mask.
ADC10 A getMemoryAddressForDMA()
uint32 t ADC10 A getMemoryAddressForDMA (
uint16 t baseAddress )
Returns the address of the memory buffer for the DMA module.
Returns the address of the memory buffer. This can be used in conjunction with the DMA to store
the converted data directly to memory.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 41
Parameters
baseAddress is the base address of the ADC10 A module.
Returns
The memory address of the memory buffer
ADC10 A getResults()
int16 t ADC10 A getResults (
uint16 t baseAddress )
Returns the raw contents of the specified memory buffer.
Returns the raw contents of the specified memory buffer. The format of the content depends on
the read-back format of the data: if the data is in signed 2's complement format then the contents
in the memory buffer will be left-justified with the least-significant bits as 0's, whereas if the data is
in unsigned format then the contents in the memory buffer will be right- justified with the
most-significant bits as 0's.
Parameters
baseAddress is the base address of the ADC10 A module.
Returns
A Signed Integer of the contents of the specified memory buffer.
ADC10 A init()
bool ADC10 A init (
uint16 t baseAddress,
uint16 t sampleHoldSignalSourceSelect,
uint8 t clockSourceSelect,
uint16 t clockSourceDivider )
Initializes the ADC10 A Module.
This function initializes the ADC module to allow for analog-to-digital conversions. Specifically this
function sets up the sample-and-hold signal and clock sources for the ADC core to use for
conversions. Upon successful completion of the initialization all of the ADC control registers will be
reset, excluding the memory controls and reference module bits, the given parameters will be set,
and the ADC core will be turned on (Note, that the ADC core only draws power during conversions
and remains off when not converting).Note that sample/hold signal sources are device dependent.
Note that if re-initializing the ADC after starting a conversion with the startConversion() function,
the disableConversion() must be called BEFORE this function can be called.
Parameters
baseAddress is the base address of the ADC10 A module.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 42
Parameters
sampleHoldSignalSourceSelect is the signal that will trigger a sample-and-hold for an input
signal to be converted. This parameter is device specific and
sources should be found in the device's datasheet Valid
values are:
ADC10 A SAMPLEHOLDSOURCE SC
ADC10 A SAMPLEHOLDSOURCE 1
ADC10 A SAMPLEHOLDSOURCE 2
ADC10 A SAMPLEHOLDSOURCE 3
Modified bits are ADC10SHSx of ADC10CTL1 register.
clockSourceSelect selects the clock that will be used by the ADC10 A core and
the sampling timer if a sampling pulse mode is enabled.
Valid values are:
ADC10 A CLOCKSOURCE ADC10OSC [Default] -
MODOSC 5 MHz oscillator from the UCS
ADC10 A CLOCKSOURCE ACLK - The Auxiliary
Clock
ADC10 A CLOCKSOURCE MCLK - The Master Clock
ADC10 A CLOCKSOURCE SMCLK - The Sub-Master
Clock
Modified bits are ADC10SSELx of ADC10CTL1
register.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 43
Parameters
clockSourceDivider selects the amount that the clock will be divided. Valid
values are:
ADC10 A CLOCKDIVIDER 1 [Default]
ADC10 A CLOCKDIVIDER 2
ADC10 A CLOCKDIVIDER 3
ADC10 A CLOCKDIVIDER 4
ADC10 A CLOCKDIVIDER 5
ADC10 A CLOCKDIVIDER 6
ADC10 A CLOCKDIVIDER 7
ADC10 A CLOCKDIVIDER 8
ADC10 A CLOCKDIVIDER 12
ADC10 A CLOCKDIVIDER 16
ADC10 A CLOCKDIVIDER 20
ADC10 A CLOCKDIVIDER 24
ADC10 A CLOCKDIVIDER 28
ADC10 A CLOCKDIVIDER 32
ADC10 A CLOCKDIVIDER 64
ADC10 A CLOCKDIVIDER 128
ADC10 A CLOCKDIVIDER 192
ADC10 A CLOCKDIVIDER 256
ADC10 A CLOCKDIVIDER 320
ADC10 A CLOCKDIVIDER 384
ADC10 A CLOCKDIVIDER 448
ADC10 A CLOCKDIVIDER 512
Modified bits are ADC10DIVx of ADC10CTL1 register;
bits ADC10PDIVx of ADC10CTL2 register.
Returns
STATUS SUCCESS or STATUS FAILURE of the initialization process.
ADC10 A isBusy()
uint16 t ADC10 A isBusy (
uint16 t baseAddress )
Returns the busy status of the ADC10 A core.
Returns the status of the ADC core if there is a conversion currently taking place.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 44
Parameters
baseAddress is the base address of the ADC10 A module.
Returns
One of the following:
ADC10 A BUSY
ADC10 A NOTBUSY
indicating if there is a conversion currently taking place
ADC10 A setDataReadBackFormat()
void ADC10 A setDataReadBackFormat (
uint16 t baseAddress,
uint16 t readBackFormat )
Use to set the read-back format of the converted data.
Sets the format of the converted data: how it will be stored into the memory buffer, and how it
should be read back. The format can be set as right-justified (default), which indicates that the
number will be unsigned, or left-justified, which indicates that the number will be signed in 2's
complement format. This change affects all memory buffers for subsequent conversions.
Parameters
baseAddress is the base address of the ADC10 A module.
readBackFormat is the specified format to store the conversions in the memory buffer. Valid
values are:
ADC10 A UNSIGNED BINARY [Default]
ADC10 A SIGNED 2SCOMPLEMENT
Modified bits are ADC10DF of ADC10CTL2 register.
Returns
None
ADC10 A setReferenceBufferSamplingRate()
void ADC10 A setReferenceBufferSamplingRate (
uint16 t baseAddress,
uint16 t samplingRateSelect )
Use to set the reference buffer's sampling rate.
Sets the reference buffer's sampling rate to the selected sampling rate. The default sampling rate
is maximum of 200-ksps, and can be reduced to a maximum of 50-ksps to conserve power.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 45
Parameters
baseAddress is the base address of the ADC10 A module.
samplingRateSelect is the specified maximum sampling rate. Valid values are:
ADC10 A MAXSAMPLINGRATE 200KSPS [Default]
ADC10 A MAXSAMPLINGRATE 50KSPS
Modified bits are ADC10SR of ADC10CTL2 register.
Returns
None
ADC10 A setResolution()
void ADC10 A setResolution (
uint16 t baseAddress,
uint8 t resolutionSelect )
Use to change the resolution of the converted data.
This function can be used to change the resolution of the converted data from the default of
12-bits.
Parameters
baseAddress is the base address of the ADC10 A module.
resolutionSelect determines the resolution of the converted data. Valid values
are:
ADC10 A RESOLUTION 8BIT
ADC10 A RESOLUTION 10BIT [Default]
Modified bits are ADC10RES of ADC10CTL2 register.
Returns
None
ADC10 A setSampleHoldSignalInversion()
void ADC10 A setSampleHoldSignalInversion (
uint16 t baseAddress,
uint16 t invertedSignal )
Use to invert or un-invert the sample/hold signal.
This function can be used to invert or un-invert the sample/hold signal. Note that if a conversion
has been started with the startConversion() function, then a call to disableConversions() is
required before this function may be called.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 46
Parameters
baseAddress is the base address of the ADC10 A module.
invertedSignal set if the sample/hold signal should be inverted Valid values are:
ADC10 A NONINVERTEDSIGNAL [Default] - a sample-and-hold of an
input signal for conversion will be started on a rising edge of the
sample/hold signal.
ADC10 A INVERTEDSIGNAL - a sample-and-hold of an input signal for
conversion will be started on a falling edge of the sample/hold signal.
Modified bits are ADC10ISSH of ADC10CTL1 register.
Returns
None
ADC10 A setupSamplingTimer()
void ADC10 A setupSamplingTimer (
uint16 t baseAddress,
uint16 t clockCycleHoldCount,
uint16 t multipleSamplesEnabled )
Sets up and enables the Sampling Timer Pulse Mode.
This function sets up the sampling timer pulse mode which allows the sample/hold signal to trigger
a sampling timer to sample-and-hold an input signal for a specified number of clock cycles without
having to hold the sample/hold signal for the entire period of sampling. Note that if a conversion
has been started with the startConversion() function, then a call to disableConversions() is
required before this function may be called.
Parameters
baseAddress is the base address of the ADC10 A module.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 47
Parameters
clockCycleHoldCount sets the amount of clock cycles to sample-and- hold for the memory
buffer. Valid values are:
ADC10 A CYCLEHOLD 4 CYCLES [Default]
ADC10 A CYCLEHOLD 8 CYCLES
ADC10 A CYCLEHOLD 16 CYCLES
ADC10 A CYCLEHOLD 32 CYCLES
ADC10 A CYCLEHOLD 64 CYCLES
ADC10 A CYCLEHOLD 96 CYCLES
ADC10 A CYCLEHOLD 128 CYCLES
ADC10 A CYCLEHOLD 192 CYCLES
ADC10 A CYCLEHOLD 256 CYCLES
ADC10 A CYCLEHOLD 384 CYCLES
ADC10 A CYCLEHOLD 512 CYCLES
ADC10 A CYCLEHOLD 768 CYCLES
ADC10 A CYCLEHOLD 1024 CYCLES
Modified bits are ADC10SHTx of ADC10CTL0 register.
multipleSamplesEnabled allows multiple conversions to start without a trigger signal from the
sample/hold signal Valid values are:
ADC10 A MULTIPLESAMPLESDISABLE - a timer trigger will
be needed to start every ADC conversion.
ADC10 A MULTIPLESAMPLESENABLE - during a
sequenced and/or repeated conversion mode, after the first
conversion, no sample/hold signal is necessary to start
subsequent samples.
Modified bits are ADC10MSC of ADC10CTL0 register.
Returns
None
ADC10 A setWindowComp()
void ADC10 A setWindowComp (
uint16 t baseAddress,
uint16 t highThreshold,
uint16 t lowThreshold )
Sets the high and low threshold for the window comparator feature.
Sets the high and low threshold for the window comparator feature. Use the ADC10HIIE,
ADC10INIE, ADC10LOIE interrupts to utilize this feature.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 48
Parameters
baseAddress is the base address of the ADC10 A module.
highThreshold is the upper bound that could trip an interrupt for the window comparator.
lowThreshold is the lower bound that could trip on interrupt for the window comparator.
Returns
None
ADC10 A startConversion()
void ADC10 A startConversion (
uint16 t baseAddress,
uint8 t conversionSequenceModeSelect )
Enables/Starts an Analog-to-Digital Conversion.
This function enables/starts the conversion process of the ADC. If the sample/hold signal source
chosen during initialization was ADC10OSC, then the conversion is started immediately, otherwise
the chosen sample/hold signal source starts the conversion by a rising edge of the signal. Keep in
mind when selecting conversion modes, that for sequenced and/or repeated modes, to keep the
sample/hold-and-convert process continuing without a trigger from the sample/hold signal source,
the multiple samples must be enabled using the ADC10 A setupSamplingTimer() function. Also
note that when a sequence conversion mode is selected, the first input channel is the one mapped
to the memory buffer, the next input channel selected for conversion is one less than the input
channel just converted (i.e. A1 comes after A2), until A0 is reached, and if in repeating mode, then
the next input channel will again be the one mapped to the memory buffer. Note that after this
function is called, the ADC10 A stopConversions() has to be called to re-initialize the ADC,
reconfigure a memory buffer control, enable/disable the sampling timer, or to change the internal
reference voltage.
Parameters
baseAddress is the base address of the ADC10 A module.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 49
Parameters
conversionSequenceModeSelect determines the ADC operating mode. Valid values are:
ADC10 A SINGLECHANNEL [Default] - one-time
conversion of a single channel into a single memory
buffer
ADC10 A SEQOFCHANNELS - one time conversion
of multiple channels into the specified starting memory
buffer and each subsequent memory buffer up until the
conversion is stored in a memory buffer dedicated as
the end-of-sequence by the memory's control register
ADC10 A REPEATED SINGLECHANNEL - repeated
conversions of one channel into a single memory
buffer
ADC10 A REPEATED SEQOFCHANNELS -
repeated conversions of multiple channels into the
specified starting memory buffer and each subsequent
memory buffer up until the conversion is stored in a
memory buffer dedicated as the end-of-sequence by
the memory's control register
Modified bits are ADC10CONSEQx of ADC10CTL1
register.
Returns
None
7.3 Programming Example
The following example shows how to initialize and use the ADC10 A API to start a single channel,
single conversion.
// Initialize ADC10 A with ADC10 A’s built-in oscillator
ADC10 A init (ADC10 A BASE,
ADC10 A SAMPLEHOLDSOURCE SC,
ADC10 A CLOCKSOURCE ADC10 AOSC,
ADC10 A CLOCKDIVIDEBY 1);
//Switch ON ADC10 A
ADC10 A enable(ADC10 A BASE);
// Setup sampling timer to sample-and-hold for 16 clock cycles
ADC10 A setupSamplingTimer (ADC10 A BASE,
ADC10 A CYCLEHOLD 16 CYCLES,
FALSE);
// Configure the Input to the Memory Buffer with the specified Reference Voltages
ADC10 A configureMemory (ADC10 A BASE,
ADC10 A INPUT A0,
ADC10 A VREF AVCC, // Vref+ = AVcc
ADC10 A VREF AVSS // Vref- = AVss
);
while (1)
{
// Start a single conversion, no repeating or sequences.
CHAPTER 7. 10-BIT ANALOG-TO-DIGITAL CONVERTER (ADC10 A) 50
ADC10 A startConversion (ADC10 A BASE,
ADC10 A SINGLECHANNEL);
// Wait for the Interrupt Flag to assert
while( !(ADC10 A getInterruptStatus(ADC10 A BASE,ADC10 AIFG0)) );
// Clear the Interrupt Flag and start another conversion
ADC10 A clearInterrupt(ADC10 A BASE,ADC10 AIFG0);
}
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 51
8 12-Bit Analog-to-Digital Converter
(ADC12 A)
Introduction ..............................................................................................51
API Functions ............................................................................................51
Programming Example ...................................................................................70
8.1 Introduction
The 12-Bit Analog-to-Digital (ADC12 A) API provides a set of functions for using the MSP430Ware
ADC12 A modules. Functions are provided to initialize the ADC12 A modules, setup signal
sources and reference voltages for each memory buffer, and manage interrupts for the ADC12 A
modules.
The ADC12 A module provides the ability to convert analog signals into a digital value in respect
to given reference voltages. The ADC12 A can generate digital values from 0 to Vcc with an 8-,
10- or 12-bit resolution, with 16 different memory buffers to store conversion results. It operates in
2 different sampling modes, and 4 different conversion modes. The sampling modes are extended
sampling and pulse sampling, in extended sampling the sample/hold signal must stay high for the
duration of sampling, while in pulse mode a sampling timer is setup to start on a rising edge of the
sample/hold signal and sample for a specified amount of clock cycles. The 4 conversion modes
are single-channel single conversion, sequence of channels single-conversion, repeated single
channel conversions, and repeated sequence of channels conversions.
The ADC12 A module can generate multiple interrupts. An interrupt can be asserted for each
memory buffer when a conversion is complete, or when a conversion is about to overwrite the
converted data in any of the memory buffers before it has been read out, and/or when a
conversion is about to start before the last conversion is complete.
8.2 API Functions
Functions
bool ADC12 A init (uint16 t baseAddress, uint16 t sampleHoldSignalSourceSelect, uint8 t
clockSourceSelect, uint16 t clockSourceDivider)
Initializes the ADC12 A Module.
void ADC12 A enable (uint16 t baseAddress)
Enables the ADC12 A block.
void ADC12 A disable (uint16 t baseAddress)
Disables the ADC12 A block.
void ADC12 A setupSamplingTimer (uint16 t baseAddress, uint16 t
clockCycleHoldCountLowMem, uint16 t clockCycleHoldCountHighMem, uint16 t
multipleSamplesEnabled)
Sets up and enables the Sampling Timer Pulse Mode.
void ADC12 A disableSamplingTimer (uint16 t baseAddress)
Disables Sampling Timer Pulse Mode.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 52
void ADC12 A configureMemory (uint16 t baseAddress, ADC12 A configureMemoryParam
param)
Configures the controls of the selected memory buffer.
void ADC12 A enableInterrupt (uint16 t baseAddress, uint32 t interruptMask)
Enables selected ADC12 A interrupt sources.
void ADC12 A disableInterrupt (uint16 t baseAddress, uint32 t interruptMask)
Disables selected ADC12 A interrupt sources.
void ADC12 A clearInterrupt (uint16 t baseAddress, uint16 t memoryInterruptFlagMask)
Clears ADC12 A selected interrupt flags.
uint16 t ADC12 A getInterruptStatus (uint16 t baseAddress, uint16 t
memoryInterruptFlagMask)
Returns the status of the selected memory interrupt flags.
void ADC12 A startConversion (uint16 t baseAddress, uint16 t startingMemoryBufferIndex,
uint8 t conversionSequenceModeSelect)
Enables/Starts an Analog-to-Digital Conversion.
void ADC12 A disableConversions (uint16 t baseAddress, bool preempt)
Disables the ADC from converting any more signals.
uint16 t ADC12 A getResults (uint16 t baseAddress, uint8 t memoryBufferIndex)
A Signed Integer of the contents of the specified memory buffer.
void ADC12 A setResolution (uint16 t baseAddress, uint8 t resolutionSelect)
Use to change the resolution of the converted data.
void ADC12 A setSampleHoldSignalInversion (uint16 t baseAddress, uint16 t invertedSignal)
Use to invert or un-invert the sample/hold signal.
void ADC12 A setDataReadBackFormat (uint16 t baseAddress, uint8 t readBackFormat)
Use to set the read-back format of the converted data.
void ADC12 A enableReferenceBurst (uint16 t baseAddress)
Enables the reference buffer's burst ability.
void ADC12 A disableReferenceBurst (uint16 t baseAddress)
Disables the reference buffer's burst ability.
void ADC12 A setReferenceBufferSamplingRate (uint16 t baseAddress, uint8 t
samplingRateSelect)
Use to set the reference buffer's sampling rate.
uint32 t ADC12 A getMemoryAddressForDMA (uint16 t baseAddress, uint8 t memoryIndex)
Returns the address of the specified memory buffer for the DMA module.
uint16 t ADC12 A isBusy (uint16 t baseAddress)
Returns the busy status of the ADC12 A core.
8.2.1 Detailed Description
The ADC12 A API is broken into three groups of functions: those that deal with initialization and
conversions, those that handle interrupts, and those that handle auxiliary features of the ADC12 A.
The ADC12 A initialization and conversion functions are
ADC12 A init()
ADC12 A configureMemory()
ADC12 A setupSamplingTimer()
ADC12 A disableSamplingTimer()
ADC12 A startConversion()
ADC12 A disableConversions()
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 53
ADC12 A readResults()
ADC12 A isBusy()
The ADC12 A interrupts are handled by
ADC12 A enableInterrupt()
ADC12 A disableInterrupt()
ADC12 A clearInterrupt()
ADC12 A getInterruptStatus()
Auxiliary features of the ADC12 A are handled by
ADC12 A setResolution()
ADC12 A setSampleHoldSignalInversion()
ADC12 A setDataReadBackFormat()
ADC12 A enableReferenceBurst()
ADC12 A disableReferenceBurst()
ADC12 A setReferenceBufferSamplingRate()
ADC12 A getMemoryAddressForDMA()
ADC12 A enable()
ADC12 A disable()
8.2.2 Function Documentation
ADC12 A clearInterrupt()
void ADC12 A clearInterrupt (
uint16 t baseAddress,
uint16 t memoryInterruptFlagMask )
Clears ADC12 A selected interrupt flags.
The selected ADC12 A interrupt flags are cleared, so that it no longer asserts. The memory buffer
interrupt flags are only cleared when the memory buffer is accessed. Note that the overflow
interrupts do not have an interrupt flag to clear; they must be accessed directly from the interrupt
vector.
Parameters
baseAddress is the base address of the ADC12 A module.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 54
Parameters
memoryInterruptFlagMask is a bit mask of the interrupt flags to be cleared. Mask value is the
logical OR of any of the following:
ADC12 A IFG0
ADC12 A IFG1
ADC12 A IFG2
ADC12 A IFG3
ADC12 A IFG4
ADC12 A IFG5
ADC12 A IFG6
ADC12 A IFG7
ADC12 A IFG8
ADC12 A IFG9
ADC12 A IFG10
ADC12 A IFG11
ADC12 A IFG12
ADC12 A IFG13
ADC12 A IFG14
ADC12 A IFG15
Modified bits of ADC12IFG register.
Returns
None
ADC12 A configureMemory()
void ADC12 A configureMemory (
uint16 t baseAddress,
ADC12 A configureMemoryParam param )
Configures the controls of the selected memory buffer.
Maps an input signal conversion into the selected memory buffer, as well as the positive and
negative reference voltages for each conversion being stored into this memory buffer. If the
internal reference is used for the positive reference voltage, the internal REF module must be used
to control the voltage level. Note that if a conversion has been started with the startConversion()
function, then a call to disableConversions() is required before this function may be called. If
conversion is not disabled, this function does nothing.
Parameters
baseAddress is the base address of the ADC12 A module.
param is the pointer to struct for memory configuration.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 55
Returns
None
References ADC12 A configureMemoryParam::endOfSequence,
ADC12 A configureMemoryParam::inputSourceSelect,
ADC12 A configureMemoryParam::memoryBufferControlIndex,
ADC12 A configureMemoryParam::negativeRefVoltageSourceSelect, and
ADC12 A configureMemoryParam::positiveRefVoltageSourceSelect.
ADC12 A disable()
void ADC12 A disable (
uint16 t baseAddress )
Disables the ADC12 A block.
This will disable operation of the ADC12 A block.
Parameters
baseAddress is the base address of the ADC12 A module.
Modified bits are ADC12ON of ADC12CTL0 register.
Returns
None
ADC12 A disableConversions()
void ADC12 A disableConversions (
uint16 t baseAddress,
bool preempt )
Disables the ADC from converting any more signals.
Disables the ADC from converting any more signals. If there is a conversion in progress, this
function can stop it immediately if the preempt parameter is set as TRUE, by changing the
conversion mode to single-channel, single- conversion and disabling conversions. If the
conversion mode is set as single-channel, single-conversion and this function is called without
preemption, then the ADC core conversion status is polled until the conversion is complete before
disabling conversions to prevent unpredictable data. If the ADC12 A startConversion() has been
called, then this function has to be called to re-initialize the ADC, reconfigure a memory buffer
control, enable/disable the sampling pulse mode, or change the internal reference voltage.
Parameters
baseAddress is the base address of the ADC12 A module.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 56
Parameters
preempt specifies if the current conversion should be pre-empted before the end of the
conversion. Valid values are:
ADC12 A COMPLETECONVERSION - Allows the ADC12 A to end the
current conversion before disabling conversions.
ADC12 A PREEMPTCONVERSION - Stops the ADC12 A immediately,
with unpredictable results of the current conversion.
Modified bits of ADC12CTL1 register and bits of ADC12CTL0 register.
Returns
None
References ADC12 A isBusy().
ADC12 A disableInterrupt()
void ADC12 A disableInterrupt (
uint16 t baseAddress,
uint32 t interruptMask )
Disables selected ADC12 A interrupt sources.
Disables the indicated ADC12 A interrupt sources. Only the sources that are enabled can be
reflected to the processor interrupt, disabled sources have no effect on the processor.
Parameters
baseAddress is the base address of the ADC12 A module.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 57
Parameters
interruptMask Mask value is the logical OR of any of the following:
ADC12 A IE0
ADC12 A IE1
ADC12 A IE2
ADC12 A IE3
ADC12 A IE4
ADC12 A IE5
ADC12 A IE6
ADC12 A IE7
ADC12 A IE8
ADC12 A IE9
ADC12 A IE10
ADC12 A IE11
ADC12 A IE12
ADC12 A IE13
ADC12 A IE14
ADC12 A IE15
ADC12 A OVERFLOW IE
ADC12 A CONVERSION TIME OVERFLOW IE
Modified bits of ADC12IE register and bits of ADC12CTL0 register.
Returns
None
ADC12 A disableReferenceBurst()
void ADC12 A disableReferenceBurst (
uint16 t baseAddress )
Disables the reference buffer's burst ability.
Disables the reference buffer's burst ability, forcing the reference buffer to remain on continuously.
Parameters
baseAddress is the base address of the ADC12 A module.
Returns
None
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 58
ADC12 A disableSamplingTimer()
void ADC12 A disableSamplingTimer (
uint16 t baseAddress )
Disables Sampling Timer Pulse Mode.
Disables the Sampling Timer Pulse Mode. Note that if a conversion has been started with the
startConversion() function, then a call to disableConversions() is required before this function may
be called.
Parameters
baseAddress is the base address of the ADC12 A module.
Modified bits are ADC12SHP of ADC12CTL0 register.
Returns
None
ADC12 A enable()
void ADC12 A enable (
uint16 t baseAddress )
Enables the ADC12 A block.
This will enable operation of the ADC12 A block.
Parameters
baseAddress is the base address of the ADC12 A module.
Modified bits are ADC12ON of ADC12CTL0 register.
Returns
None
ADC12 A enableInterrupt()
void ADC12 A enableInterrupt (
uint16 t baseAddress,
uint32 t interruptMask )
Enables selected ADC12 A interrupt sources.
Enables the indicated ADC12 A interrupt sources. Only the sources that are enabled can be
reflected to the processor interrupt, disabled sources have no effect on the processor. Does not
clear interrupt flags.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 59
Parameters
baseAddress is the base address of the ADC12 A module.
interruptMask Mask value is the logical OR of any of the following:
ADC12 A IE0
ADC12 A IE1
ADC12 A IE2
ADC12 A IE3
ADC12 A IE4
ADC12 A IE5
ADC12 A IE6
ADC12 A IE7
ADC12 A IE8
ADC12 A IE9
ADC12 A IE10
ADC12 A IE11
ADC12 A IE12
ADC12 A IE13
ADC12 A IE14
ADC12 A IE15
ADC12 A OVERFLOW IE
ADC12 A CONVERSION TIME OVERFLOW IE
Modified bits of ADC12IE register and bits of ADC12CTL0 register.
Returns
None
ADC12 A enableReferenceBurst()
void ADC12 A enableReferenceBurst (
uint16 t baseAddress )
Enables the reference buffer's burst ability.
Enables the reference buffer's burst ability, allowing the reference buffer to turn off while the ADC
is not converting, and automatically turning on when the ADC needs the generated reference
voltage for a conversion.
Parameters
baseAddress is the base address of the ADC12 A module.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 60
Returns
None
ADC12 A getInterruptStatus()
uint16 t ADC12 A getInterruptStatus (
uint16 t baseAddress,
uint16 t memoryInterruptFlagMask )
Returns the status of the selected memory interrupt flags.
Returns the status of the selected memory interrupt flags. Note that the overflow interrupts do not
have an interrupt flag to clear; they must be accessed directly from the interrupt vector.
Parameters
baseAddress is the base address of the ADC12 A module.
memoryInterruptFlagMask is a bit mask of the interrupt flags status to be returned. Mask
value is the logical OR of any of the following:
ADC12 A IFG0
ADC12 A IFG1
ADC12 A IFG2
ADC12 A IFG3
ADC12 A IFG4
ADC12 A IFG5
ADC12 A IFG6
ADC12 A IFG7
ADC12 A IFG8
ADC12 A IFG9
ADC12 A IFG10
ADC12 A IFG11
ADC12 A IFG12
ADC12 A IFG13
ADC12 A IFG14
ADC12 A IFG15
Returns
The current interrupt flag status for the corresponding mask.
ADC12 A getMemoryAddressForDMA()
uint32 t ADC12 A getMemoryAddressForDMA (
uint16 t baseAddress,
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 61
uint8 t memoryIndex )
Returns the address of the specified memory buffer for the DMA module.
Returns the address of the specified memory buffer. This can be used in conjunction with the
DMA to store the converted data directly to memory.
Parameters
baseAddress is the base address of the ADC12 A module.
memoryIndex is the memory buffer to return the address of. Valid values are:
ADC12 A MEMORY 0 [Default]
ADC12 A MEMORY 1
ADC12 A MEMORY 2
ADC12 A MEMORY 3
ADC12 A MEMORY 4
ADC12 A MEMORY 5
ADC12 A MEMORY 6
ADC12 A MEMORY 7
ADC12 A MEMORY 8
ADC12 A MEMORY 9
ADC12 A MEMORY 10
ADC12 A MEMORY 11
ADC12 A MEMORY 12
ADC12 A MEMORY 13
ADC12 A MEMORY 14
ADC12 A MEMORY 15
Returns
address of the specified memory buffer
ADC12 A getResults()
uint16 t ADC12 A getResults (
uint16 t baseAddress,
uint8 t memoryBufferIndex )
A Signed Integer of the contents of the specified memory buffer.
Returns the raw contents of the specified memory buffer. The format of the content depends on
the read-back format of the data: if the data is in signed 2's complement format then the contents
in the memory buffer will be left-justified with the least-significant bits as 0's, whereas if the data is
in unsigned format then the contents in the memory buffer will be right- justified with the
most-significant bits as 0's.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 62
Parameters
baseAddress is the base address of the ADC12 A module.
memoryBufferIndex is the specified Memory Buffer to read. Valid values
are:
ADC12 A MEMORY 0 [Default]
ADC12 A MEMORY 1
ADC12 A MEMORY 2
ADC12 A MEMORY 3
ADC12 A MEMORY 4
ADC12 A MEMORY 5
ADC12 A MEMORY 6
ADC12 A MEMORY 7
ADC12 A MEMORY 8
ADC12 A MEMORY 9
ADC12 A MEMORY 10
ADC12 A MEMORY 11
ADC12 A MEMORY 12
ADC12 A MEMORY 13
ADC12 A MEMORY 14
ADC12 A MEMORY 15
Returns
A signed integer of the contents of the specified memory buffer
ADC12 A init()
bool ADC12 A init (
uint16 t baseAddress,
uint16 t sampleHoldSignalSourceSelect,
uint8 t clockSourceSelect,
uint16 t clockSourceDivider )
Initializes the ADC12 A Module.
This function initializes the ADC module to allow for analog-to-digital conversions. Specifically this
function sets up the sample-and-hold signal and clock sources for the ADC core to use for
conversions. Upon successful completion of the initialization all of the ADC control registers will be
reset, excluding the memory controls and reference module bits, the given parameters will be set,
and the ADC core will be turned on (Note, that the ADC core only draws power during conversions
and remains off when not converting).Note that sample/hold signal sources are device dependent.
Note that if re-initializing the ADC after starting a conversion with the startConversion() function,
the disableConversion() must be called BEFORE this function can be called.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 63
Parameters
baseAddress is the base address of the ADC12 A module.
sampleHoldSignalSourceSelect is the signal that will trigger a sample-and-hold for an input
signal to be converted. This parameter is device specific and
sources should be found in the device's datasheet. Valid
values are:
ADC12 A SAMPLEHOLDSOURCE SC [Default]
ADC12 A SAMPLEHOLDSOURCE 1
ADC12 A SAMPLEHOLDSOURCE 2
ADC12 A SAMPLEHOLDSOURCE 3 - This parameter
is device specific and sources should be found in the
device's datasheet.
Modified bits are ADC12SHSx of ADC12CTL1 register.
clockSourceSelect selects the clock that will be used by the ADC12 A core, and
the sampling timer if a sampling pulse mode is enabled.
Valid values are:
ADC12 A CLOCKSOURCE ADC12OSC [Default] -
MODOSC 5 MHz oscillator from the UCS
ADC12 A CLOCKSOURCE ACLK - The Auxiliary
Clock
ADC12 A CLOCKSOURCE MCLK - The Master Clock
ADC12 A CLOCKSOURCE SMCLK - The Sub-Master
Clock
Modified bits are ADC12SSELx of ADC12CTL1
register.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 64
Parameters
clockSourceDivider selects the amount that the clock will be divided. Valid
values are:
ADC12 A CLOCKDIVIDER 1 [Default]
ADC12 A CLOCKDIVIDER 2
ADC12 A CLOCKDIVIDER 3
ADC12 A CLOCKDIVIDER 4
ADC12 A CLOCKDIVIDER 5
ADC12 A CLOCKDIVIDER 6
ADC12 A CLOCKDIVIDER 7
ADC12 A CLOCKDIVIDER 8
ADC12 A CLOCKDIVIDER 12
ADC12 A CLOCKDIVIDER 16
ADC12 A CLOCKDIVIDER 20
ADC12 A CLOCKDIVIDER 24
ADC12 A CLOCKDIVIDER 28
ADC12 A CLOCKDIVIDER 32
Modified bits are ADC12PDIV of ADC12CTL2 register;
bits ADC12DIVx of ADC12CTL1 register.
Returns
STATUS SUCCESS or STATUS FAILURE of the initialization process.
ADC12 A isBusy()
uint16 t ADC12 A isBusy (
uint16 t baseAddress )
Returns the busy status of the ADC12 A core.
Returns the status of the ADC core if there is a conversion currently taking place.
Parameters
baseAddress is the base address of the ADC12 A module.
Returns
One of the following:
ADC12 A NOTBUSY
ADC12 A BUSY
indicating if a conversion is taking place
Referenced by ADC12 A disableConversions().
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 65
ADC12 A setDataReadBackFormat()
void ADC12 A setDataReadBackFormat (
uint16 t baseAddress,
uint8 t readBackFormat )
Use to set the read-back format of the converted data.
Sets the format of the converted data: how it will be stored into the memory buffer, and how it
should be read back. The format can be set as right-justified (default), which indicates that the
number will be unsigned, or left-justified, which indicates that the number will be signed in 2's
complement format. This change affects all memory buffers for subsequent conversions.
Parameters
baseAddress is the base address of the ADC12 A module.
readBackFormat is the specified format to store the conversions in the memory buffer. Valid
values are:
ADC12 A UNSIGNED BINARY [Default]
ADC12 A SIGNED 2SCOMPLEMENT
Modified bits are ADC12DF of ADC12CTL2 register.
Returns
None
ADC12 A setReferenceBufferSamplingRate()
void ADC12 A setReferenceBufferSamplingRate (
uint16 t baseAddress,
uint8 t samplingRateSelect )
Use to set the reference buffer's sampling rate.
Sets the reference buffer's sampling rate to the selected sampling rate. The default sampling rate
is maximum of 200-ksps, and can be reduced to a maximum of 50-ksps to conserve power.
Parameters
baseAddress is the base address of the ADC12 A module.
samplingRateSelect is the specified maximum sampling rate. Valid values are:
ADC12 A MAXSAMPLINGRATE 200KSPS [Default]
ADC12 A MAXSAMPLINGRATE 50KSPS
Modified bits are ADC12SR of ADC12CTL2 register.
Returns
None
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 66
ADC12 A setResolution()
void ADC12 A setResolution (
uint16 t baseAddress,
uint8 t resolutionSelect )
Use to change the resolution of the converted data.
This function can be used to change the resolution of the converted data from the default of
12-bits.
Parameters
baseAddress is the base address of the ADC12 A module.
resolutionSelect determines the resolution of the converted data. Valid values
are:
ADC12 A RESOLUTION 8BIT
ADC12 A RESOLUTION 10BIT
ADC12 A RESOLUTION 12BIT [Default]
Modified bits are ADC12RESx of ADC12CTL2 register.
Returns
None
ADC12 A setSampleHoldSignalInversion()
void ADC12 A setSampleHoldSignalInversion (
uint16 t baseAddress,
uint16 t invertedSignal )
Use to invert or un-invert the sample/hold signal.
This function can be used to invert or un-invert the sample/hold signal. Note that if a conversion
has been started with the startConversion() function, then a call to disableConversions() is
required before this function may be called.
Parameters
baseAddress is the base address of the ADC12 A module.
invertedSignal set if the sample/hold signal should be inverted Valid values are:
ADC12 A NONINVERTEDSIGNAL [Default] - a sample-and-hold of an
input signal for conversion will be started on a rising edge of the
sample/hold signal.
ADC12 A INVERTEDSIGNAL - a sample-and-hold of an input signal for
conversion will be started on a falling edge of the sample/hold signal.
Modified bits are ADC12ISSH of ADC12CTL1 register.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 67
Returns
None
ADC12 A setupSamplingTimer()
void ADC12 A setupSamplingTimer (
uint16 t baseAddress,
uint16 t clockCycleHoldCountLowMem,
uint16 tclockCycleHoldCountHighMem,
uint16 t multipleSamplesEnabled )
Sets up and enables the Sampling Timer Pulse Mode.
This function sets up the sampling timer pulse mode which allows the sample/hold signal to trigger
a sampling timer to sample-and-hold an input signal for a specified number of clock cycles without
having to hold the sample/hold signal for the entire period of sampling. Note that if a conversion
has been started with the startConversion() function, then a call to disableConversions() is
required before this function may be called.
Parameters
baseAddress is the base address of the ADC12 A module.
clockCycleHoldCountLowMem sets the amount of clock cycles to sample- and-hold for the
higher memory buffers 0-7. Valid values are:
ADC12 A CYCLEHOLD 4 CYCLES [Default]
ADC12 A CYCLEHOLD 8 CYCLES
ADC12 A CYCLEHOLD 16 CYCLES
ADC12 A CYCLEHOLD 32 CYCLES
ADC12 A CYCLEHOLD 64 CYCLES
ADC12 A CYCLEHOLD 96 CYCLES
ADC12 A CYCLEHOLD 128 CYCLES
ADC12 A CYCLEHOLD 192 CYCLES
ADC12 A CYCLEHOLD 256 CYCLES
ADC12 A CYCLEHOLD 384 CYCLES
ADC12 A CYCLEHOLD 512 CYCLES
ADC12 A CYCLEHOLD 768 CYCLES
ADC12 A CYCLEHOLD 1024 CYCLES
Modified bits are ADC12SHT0x of ADC12CTL0 register.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 68
Parameters
clockCycleHoldCountHighMem sets the amount of clock cycles to sample-and-hold for the
higher memory buffers 8-15. Valid values are:
ADC12 A CYCLEHOLD 4 CYCLES [Default]
ADC12 A CYCLEHOLD 8 CYCLES
ADC12 A CYCLEHOLD 16 CYCLES
ADC12 A CYCLEHOLD 32 CYCLES
ADC12 A CYCLEHOLD 64 CYCLES
ADC12 A CYCLEHOLD 96 CYCLES
ADC12 A CYCLEHOLD 128 CYCLES
ADC12 A CYCLEHOLD 192 CYCLES
ADC12 A CYCLEHOLD 256 CYCLES
ADC12 A CYCLEHOLD 384 CYCLES
ADC12 A CYCLEHOLD 512 CYCLES
ADC12 A CYCLEHOLD 768 CYCLES
ADC12 A CYCLEHOLD 1024 CYCLES
Modified bits are ADC12SHT1x of ADC12CTL0 register.
multipleSamplesEnabled allows multiple conversions to start without a trigger signal
from the sample/hold signal Valid values are:
ADC12 A MULTIPLESAMPLESDISABLE [Default] - a
timer trigger will be needed to start every ADC
conversion.
ADC12 A MULTIPLESAMPLESENABLE - during a
sequenced and/or repeated conversion mode, after the
first conversion, no sample/hold signal is necessary to
start subsequent sample/hold and convert processes.
Modified bits are ADC12MSC of ADC12CTL0 register.
Returns
None
ADC12 A startConversion()
void ADC12 A startConversion (
uint16 t baseAddress,
uint16 t startingMemoryBufferIndex,
uint8 t conversionSequenceModeSelect )
Enables/Starts an Analog-to-Digital Conversion.
This function enables/starts the conversion process of the ADC. If the sample/hold signal source
chosen during initialization was ADC12OSC, then the conversion is started immediately, otherwise
the chosen sample/hold signal source starts the conversion by a rising edge of the signal. Keep in
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 69
mind when selecting conversion modes, that for sequenced and/or repeated modes, to keep the
sample/hold-and-convert process continuing without a trigger from the sample/hold signal source,
the multiple samples must be enabled using the ADC12 A setupSamplingTimer() function. Note
that after this function is called, the ADC12 A disableConversions() has to be called to re-initialize
the ADC, reconfigure a memory buffer control, enable/disable the sampling timer, or to change the
internal reference voltage.
Parameters
baseAddress is the base address of the ADC12 A module.
startingMemoryBufferIndex is the memory buffer that will hold the first or only
conversion. Valid values are:
ADC12 A MEMORY 0 [Default]
ADC12 A MEMORY 1
ADC12 A MEMORY 2
ADC12 A MEMORY 3
ADC12 A MEMORY 4
ADC12 A MEMORY 5
ADC12 A MEMORY 6
ADC12 A MEMORY 7
ADC12 A MEMORY 8
ADC12 A MEMORY 9
ADC12 A MEMORY 10
ADC12 A MEMORY 11
ADC12 A MEMORY 12
ADC12 A MEMORY 13
ADC12 A MEMORY 14
ADC12 A MEMORY 15
Modified bits are ADC12STARTADDx of ADC12CTL1
register.
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 70
Parameters
conversionSequenceModeSelect determines the ADC operating mode. Valid values are:
ADC12 A SINGLECHANNEL [Default] - one-time
conversion of a single channel into a single memory
buffer.
ADC12 A SEQOFCHANNELS - one time conversion
of multiple channels into the specified starting memory
buffer and each subsequent memory buffer up until the
conversion is stored in a memory buffer dedicated as
the end-of-sequence by the memory's control register.
ADC12 A REPEATED SINGLECHANNEL - repeated
conversions of one channel into a single memory
buffer.
ADC12 A REPEATED SEQOFCHANNELS -
repeated conversions of multiple channels into the
specified starting memory buffer and each subsequent
memory buffer up until the conversion is stored in a
memory buffer dedicated as the end-of-sequence by
the memory's control register.
Modified bits are ADC12CONSEQx of ADC12CTL1
register.
Modified bits of ADC12CTL1 register and bits of ADC12CTL0 register.
Returns
None
8.3 Programming Example
The following example shows how to initialize and use the ADC12 API to start a single channel,
single conversion.
// Initialize ADC12 with ADC12’s built-in oscillator
ADC12 A init (ADC12 A BASE,
ADC12 A SAMPLEHOLDSOURCE SC,
ADC12 A CLOCKSOURCE ADC12OSC,
ADC12 A CLOCKDIVIDEBY 1);
//Switch ON ADC12
ADC12 A enable(ADC12 A BASE);
// Setup sampling timer to sample-and-hold for 16 clock cycles
ADC12 A setupSamplingTimer (ADC12 A BASE,
ADC12 A CYCLEHOLD 64 CYCLES,
ADC12 A CYCLEHOLD 4 CYCLES,
FALSE);
// Configure the Input to the Memory Buffer with the specified Reference Voltages
ADC12 A configureMemoryParam param = {0};
param.memoryBufferControlIndex = ADC12 A MEMORY 0;
param.inputSourceSelect = ADC12 A INPUT A0;
param.positiveRefVoltageSourceSelect = ADC12 A VREFPOS AVCC;
param.negativeRefVoltageSourceSelect = ADC12 A VREFNEG AVSS;
CHAPTER 8. 12-BIT ANALOG-TO-DIGITAL CONVERTER (ADC12 A) 71
param.endOfSequence = ADC12 A NOTENDOFSEQUENCE;
ADC12 A configureMemory(ADC12 A BASE ,&param);
while (1)
{
// Start a single conversion, no repeating or sequences.
ADC12 A startConversion (ADC12 A BASE,
ADC12 A MEMORY 0,
ADC12 A SINGLECHANNEL);
// Wait for the Interrupt Flag to assert
while( !(ADC12 A getInterruptStatus(ADC12 A BASE,ADC12IFG0)) );
// Clear the Interrupt Flag and start another conversion
ADC12 A clearInterrupt(ADC12 A BASE,ADC12IFG0);
}
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 72
9 Advanced Encryption Standard (AES)
Introduction ..............................................................................................72
API Functions ............................................................................................72
Programming Example ...................................................................................82
9.1 Introduction
The AES accelerator module performs encryption and decryption of 128-bit data with 128-bit keys
according to the advanced encryption standard (AES) (FIPS PUB 197) in hardware. The AES
accelerator features are:
Encryption and decryption according to AES FIPS PUB 197 with 128-bit key
On-the-fly key expansion for encryption and decryption
Off-line key generation for decryption
Byte and word access to key, input, and output data
AES ready interrupt flag The AES256 accelerator module performs encryption and
decryption of 128-bit data with 128-/192-/256-bit keys according to the advanced encryption
standard (AES) (FIPS PUB 197) in hardware. The AES accelerator features are: AES
encryption 128 bit - 168 cycles 192 bit - 204 cycles 256 bit - 234 cycles AES decryption
128 bit - 168 cycles 192 bit - 206 cycles 256 bit - 234 cycles
On-the-fly key expansion for encryption and decryption
Offline key generation for decryption
Shadow register storing the initial key for all key lengths
Byte and word access to key, input data, and output data
AES ready interrupt flag
9.2 API Functions
Functions
uint8 t AES setCipherKey (uint16 t baseAddress, const uint8 t CipherKey)
Loads a 128 bit cipher key to AES module.
uint8 t AES encryptData (uint16 t baseAddress, const uint8 t Data, uint8 t encryptedData)
Encrypts a block of data using the AES module.
uint8 t AES decryptData (uint16 t baseAddress, const uint8 t Data, uint8 t decryptedData)
Decrypts a block of data using the AES module.
uint8 t AES setDecipherKey (uint16 t baseAddress, const uint8 t CipherKey)
Sets the decipher key The API.
void AES clearInterrupt (uint16 t baseAddress)
Clears the AES ready interrupt flag.
uint32 t AES getInterruptStatus (uint16 t baseAddress)
Gets the AES ready interrupt flag status.
void AES enableInterrupt (uint16 t baseAddress)
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 73
Enables AES ready interrupt.
void AES disableInterrupt (uint16 t baseAddress)
Disables AES ready interrupt.
void AES reset (uint16 t baseAddress)
Resets AES Module immediately.
uint8 t AES startEncryptData (uint16 t baseAddress, const uint8 t Data, uint8 t
encryptedData)
Starts an encryption process on the AES module.
uint8 t AES startDecryptData (uint16 t baseAddress, const uint8 t Data)
Decrypts a block of data using the AES module.
uint8 t AES startSetDecipherKey (uint16 t baseAddress, const uint8 t CipherKey)
Loads the decipher key.
uint8 t AES getDataOut (uint16 t baseAddress, uint8 t OutputData)
Reads back the output data from AES module.
uint8 t AES isBusy (uint16 t baseAddress)
Gets the AES module busy status.
void AES clearErrorFlag (uint16 t baseAddress)
Clears the AES error flag.
uint32 t AES getErrorFlagStatus (uint16 t baseAddress)
Gets the AES error flag status.
uint8 t AES startDecryptDataUsingEncryptionKey (uint16 t baseAddress, const uint8 t
Data)
DEPRECATED Starts an decryption process on the AES module.
uint8 t AES decryptDataUsingEncryptionKey (uint16 t baseAddress, const uint8 t Data,
uint8 t decryptedData)
DEPRECATED Decrypts a block of data using the AES module.
9.2.1 Detailed Description
The AES module APIs are
AES setCipherKey()
AES encryptData()
AES decryptDataUsingEncryptionKey()
AES setDecipherKey()
AES decryptData()
AES reset()
AES startEncryptData()
AES startDecryptDataUsingEncryptionKey()
AES startDecryptData()
AES startSetDecipherKey()
AES getDataOut()
The AES interrupt handler functions
AES enableInterrupt()
AES disableInterrupt()
AES clearInterrupt()
AES getInterruptStatus
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 74
9.2.2 Function Documentation
AES clearErrorFlag()
void AES clearErrorFlag (
uint16 t baseAddress )
Clears the AES error flag.
Clears the AES error flag that results from a key or data being written while the AES module is
busy. Modified bit is AESERRFG of AESACTL0 register.
Parameters
baseAddress is the base address of the AES module.
Modified bits are AESERRFG of AESACTL0 register.
Returns
None
AES clearInterrupt()
void AES clearInterrupt (
uint16 t baseAddress )
Clears the AES ready interrupt flag.
This function clears the AES ready interrupt flag. This flag is automatically cleared when
AESADOUT is read, or when AESAKEY or AESADIN is written. This function should be used
when the flag needs to be reset and it has not been automatically cleared by one of the previous
actions.
Parameters
baseAddress is the base address of the AES module.
Modified bits are AESRDYIFG of AESACTL0 register.
Returns
None
AES decryptData()
uint8 t AES decryptData (
uint16 t baseAddress,
const uint8 t Data,
uint8 t decryptedData )
Decrypts a block of data using the AES module.
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 75
This function requires a pre-generated decryption key. A key can be loaded and pre-generated by
using function AES startSetDecipherKey() or AES setDecipherKey(). The decryption takes 167
MCLK.
Parameters
baseAddress is the base address of the AES module.
Data is a pointer to an uint8 t array with a length of 16 bytes that contains
encrypted data to be decrypted.
decryptedData is a pointer to an uint8 t array with a length of 16 bytes in that the decrypted
data will be written.
Returns
STATUS SUCCESS
AES decryptDataUsingEncryptionKey()
uint8 t AES decryptDataUsingEncryptionKey (
uint16 t baseAddress,
const uint8 t Data,
uint8 t decryptedData )
DEPRECATED Decrypts a block of data using the AES module.
This function can be used to decrypt data by using the same key as used for a previous performed
encryption. The decryption takes 214 MCLK.
Parameters
baseAddress is the base address of the AES module.
Data is a pointer to an uint8 t array with a length of 16 bytes that contains
encrypted data to be decrypted.
decryptedData is a pointer to an uint8 t array with a length of 16 bytes in that the decrypted
data will be written.
Returns
STATUS SUCCESS
AES disableInterrupt()
void AES disableInterrupt (
uint16 t baseAddress )
Disables AES ready interrupt.
Disables AES ready interrupt. This interrupt is reset by a PUC, but not reset by AES reset.
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 76
Parameters
baseAddress is the base address of the AES module.
Modified bits are AESRDYIE of AESACTL0 register.
Returns
None
AES enableInterrupt()
void AES enableInterrupt (
uint16 t baseAddress )
Enables AES ready interrupt.
Enables AES ready interrupt. This interrupt is reset by a PUC, but not reset by AES reset. Does
not clear interrupt flags.
Parameters
baseAddress is the base address of the AES module.
Modified bits are AESRDYIE of AESACTL0 register.
Returns
None
AES encryptData()
uint8 t AES encryptData (
uint16 t baseAddress,
const uint8 t Data,
uint8 t encryptedData )
Encrypts a block of data using the AES module.
The cipher key that is used for encryption should be loaded in advance by using function
AES setCipherKey()
Parameters
baseAddress is the base address of the AES module.
Data is a pointer to an uint8 t array with a length of 16 bytes that contains data to
be encrypted.
encryptedData is a pointer to an uint8 t array with a length of 16 bytes in that the encrypted
data will be written.
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 77
Returns
STATUS SUCCESS
AES getDataOut()
uint8 t AES getDataOut (
uint16 t baseAddress,
uint8 t OutputData )
Reads back the output data from AES module.
This function is meant to use after an encryption or decryption process that was started and
finished by initiating an interrupt by use of the AES startEncryptData() or
AES startDecryptData() functions.
Parameters
baseAddress is the base address of the AES module.
OutputData is a pointer to an uint8 t array with a length of 16 bytes in which the output data
of the AES module is available. If AES module is busy returns NULL.
Returns
STATUS SUCCESS if AES is not busy, STATUS FAIL if it is busy
AES getErrorFlagStatus()
uint32 t AES getErrorFlagStatus (
uint16 t baseAddress )
Gets the AES error flag status.
Checks the AES error flag that results from a key or data being written while the AES module is
busy. If the flag is set, it needs to be cleared using AES clearErrorFlag.
Parameters
baseAddress is the base address of the AES module.
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 78
Returns
One of the following:
AES ERROR OCCURRED
AES NO ERROR
indicating if AESAKEY or AESADIN were written while an AES operation was in
progress
AES getInterruptStatus()
uint32 t AES getInterruptStatus (
uint16 t baseAddress )
Gets the AES ready interrupt flag status.
This function checks the AES ready interrupt flag. This flag is automatically cleared when
AESADOUT is read, or when AESAKEY or AESADIN is written. This function can be used to
confirm that this has been done.
Parameters
baseAddress is the base address of the AES module.
Returns
uint32 t - AES READY INTERRUPT or 0x00.
AES isBusy()
uint8 t AES isBusy (
uint16 t baseAddress )
Gets the AES module busy status.
Gets the AES module busy status. If a key or data are written while the AES module is busy, an
error flag will be thrown.
Parameters
baseAddress is the base address of the AES module.
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 79
Returns
One of the following:
AES BUSY
AES NOT BUSY
indicating if encryption/decryption/key generation is taking place
AES reset()
void AES reset (
uint16 t baseAddress )
Resets AES Module immediately.
This function performs a software reset on the AES Module, note that this does not affect the AES
ready interrupt.
Parameters
baseAddress is the base address of the AES module.
Modified bits are AESSWRST of AESACTL0 register.
Returns
None
AES setCipherKey()
uint8 t AES setCipherKey (
uint16 t baseAddress,
const uint8 t CipherKey )
Loads a 128 bit cipher key to AES module.
This function loads a 128 bit cipher key to AES module.
Parameters
baseAddress is the base address of the AES module.
CipherKey is a pointer to an uint8 t array with a length of 16 bytes that contains a 128 bit
cipher key.
Returns
STATUS SUCCESS
AES setDecipherKey()
uint8 t AES setDecipherKey (
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 80
uint16 t baseAddress,
const uint8 t CipherKey )
Sets the decipher key The API.
The API AES startSetDecipherKey() or AES setDecipherKey() must be invoked before invoking
AES setDecipherKey().
Parameters
baseAddress is the base address of the AES module.
CipherKey is a pointer to an uint8 t array with a length of 16 bytes that contains the initial
AES key.
Returns
STATUS SUCCESS
AES startDecryptData()
uint8 t AES startDecryptData (
uint16 t baseAddress,
const uint8 t Data )
Decrypts a block of data using the AES module.
This is the non-blocking equivalent of AES decryptData(). This function requires a pre-generated
decryption key. A key can be loaded and pre- generated by using function AES setDecipherKey()
or AES startSetDecipherKey(). The decryption takes 167 MCLK. It is recommended to use
interrupt to check for procedure completion then using AES getDataOut() API to retrieve the
decrypted data.
Parameters
baseAddress is the base address of the AES module.
Data is a pointer to an uint8 t array with a length of 16 bytes that contains encrypted
data to be decrypted.
Returns
STATUS SUCCESS
AES startDecryptDataUsingEncryptionKey()
uint8 t AES startDecryptDataUsingEncryptionKey (
uint16 t baseAddress,
const uint8 t Data )
DEPRECATED Starts an decryption process on the AES module.
This is the non-blocking equivalent of AES decryptDataUsingEncryptionKey(). This function can
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 81
be used to decrypt data by using the same key as used for a previous performed encryption. The
decryption takes 214 MCLK.
Parameters
baseAddress is the base address of the AES module.
Data is a pointer to an uint8 t array with a length of 16 bytes that contains encrypted
data to be decrypted.
Returns
STATUS SUCCESS
AES startEncryptData()
uint8 t AES startEncryptData (
uint16 t baseAddress,
const uint8 t Data,
uint8 t encryptedData )
Starts an encryption process on the AES module.
This is the non-blocking equivalent of AES encryptData(). The cipher key that is used for
decryption should be loaded in advance by using function AES setCipherKey(). It is
recommended to use interrupt to check for procedure completion then using AES getDataOut()
API to retrieve the encrypted data.
Parameters
baseAddress is the base address of the AES module.
Data is a pointer to an uint8 t array with a length of 16 bytes that contains data to
be encrypted.
encryptedData is a pointer to an uint8 t array with a length of 16 bytes in that the encrypted
data will be written.
Returns
STATUS SUCCESS
AES startSetDecipherKey()
uint8 t AES startSetDecipherKey (
uint16 t baseAddress,
const uint8 t CipherKey )
Loads the decipher key.
This is the non-blocking equivalent of AES setDecipherKey(). The API
AES startSetDecipherKey() or AES setDecipherKey() must be invoked before invoking
AES startSetDecipherKey().
CHAPTER 9. ADVANCED ENCRYPTION STANDARD (AES) 82
Parameters
baseAddress is the base address of the AES module.
CipherKey is a pointer to an uint8 t array with a length of 16 bytes that contains the initial
AES key.
Returns
STATUS SUCCESS
9.3 Programming Example
The following example shows some AES operations using the APIs
unsigned char Data[16] = {0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F };
unsigned char CipherKey[16] = {0xAA, 0xBB, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F };
unsigned char DataAES[16]; // Encrypted data
unsigned char DataunAES[16]; // Decrypted data
// Load a cipher key to module
AES setCipherKey(AES BASE, CipherKey);
// Encrypt data with preloaded cipher key
AES encryptData(AES BASE, Data, DataAES);
// Decrypt data with keys that were generated during encryption - takes 214 MCLK
// This function will generate all round keys needed for decryption first and then
// the encryption process starts
AES decryptDataUsingEncryptionKey(AES BASE, DataAES, DataunAES);
CHAPTER 10. BATTERY BACKUP SYSTEM 83
10 Battery Backup System
Introduction ..............................................................................................83
API Functions ............................................................................................83
10.1 Introduction
The Battery Backup System (BATBCK) API provides a set of functions for using the MSP430Ware
BATBCK modules. Functions are provided to handle the backup Battery sub-system, initialize and
enable the backup Battery charger, and control access to and from the backup RAM space.
The BATBCK module offers no interrupt, and is used only to control the Battery backup
sub-system, Battery charger, and backup RAM space.
10.2 API Functions
The BATBCK API is divided into three groups: one that handles the Battery backup sub-system,
one that controls the charger, and one that controls access to and from the backup RAM space.
The BATBCK sub-system controls are handled by
BattBak unlockBackupSubSystem()
BattBak enableBackupSupplyToADC()
BattBak disableBackupSupplyToADC()
BattBak switchToBackupSupplyManually()
BattBak disable()
The BATBCK charger is controlled by
BattBak initAndEnableCharger()
BattBak disableCharger()
The backup RAM space is accessed by
BattBak setBackupRAMData()
BattBak getBackupRAMData()
CHAPTER 11. COMPARATOR (COMP B) 84
11 Comparator (COMP B)
Introduction ..............................................................................................84
API Functions ............................................................................................84
Programming Example ...................................................................................95
11.1 Introduction
The Comparator B (COMP B) API provides a set of functions for using the MSP430Ware COMP B
modules. Functions are provided to initialize the COMP B modules, setup reference voltages for
input, and manage interrupts for the COMP B modules.
The COMP B module provides the ability to compare two analog signals and use the output in
software and on an output pin. The output represents whether the signal on the positive terminal is
higher than the signal on the negative terminal. The COMP B may be used to generate a
hysteresis. There are 16 different inputs that can be used, as well as the ability to short 2 input
together. The COMP B module also has control over the REF module to generate a reference
voltage as an input.
The COMP B module can generate multiple interrupts. An interrupt may be asserted for the
output, with separate interrupts on whether the output rises, or falls.
11.2 API Functions
Functions
bool Comp B init (uint16 t baseAddress, Comp B initParam param)
Initializes the Comp B Module.
void Comp B configureReferenceVoltage (uint16 t baseAddress,
Comp B configureReferenceVoltageParam param)
Generates a Reference Voltage to the terminal selected during initialization.
void Comp B enableInterrupt (uint16 t baseAddress, uint16 t interruptMask)
Enables selected Comp B interrupt sources.
void Comp B disableInterrupt (uint16 t baseAddress, uint16 t interruptMask)
Disables selected Comp B interrupt sources.
void Comp B clearInterrupt (uint16 t baseAddress, uint16 t interruptFlagMask)
Clears Comp B interrupt flags.
uint8 t Comp B getInterruptStatus (uint16 t baseAddress, uint16 t interruptFlagMask)
Gets the current Comp B interrupt status.
void Comp B setInterruptEdgeDirection (uint16 t baseAddress, uint16 t edgeDirection)
Explicitly sets the edge direction that would trigger an interrupt.
void Comp B toggleInterruptEdgeDirection (uint16 t baseAddress)
Toggles the edge direction that would trigger an interrupt.
void Comp B enable (uint16 t baseAddress)
Turns on the Comp B module.
void Comp B disable (uint16 t baseAddress)
Turns off the Comp B module.
void Comp B shortInputs (uint16 t baseAddress)
CHAPTER 11. COMPARATOR (COMP B) 85
Shorts the two input pins chosen during initialization.
void Comp B unshortInputs (uint16 t baseAddress)
Disables the short of the two input pins chosen during initialization.
void Comp B disableInputBuffer (uint16 t baseAddress, uint8 t inputPort)
Disables the input buffer of the selected input port to effectively allow for analog signals.
void Comp B enableInputBuffer (uint16 t baseAddress, uint8 t inputPort)
Enables the input buffer of the selected input port to allow for digital signals.
void Comp B swapIO (uint16 t baseAddress)
Toggles the bit that swaps which terminals the inputs go to, while also inverting the output of the
Comp B.
uint16 t Comp B outputValue (uint16 t baseAddress)
Returns the output value of the Comp B module.
void Comp B selectReferenceVoltage (uint16 t baseAddress, uint16 t selectType, uint16 t
selectVRef)
Modifies how comparator output selects between VREF0 or VREF1.
11.2.1 Detailed Description
The COMP B API is broken into three groups of functions: those that deal with initialization and
output, those that handle interrupts, and those that handle auxiliary features of the COMP B.
The COMP B initialization and output functions are
Comp B init()
Comp B configureReferenceVoltage()
Comp B selectReferenceVoltage()
Comp B enable()
Comp B disable()
Comp B outputValue()
The COMP B interrupts are handled by
Comp B enableInterrupt()
Comp B disableInterrupt()
Comp B clearInterrupt()
Comp B getInterruptStatus()
Comp B setInterruptEdgeDirection()
Comp B toggleInterruptEdgeDirection()
Auxiliary features of the COMP B are handled by
Comp B shortInputs()
Comp B unshortInputs()
Comp B disableInputBuffer()
Comp B enableInputBuffer()
Comp B swapIO()
CHAPTER 11. COMPARATOR (COMP B) 86
11.2.2 Function Documentation
Comp B clearInterrupt()
void Comp B clearInterrupt (
uint16 t baseAddress,
uint16 t interruptFlagMask )
Clears Comp B interrupt flags.
The Comp B interrupt source is cleared, so that it no longer asserts. The highest interrupt flag is
automatically cleared when an interrupt vector generator is used.
Parameters
baseAddress is the base address of the COMP B module.
interruptFlagMask is a bit mask of the interrupt sources to be cleared. Mask value is the
logical OR of any of the following:
COMP B OUTPUT FLAG - Output interrupt
COMP B OUTPUTINVERTED FLAG - Output interrupt inverted
polarity
Modified bits of CBINT register.
Returns
None
Comp B configureReferenceVoltage()
void Comp B configureReferenceVoltage (
uint16 t baseAddress,
Comp B configureReferenceVoltageParam param )
Generates a Reference Voltage to the terminal selected during initialization.
Use this function to generate a voltage to serve as a reference to the terminal selected at
initialization. The voltage is determined by the equation: Vbase (Numerator / 32). If the upper
and lower limit voltage numerators are equal, then a static reference is defined, whereas they are
different then a hysteresis effect is generated.
Parameters
baseAddress is the base address of the COMP B module.
param is the pointer to struct for reference voltage configuration.
CHAPTER 11. COMPARATOR (COMP B) 87
Returns
None
References Comp B configureReferenceVoltageParam::lowerLimitSupplyVoltageFractionOf32,
Comp B configureReferenceVoltageParam::referenceAccuracy,
Comp B configureReferenceVoltageParam::supplyVoltageReferenceBase, and
Comp B configureReferenceVoltageParam::upperLimitSupplyVoltageFractionOf32.
Comp B disable()
void Comp B disable (
uint16 t baseAddress )
Turns off the Comp B module.
This function clears the CBON bit disabling the operation of the Comp B module, saving from
excess power consumption.
Parameters
baseAddress is the base address of the COMP B module.
Returns
None
Comp B disableInputBuffer()
void Comp B disableInputBuffer (
uint16 t baseAddress,
uint8 t inputPort )
Disables the input buffer of the selected input port to effectively allow for analog signals.
This function sets the bit to disable the buffer for the specified input port to allow for analog signals
from any of the Comp B input pins. This bit is automatically set when the input is initialized to be
used with the Comp B module. This function should be used whenever an analog input is
connected to one of these pins to prevent parasitic voltage from causing unexpected results.
Parameters
baseAddress is the base address of the COMP B module.
CHAPTER 11. COMPARATOR (COMP B) 88
Parameters
inputPort is the port in which the input buffer will be disabled. Valid values are:
COMP B INPUT0 [Default]
COMP B INPUT1
COMP B INPUT2
COMP B INPUT3
COMP B INPUT4
COMP B INPUT5
COMP B INPUT6
COMP B INPUT7
COMP B INPUT8
COMP B INPUT9
COMP B INPUT10
COMP B INPUT11
COMP B INPUT12
COMP B INPUT13
COMP B INPUT14
COMP B INPUT15
COMP B VREF
Modified bits are CBPDx of CBCTL3 register.
Returns
None
Comp B disableInterrupt()
void Comp B disableInterrupt (
uint16 t baseAddress,
uint16 t interruptMask )
Disables selected Comp B interrupt sources.
Disables the indicated Comp B interrupt sources. Only the sources that are enabled can be
reflected to the processor interrupt; disabled sources have no effect on the processor.
Parameters
baseAddress is the base address of the COMP B module.
interruptMask is the bit mask of the interrupt sources to be disabled. Mask value is the logical
OR of any of the following:
COMP B OUTPUT INT - Output interrupt
COMP B OUTPUTINVERTED INT - Output interrupt inverted polarity
Modified bits of CBINT register.
CHAPTER 11. COMPARATOR (COMP B) 89
Returns
None
Comp B enable()
void Comp B enable (
uint16 t baseAddress )
Turns on the Comp B module.
This function sets the bit that enables the operation of the Comp B module.
Parameters
baseAddress is the base address of the COMP B module.
Returns
None
Comp B enableInputBuffer()
void Comp B enableInputBuffer (
uint16 t baseAddress,
uint8 t inputPort )
Enables the input buffer of the selected input port to allow for digital signals.
This function clears the bit to enable the buffer for the specified input port to allow for digital
signals from any of the Comp B input pins. This should not be reset if there is an analog signal
connected to the specified input pin to prevent from unexpected results.
Parameters
baseAddress is the base address of the COMP B module.
CHAPTER 11. COMPARATOR (COMP B) 90
Parameters
inputPort is the port in which the input buffer will be enabled. Valid values are:
COMP B INPUT0 [Default]
COMP B INPUT1
COMP B INPUT2
COMP B INPUT3
COMP B INPUT4
COMP B INPUT5
COMP B INPUT6
COMP B INPUT7
COMP B INPUT8
COMP B INPUT9
COMP B INPUT10
COMP B INPUT11
COMP B INPUT12
COMP B INPUT13
COMP B INPUT14
COMP B INPUT15
COMP B VREF
Modified bits are CBPDx of CBCTL3 register.
Returns
None
Comp B enableInterrupt()
void Comp B enableInterrupt (
uint16 t baseAddress,
uint16 t interruptMask )
Enables selected Comp B interrupt sources.
Enables the indicated Comp B interrupt sources. Only the sources that are enabled can be
reflected to the processor interrupt; disabled sources have no effect on the processor. Does not
clear interrupt flags.
Parameters
baseAddress is the base address of the COMP B module.
CHAPTER 11. COMPARATOR (COMP B) 91
Parameters
interruptMask is the bit mask of the interrupt sources to be enabled. Mask value is the logical
OR of any of the following:
COMP B OUTPUT INT - Output interrupt
COMP B OUTPUTINVERTED INT - Output interrupt inverted polarity
Modified bits of CBINT register.
Returns
None
Comp B getInterruptStatus()
uint8 t Comp B getInterruptStatus (
uint16 t baseAddress,
uint16 t interruptFlagMask )
Gets the current Comp B interrupt status.
This returns the interrupt status for the Comp B module based on which flag is passed.
Parameters
baseAddress is the base address of the COMP B module.
interruptFlagMask is the masked interrupt flag status to be returned. Mask value is the logical
OR of any of the following:
COMP B OUTPUT FLAG - Output interrupt
COMP B OUTPUTINVERTED FLAG - Output interrupt inverted
polarity
Returns
Logical OR of any of the following:
COMP B OUTPUT FLAG Output interrupt
COMP B OUTPUTINVERTED FLAG Output interrupt inverted polarity
indicating the status of the masked interrupts
Comp B init()
bool Comp B init (
uint16 t baseAddress,
Comp B initParam param )
Initializes the Comp B Module.
Upon successful initialization of the Comp B module, this function will have reset all necessary
register bits and set the given options in the registers. To actually use the Comp B module, the
CHAPTER 11. COMPARATOR (COMP B) 92
Comp B enable() function must be explicitly called before use. If a Reference Voltage is set to a
terminal, the Voltage should be set using the Comp B setReferenceVoltage() function.
Parameters
baseAddress is the base address of the COMP B module.
param is the pointer to struct for initialization.
Returns
STATUS SUCCESS or STATUS FAILURE of the initialization process.
References Comp B initParam::invertedOutputPolarity, Comp B initParam::negativeTerminalInput,
Comp B initParam::outputFilterEnableAndDelayLevel, Comp B initParam::positiveTerminalInput,
and Comp B initParam::powerModeSelect.
Comp B outputValue()
uint16 t Comp B outputValue (
uint16 t baseAddress )
Returns the output value of the Comp B module.
Returns the output value of the Comp B module.
Parameters
baseAddress is the base address of the COMP B module.
Returns
One of the following:
COMP B LOW
COMP B HIGH
indicating the output value of the Comp B module
Comp B selectReferenceVoltage()
void Comp B selectReferenceVoltage (
uint16 t baseAddress,
uint16 t selectType,
uint16 t selectVRef )
Modifies how comparator output selects between VREF0 or VREF1.
Only applicable in certain Comp B reference sources. Consult
Comp B configureReferenceVoltage for details. If COMP B VREF AUTO SELECT, then
comparator output state chooses between VREF0 and VREF1. If
COMP B VREF MANUAL SELECT, then selectVRef param chooses.
CHAPTER 11. COMPARATOR (COMP B) 93
Parameters
baseAddress is the base address of the COMP B module.
selectType determines whether VREF instance is chosen automatically or manually Valid
values are:
COMP B VREF AUTO SELECT [Default] - VREF instance is chosen by
comparator output state.
COMP B VREF MANUAL SELECT - VREF instance is chosen by user
(CBCTL1. CBMRVL bit)
Modified bits are CBMRVS of CBCTL1 register.
selectVRef selects VREF0 or VREF1. Only applicable if VREF instance is set up to be
chosen manually Valid values are:
COMP B SELECT VREF0 [Default]
COMP B SELECT VREF1
Modified bits are CBMRVL of CBCTL1 register.
Comp B setInterruptEdgeDirection()
void Comp B setInterruptEdgeDirection (
uint16 t baseAddress,
uint16 t edgeDirection )
Explicitly sets the edge direction that would trigger an interrupt.
This function will set which direction the output will have to go, whether rising or falling, to generate
an interrupt based on a non-inverted interrupt.
Parameters
baseAddress is the base address of the COMP B module.
edgeDirection determines which direction the edge would have to go to generate an interrupt
based on the non-inverted interrupt flag. Valid values are:
COMP B RISINGEDGE [Default] - sets the bit to generate an interrupt
when the output of the Comp B falls from LOW to HIGH if the normal
interrupt bit is set(and HIGH to LOW if the inverted interrupt enable bit is
set).
COMP B FALLINGEDGE - sets the bit to generate an interrupt when the
output of the Comp B rises from HIGH to LOW if the normal interrupt bit
is set(and LOW to HIGH if the inverted interrupt enable bit is set).
Modified bits are CBIES of CBCTL1 register.
CHAPTER 11. COMPARATOR (COMP B) 94
Returns
None
Comp B shortInputs()
void Comp B shortInputs (
uint16 t baseAddress )
Shorts the two input pins chosen during initialization.
This function sets the bit that shorts the devices attached to the input pins chosen from the
initialization of the Comp B.
Parameters
baseAddress is the base address of the COMP B module.
Returns
None
Comp B swapIO()
void Comp B swapIO (
uint16 t baseAddress )
Toggles the bit that swaps which terminals the inputs go to, while also inverting the output of the
Comp B.
This function toggles the bit that controls which input goes to which terminal. After initialization,
this bit is set to 0, after toggling it once the inputs are routed to the opposite terminal and the
output is inverted.
Parameters
baseAddress is the base address of the COMP B module.
Returns
None
Comp B toggleInterruptEdgeDirection()
void Comp B toggleInterruptEdgeDirection (
uint16 t baseAddress )
Toggles the edge direction that would trigger an interrupt.
This function will toggle which direction the output will have to go, whether rising or falling, to
generate an interrupt based on a non-inverted interrupt. If the direction was rising, it is now falling,
CHAPTER 11. COMPARATOR (COMP B) 95
if it was falling, it is now rising.
Parameters
baseAddress is the base address of the COMP B module.
Returns
None
Comp B unshortInputs()
void Comp B unshortInputs (
uint16 t baseAddress )
Disables the short of the two input pins chosen during initialization.
This function clears the bit that shorts the devices attached to the input pins chosen from the
initialization of the Comp B.
Parameters
baseAddress is the base address of the COMP B module.
Returns
None
11.3 Programming Example
The following example shows how to initialize and use the COMP B API to turn on an LED when
the input to the positive terminal is higher than the input to the negative terminal.
// Initialize the Comparator B module
/*Base Address of Comparator B,
Pin CB0 to Positive(+) Terminal,
Reference Voltage to Negative(-) Terminal,
Normal Power Mode,
Output Filter On with minimal delay,
Non-Inverted Output Polarity
*/
Comp B initParam param = {0};
param.positiveTerminalInput = COMP B INPUT0;
param.negativeTerminalInput = COMP B VREF;
param.powerModeSelect = COMP B POWERMODE NORMALMODE;
param.outputFilterEnableAndDelayLevel = COMP B FILTEROUTPUT DLYLVL1;
param.invertedOutputPolarity = COMP B NORMALOUTPUTPOLARITY;
Comp B init(COMP B BASE, &param);
// Set the reference voltage that is being supplied to the (-) terminal
/*Base Address of Comparator B,
Reference Voltage of 2.0 V,
Upper Limit of 2.0*(32/32) = 2.0V,
Lower Limit of 2.0*(32/32) = 2.0V
*/
Comp B setReferenceVoltage(COMP B BASE,
CHAPTER 11. COMPARATOR (COMP B) 96
COMP B VREFBASE2 5V,
32,
32
);
// Allow power to Comparator module
Comp B enable(COMP B BASE);
// delay for the reference to settle
delay cycles(75);
CHAPTER 12. CYCLICAL REDUNDANCY CHECK (CRC) 97
12 Cyclical Redundancy Check (CRC)
Introduction ..............................................................................................97
API Functions ............................................................................................97
Programming Example ..................................................................................101
12.1 Introduction
The Cyclic Redundancy Check (CRC) API provides a set of functions for using the MSP430Ware
CRC module. Functions are provided to initialize the CRC and create a CRC signature to check
the validity of data. This is mostly useful in the communication of data, or as a startup procedure
to as a more complex and accurate check of data.
The CRC module offers no interrupts and is used only to generate CRC signatures to verify
against pre-made CRC signatures (Checksums).
12.2 API Functions
Functions
void CRC setSeed (uint16 t baseAddress, uint16 t seed)
Sets the seed for the CRC.
void CRC set16BitData (uint16 t baseAddress, uint16 t dataIn)
Sets the 16 bit data to add into the CRC module to generate a new signature.
void CRC set8BitData (uint16 t baseAddress, uint8 t dataIn)
Sets the 8 bit data to add into the CRC module to generate a new signature.
void CRC set16BitDataReversed (uint16 t baseAddress, uint16 t dataIn)
Translates the 16 bit data by reversing the bits in each byte and then sets this data to add into the
CRC module to generate a new signature.
void CRC set8BitDataReversed (uint16 t baseAddress, uint8 t dataIn)
Translates the 8 bit data by reversing the bits in each byte and then sets this data to add into the
CRC module to generate a new signature.
uint16 t CRC getData (uint16 t baseAddress)
Returns the value currently in the Data register.
uint16 t CRC getResult (uint16 t baseAddress)
Returns the value pf the Signature Result.
uint16 t CRC getResultBitsReversed (uint16 t baseAddress)
Returns the bit-wise reversed format of the Signature Result.
12.2.1 Detailed Description
The CRC API is one group that controls the CRC module. The APIs that are used to set the seed
and data are
CRC setSeed()
CRC set16BitData()
CHAPTER 12. CYCLICAL REDUNDANCY CHECK (CRC) 98
CRC set8BitData()
CRC set16BitDataReversed()
CRC set8BitDataReversed()
CRC setSeed()
The APIs that are used to get the data and results are
CRC getData()
CRC getResult()
CRC getResultBitsReversed()
12.2.2 Function Documentation
CRC getData()
uint16 t CRC getData (
uint16 t baseAddress )
Returns the value currently in the Data register.
This function returns the value currently in the data register. If set in byte bits reversed format,
then the translated data would be returned.
Parameters
baseAddress is the base address of the CRC module.
Returns
The value currently in the data register
CRC getResult()
uint16 t CRC getResult (
uint16 t baseAddress )
Returns the value pf the Signature Result.
This function returns the value of the signature result generated by the CRC.
Parameters
baseAddress is the base address of the CRC module.
CHAPTER 12. CYCLICAL REDUNDANCY CHECK (CRC) 99
Returns
The value currently in the data register
CRC getResultBitsReversed()
uint16 t CRC getResultBitsReversed (
uint16 t baseAddress )
Returns the bit-wise reversed format of the Signature Result.
This function returns the bit-wise reversed format of the Signature Result.
Parameters
baseAddress is the base address of the CRC module.
Returns
The bit-wise reversed format of the Signature Result
CRC set16BitData()
void CRC set16BitData (
uint16 t baseAddress,
uint16 t dataIn )
Sets the 16 bit data to add into the CRC module to generate a new signature.
This function sets the given data into the CRC module to generate the new signature from the
current signature and new data.
Parameters
baseAddress is the base address of the CRC module.
dataIn is the data to be added, through the CRC module, to the signature.
Modified bits are CRCDI of CRCDI register.
Returns
None
CRC set16BitDataReversed()
void CRC set16BitDataReversed (
uint16 t baseAddress,
uint16 t dataIn )
Translates the 16 bit data by reversing the bits in each byte and then sets this data to add into the
CRC module to generate a new signature.
CHAPTER 12. CYCLICAL REDUNDANCY CHECK (CRC) 100
This function first reverses the bits in each byte of the data and then generates the new signature
from the current signature and new translated data.
Parameters
baseAddress is the base address of the CRC module.
dataIn is the data to be added, through the CRC module, to the signature.
Modified bits are CRCDIRB of CRCDIRB register.
Returns
None
CRC set8BitData()
void CRC set8BitData (
uint16 t baseAddress,
uint8 t dataIn )
Sets the 8 bit data to add into the CRC module to generate a new signature.
This function sets the given data into the CRC module to generate the new signature from the
current signature and new data.
Parameters
baseAddress is the base address of the CRC module.
dataIn is the data to be added, through the CRC module, to the signature.
Modified bits are CRCDI of CRCDI register.
Returns
None
CRC set8BitDataReversed()
void CRC set8BitDataReversed (
uint16 t baseAddress,
uint8 t dataIn )
Translates the 8 bit data by reversing the bits in each byte and then sets this data to add into the
CRC module to generate a new signature.
This function first reverses the bits in each byte of the data and then generates the new signature
from the current signature and new translated data.
Parameters
baseAddress is the base address of the CRC module.
dataIn is the data to be added, through the CRC module, to the signature.
Modified bits are CRCDIRB of CRCDIRB register.
CHAPTER 12. CYCLICAL REDUNDANCY CHECK (CRC) 101
Returns
None
CRC setSeed()
void CRC setSeed (
uint16 t baseAddress,
uint16 t seed )
Sets the seed for the CRC.
This function sets the seed for the CRC to begin generating a signature with the given seed and all
passed data. Using this function resets the CRC signature.
Parameters
baseAddress is the base address of the CRC module.
seed is the seed for the CRC to start generating a signature from.
Modified bits are CRCINIRES of CRCINIRES register.
Returns
None
12.3 Programming Example
The following example shows how to initialize and use the CRC API to generate a CRC signature
on an array of data.
unsigned int crcSeed = 0xBEEF;
unsigned int data[] = {0x0123,
0x4567,
0x8910,
0x1112,
0x1314};
unsigned int crcResult;
int i;
// Stop WDT
WDT hold(WDT A BASE);
// Set P1.0 as an output
GPIO setAsOutputPin(GPIO PORT P1,
GPIO PIN0);
// Set the CRC seed
CRC setSeed(CRC BASE,
crcSeed);
for (i = 0; i < 5; i++)
{
//Add all of the values into the CRC signature
CRC set16BitData(CRC BASE,
data[i]);
}
// Save the current CRC signature checksum to be compared for later
crcResult = CRC getResult(CRC BASE);
CHAPTER 13. 16-BIT SIGMA DELTA CONVERTER (CTSD16) 102
13 16-Bit Sigma Delta Converter (CTSD16)
Introduction .............................................................................................102
API Functions ..........................................................................................102
Programming Example ..................................................................................103
13.1 Introduction
The CTSD16 module consists of up to seven independent sigma-delta analog-to-digital multi-input
and multi-converters. The converters are based on second-order oversampling sigma-delta
modulators and digital decimation filters. The decimation filters are comb type filters with
selectable oversampling ratios of up to 256. Additional filtering can be done in software.
A sigma-delta analog-to-digital converter basically consists of two parts: the analog part
called modulator - and the digital part - a decimation filter. The modulator of the CTSD16 with
fixed frequency 1.024Mhz, provides a bit stream of zeros and ones to the digital decimation
filter. The digital filter averages the bitstream from the modulator over a given number of bits
(specified by the oversampling rate) and provides samples at a reduced rate for further
processing to the CPU.
As commonly known averaging can be used to increase the signal-to-noise performance of a
conversion. With a conventional ADC each factor-of-4 oversampling can improve the SNR by
about 6 dB or 1 bit. To achieve a 16-bit resolution out of a simple 1-bit ADC would require an
impractical oversampling rate of 415 = 1.073.741.824. To overcome this limitation the sigma-delta
modulator implements a technique called noise-shaping - due to an implemented feedback-loop
and integrators the quantization noise is pushed to higher frequencies and thus much lower
oversampling rates are sufficient to achieve high resolutions.
13.2 API Functions
The CTSD16 API is broken into three groups of functions: those that deal with initialization and
conversions, those that handle interrupts, and those that handle auxiliary features of the CTSD16.
The CTSD16 initialization and conversion functions are
CTSD16 init()
CTSD16 initConverter()
CTSD16 initConverterAdvanced()
CTSD16 stopConverterConversion()
CTSD16 startConverterConversion()
CTSD16 getResults()
The CTSD16 interrupts are handled by
CTSD16 enableInterrupt()
CTSD16 disableInterrupt()
CHAPTER 13. 16-BIT SIGMA DELTA CONVERTER (CTSD16) 103
CTSD16 clearInterrupt()
CTSD16 getInterruptStatus()
Auxiliary features of the CTSD16 are handled by
CTSD16 setInputChannel()
CTSD16 setDataFormat()
CTSD16 setInterruptDelay()
CTSD16 setConversionDelay()
CTSD16 setOversampling()
CTSD16 setGain()
CTSD16 setRailToRailInput()
CTSD16 isRailToRailInputReady()
13.3 Programming Example
The following example shows how to initialize and use the CTSD16 API to start a single channel,
single conversion.
uint16 t result;
// Initialize CTSD16 using internal reference and internal resistor for clock
CTSD16 init(CTSD16 BASE,
CTSD16 RTR INPUT CHARGEPUMP BURST REQUEST DISABLE, CTSD16 REF INTERNAL);
// Initialize converter 0: AD0+ / AD0- as input, 2s complement, channel 9
CTSD16 initConverterParam convParam = {0};
convParam.converter = CTSD16 CONVERTER 0;
convParam.conversionMode = CTSD16 SINGLE MODE;
convParam.groupEnable = CTSD16 NOT GROUPED;
convParam.inputChannel = CTSD16 INPUT CH9;
convParam.dataFormat = CTSD16 DATA FORMAT 2COMPLEMENT;
convParam.railToRailInput = CTSD16 RTR INPUT DISABLE;
convParam.interruptDelay = CTSD16 FOURTH SAMPLE INTERRUPT;
convParam.oversampleRatio = CTSD16 OVERSAMPLE 256;
convParam.gain = CTSD16 GAIN 1;
CTSD16 initConverter(CTSD16 BASE, &convParam);
// Delay ˜120us for 1.2V ref to settle
delay cycles(2000);
while(1) {
// Set bit to start conversion
CTSD16 startConverterConversion(CTSD16 BASE, CTSD16 CONVERTER 0);
// Poll IFG until conversion completes
while(!CTSD16 getInterruptStatus(CTSD16 BASE, CTSD16 CONVERTER 0, CTSD16 CONVERTER INTERRUPT));
// Save CTSD16 conversion results
result = CTSD16 getResults(CTSD16 BASE, CTSD16 CONVERTER 0);
}
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 104
14 12-bit Digital-to-Analog Converter
(DAC12 A)
Introduction .............................................................................................104
API Functions ..........................................................................................104
Programming Example ..................................................................................116
14.1 Introduction
The 12-Bit Digital-to-Analog (DAC12 A) API provides a set of functions for using the MSP430Ware
DAC12 A modules. Functions are provided to initialize setup the DAC12 A modules, calibrate the
output signal, and manage the interrupts for the DAC12 A modules.
The DAC12 A module provides the ability to convert digital values into an analog signal for output
to a pin. The DAC12 A can generate signals from 0 to Vcc from an 8- or 12-bit value. There can
be one or two DAC12 A modules in a device, and if there are two they can be grouped together to
create two analog signals in simultaneously. There are 3 ways to latch data in to the DAC module,
and those are by software with the startConversion API function call, as well as by the Timer A
output of CCR1 or Timer B output of CCR2.
The calibration API will unlock and start calibration, then wait for the calibration to end before
locking it back up, all in one API. There are also functions to read out the calibration data, as well
as be able to set it manually.
The DAC12 A module can generate one interrupt for each DAC module. It will generate the
interrupt when the data has been latched into the DAC module to be output into an analog signal.
14.2 API Functions
Functions
bool DAC12 A init (uint16 t baseAddress, DAC12 A initParam param)
Initializes the DAC12 A module with the specified settings.
void DAC12 A setAmplifierSetting (uint16 t baseAddress, uint8 t submoduleSelect, uint8 t
amplifierSetting)
Sets the amplifier settings for the Vref+ and Vout buffers.
void DAC12 A disable (uint16 t baseAddress, uint8 t submoduleSelect)
Clears the amplifier settings to disable the DAC12 A module.
void DAC12 A enableGrouping (uint16 t baseAddress)
Enables grouping of two DAC12 A modules in a dual DAC12 A system.
void DAC12 A disableGrouping (uint16 t baseAddress)
Disables grouping of two DAC12 A modules in a dual DAC12 A system.
void DAC12 A enableInterrupt (uint16 t baseAddress, uint8 t submoduleSelect)
Enables the DAC12 A module interrupt source.
void DAC12 A disableInterrupt (uint16 t baseAddress, uint8 t submoduleSelect)
Disables the DAC12 A module interrupt source.
uint16 t DAC12 A getInterruptStatus (uint16 t baseAddress, uint8 t submoduleSelect)
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 105
Returns the status of the DAC12 A module interrupt flag.
void DAC12 A clearInterrupt (uint16 t baseAddress, uint8 t submoduleSelect)
Clears the DAC12 A module interrupt flag.
void DAC12 A calibrateOutput (uint16 t baseAddress, uint8 t submoduleSelect)
Calibrates the output offset.
uint16 t DAC12 A getCalibrationData (uint16 t baseAddress, uint8 t submoduleSelect)
Returns the calibrated offset of the output buffer.
void DAC12 A setCalibrationOffset (uint16 t baseAddress, uint8 t submoduleSelect, uint16 t
calibrationOffsetValue)
Returns the calibrated offset of the output buffer.
void DAC12 A enableConversions (uint16 t baseAddress, uint8 t submoduleSelect)
Enables triggers to start conversions.
void DAC12 A setData (uint16 t baseAddress, uint8 t submoduleSelect, uint16 t data)
Sets the given data into the buffer to be converted.
void DAC12 A disableConversions (uint16 t baseAddress, uint8 t submoduleSelect)
Disables triggers to start conversions.
void DAC12 A setResolution (uint16 t baseAddress, uint8 t submoduleSelect, uint16 t
resolutionSelect)
Sets the resolution to be used by the DAC12 A module.
void DAC12 A setInputDataFormat (uint16 t baseAddress, uint8 t submoduleSelect, uint8 t
inputJustification, uint8 t inputSign)
Sets the input data format for the DAC12 A module.
uint32 t DAC12 A getDataBufferMemoryAddressForDMA (uint16 t baseAddress, uint8 t
submoduleSelect)
Returns the address of the specified DAC12 A data buffer for the DMA module.
14.2.1 Detailed Description
The DAC12 A API is broken into three groups of functions: those that deal with initialization and
conversions, those that deal with calibration of the output, and those that handle interrupts.
The DAC12 A initialization and conversion functions are
DAC12 A init()
DAC12 A setAmplifierSetting()
DAC12 A disable()
DAC12 A enableGrouping()
DAC12 A disableGrouping()
DAC12 A enableConversions()
DAC12 A setData()
DAC12 A disableConversions()
DAC12 A setResolution()
DAC12 A setInputDataFormat()
DAC12 A getDataBufferMemoryAddressForDMA()
Calibration features of the DAC12 A are handled by
DAC12 A calibrateOutput()
DAC12 A getCalibrationData()
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 106
DAC12 A setCalibrationOffset()
The DAC12 A interrupts are handled by
DAC12 A enableInterrupt()
DAC12 A disableInterrupt()
DAC12 A getInterruptStatus()
DAC12 A clearInterrupt()
14.2.2 Function Documentation
DAC12 A calibrateOutput()
void DAC12 A calibrateOutput (
uint16 t baseAddress,
uint8 t submoduleSelect )
Calibrates the output offset.
This function disables the calibration lock, starts the calibration, whats for the calibration to
complete, and then re-locks the calibration lock. Please note, this function should be called after
initializing the dac12 module, and before using it.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Modified bits are DAC12CALON of DAC12 xCTL0 register; bits DAC12PW of DAC12 xCALCTL
register.
Returns
None
DAC12 A clearInterrupt()
void DAC12 A clearInterrupt (
uint16 t baseAddress,
uint8 t submoduleSelect )
Clears the DAC12 A module interrupt flag.
The DAC12 A module interrupt flag is cleared, so that it no longer asserts. Note that an interrupt
is not thrown when DAC12 A TRIGGER ENCBYPASS has been set for the parameter
conversionTriggerSelect in initialization.
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 107
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Modified bits are DAC12IFG of DAC12 xCTL0 register.
Returns
None
DAC12 A disable()
void DAC12 A disable (
uint16 t baseAddress,
uint8 t submoduleSelect )
Clears the amplifier settings to disable the DAC12 A module.
This function clears the amplifier settings for the selected DAC12 A module to disable the
DAC12 A module.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Modified bits are DAC12AMP 7 of DAC12 xCTL0 register.
Returns
None
DAC12 A disableConversions()
void DAC12 A disableConversions (
uint16 t baseAddress,
uint8 t submoduleSelect )
Disables triggers to start conversions.
This function is used to disallow triggers to start a conversion. Note that this function does not
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 108
have any affect if DAC12 A TRIGGER ENCBYPASS was set for the conversionTriggerSelect
parameter during initialization.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Modified bits are DAC12ENC of DAC12 xCTL0 register.
Returns
None
DAC12 A disableGrouping()
void DAC12 A disableGrouping (
uint16 t baseAddress )
Disables grouping of two DAC12 A modules in a dual DAC12 A system.
This function disables grouping of two DAC12 A modules in a dual DAC12 A system.
Parameters
baseAddress is the base address of the DAC12 A module.
Returns
None
DAC12 A disableInterrupt()
void DAC12 A disableInterrupt (
uint16 t baseAddress,
uint8 t submoduleSelect )
Disables the DAC12 A module interrupt source.
Enables the DAC12 A module interrupt source. Only the sources that are enabled can be
reflected to the processor interrupt; disabled sources have no effect on the processor.
Parameters
baseAddress is the base address of the DAC12 A module.
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 109
Parameters
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Returns
None
DAC12 A enableConversions()
void DAC12 A enableConversions (
uint16 t baseAddress,
uint8 t submoduleSelect )
Enables triggers to start conversions.
This function is used to allow triggers to start a conversion. Note that this function does not need
to be used if DAC12 A TRIGGER ENCBYPASS was set for the conversionTriggerSelect
parameter during initialization. If DAC grouping is enabled, this has to be called for both DAC's.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Modified bits are DAC12ENC of DAC12 xCTL0 register.
Returns
None
DAC12 A enableGrouping()
void DAC12 A enableGrouping (
uint16 t baseAddress )
Enables grouping of two DAC12 A modules in a dual DAC12 A system.
This function enables grouping two DAC12 A modules in a dual DAC12 A system. Both DAC12 A
modules will work in sync, converting data at the same time. To convert data, the same trigger
should be set for both DAC12 A modules during initialization (which should not be
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 110
DAC12 A TRIGGER ENCBYPASS), the enableConversions() function needs to be called with
both DAC12 A modules, and data needs to be set for both DAC12 A modules separately.
Parameters
baseAddress is the base address of the DAC12 A module.
Modified bits are DAC12GRP of DAC12 xCTL0 register.
Returns
None
DAC12 A enableInterrupt()
void DAC12 A enableInterrupt (
uint16 tbaseAddress,
uint8 t submoduleSelect )
Enables the DAC12 A module interrupt source.
This function to enable the DAC12 A module interrupt, which throws an interrupt when the data
buffer is available for new data to be set. Only the sources that are enabled can be reflected to the
processor interrupt; disabled sources have no effect on the processor. Note that an interrupt is not
thrown when DAC12 A TRIGGER ENCBYPASS has been set for the parameter
conversionTriggerSelect in initialization. Does not clear interrupt flags.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Returns
None
DAC12 A getCalibrationData()
uint16 t DAC12 A getCalibrationData (
uint16 t baseAddress,
uint8 t submoduleSelect )
Returns the calibrated offset of the output buffer.
This function returns the calibrated offset of the output buffer. The output buffer offset is used to
obtain accurate results from the output pin. This function should only be used while the calibration
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 111
lock is enabled. Only the lower byte of the word of the register is returned, and the value is
between -128 and +127.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Returns
The calibrated offset of the output buffer.
DAC12 A getDataBufferMemoryAddressForDMA()
uint32 t DAC12 A getDataBufferMemoryAddressForDMA (
uint16 t baseAddress,
uint8 t submoduleSelect )
Returns the address of the specified DAC12 A data buffer for the DMA module.
Returns the address of the specified memory buffer. This can be used in conjunction with the
DMA to obtain the data directly from memory.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Returns
The address of the specified memory buffer
DAC12 A getInterruptStatus()
uint16 t DAC12 A getInterruptStatus (
uint16 t baseAddress,
uint8 t submoduleSelect )
Returns the status of the DAC12 A module interrupt flag.
This function returns the status of the DAC12 A module interrupt flag. Note that an interrupt is not
thrown when DAC12 A TRIGGER ENCBYPASS has been set for the conversionTriggerSelect
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 112
parameter in initialization.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
Returns
One of the following:
DAC12 A INT ACTIVE
DAC12 A INT INACTIVE
indicating the status for the selected DAC12 A module
DAC12 A init()
bool DAC12 A init (
uint16 t baseAddress,
DAC12 A initParam param )
Initializes the DAC12 A module with the specified settings.
This function initializes the DAC12 A module with the specified settings. Upon successful
completion of the initialization of this module the control registers and interrupts of this module are
all reset, and the specified variables will be set. Please note, that if conversions are enabled with
the enableConversions() function, then disableConversions() must be called before re-initializing
the DAC12 A module with this function.
Parameters
baseAddress is the base address of the DAC12 A module.
param is the pointer to struct for initialization.
Returns
STATUS SUCCESS or STATUS FAILURE of the initialization process.
References DAC12 A initParam::amplifierSetting, DAC12 A initParam::conversionTriggerSelect,
DAC12 A initParam::outputSelect, DAC12 A initParam::outputVoltageMultiplier,
DAC12 A initParam::positiveReferenceVoltage, and DAC12 A initParam::submoduleSelect.
DAC12 A setAmplifierSetting()
void DAC12 A setAmplifierSetting (
uint16 t baseAddress,
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 113
uint8 t submoduleSelect,
uint8 t amplifierSetting )
Sets the amplifier settings for the Vref+ and Vout buffers.
This function sets the amplifier settings of the DAC12 A module for the Vref+ and Vout buffers
without re-initializing the DAC12 A module. This can be used to disable the control of the pin by
the DAC12 A module.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
amplifierSetting is the setting of the settling speed and current of the Vref+ and the Vout
buffer. Valid values are:
DAC12 A AMP OFF PINOUTHIGHZ [Default] - Initialize the
DAC12 A Module with settings, but do not turn it on.
DAC12 A AMP OFF PINOUTLOW - Initialize the DAC12 A Module
with settings, and allow it to take control of the selected output pin to
pull it low (Note: this takes control away port mapping module).
DAC12 A AMP LOWIN LOWOUT - Select a slow settling speed and
current for Vref+ input buffer and for Vout output buffer.
DAC12 A AMP LOWIN MEDOUT - Select a slow settling speed and
current for Vref+ input buffer and a medium settling speed and current
for Vout output buffer.
DAC12 A AMP LOWIN HIGHOUT - Select a slow settling speed and
current for Vref+ input buffer and a high settling speed and current for
Vout output buffer.
DAC12 A AMP MEDIN MEDOUT - Select a medium settling speed
and current for Vref+ input buffer and for Vout output buffer.
DAC12 A AMP MEDIN HIGHOUT - Select a medium settling speed
and current for Vref+ input buffer and a high settling speed and
current for Vout output buffer.
DAC12 A AMP HIGHIN HIGHOUT - Select a high settling speed and
current for Vref+ input buffer and for Vout output buffer.
Returns
None
DAC12 A setCalibrationOffset()
void DAC12 A setCalibrationOffset (
uint16 t baseAddress,
uint8 t submoduleSelect,
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 114
uint16 t calibrationOffsetValue )
Returns the calibrated offset of the output buffer.
This function is used to manually set the calibration offset value. The calibration is automatically
unlocked and re-locked to be able to allow for the offset value to be set.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
calibrationOffsetValue calibration offset value
Modified bits are DAC12LOCK of DAC12 xCALDAT register; bits DAC12PW of DAC12 xCTL0
register; bits DAC12PW of DAC12 xCALCTL register.
Returns
None
DAC12 A setData()
void DAC12 A setData (
uint16 t baseAddress,
uint8 t submoduleSelect,
uint16 t data )
Sets the given data into the buffer to be converted.
This function is used to set the given data into the data buffer of the DAC12 A module. The data
given should be in the format set (12-bit Unsigned, Right-justified by default). Note if
DAC12 A TRIGGER ENCBYPASS was set for the conversionTriggerSelect during initialization
then using this function will set the data and automatically trigger a conversion. If any other trigger
was set during initialization, then the DAC12 A enableConversions() function needs to be called
before a conversion can be started. If grouping DAC's and DAC12 A TRIGGER ENC was set
during initialization, then both data buffers must be set before a conversion will be started.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
data is the data to be set into the DAC12 A data buffer to be converted.
Modified bits are DAC12 DATA of DAC12 xDAT register.
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 115
Modified bits of DAC12 xDAT register.
Returns
None
DAC12 A setInputDataFormat()
void DAC12 A setInputDataFormat (
uint16 t baseAddress,
uint8 t submoduleSelect,
uint8 t inputJustification,
uint8 t inputSign )
Sets the input data format for the DAC12 A module.
This function sets the input format for the binary data to be converted.
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
inputJustification is the justification of the data to be converted. Valid values are:
DAC12 A JUSTIFICATION RIGHT [Default]
DAC12 A JUSTIFICATION LEFT
Modified bits are DAC12DFJ of DAC12 xCTL1 register.
inputSign is the sign of the data to be converted. Valid values are:
DAC12 A UNSIGNED BINARY [Default]
DAC12 A SIGNED 2SCOMPLEMENT
Modified bits are DAC12DF of DAC12 xCTL0 register.
Returns
None
DAC12 A setResolution()
void DAC12 A setResolution (
uint16 t baseAddress,
uint8 t submoduleSelect,
uint16 t resolutionSelect )
Sets the resolution to be used by the DAC12 A module.
This function sets the resolution of the data to be converted.
CHAPTER 14. 12-BIT DIGITAL-TO-ANALOG CONVERTER (DAC12 A) 116
Parameters
baseAddress is the base address of the DAC12 A module.
submoduleSelect decides which DAC12 A sub-module to configure. Valid values
are:
DAC12 A SUBMODULE 0
DAC12 A SUBMODULE 1
resolutionSelect is the resolution to use for conversions. Valid values are:
DAC12 A RESOLUTION 8BIT
DAC12 A RESOLUTION 12BIT [Default]
Modified bits are DAC12RES of DAC12 xCTL0 register.
Modified bits are DAC12ENC and DAC12RES of DAC12 xCTL0 register.
Returns
None
14.3 Programming Example
The following example shows how to initialize and use the DAC12 A API to output a 1.5V analog
signal.
DAC12 A initParam param = {0};
param.submoduleSelect = DAC12 A SUBMODULE 0;
param.outputSelect = DAC12 A OUTPUT 1;
param.positiveReferenceVoltage = DAC12 A VREF AVCC;
param.outputVoltageMultiplier = DAC12 A VREFx1;
param.amplifierSetting = DAC12 A AMP MEDIN MEDOUT;
param.conversionTriggerSelect = DAC12 A TRIGGER ENCBYPASS;
DAC12 A init(DAC12 A BASE, &param);
// Calibrate output buffer for DAC12 A 0
DAC12 A calibrateOutput(DAC12 A BASE,
DAC12 A SUBMODULE 0);
DAC12 A setData(DAC12 A BASE,
DAC12 A SUBMODULE 0, // Set 0x7FF (˜1.5V)
0x7FF // into data buffer for DAC12 A 0
);
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 117
15 Direct Memory Access (DMA)
Introduction .............................................................................................117
API Functions ..........................................................................................117
Programming Example ..................................................................................130
15.1 Introduction
The Direct Memory Access (DMA) API provides a set of functions for using the MSP430Ware
DMA modules. Functions are provided to initialize and setup each DMA channel with the source
and destination addresses, manage the interrupts for each channel, and set bits that affect all
DMA channels.
The DMA module provides the ability to move data from one address in the device to another, and
that includes other peripheral addresses to RAM or vice-versa, all without the actual use of the
CPU. Please be advised, that the DMA module does halt the CPU for 2 cycles while transferring,
but does not have to edit any registers or anything. The DMA can transfer by bytes or words at a
time, and will automatically increment or decrement the source or destination address if desired.
There are also 6 different modes to transfer by, including single-transfer, block-transfer, and
burst-block-transfer, as well as repeated versions of those three different kinds which allows
transfers to be repeated without having re-enable transfers.
The DMA settings that affect all DMA channels include prioritization, from a fixed priority to
dynamic round-robin priority. Another setting that can be changed is when transfers occur, the
CPU may be in a read-modify-write operation which can be disastrous to time sensitive material,
so this can be disabled. And Non-Maskable-Interrupts can indeed be maskable to the DMA
module if not enabled.
The DMA module can generate one interrupt per channel. The interrupt is only asserted when the
specified amount of transfers has been completed. With single-transfer, this occurs when that
many single transfers have occurred, while with block or burst-block transfers, once the block is
completely transferred the interrupt is asserted.
15.2 API Functions
Functions
void DMA init (DMA initParam param)
Initializes the specified DMA channel.
void DMA setTransferSize (uint8 t channelSelect, uint16 t transferSize)
Sets the specified amount of transfers for the selected DMA channel.
uint16 t DMA getTransferSize (uint8 t channelSelect)
Gets the amount of transfers for the selected DMA channel.
void DMA setSrcAddress (uint8 t channelSelect, uint32 t srcAddress, uint16 t
directionSelect)
Sets source address and the direction that the source address will move after a transfer.
void DMA setDstAddress (uint8 t channelSelect, uint32 t dstAddress, uint16 t
directionSelect)
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 118
Sets the destination address and the direction that the destination address will move after a transfer.
void DMA enableTransfers (uint8 t channelSelect)
Enables transfers to be triggered.
void DMA disableTransfers (uint8 t channelSelect)
Disables transfers from being triggered.
void DMA startTransfer (uint8 t channelSelect)
Starts a transfer if using the default trigger source selected in initialization.
void DMA enableInterrupt (uint8 t channelSelect)
Enables the DMA interrupt for the selected channel.
void DMA disableInterrupt (uint8 t channelSelect)
Disables the DMA interrupt for the selected channel.
uint16 t DMA getInterruptStatus (uint8 t channelSelect)
Returns the status of the interrupt flag for the selected channel.
void DMA clearInterrupt (uint8 t channelSelect)
Clears the interrupt flag for the selected channel.
uint16 t DMA getNMIAbortStatus (uint8 t channelSelect)
Returns the status of the NMIAbort for the selected channel.
void DMA clearNMIAbort (uint8 t channelSelect)
Clears the status of the NMIAbort to proceed with transfers for the selected channel.
void DMA disableTransferDuringReadModifyWrite (void)
Disables the DMA from stopping the CPU during a Read-Modify-Write Operation to start a transfer.
void DMA enableTransferDuringReadModifyWrite (void)
Enables the DMA to stop the CPU during a Read-Modify-Write Operation to start a transfer.
void DMA enableRoundRobinPriority (void)
Enables Round Robin prioritization.
void DMA disableRoundRobinPriority (void)
Disables Round Robin prioritization.
void DMA enableNMIAbort (void)
Enables a NMI to interrupt a DMA transfer.
void DMA disableNMIAbort (void)
Disables any NMI from interrupting a DMA transfer.
15.2.1 Detailed Description
The DMA API is broken into three groups of functions: those that deal with initialization and
transfers, those that handle interrupts, and those that affect all DMA channels.
The DMA initialization and transfer functions are: DMA init() DMA setSrcAddress()
DMA setDstAddress() DMA enableTransfers() DMA disableTransfers() DMA startTransfer()
DMA setTransferSize() DMA getTransferSize()
The DMA interrupts are handled by: DMA enableInterrupt() DMA disableInterrupt()
DMA getInterruptStatus() DMA clearInterrupt() DMA getNMIAbortStatus() DMA clearNMIAbort()
Features of the DMA that affect all channels are handled by:
DMA disableTransferDuringReadModifyWrite() DMA enableTransferDuringReadModifyWrite()
DMA enableRoundRobinPriority() DMA disableRoundRobinPriority() DMA enableNMIAbort()
DMA disableNMIAbort()
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 119
15.2.2 Function Documentation
DMA clearInterrupt()
void DMA clearInterrupt (
uint8 t channelSelect )
Clears the interrupt flag for the selected channel.
This function clears the DMA interrupt flag is cleared, so that it no longer asserts.
Parameters
channelSelect is the specified channel to clear the interrupt flag for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
Returns
None
DMA clearNMIAbort()
void DMA clearNMIAbort (
uint8 t channelSelect )
Clears the status of the NMIAbort to proceed with transfers for the selected channel.
This function clears the status of the NMI Abort flag for the selected channel to allow for transfers
on the channel to continue.
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 120
Parameters
channelSelect is the specified channel to clear the NMI Abort flag for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
Returns
None
DMA disableInterrupt()
void DMA disableInterrupt (
uint8 t channelSelect )
Disables the DMA interrupt for the selected channel.
Disables the DMA interrupt source. Only the sources that are enabled can be reflected to the
processor interrupt; disabled sources have no effect on the processor.
Parameters
channelSelect is the specified channel to disable the interrupt for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 121
Returns
None
DMA disableNMIAbort()
void DMA disableNMIAbort (
void )
Disables any NMI from interrupting a DMA transfer.
This function disables NMI's from interrupting any DMA transfer currently in progress.
Returns
None
DMA disableRoundRobinPriority()
void DMA disableRoundRobinPriority (
void )
Disables Round Robin prioritization.
This function disables Round Robin Prioritization, enabling static prioritization of the DMA
channels. In static prioritization, the DMA channels are prioritized with the lowest DMA channel
index having the highest priority (i.e. DMA Channel 0 has the highest priority).
Returns
None
DMA disableTransferDuringReadModifyWrite()
void DMA disableTransferDuringReadModifyWrite (
void )
Disables the DMA from stopping the CPU during a Read-Modify-Write Operation to start a transfer.
This function allows the CPU to finish any read-modify-write operations it may be in the middle of
before transfers of and DMA channel stop the CPU.
Returns
None
DMA disableTransfers()
void DMA disableTransfers (
uint8 t channelSelect )
Disables transfers from being triggered.
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 122
This function disables transfer from being triggered for the selected channel. This function should
be called before any re-initialization of the selected DMA channel.
Parameters
channelSelect is the specified channel to disable transfers for. Valid values
are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
Returns
None
DMA enableInterrupt()
void DMA enableInterrupt (
uint8 t channelSelect )
Enables the DMA interrupt for the selected channel.
Enables the DMA interrupt source. Only the sources that are enabled can be reflected to the
processor interrupt; disabled sources have no effect on the processor. Does not clear interrupt
flags.
Parameters
channelSelect is the specified channel to enable the interrupt for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 123
Returns
None
DMA enableNMIAbort()
void DMA enableNMIAbort (
void )
Enables a NMI to interrupt a DMA transfer.
This function allow NMI's to interrupting any DMA transfer currently in progress and stops any
future transfers to begin before the NMI is done processing.
Returns
None
DMA enableRoundRobinPriority()
void DMA enableRoundRobinPriority (
void )
Enables Round Robin prioritization.
This function enables Round Robin Prioritization of DMA channels. In the case of Round Robin
Prioritization, the last DMA channel to have transferred data then has the last priority, which
comes into play when multiple DMA channels are ready to transfer at the same time.
Returns
None
DMA enableTransferDuringReadModifyWrite()
void DMA enableTransferDuringReadModifyWrite (
void )
Enables the DMA to stop the CPU during a Read-Modify-Write Operation to start a transfer.
This function allows the DMA to stop the CPU in the middle of a read- modify-write operation to
transfer data.
Returns
None
DMA enableTransfers()
void DMA enableTransfers (
uint8 t channelSelect )
Enables transfers to be triggered.
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 124
This function enables transfers upon appropriate trigger of the selected trigger source for the
selected channel.
Parameters
channelSelect is the specified channel to enable transfer for. Valid values
are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
Returns
None
DMA getInterruptStatus()
uint16 t DMA getInterruptStatus (
uint8 t channelSelect )
Returns the status of the interrupt flag for the selected channel.
Returns the status of the interrupt flag for the selected channel.
Parameters
channelSelect is the specified channel to return the interrupt flag status from. Valid values
are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 125
Returns
One of the following:
DMA INT INACTIVE
DMA INT ACTIVE
indicating the status of the current interrupt flag
DMA getNMIAbortStatus()
uint16 t DMA getNMIAbortStatus (
uint8 t channelSelect )
Returns the status of the NMIAbort for the selected channel.
This function returns the status of the NMI Abort flag for the selected channel. If this flag has been
set, it is because a transfer on this channel was aborted due to a interrupt from an NMI.
Parameters
channelSelect is the specified channel to return the status of the NMI Abort flag for. Valid
values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
Returns
One of the following:
DMA NOTABORTED
DMA ABORTED
indicating the status of the NMIAbort for the selected channel
DMA getTransferSize()
uint16 t DMA getTransferSize (
uint8 t channelSelect )
Gets the amount of transfers for the selected DMA channel.
This function gets the amount of transfers for the selected DMA channel without having to
reinitialize the DMA channel.
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 126
Parameters
channelSelect is the specified channel to set source address direction for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
Returns
the amount of transfers
DMA init()
void DMA init (
DMA initParam param )
Initializes the specified DMA channel.
This function initializes the specified DMA channel. Upon successful completion of initialization of
the selected channel the control registers will be cleared and the given variables will be set.
Please note, if transfers have been enabled with the enableTransfers() function, then a call to
disableTransfers() is necessary before re-initialization. Also note, that the trigger sources are
device dependent and can be found in the device family data sheet. The amount of DMA channels
available are also device specific.
Parameters
param is the pointer to struct for initialization.
Returns
STATUS SUCCESS or STATUS FAILURE of the initialization process.
References DMA initParam::channelSelect, DMA initParam::transferModeSelect,
DMA initParam::transferSize, DMA initParam::transferUnitSelect,
DMA initParam::triggerSourceSelect, and DMA initParam::triggerTypeSelect.
DMA setDstAddress()
void DMA setDstAddress (
uint8 t channelSelect,
uint32 t dstAddress,
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 127
uint16 t directionSelect )
Sets the destination address and the direction that the destination address will move after a
transfer.
This function sets the destination address and the direction that the destination address will move
after a transfer is complete. It may be incremented, decremented, or unchanged.
Parameters
channelSelect is the specified channel to set the destination address direction for. Valid
values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
dstAddress is the address of where the data will be transferred to.
Modified bits are DMAxDA of DMAxDA register.
directionSelect is the specified direction of the destination address after a transfer. Valid
values are:
DMA DIRECTION UNCHANGED
DMA DIRECTION DECREMENT
DMA DIRECTION INCREMENT
Modified bits are DMADSTINCR of DMAxCTL register.
Returns
None
DMA setSrcAddress()
void DMA setSrcAddress (
uint8 t channelSelect,
uint32 t srcAddress,
uint16 t directionSelect )
Sets source address and the direction that the source address will move after a transfer.
This function sets the source address and the direction that the source address will move after a
transfer is complete. It may be incremented, decremented or unchanged.
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 128
Parameters
channelSelect is the specified channel to set source address direction for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
srcAddress is the address of where the data will be transferred from.
Modified bits are DMAxSA of DMAxSA register.
directionSelect is the specified direction of the source address after a transfer. Valid values
are:
DMA DIRECTION UNCHANGED
DMA DIRECTION DECREMENT
DMA DIRECTION INCREMENT
Modified bits are DMASRCINCR of DMAxCTL register.
Returns
None
DMA setTransferSize()
void DMA setTransferSize (
uint8 t channelSelect,
uint16 t transferSize )
Sets the specified amount of transfers for the selected DMA channel.
This function sets the specified amount of transfers for the selected DMA channel without having
to reinitialize the DMA channel.
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 129
Parameters
channelSelect is the specified channel to set source address direction for. Valid values are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
transferSize is the amount of transfers to complete in a block transfer mode, as well as how
many transfers to complete before the interrupt flag is set. Valid value is
between 1-65535, if 0, no transfers will occur.
Modified bits are DMAxSZ of DMAxSZ register.
Returns
None
DMA startTransfer()
void DMA startTransfer (
uint8 t channelSelect )
Starts a transfer if using the default trigger source selected in initialization.
This functions triggers a transfer of data from source to destination if the trigger source chosen
from initialization is the DMA TRIGGERSOURCE 0. Please note, this function needs to be called
for each (repeated-)single transfer, and when transferAmount of transfers have been complete in
(repeated-)block transfers.
Parameters
channelSelect is the specified channel to start transfers for. Valid values
are:
DMA CHANNEL 0
DMA CHANNEL 1
DMA CHANNEL 2
DMA CHANNEL 3
DMA CHANNEL 4
DMA CHANNEL 5
DMA CHANNEL 6
DMA CHANNEL 7
CHAPTER 15. DIRECT MEMORY ACCESS (DMA) 130
Returns
None
15.3 Programming Example
The following example shows how to initialize and use the DMA API to transfer words from one
spot in RAM to another.
// Initialize and Setup DMA Channel 0
/*
*Base Address of the DMA Module
*Configure DMA channel 0
*Configure channel for repeated block transfers
*DMA interrupt flag will be set after every 16 transfers
*Use DMA startTransfer() function to trigger transfers
*Transfer Word-to-Word
*Trigger upon Rising Edge of Trigger Source Signal
*/
DMA initParam param = {0};
param.channelSelect = DMA CHANNEL 0;
param.transferModeSelect = DMA TRANSFER REPEATED BLOCK;
param.transferSize = 16;
param.triggerSourceSelect = DMA TRIGGERSOURCE 0;
param.transferUnitSelect = DMA SIZE SRCWORD DSTWORD;
param.triggerTypeSelect = DMA TRIGGER RISINGEDGE;
DMA init(&param);
/*
*Base Address of the DMA Module
*Configure DMA channel 0
*Use 0x1C00 as source
*Increment source address after every transfer
*/
DMA setSrcAddress(DMA CHANNEL 0,
0x1C00,
DMA DIRECTION INCREMENT);
/*
*Base Address of the DMA Module
*Configure DMA channel 0
*Use 0x1C20 as destination
*Increment destination address after every transfer
*/
DMA setDstAddress(DMA CHANNEL 0,
0x1C20,
DMA DIRECTION INCREMENT);
// Enable transfers on DMA channel 0
DMA enableTransfers(DMA CHANNEL 0);
while(1)
{
// Start block transfer on DMA channel 0
DMA startTransfer(DMA CHANNEL 0);
}
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 131
16 EUSCI Universal Asynchronous
Receiver/Transmitter (EUSCI A UART)
Introduction .............................................................................................131
API Functions ..........................................................................................131
Programming Example ..................................................................................142
16.1 Introduction
The MSP430Ware library for UART mode features include:
Odd, even, or non-parity
Independent transmit and receive shift registers
Separate transmit and receive buffer registers
LSB-first or MSB-first data transmit and receive
Built-in idle-line and address-bit communication protocols for multiprocessor systems
Receiver start-edge detection for auto wake up from LPMx modes
Status flags for error detection and suppression
Status flags for address detection
Independent interrupt capability for receive and transmit
In UART mode, the USCI transmits and receives characters at a bit rate asynchronous to another
device. Timing for each character is based on the selected baud rate of the USCI. The transmit
and receive functions use the same baud-rate frequency.
16.2 API Functions
Functions
bool EUSCI A UART init (uint16 t baseAddress, EUSCI A UART initParam param)
Advanced initialization routine for the UART block. The values to be written into the clockPrescalar,
firstModReg, secondModReg and overSampling parameters should be pre-computed and passed
into the initialization function.
void EUSCI A UART transmitData (uint16 t baseAddress, uint8 t transmitData)
Transmits a byte from the UART Module.Please note that if TX interrupt is disabled, this function
manually polls the TX IFG flag waiting for an indication that it is safe to write to the transmit buffer
and does not time-out.
uint8 t EUSCI A UART receiveData (uint16 t baseAddress)
Receives a byte that has been sent to the UART Module.
void EUSCI A UART enableInterrupt (uint16 t baseAddress, uint8 t mask)
Enables individual UART interrupt sources.
void EUSCI A UART disableInterrupt (uint16 t baseAddress, uint8 t mask)
Disables individual UART interrupt sources.
uint8 t EUSCI A UART getInterruptStatus (uint16 t baseAddress, uint8 t mask)
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 132
Gets the current UART interrupt status.
void EUSCI A UART clearInterrupt (uint16 t baseAddress, uint16 t mask)
Clears UART interrupt sources.
void EUSCI A UART enable (uint16 t baseAddress)
Enables the UART block.
void EUSCI A UART disable (uint16 t baseAddress)
Disables the UART block.
uint8 t EUSCI A UART queryStatusFlags (uint16 t baseAddress, uint8 t mask)
Gets the current UART status flags.
void EUSCI A UART setDormant (uint16 t baseAddress)
Sets the UART module in dormant mode.
void EUSCI A UART resetDormant (uint16 t baseAddress)
Re-enables UART module from dormant mode.
void EUSCI A UART transmitAddress (uint16 t baseAddress, uint8 t transmitAddress)
Transmits the next byte to be transmitted marked as address depending on selected multiprocessor
mode.
void EUSCI A UART transmitBreak (uint16 t baseAddress)
Transmit break.
uint32 t EUSCI A UART getReceiveBufferAddress (uint16 t baseAddress)
Returns the address of the RX Buffer of the UART for the DMA module.
uint32 t EUSCI A UART getTransmitBufferAddress (uint16 t baseAddress)
Returns the address of the TX Buffer of the UART for the DMA module.
void EUSCI A UART selectDeglitchTime (uint16 t baseAddress, uint16 t deglitchTime)
Sets the deglitch time.
16.2.1 Detailed Description
The EUSI A UART API provides the set of functions required to implement an interrupt driven
EUSI A UART driver. The EUSI A UART initialization with the various modes and features is done
by the EUSCI A UART init(). At the end of this function EUSI A UART is initialized and stays
disabled. EUSCI A UART enable() enables the EUSI A UART and the module is now ready for
transmit and receive. It is recommended to initialize the EUSI A UART via EUSCI A UART init(),
enable the required interrupts and then enable EUSI A UART via EUSCI A UART enable().
The EUSI A UART API is broken into three groups of functions: those that deal with configuration
and control of the EUSI A UART modules, those used to send and receive data, and those that
deal with interrupt handling and those dealing with DMA.
Configuration and control of the EUSI UART are handled by the
EUSCI A UART init()
EUSCI A UART initAdvance()
EUSCI A UART enable()
EUSCI A UART disable()
EUSCI A UART setDormant()
EUSCI A UART resetDormant()
EUSCI A UART selectDeglitchTime()
Sending and receiving data via the EUSI UART is handled by the
EUSCI A UART transmitData()
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 133
EUSCI A UART receiveData()
EUSCI A UART transmitAddress()
EUSCI A UART transmitBreak()
EUSCI A UART getTransmitBufferAddress()
EUSCI A UART getTransmitBufferAddress()
Managing the EUSI UART interrupts and status are handled by the
EUSCI A UART enableInterrupt()
EUSCI A UART disableInterrupt()
EUSCI A UART getInterruptStatus()
EUSCI A UART clearInterrupt()
EUSCI A UART queryStatusFlags()
16.2.2 Function Documentation
EUSCI A UART clearInterrupt()
void EUSCI A UART clearInterrupt (
uint16 t baseAddress,
uint16 t mask )
Clears UART interrupt sources.
The UART interrupt source is cleared, so that it no longer asserts. The highest interrupt flag is
automatically cleared when an interrupt vector generator is used.
Parameters
baseAddress is the base address of the EUSCI A UART module.
mask is a bit mask of the interrupt sources to be cleared. Mask value is the logical
OR of any of the following:
EUSCI A UART RECEIVE INTERRUPT FLAG
EUSCI A UART TRANSMIT INTERRUPT FLAG
EUSCI A UART STARTBIT INTERRUPT FLAG
EUSCI A UART TRANSMIT COMPLETE INTERRUPT FLAG
Modified bits of UCAxIFG register.
Returns
None
EUSCI A UART disable()
void EUSCI A UART disable (
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 134
uint16 t baseAddress )
Disables the UART block.
This will disable operation of the UART block.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Modified bits are UCSWRST of UCAxCTL1 register.
Returns
None
EUSCI A UART disableInterrupt()
void EUSCI A UART disableInterrupt (
uint16 t baseAddress,
uint8 t mask )
Disables individual UART interrupt sources.
Disables the indicated UART interrupt sources. Only the sources that are enabled can be reflected
to the processor interrupt; disabled sources have no effect on the processor.
Parameters
baseAddress is the base address of the EUSCI A UART module.
mask is the bit mask of the interrupt sources to be disabled. Mask value is the logical
OR of any of the following:
EUSCI A UART RECEIVE INTERRUPT - Receive interrupt
EUSCI A UART TRANSMIT INTERRUPT - Transmit interrupt
EUSCI A UART RECEIVE ERRONEOUSCHAR INTERRUPT - Receive
erroneous-character interrupt enable
EUSCI A UART BREAKCHAR INTERRUPT - Receive break character
interrupt enable
EUSCI A UART STARTBIT INTERRUPT - Start bit received interrupt
enable
EUSCI A UART TRANSMIT COMPLETE INTERRUPT - Transmit
complete interrupt enable
Modified bits of UCAxCTL1 register and bits of UCAxIE register.
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 135
Returns
None
EUSCI A UART enable()
void EUSCI A UART enable (
uint16 t baseAddress )
Enables the UART block.
This will enable operation of the UART block.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Modified bits are UCSWRST of UCAxCTL1 register.
Returns
None
EUSCI A UART enableInterrupt()
void EUSCI A UART enableInterrupt (
uint16 t baseAddress,
uint8 t mask )
Enables individual UART interrupt sources.
Enables the indicated UART interrupt sources. The interrupt flag is first and then the
corresponding interrupt is enabled. Only the sources that are enabled can be reflected to the
processor interrupt; disabled sources have no effect on the processor. Does not clear interrupt
flags.
Parameters
baseAddress is the base address of the EUSCI A UART module.
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 136
Parameters
mask is the bit mask of the interrupt sources to be enabled. Mask value is the logical
OR of any of the following:
EUSCI A UART RECEIVE INTERRUPT - Receive interrupt
EUSCI A UART TRANSMIT INTERRUPT - Transmit interrupt
EUSCI A UART RECEIVE ERRONEOUSCHAR INTERRUPT - Receive
erroneous-character interrupt enable
EUSCI A UART BREAKCHAR INTERRUPT - Receive break character
interrupt enable
EUSCI A UART STARTBIT INTERRUPT - Start bit received interrupt
enable
EUSCI A UART TRANSMIT COMPLETE INTERRUPT - Transmit
complete interrupt enable
Modified bits of UCAxCTL1 register and bits of UCAxIE register.
Returns
None
EUSCI A UART getInterruptStatus()
uint8 t EUSCI A UART getInterruptStatus (
uint16 t baseAddress,
uint8 t mask )
Gets the current UART interrupt status.
This returns the interrupt status for the UART module based on which flag is passed.
Parameters
baseAddress is the base address of the EUSCI A UART module.
mask is the masked interrupt flag status to be returned. Mask value is the logical OR
of any of the following:
EUSCI A UART RECEIVE INTERRUPT FLAG
EUSCI A UART TRANSMIT INTERRUPT FLAG
EUSCI A UART STARTBIT INTERRUPT FLAG
EUSCI A UART TRANSMIT COMPLETE INTERRUPT FLAG
Modified bits of UCAxIFG register.
Returns
Logical OR of any of the following:
EUSCI A UART RECEIVE INTERRUPT FLAG
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 137
EUSCI A UART TRANSMIT INTERRUPT FLAG
EUSCI A UART STARTBIT INTERRUPT FLAG
EUSCI A UART TRANSMIT COMPLETE INTERRUPT FLAG
indicating the status of the masked flags
EUSCI A UART getReceiveBufferAddress()
uint32 t EUSCI A UART getReceiveBufferAddress (
uint16 t baseAddress )
Returns the address of the RX Buffer of the UART for the DMA module.
Returns the address of the UART RX Buffer. This can be used in conjunction with the DMA to
store the received data directly to memory.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Returns
Address of RX Buffer
EUSCI A UART getTransmitBufferAddress()
uint32 t EUSCI A UART getTransmitBufferAddress (
uint16 t baseAddress )
Returns the address of the TX Buffer of the UART for the DMA module.
Returns the address of the UART TX Buffer. This can be used in conjunction with the DMA to
obtain transmitted data directly from memory.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Returns
Address of TX Buffer
EUSCI A UART init()
bool EUSCI A UART init (
uint16 t baseAddress,
EUSCI A UART initParam param )
Advanced initialization routine for the UART block. The values to be written into the
clockPrescalar, firstModReg, secondModReg and overSampling parameters should be
pre-computed and passed into the initialization function.
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 138
Upon successful initialization of the UART block, this function will have initialized the module, but
the UART block still remains disabled and must be enabled with EUSCI A UART enable(). To
calculate values for clockPrescalar, firstModReg, secondModReg and overSampling please use
the link below.
http://software-dl.ti.com/msp430/msp430 public sw/mcu/msp430/MSP430Baud-
RateConverter/index.html
Parameters
baseAddress is the base address of the EUSCI A UART module.
param is the pointer to struct for initialization.
Modified bits are UCPEN,UCPAR,UCMSB,UC7BIT,UCSPB,UCMODEx and UCSYNC of
UCAxCTL0 register; bits UCSSELx and UCSWRST of UCAxCTL1 register.
Returns
STATUS SUCCESS or STATUS FAIL of the initialization process
References EUSCI A UART initParam::clockPrescalar, EUSCI A UART initParam::firstModReg,
EUSCI A UART initParam::msborLsbFirst, EUSCI A UART initParam::numberofStopBits,
EUSCI A UART initParam::overSampling, EUSCI A UART initParam::parity,
EUSCI A UART initParam::secondModReg, EUSCI A UART initParam::selectClockSource, and
EUSCI A UART initParam::uartMode.
EUSCI A UART queryStatusFlags()
uint8 t EUSCI A UART queryStatusFlags (
uint16 t baseAddress,
uint8 t mask )
Gets the current UART status flags.
This returns the status for the UART module based on which flag is passed.
Parameters
baseAddress is the base address of the EUSCI A UART module.
mask is the masked interrupt flag status to be returned. Mask value is the logical OR
of any of the following:
EUSCI A UART LISTEN ENABLE
EUSCI A UART FRAMING ERROR
EUSCI A UART OVERRUN ERROR
EUSCI A UART PARITY ERROR
EUSCI A UART BREAK DETECT
EUSCI A UART RECEIVE ERROR
EUSCI A UART ADDRESS RECEIVED
EUSCI A UART IDLELINE
EUSCI A UART BUSY
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 139
Modified bits of UCAxSTAT register.
Returns
Logical OR of any of the following:
EUSCI A UART LISTEN ENABLE
EUSCI A UART FRAMING ERROR
EUSCI A UART OVERRUN ERROR
EUSCI A UART PARITY ERROR
EUSCI A UART BREAK DETECT
EUSCI A UART RECEIVE ERROR
EUSCI A UART ADDRESS RECEIVED
EUSCI A UART IDLELINE
EUSCI A UART BUSY
indicating the status of the masked interrupt flags
EUSCI A UART receiveData()
uint8 t EUSCI A UART receiveData (
uint16 t baseAddress )
Receives a byte that has been sent to the UART Module.
This function reads a byte of data from the UART receive data Register.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Modified bits of UCAxRXBUF register.
Returns
Returns the byte received from by the UART module, cast as an uint8 t.
EUSCI A UART resetDormant()
void EUSCI A UART resetDormant (
uint16 t baseAddress )
Re-enables UART module from dormant mode.
Not dormant. All received characters set UCRXIFG.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Modified bits are UCDORM of UCAxCTL1 register.
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 140
Returns
None
EUSCI A UART selectDeglitchTime()
void EUSCI A UART selectDeglitchTime (
uint16 t baseAddress,
uint16 t deglitchTime )
Sets the deglitch time.
Parameters
baseAddress is the base address of the EUSCI A UART module.
deglitchTime is the selected deglitch time Valid values are:
EUSCI A UART DEGLITCH TIME 2ns
EUSCI A UART DEGLITCH TIME 50ns
EUSCI A UART DEGLITCH TIME 100ns
EUSCI A UART DEGLITCH TIME 200ns
Returns
None
EUSCI A UART setDormant()
void EUSCI A UART setDormant (
uint16 t baseAddress )
Sets the UART module in dormant mode.
Puts USCI in sleep mode Only characters that are preceded by an idle-line or with address bit set
UCRXIFG. In UART mode with automatic baud-rate detection, only the combination of a break
and sync field sets UCRXIFG.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Modified bits of UCAxCTL1 register.
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 141
Returns
None
EUSCI A UART transmitAddress()
void EUSCI A UART transmitAddress (
uint16 t baseAddress,
uint8 t transmitAddress )
Transmits the next byte to be transmitted marked as address depending on selected
multiprocessor mode.
Parameters
baseAddress is the base address of the EUSCI A UART module.
transmitAddress is the next byte to be transmitted
Modified bits of UCAxTXBUF register and bits of UCAxCTL1 register.
Returns
None
EUSCI A UART transmitBreak()
void EUSCI A UART transmitBreak (
uint16 t baseAddress )
Transmit break.
Transmits a break with the next write to the transmit buffer. In UART mode with automatic
baud-rate detection, EUSCI A UART AUTOMATICBAUDRATE SYNC(0x55) must be written into
UCAxTXBUF to generate the required break/sync fields. Otherwise, DEFAULT SYNC(0x00) must
be written into the transmit buffer. Also ensures module is ready for transmitting the next data.
Parameters
baseAddress is the base address of the EUSCI A UART module.
Modified bits of UCAxTXBUF register and bits of UCAxCTL1 register.
Returns
None
EUSCI A UART transmitData()
void EUSCI A UART transmitData (
uint16 t baseAddress,
CHAPTER 16. EUSCI UNIVERSAL ASYNCHRONOUS RECEIVER/TRANSMITTER (EUSCI A UART) 142
uint8 t transmitData )
Transmits a byte from the UART Module.Please note that if TX interrupt is disabled, this function
manually polls the TX IFG flag waiting for an indication that it is safe to write to the transmit buffer
and does not time-out.
This function will place the supplied data into UART transmit data register to start transmission
Parameters
baseAddress is the base address of the EUSCI A UART module.
transmitData data to be transmitted from the UART module
Modified bits of UCAxTXBUF register.
Returns
None
16.3 Programming Example
The following example shows how to use the EUSI UART API to initialize the EUSI UART,
transmit characters, and receive characters.
// Configure UART
EUSCI A UART initParam param = {0};
param.selectClockSource = EUSCI A UART CLOCKSOURCE ACLK;
param.clockPrescalar = 15;
param.firstModReg = 0;
param.secondModReg = 68;
param.parity = EUSCI A UART NO PARITY;
param.msborLsbFirst = EUSCI A UART LSB FIRST;
param.numberofStopBits = EUSCI A UART ONE STOP BIT;
param.uartMode = EUSCI A UART MODE;
param.overSampling = EUSCI A UART LOW FREQUENCY BAUDRATE GENERATION;
if (STATUS FAIL == EUSCI A UART init(EUSCI A0 BASE, &param)) {
return;
}
EUSCI A UART enable(EUSCI A0 BASE);
// Enable USCI A0 RX interrupt
EUSCI A UART enableInterrupt(EUSCI A0 BASE,
EUSCI A UART RECEIVE INTERRUPT);
CHAPTER 17. EUSCI SYNCHRONOUS PERIPHERAL INTERFACE (EUSCI A SPI) 143
17 EUSCI Synchronous Peripheral Interface
(EUSCI A SPI)
Introduction .............................................................................................143
API Functions ..........................................................................................143
Programming Example ..................................................................................152
17.1 Introduction
The Serial Peripheral Interface Bus or SPI bus is a synchronous serial data link standard named
by Motorola that operates in full duplex mode. Devices communicate in master/slave mode where
the master device initiates the data frame.
This library provides the API for handling a SPI communication using EUSCI.
The SPI module can be configured as either a master or a slave device.
The SPI module also includes a programmable bit rate clock divider and prescaler to generate the
output serial clock derived from the module's input clock.
17.2 Functions
Functions
void EUSCI A SPI initMaster (uint16 t baseAddress, EUSCI A SPI initMasterParam param)
Initializes the SPI Master block.
void EUSCI A SPI select4PinFunctionality (uint16 t baseAddress, uint16 t
select4PinFunctionality)
Selects 4Pin Functionality.
void EUSCI