Table Of ContentEmbedded
Systems Design
Using the MSP430FR2355 LaunchPad™
Brock J. LaMeres
E S D
MBEDDED YSTEMS ESIGN
MSP430FR2355
USING THE
™
L P
AUNCH AD
E S D
MBEDDED YSTEMS ESIGN
MSP430FR2355
USING THE
™
L P
AUNCH AD
Brock J. LaMeres
Editor
BrockJ.LaMeres
Bozeman,MT,USA
ISBN978-3-030-40573-1 ISBN978-3-030-40574-8(eBook)
https://doi.org/10.1007/978-3-030-40574-8
#SpringerNatureSwitzerlandAG2020
Thisworkissubjecttocopyright.AllrightsarereservedbythePublisher,whetherthewholeorpartofthematerialis
concerned,specificallytherightsoftranslation,reprinting,reuseofillustrations,recitation,broadcasting,reproduction
on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic
adaptation,computersoftware,orbysimilarordissimilarmethodologynowknownorhereafterdeveloped.
Theuseofgeneraldescriptivenames,registerednames,trademarks,servicemarks,etc.inthispublicationdoesnot
imply,evenintheabsenceofaspecificstatement,thatsuchnamesareexemptfromtherelevantprotectivelawsand
regulationsandthereforefreeforgeneraluse.
Thepublisher,theauthorsandtheeditorsaresafetoassumethattheadviceandinformationinthisbookarebelieved
tobetrueandaccurateatthedateofpublication.Neitherthepublishernortheauthorsortheeditorsgiveawarranty,
expressedorimplied,withrespecttothematerialcontainedhereinorforanyerrorsoromissionsthatmayhavebeen
made.Thepublisherremainsneutralwithregardtojurisdictionalclaimsinpublishedmapsandinstitutionalaffiliations.
ThisSpringerimprintispublishedbytheregisteredcompanySpringerNatureSwitzerlandAG
Theregisteredcompanyaddressis:Gewerbestrasse11,6330Cham,Switzerland
Preface
Why Another Book on Embedded Systems?
Embedded computers representone of themost pervasive technologies of ourtime. Whenmost
peoplethinkofcomputers,theythinkoftheirlaptopsandworkstations,oreventheserversthatarethe
backbone of the internet; however, when one begins to contemplate how many technologies around
themusesmall,inexpensivecomputersembeddedastheir“brains,”onebeginstomorefullyunderstand
themagnitudeofhowmanyembeddedcomputersexistinoursociety.Ifyoulookaroundanyroom,you
willseetechnologythatissocommonplace,youmaynotevenrealizethatmostofitisrunbyaninternal
computer. Technologies such as appliances, thermostats, handheld devices, projectors, televisions,
personal assistants, and radios all have small computers within them that control their operation. As
onestartstonoticealloftheembeddedcomputersaroundthem,theywillquicklynoticethatthereare
ordersofmagnitudemoreembeddedcomputersthanthestandardgeneral-purposecomputersthatrun
Windows®oriOS™.AsthesetechnologiesbecomesmarterandareWi-Ficonnected,wemoveintoan
eracalled theInternet ofThings. Thisnexttechnologicalparadigm shift will turnallof theembedded
computers into a collaborative network in an attempt to make our lives better by automating taking
mundanetasks.
Simultaneous to the exponential increase in embedded computers in our society is the need for
engineersandsoftwaredevelopersthatcanbuildandprogramthesesystems.Duetothehighpopularity
of embedded computers, there is also a wide range of embedded computer platforms. As such, the
textbooks that exist to aid in the education of embedded computers are somewhat fragmented.
Textbooks for embedded computers are not able to be written at only the theoretical level such as
circuitsandelectronicstextbooks.Instead,theymustidentifyacomputerplatformandfocusthecontent
onthat specific embeddedcomputer technology. Thisleadsto a largenumberof embeddedsystems
bookstosupportthelargenumberofembeddedplatforms.Thisalsoleadstobooksbecomingobsolete
muchfasterthantraditionalengineeringtextbooks.
Onereasonforanewbookinthisareaiscreatingcomprehensivecontentaroundawidelypopular
embeddedcomputer,theTexasInstrumentsMSP430.TheMSP430isamoderncomputerplatformthat
ismatureinthemarketandhasagreatdealoftechnicalandeducationalsupportbehindit.Thismeans
thatthisplatformwillberelevantandsupportedforatleastthenext10–15years.
Thesecondreasonforanewbookinthisareaistoprovidecontentthewaypeopleactuallylearn
(i.e., by doing). Current embedded systems books, even those targeting the MSP430, tend to only
providesmallcodesegmentsthatcannotbedirectlyrunonatargetplatform.Thisnewbookapproaches
contentdeliveryaroundthemodelthatthereaderissittingatacomputerwithanMSP430pluggedinand
runningeachoftheexamplesastheymovethroughthebook.Thislearn-a-little,do-a-littleisaproven
pedagogical strategy. It also supports both active learning within the classroom and self-regulated
learningforindividualreaders.
The third reason for a new book in this area is to provide a seamless delivery of both assembly
languageandClanguageprogrammingoftheMSP430.Mostembeddedsystemsbooksarestructured
inoneofthethreeways:(1)theyonlycoverassembly;(2)theyonlycoverC;(3)theyattempttocover
bothbutdonotprovidesufficientdetailsofeither.Thisnewbookwillbegininassemblylanguageasa
meanstoshowthelower-leveloperationofthecomputerhardware.ItwillthenmoveintoCtoimplement
morecomplexsystemsthat requireabstractingthelower-levelhardware.Withthedesignof thebook
consisting of examples in both languages that can be directly coded and ran, there will not be a void
betweentheexamplesandrealimplementationoftheconceptsasseeninotherbooks.
v
vi (cid:129) Preface
Thethreeguidingprinciplesforthedesignofthisbookare:
Learn by Example This book is designed to teach the material the way it is learned, through
example. Every concept covered in this book is supported by numerous programming examples that
provide the reader with a step-by-step explanation for how and why the computer is doing what it is
doing.
LearnbyDoing ThisbooktargetstheTexasInstrumentsMSP430microcontroller.Thisplatformisa
widelypopular,low-costembeddedsystemthatisusedtoillustrateeachconceptinthebook.Thebook
isdesignedforareaderthatisattheircomputerwiththeMSP430pluggedinsothateachexamplecan
becodedandranastheylearn.
BuildaFoundationalUnderstandingFirst,ThenMoveintoAbstraction Thisbookteaches
the basic operation of an embedded computer using assembly language first so that the computer
operation can be explored at a low-level. Once more complicated systems are introduced (i.e., serial
communication and analog-to-digital converters), the book moves into the C programming language.
Moving to C allows the learner to abstract the operation of the lower-level hardware and focus on
understandinghowto“makethingswork.”Byspendingtimeinassemblytounderstandtheunderlying
hardware,thetransitiontoCcanhappenmorerapidlywhilestillleavingthereaderwithafoundational
understandingoftheunderlyinghardware.
Ifthislearningmodelisfollowed,thereaderwillcomeawaywithmuchmorethanknowledgeoffacts
andfigures,butaskillsetandexperiencewithembeddedsystemsthatwillbebothmarketableandof
keyimportancetooursociety.
How to Use This Book
Thisbook isthemost effectivewhenthereader hastheTexasInstrumentsInc. MSP430FR2355
LaunchPad™DevelopmentKitandcodesalongwiththematerial.Allexamplescanbedirectlyrunon
theLaunchPad™board.AllprogramswerecreatedandcompiledusingtheTexasInstrumentsInc.Code
ComposerStudio(CCS).ThisdevelopmentenvironmentisfreefromTexasInstrumentsandcanberun
onmultipleoperatingsystems.Eachoftheexamplesnotedwithakeyboardareonesthatareintendedto
becodedinCCSandrunontheLaunchPad™board.
TherearethreesupportingdocumentsthatshouldalsobedownloadedfromTexasInstrumentsto
provide background for the material in this book. The first is the MSP430FR4xx and MSP430FR2xx
Family User’s Guide [1]. This document gives the general concept of operation for the MSP430
architecture that is used on the specific microcontroller targeted in this book. Throughout this book,
this document is referred to as the “MSP430 User’s Guide.” The second document that should be
retrievedistheMSP430FR235x,MSP430FR215xMixed-SignalMicrocontrollersDevice-SpecificData
Sheet [2]. This second document provides the specific details of the MSP430FR2355 microcontroller
devicethatisusedineachexample.Throughoutthisbook,thisdocumentisreferredtoasthe“Device-
SpecificDataSheet.”ThefinaldocumentthatshouldberetrievedistheMSP430FR235xLaunchPad™
DevelopmentKitUser’sGuide[3].ThisdocumentdescribesthecircuitryimplementedontheLaunch-
Pad™ board. This document is critical to understanding the types of input/output and programming
capabilitythatareavailableontheLaunchPad™board.
Additional Resources
Supportingvideoswillbepostedtotheauthor’sYouTubechannel,whichcanbefoundat:https://
www.youtube.com/c/DigitalLogicProgramming_LaMeres. This channel contains many other videos
Preface (cid:129) vii
beyond embedded systems to help people learn digital logic, basic programming, and robotics. Sub-
scribetothischannelinordertobenotifiedwhennewvideosforthisbookareposted.
Bozeman,MT,USA BrockJ.LaMeres
References
1.TexasInstrumentsInc.(2019)MSP430FR4xxandMSP430FR2xxFamilyUser’sGuide,LiteratureNumber:
SLAU445I, October 2014 – Revised March 2019. Retrieved from: https://www.ti.com/lit/ug/slau445i/
slau445i.pdf
2. Texas Instruments Inc. (2019) MSP430FR235x, MSP430FR215x Mixed-Signal Microcontrollers [device-
specificdatasheet],LiteratureNumber:SLASEC4D,May2018–RevisedDecember2019.Retrievedfrom:
https://www.ti.com/lit/ds/symlink/msp430fr2355.pdf
3. Texas Instruments Inc. (2019) MSP430FR235x LaunchPad™ Development Kit User’s Guide, Literature
Number:SLAU680,May2018.Retrievedfrom:https://www.ti.com/lit/ug/slau680/slau680.pdf
Acknowledgements
Thisbookwouldnotbepossiblewithouttheendlesssupportofmyfamily.ToJoAnn,youarethe
heartofmylifeandIamsothankfultobeonthisjourneywithyou.ToAlexis,yourkindnessand
warmthbringsjoytotheworld.ToKylie,youfilltheworldwithhappinessbecauseofwhoyouare.
I would also like to thank the students at Montana State University for helping guide the
developmentofthisbookandforproofreadingtheearlyversions.GoBobcats!
ix
Contents
1:INTRODUCTIONTOEMBEDDEDSYSTEMS....................................................... 1
1.1 WHATISANEMBEDDEDSYSTEM?............................................................................... 1
REFERENCES.................................................................................................................... 5
2:DIGITALLOGICBASICS........................................................................................ 7
2.1 NUMBERSYSTEMS.................................................................................................... 7
2.1.1 PositionalNumberSystems.......................................................................... 7
2.1.2 BaseConversion........................................................................................... 11
2.1.3 BinaryArithmetic............................................................................................ 20
2.1.4 UnsignedandSignedNumbers.................................................................... 23
2.2 COMBINATIONALLOGIC............................................................................................... 31
2.2.1 BasicGates.................................................................................................... 31
2.2.2 BooleanAlgebra............................................................................................ 34
2.2.3 CombinationalLogicSynthesis..................................................................... 36
2.2.4 MSILogic....................................................................................................... 59
2.3 SEQUENTIALLOGIC................................................................................................... 74
2.3.1 SequentialLogicStorageDevices................................................................ 74
2.3.2 FiniteStateMachines.................................................................................... 90
2.4 MEMORY.................................................................................................................. 110
2.4.1 MemoryTerminology..................................................................................... 110
2.4.2 MemoryArchitecture...................................................................................... 112
2.4.3 MemoryTechnologies.................................................................................... 117
REFERENCE..................................................................................................................... 127
3:COMPUTERSYSTEMS.......................................................................................... 129
3.1 COMPUTEROVERVIEW............................................................................................... 129
3.2 COMPUTERHARDWARE.............................................................................................. 130
3.2.1 ProgramMemory........................................................................................... 130
3.2.2 DataMemory................................................................................................. 131
3.2.3 CentralProcessingUnit................................................................................. 131
3.2.4 Input/OutputPorts.......................................................................................... 133
3.2.5 BusSystem.................................................................................................... 133
3.3 COMPUTERSOFTWARE.............................................................................................. 134
3.3.1 ClassesofInstructions.................................................................................. 135
3.3.2 Op-codesandOperands............................................................................... 135
3.3.3 ProgramDevelopmentFlow.......................................................................... 138
REFERENCES.................................................................................................................... 141
4:THEMSP430........................................................................................................... 143
4.1 MSP430HARDWAREOVERVIEW................................................................................ 143
4.1.1 WordVs.ByteMemoryAccess..................................................................... 144
4.1.2 ProgramMemory........................................................................................... 145
xi
xii (cid:129) Contents
4.1.3 DataMemory................................................................................................. 145
4.1.4 CentralProcessingUnit................................................................................. 145
4.1.5 Input/OutputPorts&Peripherals................................................................... 147
4.1.6 BusSystem.................................................................................................... 149
4.1.7 MSP430PartNumbering............................................................................... 150
4.2 MSP430SOFTWAREOVERVIEW................................................................................ 151
4.2.1 TheMSP430InstructionSet.......................................................................... 151
4.2.2 Word(.W)Vs.Byte(.B)Operations.............................................................. 153
4.2.3 TheTICodeComposerStudioDevelopmentEnvironment......................... 154
4.3 MSP430FR2355LAUNCHPAD-™DEVELOPMENTKIT................................................. 156
REFERENCES.................................................................................................................... 161
5:GETTINGSTARTEDPROGRAMMINGTHEMSP430INASSEMBLY.................. 163
5.1 THEANATOMYOFANASSEMBLYPROGRAMFILED......................................................... 163
5.1.1 InstructionStatements................................................................................... 163
5.1.2 AssemblerDirectives..................................................................................... 164
5.1.3 MiscellaneousSyntaxNotes......................................................................... 167
5.2 YOURFIRSTPROGRAM:BLINKINGLED....................................................................... 167
5.3 USINGTHECCSDEBUGGER...................................................................................... 171
5.3.1 Resume,Terminate,andSuspend................................................................ 171
5.3.2 Breakpoints.................................................................................................... 172
5.3.3 ViewingRegisterContents............................................................................ 173
5.3.4 ViewingtheContentsofMemory.................................................................. 175
5.3.5 SteppingYourProgram................................................................................. 175
REFERENCES.................................................................................................................... 178
6:DATAMOVEMENTINSTRUCTIONS...................................................................... 179
6.1 THEMOVINSTRUCTIONWITHREGISTERMODE(RN)ADDRESSING................................. 179
6.2 THEMOVINSTRUCTIONWITHIMMEDIATEMODE(#N)ADDRESSING................................. 181
6.3 THEMOVINSTRUCTIONWITHABSOLUTEMODE(&ADDR)ADDRESSING........................ 183
6.4 THEMOVINSTRUCTIONWITHSYMBOLICMODE(ADDR)ADDRESSING........................... 185
6.5 THEMOVINSTRUCTIONWITHINDIRECTREGISTERMODE(@RN)ADDRESSING................ 187
6.6 THEMOVINSTRUCTIONWITHINDIRECTAUTOINCREMENTMODE(@RN+)ADDRESSING..... 189
6.7 THEMOVINSTRUCTIONWITHINDEXEDMODE(X(RN))ADDRESSING.............................. 191
REFERENCE..................................................................................................................... 197
7:DATAMANIPULATIONINSTRUCTIONS............................................................... 199
7.1 ARITHMETICINSTRUCTIONS......................................................................................... 199
7.1.1 AdditionInstructions...................................................................................... 200
7.1.2 SubtractionInstructions................................................................................. 203
7.1.3 IncrementsandDecrements......................................................................... 206
7.2 LOGICINSTRUCTIONS................................................................................................. 207
7.3 BITSETANDBITCLEARINSTRUCTIONS........................................................................ 211
7.4 TESTINSTRUCTIONS.................................................................................................. 212
7.5 ROTATEOPERATIONS................................................................................................. 214
REFERENCE..................................................................................................................... 221