7 6 5 4 3 2 1 0
P1IN
P1OUT
P1DIR 1
PxDIR.y: 0 = input Register example:
1 = output P1DIR |= 0x80;
Each bit in each PxDIR register selects the direction of the corresponding I/O pin, regardless
of the selected function for the pin.
GPIO Output
P1IN.7
P1OUT.7
1
1
P1DIR.7
1
7 6 5 4 3 2 1 0
P1IN x
P1OUT 1
P1DIR 1
If the pin is configured as I/O function, input direction and the pullup or
pulldown resistor are enabled; the corresponding bit in the PxOUT register
selects pullup or pulldown.
Bit = 0: Pin is pulled down
Bit = 1: Pin is pulled up
6 Input
Input pins
pins are
are4held
held in
in high-impedance
3high-impedance1(Hi-Z)
(Hi-Z) state,
state, so
so
7 5 2 0
they
they can
can react
react to
to 00 or
or 11
P1IN x
When
When notnot driven,
driven, Hi-Z
Hi-Z inputs
inputs may
may float
float up/down
up/down
P1OUT 1 prevent
prevent this
this with
with pullup/pulldown
pullup/pulldown resistors
resistors
P1DIR 0
PxREN
PxREN enables
enables resistors
resistors
P1REN 1 PxOUT
PxOUT selects
selects pull-up
pull-up (1)(1) or
or -down
-down (0)
(0)
Lower
Lower cost
cost devices
devices may
may notnot provide
provide up/down
up/down resistors
resistors
for
for all
all ports
ports
Controlling GPIO Ports
PxSEL = 0
IN / OUT
Peripheral
(e.g. Timer) PxSEL = 1
GPIO Summary: F5529 vs FR5969 vs G2553
PA PB PC PD
PJ*
P1
P2 P3 P4 P5 P6 P7 P8 (4-bit )
PxIN
PxOUT F55
F5529
PxDIR All FR4133 F5529 (P8 x3-bits) &
FR5969 FR4133 (P8 x12-bits) FR59
PxREN Four
(only)
PxDS Devices
PxSEL support
PxIV Ports 1 and
PxIES 2 FR5969
PxIE (only)
PxIFG
On the other hand we can also take the new register full of 1s and make it
all zeros again (this will make all pins in port 1 to become LOW):
P1OUT |= 0x02;
This results in adding the 1 to position 1, while leaving
the register as it was elsewhere
MSP430 header
MSP430 header includes the exact definitions for the bits up to 16 bits:
P1OUT |= 0x0001;
Some examples
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P4DIR |= BIT7; // Set P4.7 to output direction
P2REN |= BIT1;
P2OUT |=~ BIT1;
while(1) {
if ((P2IN & BIT1)) { // If button is open(P2.1 HIGH)
P4OUT = P4OUT | BIT7; // ... turn on LED
} // or P4OUT |= BIT7;
else {
P4OUT = P4OUT & ~BIT7;// ... else turn it off.
// or P4OUT &= ~BIT7
}
}
}
MSP430 Clocks
What Clocks Do You Need?
REFO 32768 Hz
Clock System
CS FR2xx / FR4xx
(slightly different than FR5xx/6xx version)
Clock System
CS FR2xx / FR4xx
(slightly different than FR5xx/6xx version)
UCS
UCS is is available
available on
on F5xx/F6xx
F5xx/F6xx devices
devices
Six
Six independent
independent clock
clock sources
sources
Low
Low Frequency
Frequency
LF
LF XT1
XT1 32768
32768 Hz
Hz
crystal
crystal
VLO
VLO 10
10 kHz
kHz
REFO
REFO 32
32 kHz
kHz
High
High Frequency
Frequency
HF
HF XT1
XT1 44 32
32 MHz
MHz
crystal
crystal
XT2
XT2 44 32
32 MHz
MHz
crystal
crystal
DCO
DCO FLL
FLL
calibration
calibration
FLL
FLL references
references (divisible,
(divisible, too)
too)
LFXT1
LFXT1 // XT1
XT1
REFO
REFO
XT2
XT2
Selecting various clocks
UCS module supplies
Five selectable clock sources
Three selectable clock signals
ACLK
MCLK
SMCLK