Cpre 288 - Introduction To Embedded Systems: Instructors: Dr. Phillip Jones
Cpre 288 - Introduction To Embedded Systems: Instructors: Dr. Phillip Jones
Cpre 288 - Introduction To Embedded Systems: Instructors: Dr. Phillip Jones
Instructors:
Dr. Phillip Jones
http://class.ece.iastate.edu/cpre288 1
Announcements
http://class.ece.iastate.edu/cpre288 2
4
BITWISE OPERATIONS
http://class.ece.iastate.edu/cpre288 10
Why Bitwise Operation
Why use bitwise operations in embedded systems
programming?
Each single bit may have its own meaning
– Push button array: Bit n is 0 if push button n is pushed
– LED array: Set bit n to 0 to light LED n
Data from/to I/O ports may be packed
– Two bits for shaft encoder, six bits for push button packed in
PINC
– Keypad input: three bits for row position, three bits for
column position
Data in memory may be packed to save space
– Split one byte into two 4-bit integers
http://class.ece.iastate.edu/cpre288 11
Why Bitwise Operation
http://class.ece.iastate.edu/cpre288 12
Bitwise Operations
http://class.ece.iastate.edu/cpre288 13
Bitwise Operators: Clear/Force-to-0 Bits
1 Preserve
Consider a single bit x & x
x AND 1 = x Preserve x
Force 0
x AND 0 = 0 Clear/Force 0 0
0
&
Truth Table x
Bit x Mask bit Bit x & Mask bit
x 0 0 (Forced to 0)
x 1 x (Value preserved)
http://class.ece.iastate.edu/cpre288 14
Bitwise Operators: Clear/Force-to-0 Bits
ch = ch & 0x3C;
x7 x6 x5 x4 x3 x2 x1 x0
AND 0 0 1 1 1 1 0 0
0 0 x5 x4 x3 x2 0 0
Clear bits 7, 6, 1, 0
Preserve bits 5, 4, 3, 2
Another example:
http://class.ece.iastate.edu/cpre288 16
Class Exercise
char ch;
http://class.ece.iastate.edu/cpre288 17
Bitwise Operators: Set Bits
C bitwise OR: |
http://class.ece.iastate.edu/cpre288 18
Bitwise Operators: Set Bits
ch = ch | 0xC3;
x7 x6 x5 x4 x3 x2 x1 x0
OR 1 1 0 0 0 0 1 1
1 1 x5 x4 x3 x2 1 1
Set bits 7, 6, 1, 0
Preserve bits 5, 4, 3, 2
Another example:
http://class.ece.iastate.edu/cpre288 20
Bitwise Operators: Toggle Bits
C bitwise XOR: ^
http://class.ece.iastate.edu/cpre288 21
Bitwise Operators: Toggle Bits
x7 x6 x5 x4 x3 x2 x1 x0
XOR 0 0 1 1 1 1 0 0
x7 x6 x5 x4 x3 x2 x1 x0
Toggle bits 5, 4, 3, 2
Preserve bits 7, 6, 1, 0
INV x7 x6 x5 x4 x3 x2 x1 x0
x7 x6 x5 x4 x3 x2 x1 x0
Example: ch = 0b00001111;
~ch == 0b11110000
http://class.ece.iastate.edu/cpre288 23
Class Exercise
unsiged char ch;
short n;
http://class.ece.iastate.edu/cpre288 24
Bitwise Operators: Shift-Left
http://class.ece.iastate.edu/cpre288 25
Bitwise Operators: Shift-Right Logical
http://class.ece.iastate.edu/cpre288 26
Bitwise Operators: Shift-Right Arithmetic
signed char my_reg = 0b10000000;
unsigned char shift_amount = 5;
unsigned char my_result;
n << k is equivalent to n * 2k
Example: 5 << 2 = 5*4 = 20
0b0000 0101 << 2 = 0b0001 0100
n >> k is equivalent to n / 2k
Example: 20 >> 2 = 5
0b0001 0100 >> 2 = 0b0000 0101
http://class.ece.iastate.edu/cpre288 28
Bitwise Operators: Shift and Multiple/Divide
http://class.ece.iastate.edu/cpre288 29
Bitwise Operators: Shift and Set
http://class.ece.iastate.edu/cpre288 31
Bitwise Operators: Shift and Clear
http://class.ece.iastate.edu/cpre288 34
Bitwise Testing
if (0x02 | 0x44)
TRUE or FASE?
http://class.ece.iastate.edu/cpre288 35
Bitwise Testing
Example
Find out if bit 7 of variable nVal is set to 1
Bit 7 = 0x80 in hex
http://class.ece.iastate.edu/cpre288 36
Bitwise Testing: Any Bit is Set to 1?
Example
See if bit 2 or 3 is set to 1
Bits 2,3 = 0x0C in hex
http://class.ece.iastate.edu/cpre288 38
Bitwise Testing
• Testing if any of a set of bits is set to 1
1) Decide which bits you want to test
2) Isolate those bits (i.e. force all other bits to 0)
• Testing if all bits of a set of bits are set to 1
1) Decide which bits you want to test
2) Isolate those bits (i.e. force all other bits to 0)
3) Compare for equality with the Mask
• For the case of testing for bits set to 0. Follow bit(s) set to 1 testing
procedure, but invert the variable that you are testing.
• Generic systematic checking example
if( (x & MASK_ALL1s) == MASK_ALL1 &&
(~x & MASK_ALL0s) == MASK_ALL0s &&
(x & MASK_ANY1s) &&
(~x & MASK_ANY0s) )
http://class.ece.iastate.edu/cpre288 39
Exercise
char ch;
Test if all of bits 7 and 6 are set to 1, and if bits 5 and 4 are
cleared to 0
http://class.ece.iastate.edu/cpre288 40
Bitwise operations: Summary
•Forcing bits to 0: & (AND)
•Forcing bits to 1: | (OR)
•Toggle bits: ^ (XOR)
•Testing for bits set to 1
•Testing for bits cleared to 0
•Generic systematic testing approach:
if( (val & MASK_ALL1s) == MASK_ALL1 &&
(~val & MASK_ALL0s) == MASK_ALL0s &&
(val & MASK_ANY1s) &&
(~val & MASK_ANY0s) )
*Where: MASK_XXX is a mask with 1s in the positions being tested
http://class.ece.iastate.edu/cpre288 41
Memory Mapped I/O
http://class.ece.iastate.edu/cpre288 43
Microcontroller / System-on-Chip (SoC)
Microcontroller Outside
Program Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
ADC PCTL
CFG|DATA|STATUS 7
0 6
Port X (8-bits)
5
UART X 4
CFG|DATA|STATUS
NVIC Y AFSEL
3
Timers 0
1 2
CFG|DATA|STATUS
1
GPIO_DATA 0
http://class.ece.iastate.edu/cpre288 44
Memory Mapped I/O
•Package Pins
•Pins with shared (multiplexed) functionality
– General Purpose I/O
– Device I/O
•Memory mapped registers
– Configuration registers
– Data registers
– Status registers
http://class.ece.iastate.edu/cpre288 45
TM4C123 I/O Ports
• 64 package pins
http://class.ece.iastate.edu/cpre288 46
TM4C123 I/O Ports
• 64 package pins
Allows Software to access the
world outside of the chip
http://class.ece.iastate.edu/cpre288 47
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
http://class.ece.iastate.edu/cpre288 48
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
PORT A
http://class.ece.iastate.edu/cpre288 49
TM4C123 I/O Ports
PORT
• 64 package pins B
• 6 GPIOs Ports(A – F)
–Each 8-bits
PORT
PORT
B
B
http://class.ece.iastate.edu/cpre288 50
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
PORT
C
PORT C
http://class.ece.iastate.edu/cpre288 51
TM4C123 I/O Ports
PORT PORT
• 64 package pins D D
• 6 GPIOs Ports(A – F)
–Each 8-bits
PORT D
PORT
D
http://class.ece.iastate.edu/cpre288 52
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
PORT E
PORT
E
http://class.ece.iastate.edu/cpre288 53
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
PORT F
PORT F
http://class.ece.iastate.edu/cpre288 54
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
• Many GPIOs have
alternate functions
http://class.ece.iastate.edu/cpre288 55
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
• Many GPIOs have
alternate functions
http://class.ece.iastate.edu/cpre288 56
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
• Many GPIOs have
alternate functions
select
U0Tx
MUX
PA1
http://class.ece.iastate.edu/cpre288 57
TM4C123 I/O Ports
• 64 package pins
• 6 GPIOs Ports(A – F)
–Each 8-bits
• Many GPIOs have
alternate functions
select
U0Tx
MUX
PA1
http://class.ece.iastate.edu/cpre288 58
TM4C123 I/O Ports
Microcontroller Outside
Program Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
SW writes Configuration Register
MUX
PA1
Devices GPIO
Interrupts
SW writes Configuration Register
U0Tx
Hardware device logic select
Config Data Status
MUX
PA1
Devices GPIO
Interrupts
SW writes Configuration Register
U0Tx
Hardware device logic select
Config Data Status
MUX
PA1
7 6 5 4 3 2 1 0
GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 61
TM4C123 I/O Ports
Microcontroller Outside
Program Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
SW writes Configuration Register
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 62
TM4C123 I/O Ports
Microcontroller Outside
Program Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 63
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 64
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
Devices GPIO
Interrupts
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 65
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 66
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 67
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
0x4000C000 - 0x4000CFFF
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 68
CPRE 288 Microntroller: Full Memory Map
70
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
0x4000C000 - 0x4000CFFF
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 71
Memory Mapped General Purpose I/O (GPIO) Ports
TM4C123GH6PM:
• 6 general purpose I/O ports: Port A, B, C, D, E, F
• Processor communicates with them through
memory mapped registers.
• A set of data and control registers associated
with each port.
http://class.ece.iastate.edu/cpre288
72 72
Memory Mapped General Purpose I/O (GPIO) Ports
http://class.ece.iastate.edu/cpre288 73
Memory Mapped General Purpose I/O (GPIO) Ports
E.g.:
//Enable Port F & B clocks
SYSCTL_RCGCGPIO_R |= 0b100010;
http://class.ece.iastate.edu/cpre288 74
Memory Mapped General Purpose I/O (GPIO) Ports
Example:
// Enable Digital functionality for pin
// 8 and 0 of Port A, and preserve the others
GPIO_PORTA_DIR_R |= 0b10000001;
http://class.ece.iastate.edu/cpre288
75 75
Memory Mapped General Purpose I/O (GPIO) Ports
Example:
//All bits of port A prog for input except bit0
GPIO_PORTA_DIR_R = 0b00000001;
http://class.ece.iastate.edu/cpre288
76 76
Memory Mapped General Purpose I/O (GPIO) Ports
GPIO_PORTX_DATA_R Register:
For output configured port: If a bit in in the Port’s DATA register
is written when the corresponding pin is configured as an
output, then the port’s pin will be driven with this value.
http://class.ece.iastate.edu/cpre288 77
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
GPIO_PORTA_DATA_R = my_char;
0x4000C000 - 0x4000CFFF
UART select
CFG|DATA|STATUS
MUX
“magic” variable name. PA1
char *ptr; 7 6 5 4 3 2 1 0
ptr = 0x4000_43FC;
*ptr = my_char; 0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 78
Memory Mapped General Purpose I/O (GPIO) Ports
GPIO_PORTX_DATA_R Register:
For output configured port: If a bit in in the Port’s DATA register
is written when the corresponding pin is configured as an
output, then the port’s pin will be driven with this value.
0x4000C000 - 0x4000CFFF
UART select
CFG|DATA|STATUS
MUX
PA1
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 84
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
0x4000C000 - 0x4000CFFF
UART select
CFG|DATA|STATUS
MUX
Timers PA1
CFG|DATA|STATUS
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 85
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
ADC
CFG|DATA|STATUS
UART select
CFG|DATA|STATUS
?
MUX
Timers PA1
CFG|DATA|STATUS
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 86
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
ADC
CFG|DATA|STATUS
UART select
CFG|DATA|STATUS select
MUX
MUX
Timers PA1
CFG|DATA|STATUS
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 87
TM4C123 I/O Ports
Microcontroller Outside
Program Address Decode
Data
World
CPU 0x20000000
Memory 0x20007FFF Memory
0x40000000 Devices GPIO
Interrupts 0x400FFFFF
ADC
CFG|DATA|STATUS
UART select
CFG|DATA|STATUS select
MUX
MUX
Timers PA1
CFG|DATA|STATUS
7 6 5 4 3 2 1 0
0x400043FC GPIO_PORTA_DATA
http://class.ece.iastate.edu/cpre288 88
Microcontroller / System-on-Chip (SoC)
Microcontroller Outside
Program Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
ADC PCTL
CFG|DATA|STATUS 7
0 6
Port X (8-bits)
5
UART X 4
CFG|DATA|STATUS
NVIC Y AFSEL
3
Timers 0
1 2
CFG|DATA|STATUS
1
GPIO_DATA 0
http://class.ece.iastate.edu/cpre288 89
Microcontroller / System-on-Chip (SoC)
Microcontroller Outside
Program Data
World
Memory CPU
Memory
Devices GPIO
Interrupts
ADC PCTL
CFG|DATA|STATUS 7
0 6
Port X (8-bits)
5
UART X 4
CFG|DATA|STATUS
NVIC Y AFSEL
3
Timers 0
1 2
CFG|DATA|STATUS
1
GPIO_DATA 0
http://class.ece.iastate.edu/cpre288 90
GPIO Port: Alternative Function Architecture
Hardware writes
(Alternative Function)
Software writes
(GPIO)
Devices GPIO
Interrupts
ADC PCTL
CFG|DATA|STATUS 7
0 6
Port X (8-bits)
5
UART X 4
CFG|DATA|STATUS
NVIC Y AFSEL
3
Timers 0
1 2
CFG|DATA|STATUS
1
GPIO_DATA 0
http://class.ece.iastate.edu/cpre288 92
GPIO Port: Alternative Function Architecture
31 7 6 5 4 3 2 1 0
GPIOAFSEL …... 1 1
31 28 27 24 23 20 19 16 15 12 11 8 7 4 3 0
GPIOPCTL PMC7 PMC6 PMC5 PMC4 PMC3 PMC2 PMC1 PMC0
http://class.ece.iastate.edu/cpre288 93
GPIO Port: Alternative Function Architecture
Table 2.6 GPIO Pins and Alternate Functions
Analog Digital Functions (GPIOPCTL PMCx Bit Field Encoding)
I/O Pin
Function 1 2 3 4 5 6 7 8 9 14
PA0 17 - U0RX - - - - - - CAN1RX - -
PA1 18 - U0TX - - - - - - CAN1TX - -
PA2 19 - - SSI0CLK - - - - - - - -
PA3 20 - - SSI0FSS - - - - - - - -
PA4 21 - - SSI0RX - - - - - - - -
PA5 22 - - SSI0TX - - - - - - - -
PA6 23 - - - I2C1SCL - M1PWM2 - - - - -
PA7 24 - - - I2C1SDC - M1PWM3 - - - - -
PB0 45 USB0ID U1RX - - - - - T2CCP0 - - -
PB1 46 USB0VBUS U1TX - - - - - T2CCP1 - - -
PB2 47 - - - I2C0SCL - - - T3CCP0 - - -
PB3 48 - - - I2C0SDC - - - T3CCP1 - - -
PB4 58 AIN10 - SSI2CLK - M0PWM2 - - T1CCP0 CAN0RX - -
PB5 57 AIN11 - SSI2FSS - M0PWM3 - - T1CCP1 CAN0TX - -
PB6 1 - - SSI2RX - M0PWM0 - - T0CCP0 - - -
PB7 4 - - SSI2TX - M0PWM1 - - T0CCP1 - - -
TCK
PC0 52 - - - - - - T4CCP0 - - -
SWCLK
TMS
PC1 51 - - - - - - T4CCP1 - - -
SWDIO
PC2 50 - TDI - - - - - T5CCP0 - - -
TDO
PC3 49 - - - - - - T5CCP1 - - -
SWO
PC4 16 C1- U4RX U1RX - M0PWM6 - IDX1 WT0CCP0 U1RTS - -
PC5 15 C1+ U4TX U1TX - M0PWM7 - PHA1 WT0CCP1 U1CTS - -
http://class.ece.iastate.edu/cpre288 94
GPIO Port: Alternative Function Architecture
• What values do GPIOAFSEL and GPIOPCTL need to be given
to configure Port B to use UART1 TX?
http://class.ece.iastate.edu/cpre288 95
GPIO Port: Alternative Function Architecture
• What values do GPIOAFSEL and GPIOPCTL need to be given to
configure Port B to use UART1 TX?
Table 2.6 GPIO Pins and Alternate Functions
Analog Digital Functions (GPIOPCTL PMCx Bit Field Encoding)
I/O Pin
Function 1 2 3 4 5 6 7 8
PB0 45 USB0ID U1RX - - - - - T2CCP0 -
PB1 46 USB0VBUS U1TX - - - - - T2CCP1 -
PB2 47 - - - I2C0SCL - - - T3CCP0 -
PB3 48 - - - I2C0SDC - - - T3CCP1 -
PB4 58 AIN10 - SSI2CLK - M0PWM2 - - T1CCP0 CAN0RX
PB5 57 AIN11 - SSI2FSS - M0PWM3 - - T1CCP1 CAN0TX
PB6 1 - - SSI2RX - M0PWM0 - - T0CCP0 -
PB7 4 - - SSI2TX - M0PWM1 - - T0CCP1 -
http://class.ece.iastate.edu/cpre288 96
GPIO Port: Alternative Function Architecture
• What values do GPIOAFSEL and GPIOPCTL need to be given to
configure Port B to use UART1 TX?
Table 2.6 GPIO Pins and Alternate Functions
Analog Digital Functions (GPIOPCTL PMCx Bit Field Encoding)
I/O Pin
Function 1 2 3 4 5 6 7 8
PB0 45 USB0ID U1RX - - - - - T2CCP0 -
PB1 46 USB0VBUS U1TX - - - - - T2CCP1 -
PB2 47 - - - I2C0SCL - - - T3CCP0 -
PB3 48 - - - I2C0SDC - - - T3CCP1 -
PB4 58 AIN10 - SSI2CLK - M0PWM2 - - T1CCP0 CAN0RX
PB5 57 AIN11 - SSI2FSS - M0PWM3 - - T1CCP1 CAN0TX
PB6 1 - - SSI2RX - M0PWM0 - - T0CCP0 -
PB7 4 - - SSI2TX - M0PWM1 - - T0CCP1 -
GPIO_PORTB_AFSEL
7 6 5 4 3 2 1 0
http://class.ece.iastate.edu/cpre288 97
GPIO Port: Alternative Function Architecture
• What values do GPIOAFSEL and GPIOPCTL need to be given to
configure Port B to use UART1 TX?
Table 2.6 GPIO Pins and Alternate Functions
Analog Digital Functions (GPIOPCTL PMCx Bit Field Encoding)
I/O Pin
Function 1 2 3 4 5 6 7 8
PB0 45 USB0ID U1RX - - - - - T2CCP0 -
PB1 46 USB0VBUS U1TX - - - - - T2CCP1 -
PB2 47 - - - I2C0SCL - - - T3CCP0 -
PB3 48 - - - I2C0SDC - - - T3CCP1 -
PB4 58 AIN10 - SSI2CLK - M0PWM2 - - T1CCP0 CAN0RX
PB5 57 AIN11 - SSI2FSS - M0PWM3 - - T1CCP1 CAN0TX
PB6 1 - - SSI2RX - M0PWM0 - - T0CCP0 -
PB7 4 - - SSI2TX - M0PWM1 - - T0CCP1 -
GPIO_PORTB_AFSEL
7 6 5 4 3 2 1 0
PortB
1
Wire 1
0
http://class.ece.iastate.edu/cpre288 98
GPIO Port: Alternative Function Architecture
• What values do GPIOAFSEL and GPIOPCTL need to be given to
configure Port B to use UART1 TX?
Table 2.6 GPIO Pins and Alternate Functions
Analog Digital Functions (GPIOPCTL PMCx Bit Field Encoding)
I/O Pin
Function 1 2 3 4 5 6 7 8
PB0 45 USB0ID U1RX - - - - - T2CCP0 -
PB1 46 USB0VBUS U1TX - - - - - T2CCP1 -
PB2 47 - - - I2C0SCL - - - T3CCP0 -
PB3 48 - - - I2C0SDC - - - T3CCP1 -
PB4 58 AIN10 - SSI2CLK - M0PWM2 - - T1CCP0 CAN0RX
PB5 57 AIN11 - SSI2FSS - M0PWM3 - - T1CCP1 CAN0TX
PB6 1 - - SSI2RX - M0PWM0 - - T0CCP0 -
PB7 4 - - SSI2TX - M0PWM1 - - T0CCP1 -
GPIO_PORTB_PCTL
PMC7 PMC6 PMC5 PMC4 PMC3 PMC2 PMC1 PMC0 GPIO_PORTB_AFSEL
7 6 5 4 3 2 1 0
31 28 27 24 23 21 20 16 15 12 11 87 43 0
PortB
1
Wire 1
0
http://class.ece.iastate.edu/cpre288 99
GPIO Port: Alternative Function Architecture
• What values do GPIOAFSEL and GPIOPCTL need to be given to
configure Port B to use UART1 TX?
Table 2.6 GPIO Pins and Alternate Functions
Analog Digital Functions (GPIOPCTL PMCx Bit Field Encoding)
I/O Pin
Function 1 2 3 4 5 6 7 8
PB0 45 USB0ID U1RX - - - - - T2CCP0 -
PB1 46 USB0VBUS U1TX - - - - - T2CCP1 -
PB2 47 - - - I2C0SCL - - - T3CCP0 -
PB3 48 - - - I2C0SDC - - - T3CCP1 -
PB4 58 AIN10 - SSI2CLK - M0PWM2 - - T1CCP0 CAN0RX
PB5 57 AIN11 - SSI2FSS - M0PWM3 - - T1CCP1 CAN0TX
PB6 1 - - SSI2RX - M0PWM0 - - T0CCP0 -
PB7 4 - - SSI2TX - M0PWM1 - - T0CCP1 -
GPIO_PORTB_PCTL
PMC7 PMC6 PMC5 PMC4 PMC3 PMC2 PMC1 PMC0 GPIO_PORTB_AFSEL
7 6 5 4 3 2 1 0
31 28 27 24 23 21 20 16 15 12 11 87 43 0
15
PortB
1
0
Wire 1
0
http://class.ece.iastate.edu/cpre288 100