MSP432 Chapter2 v1
MSP432 Chapter2 v1
1
Chapter Review
4
Memory Map in MSP432401P401R
5
TI's naming convention for MSP432
6
TI's naming convention for MSP432 (Cont.)
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
11
GPIO
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
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
• 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
21
Some commonly Used Registers of PORT2
22
Some commonly Used Registers for PORT3
23
Some commonly Used Registers of PORT4
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.)
28
Alternate pin functions and the simple GPIO
(Cont.)
29
Alternate pin functions and the simple GPIO
(Cont.)
31
MSP432 Port1 Alternative Pin Functions
32
MSP432 Port2 Alternative Pin Functions
35
MSP432 Port5 Alternative Pin Functions
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
38
MSP432 Port8 Alternative Pin Functions
39
MSP432 Port9 Alternative Pin Functions
40
MSP432 Port10 Alternative Pin Functions
41
LED connection in MSP432 LaunchPad board
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;
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
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 */
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
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