0% found this document useful (0 votes)
411 views59 pages

MSP432 Chapter2 v1

MsP432 interfacing

Uploaded by

Akshat Tulsani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
411 views59 pages

MSP432 Chapter2 v1

MsP432 interfacing

Uploaded by

Akshat Tulsani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

Chapter 2

MSP432 ARM I/O Programming

1
Chapter Review

• Section 2.1: MSP432 Microcontroller and LaunchPad


• Section 2.2: GPIO (General Purpose I/O) Programming and Interfacing
• Section 2.3: Seven-segment LED interfacing and programming
• Section 2.4: I/O Port Programming in Assembly
• Section 2.5:16-BIT I/O ports in MSP432
• Section 2.6: Port Mapping Controller
2
MSP432P401R Main Features

ARM® Cortex™-M4 processor


100-pin microcontroller chip
256K bytes (256KB) of on-chip Flash memory for code
64KB of on-chip SRAM for data
large number of on-chip peripherals
3
TI MSP432P401R Microcontroller High-Level
Block Diagram

4
Memory Map in MSP432401P401R

Allocated size Allocated address


Flas
256KB 0x0000 0000 to 0x0003 FFFF
h
SRA
64KB 0x2000 0000 to 0x2000 FFFF
M
I/O All the peripherals 0x4000 0000 to 0x4001 FFFF

5
TI's naming convention for MSP432

6
TI's naming convention for MSP432 (Cont.)

Processor Family MSP = Mixed Signal Processor


XMS = Experimental Silicon
432 MCU Platform TI’s 32-bit Low-Power Microcontroller Platform
Series P = Performance and Low-Power Series
Feature Set First Digit Second Digit Third Digit Fourth Digit
4 = Flash based devices 0 = General 1 = ADC14 R = 256KB of Flash
up to 48 MHz Purpose 64KB of SRAM
M = 128KB of Flash
32KB of SRAM
Optional: S = 0°C to 50 °C
Temperature Range I = 40 °C to 85 °C
T = –40 °C to 105 °C
Packaging PZ = LQFP

7
Memory zones in MS432

8
History and Features of MSP432

• TI used the venerable 8051 microcontroller for their mixed signal processors
• TI came up with MSP430 chip Due to the need for low power chip and 8051
limitations
• MSP stands for Mixed Signal Processor
• The MSP430 is a 16-bit RISC CPU designed and marketed exclusively by TI
• In 2015, TI introduced an ARM-based device to the MSP430 Family and
called it MSP432
9
History and Features of MSP432 (Cont.)

10
Section 2.2: GPIO (General Purpose I/O)
Programming and Interfacing

• In the microcontroller, we have two types of I/O:


a.General Purpose I/O (GPIO): The GPIO ports are used for interfacing devices
such as LEDs, switches, LCD, keypad, and so on.
• Special purpose I/O: These I/O ports have designated function such as ADC
(Analog-to-Digital), Timer, UART (universal asynchronous receiver
transmitter), and so on.

11
GPIO

• The GPIO ports in MSP432 are designated as port P1 to P10 + PJ


• P1 to P10 are also referred as the Simple I/O or Digital I/O ports
• port J has special function such as external crystal oscillator and JTAG
connections
• The base address of I/O port is 0x4000 4C00
12
GPIO Offset Addresses

 GPIO P1 : 0x4000 4C00 + 0 (even addresses)


 GPIO P2 : 0x4000 4C00 + 1 (odd addresses)
 GPIO P3 : 0x4000 4C00 + 20 (even addresses)
 GPIO P4 : 0x4000 4C00 + 21 (odd addresses)
 GPIO P5 : 0x4000 4C00 + 40 (even addresses)
 GPIO P6 : 0x4000 4C00 + 41 (odd addresses)
 GPIO P7 : 0x4000 4C00 + 60 (even addresses)
 GPIO P8 : 0x4000 4C00 + 61 (odd addresses)
 GPIO P9 : 0x4000 4C00 + 80 (even addresses)
 GPIO P10 : 0x4000 4C00 + 81 (odd addresses)

13
I/O Pins in MSP432 LaunchPad board

• I/O ports are named with numbers P1, P2, P3, and so on
• The pins are designated as P1.0-P1.7, P2.0-P2.7, P3.0-P3.7, and so on
• The MSP432P401R has Ports P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 and
PJ
• P10 and PJ have only 6 pins while all other ports have 8 pins
• we can combine two 8-bit ports to come up with 16-bit port
14
MSP432P401R 100-pin package pin-out

15
Direction and Data Registers

• Generally every microcontroller has minimum of three registers associated


with each of GPIO port
• Data IN, Data Out, and Direction
• The Direction register is used to make the pin either input or output
• we use the Data register to actually write to the pin (PxOUT) or read data
from the pin (PxIN)

16
The Data and Direction Registers and a
Simplified View of an I/O pin

17
Direction Register in MSP432 ARM

• each of the Direction register bit needs to be a 0 to configure the port pin as
input and a 1 as output

• For example, by writing 0x03 (0b00000011 in binary) into the P1DIR register,
pins 0 and 1 of P1 become outputs while the other pins become inputs.

18
Port Data Output Register (PxOUT) in MSP432
ARM

• To send data to pins, we write it to PxOUT register after the pin is


configured as an output in the PxDIR register

• For example, by writing 0x03 into the P1DIR register and 0x02 in P1OUT
register, pin 0 of P1 become 0 while pin 1 of P1 become 1.

19
Port Data Input Register (PxIN) in MSP432
ARM

• To bring into CPU data from a pin, we read it from PxIN register after the pin
is configured as an input in the PxDIR register

20
Some commonly Used Registers of PORT1

Address Name Description Type Reset Value


0x4000 4C00 P1IN Port1 Input Register R 0b00000000
0x4000 4C02 P1OUT Port1 Output Register R/W 0b00000000
0x4000 4C04 P1DIR Port1Direction Register R/W 0b00000000
0x4000 4C06 P1REN Port1 Resistor Enable Register R/W 0b00000000
0x4000 4C08 P1DS Port1 Drive Strength Register R/W 0b00000000
0x4000 4C0A P1SEL0 Port1Select 0 Register R/W 0b00000000
0x4000 4C0C P1SEL1 Port1Select 1 Register R/W 0b00000000

21
Some commonly Used Registers of PORT2

Address Name Description Type Reset Value


0x4000 4C01 P2IN Port2 Input Register R 0b00000000
0x4000 4C03 P2OUT Port2 Output Register R/W 0b00000000
0x4000 4C05 P2DIR Port2 Direction Register R/W 0b00000000
0x4000 4C07 P2REN Port2 Resistor Enable Register R/W 0b00000000
0x4000 4C09 P2DS Port2 Drive Strength Register R/W 0b00000000
0x4000 4C0B P2SEL0 Port2 Select 0 Register R/W 0b00000000
0x4000 4C0D P2SEL1 Port2 Select 1 Register R/W 0b00000000

22
Some commonly Used Registers for PORT3

Address Name Description Type Reset Value


0x4000 4C20 P3IN Port3 Input Register R 0b00000000
0x4000 4C22 P3OUT Port3 Output Register R/W 0b00000000
0x4000 4C24 P3DIR Port3 Direction Register R/W 0b00000000
0x4000 4C26 P3REN Port3 Resistor Enable Register R/W 0b00000000
0x4000 4C28 P3DS Port3 Drive Strength Register R/W 0b00000000
0x4000 4C2A P3SEL0 Port3 Select 0 Register R/W 0b00000000
0x4000 4C2C P3SEL1 Port3 Select 1 Register R/W 0b00000000

23
Some commonly Used Registers of PORT4

Address Name Description Type Reset Value


0x4000 4C21 P4IN Port4 Input Register R 0b00000000
0x4000 4C23 P4OUT Port4 Output Register R/W 0b00000000
0x4000 4C25 P4DIR Port4 Direction Register R/W 0b00000000
0x4000 4C27 P4REN Port4 Resistor Enable Register R/W 0b00000000
0x4000 4C29 P4DS Port4 Drive Strength Register R/W 0b00000000
0x4000 4C2B P4SEL0 Port4 Select 0 Register R/W 0b00000000
0x4000 4C2D P4SEL1 Port4 Select 1 Register R/W 0b00000000

24
Port Pull-up or Pull-down Resistor Enable
Register (PxREN) in MSP432 ARM
• When a pin is configured as an input pin, you may enable the built-in pull-up or pull-
down resistor attached to that pin
• To enable the pull resistor, you need to set the corresponding bit in the PxREN
register of that port

• Pull-up or pull-down resistor is only used when the pin is configured as an input pin
25
Example

• Find the value for P2DIR, P2OUT, and P2REN to configure the P2 pins as
inputs. Pull down P2.0 and pull up P2.1.
• Solution:
P2DIR = 0b00000000 = 0x00
P2REN = 0b00000011 = 0x03
P2OUT = 0b00000010 = 0x02

26
Alternate pin functions and the simple GPIO

• Each pin of the MSP432 ARM chip can be used for one of several functions
• The function associated with a pin is chosen by programming PxSEL1 and PxSEL0
function selection registers
• For example, a given pin can be used as simple digital I/O (GPIO), analog input, or
I2C pin
• Using a single pin for multiple functions is called pin multiplexing
• In the absence of pin multiplexing, a microcontroller will need many more pins to
support all of its on-chip features.
27
Alternate pin functions and the simple GPIO
(Cont.)

• The PxSEL1 and PxSEL0 (Portx Selection 1 and 0 function selection)


registers allow us to program a pin to be used for a given alternate function
• Upon reset, ports 1 to 10 are configured for simple I/O. At any given
situation
• To use a pin as simple digital I/O, we must choose PxSEL1:PxSEL0=00
option

28
Alternate pin functions and the simple GPIO
(Cont.)

29
Alternate pin functions and the simple GPIO
(Cont.)

• Upon power-on reset, the default selection is Simple I/O (PxSEL1:PXSEL0 =


00) for all pins
• For option PxSEL1:PXSEL0 = 01, the pins may have alternate functions of
UART, SPI, and I2C, timers, and so on
• For option 2, some of the alternate functions are associated with timers
• The analog functions ADC and comparators use alternate function 3
30
Alternate pin functions and the simple GPIO
(Cont.)

PxSEL1 PxSEL0 Meaning


.y .y
0 0 Alternative 0 (Default) Simple I/O
0 1 Alternative 1 (UART, SPI, I2C, …)
1 0 Alternative 2 (Timers, …)
1 1 Alternative 3 (ADC, Comparator, …)

31
MSP432 Port1 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P1.0 Simple I/O UCA0STE - -
P1.1 Simple I/O UCA0CLK - -
P1.2 Simple I/O UCA0RXD/UCA0SOMI - -
P1.3 Simple I/O UCA0TXD/UCA0SIMO - -
P1.4 Simple I/O UCB0STE - -
P1.5 Simple I/O UCB0CLK - -
P1.6 Simple I/O UCB0SIMO/UCB0SDA - -
P1.7 Simple I/O UCB0SOMI/UCB0SCL - -

32
MSP432 Port2 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P2.0 Simple I/O PM_UCA1STE - -
P2.1 Simple I/O PM_UCA1CLK - -
PM_UCA1RXD/
P2.2 Simple I/O - -
PM_UCA1SOMI
PM_UCA1TXD/
P2.3 Simple I/O - -
PM_UCA1SIMO
P2.4 Simple I/O PM_TA0.1 - -
P2.5 Simple I/O PM_TA0.2 - -
P2.6 Simple I/O PM_TA0.3 - -
P2.7 Simple I/O PM_TA0.4 - -
33
MSP432 Port3 Alternative Pin Functions
Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11
P3.0 Simple I/O PM_UCA2STE - -
P3.1 Simple I/O PM_UCA2CLK - -
PM_UCA2RXD/
P3.2 Simple I/O - -
PM_UCA2SOMI
PM_UCA2TXD/
P3.3 Simple I/O - -
PM_UCA2SIMO
P3.4 Simple I/O PM_UCB2STE - -
P3.5 Simple I/O PM_UCB2CLK - -
PM_UCB2SIMO/
P3.6 Simple I/O - -
PM_UCB2SDA
PM_UCB2SOMI/
P3.7 Simple I/O - -
PM_UCB2SCL
34
MSP432 Port4 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P4.0 Simple I/O - - A13
P4.1 Simple I/O - - A12
P4.2 Simple I/O ACLK TA2CLK A11
P4.3 Simple I/O MCLK RTCCLK A10
P4.4 Simple I/O HSMCLK SVMHOUT A9
P4.5 Simple I/O - - A8
P4.6 Simple I/O - - A7
P4.7 Simple I/O - - A6

35
MSP432 Port5 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P5.0 Simple I/O - - A5
P5.1 Simple I/O - - A4
P5.2 Simple I/O - - A3
P5.3 Simple I/O - - A2
P5.4 Simple I/O - - A1
P5.5 Simple I/O - - A0
P5.6 Simple I/O TA2.1 - VREF+/VeREF+/C1.7
P5.7 Simple I/O TA2.2 - VREF-/VeREF-/C1.6

36
MSP432 Port6 Alternative Pin Functions
Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11
P6.0 Simple I/O - - A15
P6.1 Simple I/O - - A14
P6.2 Simple I/O UCB1STE - C1.5
P6.3 Simple I/O UCB1CLK - C1.4
UCB1SIMO/
P6.4 Simple I/O - C1.3
UCB1SDA
UCB1SOMI/
P6.5 Simple I/O - C1.2
UCB1SCL
UCB3SIMO/
P6.6 Simple I/O TA2.3 C1.1
UCB3SDA
UCB3SOMI/
P6.7 Simple I/O TA2.4 C1.0
UCB3SCL
37
MSP432 Port7 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


PM_SMCLK/
P7.0 Simple I/O - -
PM_DMAE0
PM_C0OUT/
P7.1 Simple I/O - -
PM_TA0CLK
PM_C1OUT/
P7.2 Simple I/O - -
PM_TA1CLK
P7.3 Simple I/O PM_TA0.0 - -
P7.4 Simple I/O PM_TA1.4 - C0.5
P7.5 Simple I/O PM_TA1.3 - C0.4
P7.6 Simple I/O PM_TA1.2 - C0.3
P7.7 Simple I/O PM_TA1.1 - C0.2

38
MSP432 Port8 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P8.0 UCB3STE TA1.0 C0.1
P8.1 UCB3CLK TA2.0 C0.0
P8.2 TA3.2 C0.0
P8.3 TA3CLK A22
P8.4 A21
P8.5 A20
P8.6 A19
P8.7 A18

39
MSP432 Port9 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P9.0 A17
P9.1 A16
P9.2 TA3.3
P9.3 TA3.4
P9.4 UCA3STE
P9.5 UCA3CLK
UCA3RXD/
P9.6
UCA3SOMI
UCA3TXD/
P9.7
UCA3SIMO

40
MSP432 Port10 Alternative Pin Functions

Pin Name SEL = 00 SEL = 01 SEL = 10 SEL = 11


P10.0 UCB3STE
P10.1 UCB3CLK
UCB3SIMO/
P10.2
UCB3SDA
UCB3SOMI/
P10.3
UCB3SCL
P10.4 TA3.0 C0.7
P10.5 TA3.1 C0.6

41
LED connection in MSP432 LaunchPad board

• In the MSP432 LaunchPad board, we have a tri-color RGB LED connected to


P2.0 (red), P2.1 (green), and P2.2 (blue)

42
Toggling LEDs in MSP432 LaunchPad board in
C
1. Configure P2.1 (P2SEL1:P2SEL0 Register) to select simple GPIO function for P2.1,
2. set the Direction register bit 1of P2DIR as output,
3. write HIGH to bit 1 of P2OUT register to turn on the green LED,
4. call a delay function,
5. write LOW to bit 1 of P2OUT register to turn off the green LED,
6. call a delay function,
7. Repeat steps 3 to 7.
43
Toggling green LED on MSP432 LaunchPad in
C (C Code)
int main(void) {
P2->SEL1 &= ~2; /* configure P2.1 as simple I/O */
P2->SEL0 &= ~2;
P2->DIR |= 2; /* P2.1 set as output pin */

while (1) {
P2->OUT |= 2; /* turn on P2.1 green LED */
delayMs(500);
P2->OUT &= ~2; /* turn off P2.1 green LED */
delayMs(500);
}
}

44
Toggling all three LEDs on MSP432 LaunchPad
board (C Code)
int main(void) {
P2->SEL1 &= ~7; /* configure P2.2-P2.0 as simple I/O */
P2->SEL0 &= ~7;

P2->DIR |= 7; /* P2.2-2.0 set as output */


P2->OUT |= 7; /* turn all three LEDs on */

while (1) {
P2->OUT ^= 7; /* toggle P2.2-P2.0 all three LEDs */
delayMs(500);
}
}

45
CPU clock frequency and time delay

• Usually microcontrollers have at least two types of clock source: the on-chip
oscillator and the oscillator connected to external crystal
• The advantage of the external crystal oscillator is the higher precision
• The advantage of the on-chip oscillator is that it is always there
• The clock from the source may be modified by a divider to reduce the clock
rate or use a phase lock loop (PLL) circuit to produce a wider range of clock
rates
46
CPU clock frequency and time delay in
MSP432

• The MSP432 has two oscillators connected to external crystal, LFXT and HFXT for
low frequency crystal and high frequency crystal
• The LFXT is designed to use a 32.768 KHz watch crystal
• The HFXT can be used with crystals or resonators ranging from 1 MHz to 48 MHz
• The MSP432 has five internal oscillators, among them the Digitally Controlled
Oscillator (DCO) is the most flexible clock source that provides a wide range of
clock frequencies

47
Measuring time delay in a C program loop

• One simple way of creating a time delay is using a for-loop in C language


• The length of time delay loop for a given system is function of two factors:
a) the CPU frequency and b) the compiler
• Regardless of clock source to CPU and the C compiler used, always use
oscilloscope to measure the length of time delay loop for a given system
with a given compiler and compiler option setting

48
Connecting switches to MSP432

49
Reading a switch in MSP432 LaunchPad board

50
Reading a switch in MSP432
1) configure P1.1 as simple I/O in P1SEL1:P1SEL0 registers,
2) make P1.1 input pin in P1DIR register for push-button switch S1,
3) configure P1REN register to enable the pull resistor,
4) configure P1OUT register to select the pull-up resistor,
5) configure P2.0 as simple I/O in P2SEL1:P2SEL0 registers,
6) make P2.0 output pin in P2DIR register for red LED,
7) read switch from P1.1,
8) if P1.1(switch) is high, set P2.0 (red LED)
9) else clear P2.0 (red LED)
10)Repeat steps 7 to 9.
51
Reading a switch and displaying it on LED

int main(void) {
P1->SEL1 &= ~2; /* configure P1.1 as simple I/O */
P1->SEL0 &= ~2;
P1->DIR &= ~2; /* P1.1 set as input */
P1->REN |= 2; /* P1.1 pull resistor enabled */
P1->OUT |= 2; /* Pull up/down is selected by P1->OUT */

P2->SEL1 &= ~1; /* configure P2.0 as simple I/O */


P2->SEL0 &= ~1;
P2->DIR |= 1; /* P2.0 set as output pin */

while (1) {
if (P1->IN & 2) /* use switch 1 to control red LED */
P2->OUT &= ~1; /* turn off P2.0 red LED when SW is not pressed */
else
P2->OUT |= 1; /* turn on P2.0 red LED when SW is pressed */
}

52
Seven-Segment LED

53
Assignments of port pins to each segments of
a 7-seg LED

D7 D6 D5 D4 D3 D2 D1 D0
. g f e d c b a

54
Segment patterns for the 10 decimal digits for
a common cathode 7-seg LED

Num D7 D6 D5 D4 D3 D2 D1 D0 Hex value


. g f e d c b a
0 0 0 1 1 1 1 1 1 0x3F
1 0 0 0 0 0 1 1 0 0x06
2 0 1 0 1 1 0 1 1 0x5B
3 0 1 0 0 1 1 1 1 0x4F
4 0 1 1 0 0 1 1 0 0x66
5 0 1 1 0 1 1 0 1 0x6D
6 0 1 1 1 1 1 0 1 0x7D
7 0 0 0 0 0 1 1 1 0x07
8 0 1 1 1 1 1 1 1 0x7F
9 0 1 1 0 1 1 1 1 0x6F

55
Microcontroller Connection to 7-segment LED

56
Microcontroller Connection to 7-segment LED
with Buffer Driver

57
Seven-segment LED interfacing and
programming
if we want to display number 75 on the 7-seg LED, the following steps should be used:
1) Configure Port 4 as output port to drive the segments,
2) Configure Port 5 as output port to select the digits,
3) Write the pattern of numeral 7 from Table 2 10 to Port 4,
4) Clear the P5.0 pin to turn off the ones digit,
5) Set the P5.1 pin HIGH to activate the tens digit,
6) Delay for some time,
7) Write the pattern of numeral 5 from Table 2 10 to Port 4,
8) Clear the P5.1 pin to turn off the tens digit,
9) Set the P5.0 pin HIGH to activate the ones digit,
10) Delay for some time,
11) Repeat from step 3 to 11.

58
16-bit I/O Memory Map

59

You might also like