8/20/2019 Introduction to MSP430 microcontrollers
1/32
Introduction to MSP430G2553 and
MPU6050
1
8/20/2019 Introduction to MSP430 microcontrollers
2/32
Outline
• Key Features• PU Introduction• Interru!t
• I"O• loc#• $i%er • &'
• USI
2
8/20/2019 Introduction to MSP430 microcontrollers
3/32
Key (eatures
Ultralo)*!o)er arc+itecture e,tends -attery li(e
. 0/1 & &M retention
. 0/ & real*ti%e cloc# %ode
. 250 &"MIPS actie 16*-it IS PU ena-les ne) a!!lications at a (raction o( t+e code sie/
. are reister (ile eli%inates )or#in (ile -ottlenec# . o%!act core desin reduces !o)er consu%!tion and cost
. O!ti%ied (or %odern +i+*leel !rora%%in
. Only 27 core instructions and seen addressin %odes
. 8,tensie ectored*interru!t ca!a-ility In*syste% !rora%%a-le Flas+916K:; !er%its (le,i-le code c+anes< (ield
u!rades and data loin/
3
8/20/2019 Introduction to MSP430 microcontrollers
4/32
MSP430 &rc+itecture
4
8/20/2019 Introduction to MSP430 microcontrollers
5/32
PU Introduction
• IS arc+itecture )it+ 27 instructions and 7
addressin %odes/• Full reister access includin !rora% counter<
status reisters< and stac# !ointer/• Sinle*cycle reister o!erations/• are 16*-it reister (ile reduces (etc+es to
%e%ory/• 16*-it address -us allo)s direct access and
-ranc+in t+rou+out entire %e%ory rane/• 16*-it data -us allo)s direct %ani!ulation o(
)ord*)ide aru%ents/• onstant enerator !roides si, %ost used
i%%ediate alues and reduces code sie/• 'irect %e%ory*to*%e%ory trans(ers )it+out
inter%ediate reister +oldin/• =ord and -yte addressin and instruction
(or%ats/
5
8/20/2019 Introduction to MSP430 microcontrollers
6/32
27 Core RISC Instructions
6
8/20/2019 Introduction to MSP430 microcontrollers
7/32
3 Instruction Formats
7
8/20/2019 Introduction to MSP430 microcontrollers
8/32
CPU Operating modes
8/20/2019 Introduction to MSP430 microcontrollers
9/32
&re eents a!!lied to t+e a!!lication !rora% t+at (orce a detour
in !rora% (lo)> ause PU su-!rora% e,ecution 9IS;>=+en Interru!t Serice outine 9IS; ends< t+e !rora% (lo)
returns to t+e !reious state/ $+ere are t+ree classes o( interru!ts?
eset/
Interru!ts not %as#a-le -y GI8 )+ic+ cannot -e disa-led -yt+e eneral interru!t ena-le -it 9GI8;< -ut are ena-led -y
indiidual interru!t ena-le -its 9@MII8< &AI8< OFI8;/ Used
(or +i+ !riority eents/ Interru!ts %as#a-le -y GI8 )+ere !eri!+erals )it+ interru!t
ca!a-ility or t+e )atc+do ti%er oer(lo) in interal ti%er
%ode< etc/ an -e s)itc+ed o(( -y so(t)are/
Interrupt
$+e interrupt latency is t+e ti%e -et)een t+e eent -einnin and
t+e IS e,ecution> @or%ally needs 6 cycles
B
8/20/2019 Introduction to MSP430 microcontrollers
10/32
Interrupt vector
11
8/20/2019 Introduction to MSP430 microcontrollers
11/32
8/20/2019 Introduction to MSP430 microcontrollers
12/32
Clock
• &K? &u,iliary cloc#/ &K is diided -y 1< 2< 4< or and is
so(t)are selecta-le (or indiidual !eri!+eral %odules/• MK? Master cloc#/ MK is diided -y 1< 2< 4< or and is
used -y t+e PU and syste%/• SMK? Su-*%ain cloc#/ SMK is diided -y 1< 2< 4< or and
is so(t)are selecta-le (or indiidual !eri!+eral %odules/
13
8/20/2019 Introduction to MSP430 microcontrollers
13/32
Digital IO Introduction
MSP430G2553 +as 2 !orts 9P1 and P2;< eac+ !ort +as u! to ei+t I"O!ins 9P1/0P1/7< P2/0*P2/5;/ 8ery I"O !in is indiidually con(iura-le
(or in!ut or out!ut direction< and eac+ I"O line can -e indiidually read or
)ritten to/
• Inde!endently !rora%%a-le indiidual I"Os
• &ny co%-ination o( in!ut or out!ut• Indiidually con(iura-le P1 and P2 interru!ts• Inde!endent in!ut and out!ut data reisters• Indiidually con(iura-le !ullu! or !ulldo)n resistors
• 'irection eisters P,'I 9P1'ID0,01;• In!ut eister P,I@• Out!ut eisters P,OU$
14
8/20/2019 Introduction to MSP430 microcontrollers
14/32
8/20/2019 Introduction to MSP430 microcontrollers
15/32
!imer
='$ is 16*-it ti%er t+at can -e
used as a )atc+do or as an
interal ti%er/ ='$ %odule
!er(or%s a controlled syste%
restart a(ter a so(t)are !ro-le%
occurs9Four software-selectable time intervals;/
='$ ontrol reister is !ass)ord
!rotected and is Po)ers*u!
actie/
='$$ D ='$P= L ='$O'>
15
8/20/2019 Introduction to MSP430 microcontrollers
16/32
!imer"#
$i%erE& is a 16*-it ti%er"counter )it+ t+ree ca!ture"co%!are reisters
• &sync+ronous 16*-it ti%er"counter )it+ (our o!eratin %odes• Selecta-le and con(iura-le cloc# source• $)o or t+ree con(iura-le ca!ture"co%!are reisters• on(iura-le out!uts )it+ P=M ca!a-ility
16
8/20/2019 Introduction to MSP430 microcontrollers
17/32
17
8/20/2019 Introduction to MSP430 microcontrollers
18/32
!imer control register$!#C!%&
1
8/20/2019 Introduction to MSP430 microcontrollers
19/32
#DC
$+e &'10 %odule su!!orts (ast< 10*-it analo*to*diital conersions/
• 200*#-!s %a,i%u% conersion rate• Sa%!le*and*+old )it+ !rora%%a-le sa%!le !eriods• onersion initiation -y so(t)are or $i%erE&
• So(t)are selecta-le on*c+i! re(erence oltae eneration 91/5 A or 2/5 A;• So(t)are selecta-le internal or e,ternal re(erence• U! to ei+t e,ternal in!ut c+annels• Selecta-le conersion cloc# source• Sinle*c+annel< re!eated sinle*c+annel< seNuence< and re!eated
seNuence conersion %odes
• &' core and re(erence oltae can -e !o)ered do)n se!arately• 'ata trans(er controller (or auto%atic storae o( conersion results
1B
8/20/2019 Introduction to MSP430 microcontrollers
20/32
ere are t+e ste!s you %ust ta#e to !er(or% an &"' o!eration?
•'e(ine t+e !ort !ins t+at )ill -e used as analo in!ut c+annels/ 9I'C();
•Select a cloc# source (or t+e conersion o!eration< or set u! t+e =atc+do
ti%er/9#DC*+SS,%);
•Select a conersion %ode 9e//< continuous< one*ti%e conersion< etc;/
9CO'S,-);
•Select t+e re(erence oltae A8F/ 9SR,F);
•Select t+e sa%!le*and*+old ti%e (or t+e conersion/ 9#DC*+S(!);
•8na-le t+e corres!ondin c+osen !in (or analo in!ut/
•S)itc+ O@ t+e &' (unctionality/ 9#DC*+O';
•8na-le &' 9take a reading;
•ead t+e alue a(ter conersion> set a !rora% aria-le to t+e readin/
#DC operation steps
20
8/20/2019 Introduction to MSP430 microcontrollers
21/32
&'10$1 D I@E3 L O@S8E1> "" &3"&2"&1< sinle seNuence
&'10$0 D &'10O@ L &'10I8> "" &'10O@< interru!t ena-led
&'10&80 JD 0,08> "" P1/1
8/20/2019 Introduction to MSP430 microcontrollers
22/32
USCI I2C .ode
Figure / I2C 0us Connection
Diagram
$+e t)o !ull u! resistor is necessary (or I2 %ode to )or# !ro!erly
22
8/20/2019 Introduction to MSP430 microcontrollers
23/32
8/20/2019 Introduction to MSP430 microcontrollers
24/32
Figure / I2C .odule Data !rans1er
$+e (irst -yte a(ter a S$&$ condition consists o( a 7*-it slae address and t+e
"= -it/ =+en "= D 0< t+e %aster trans%its data to a slae/ =+en "= D 1<
t+e %aster receies data (ro% a slae/ $+e &K -it is sent (ro% t+e receier
a(ter eac+ -yte on t+e Bt+ S cloc#/
I2C data trans1er
24
8/20/2019 Introduction to MSP430 microcontrollers
25/32
void Init"i2c$uint"t dev#ddr&
U:0$1 JD US=S$> "" 8na-le S= reset
U:0$0 D UMS$ L UMO'8E3 L US@> "" I2 Master< sync+ronous %ode
U:0$1 D USS8E2 L US=S$> "" Use SMK< #ee! S= reset U:0:0 D 10> "" (S D 1M+"10 D Q100#
U:0:1 D 0>
P1S8 D :I$6 L :I$7> "" &ssin I2 !ins to USIE:0
P1S82 D :I$6 L :I$7> "" &ssin I2 !ins to USIE:0
U:0I2S& D de&ddr> "" Slae &ddress is 06B+
U:0$1 RD QUS=S$> "" Initialie USI state %ac+ine I82 JD U:0HI8 L U:0$HI8> "" 8na-le H and $H interru!t
I2C initialiation code
25
8/20/2019 Introduction to MSP430 microcontrollers
26/32
USCI U#R! .ode
In async+ronous %ode< t+e USIE&, %odules connect t+e MSP430
to an e,ternal syste% ia t)o e,ternal !ins< U&,H' and
U&,$H'/ U&$ %ode is selected )+en t+e US@ -it is cleared/
In U&$ %ode< t+e USI trans%its and receies c+aracters at a -it
rate async+ronous to anot+er deice/ $i%in (or eac+ c+aracter is
-ased on t+e selected -aud rate o( t+e USI/ $+e trans%it and
receie (unctions use t+e sa%e -aud rate (reNuency/
26
8/20/2019 Introduction to MSP430 microcontrollers
27/32
U#R! initialiation code
void initUart$void&
U&0$1 JD USS8E2> "" Use SMK
U&0:0 D 104> "" 1M B600
U&0:1 D 0> "" 1M B600 U&0M$ D U:S0> "" Modulation U:S, D 1
P1S8 D :I$1 L :I$2 > "" P1/1 D H'< P1/2D$H'
P1S82 D :I$1 L :I$2 > "" P1/1 D H'< P1/2D$H'
U&0$1 RD QUS=S$> "" Initialie USI state %ac+ine
I82 JD U&0$HI8>
27
8/20/2019 Introduction to MSP430 microcontrollers
28/32
• SPI %ode (eatures include?• 7*-it or *-it data lent+• 3*!in and 4*!in SPI o!eration• Master or slae %odes
• Inde!endent trans%it and receie s+i(t reisters• Se!arate trans%it and receie -u((er reisters• Selecta-le UK !olarity and !+ase control• Prora%%a-le UK (reNuency in %aster %ode• Inde!endent interru!t ca!a-ility (or receie and trans%it
USCI SPI .ode
2
8/20/2019 Introduction to MSP430 microcontrollers
29/32
2B
USCI SPI .ode
8/20/2019 Introduction to MSP430 microcontrollers
30/32
SPI e)ample code
30
P1S8 D :I$1 L :I$2 L :I$4>P1S82 D :I$1 L :I$2 L :I$4>
U&0$0 JD UKP L UMS: L UMS$ L US@>
U&0$1 JD USS8E2>
U&0:0 JD 0,02>
U&0:1 D 0>
U&0$1 RD QUS=S$>I82 JD U&0HI8>
8/20/2019 Introduction to MSP430 microcontrollers
31/32
MPU6050
MPU6050? Gyrosco!e L &ccelero%eter
T2< T4< T and T16
T250< T500< T1000< and T2000"sec
A and G@' (or !o)er su!!ly?3*5
S and S'& (or I2 co%%unication )it+ MSP430
H and H'& to connect %anetic sensor
e(erence ? MSP430 ,2,, user uide
MPU6050 datas+eet and reister (ile
8/20/2019 Introduction to MSP430 microcontrollers
32/32
https://estore.ti.com/MSP-EXP43!"-MSP43-#aunchPa$-%alue-#ine-&evelopment-'it-P"3(.asp)
http://www.eba*.com/itm/MP+-,-3-)is-ccelerometer-Sensor-!*roscope-,&F-Mo$ule-3-3%-%-For-r$uino-/(,((041"4142
pt#5&efault&omain56hashitem"0"$0ce
MSP430G2 $9.99
MPU6050 $5.75
!ere t" #%