GPIO
Basic I/O
The functions listed below are applicable to operating a single input/output pin in a manual configuration; that is, the code directly reads or controls the pin values.
For each of these functions, the value for the first argument, uint8_t port
, may simply be the port number (1-10, 11 for port J), or the predefined symbols GPIO_PORT_Pn
can be used, where n
is the port number. The second argument, uint8_t pins
, should use the predefined symbols GPIO_PINm
, where m
is the pin number. These functions will not work correctly if the pin number is directly given to the function.
uint8_t GPIO_getInputPinValue(uint8_t port,uint8_t pins)
: Read the value of a pin within the selected port. Returns0x01
if the input is High and0x00
if the input is Low.void GPIO_setOutputLowOnPin(uint8_t port,uint8_t pins)
: Set one or multiple pins on a port to output Low if configured as outputs.void GPIO_setOutputHighOnPin(uint8_t port,uint8_t pins)
: Set one or multiple pins on a port to output High if configured as outputs.void GPIO_toggleOutputOnPin(uint8_t port,uint8_t pins)
: Invert the output level of one or multiple pins on a port if configured as outputs.void GPIO_setAsOutputPin(uint8_t port,uint8_t pins)
: Configure one or multiple pins on a port to be outputs.void GPIO_setAsInputPin(uint8_t port,uint8_t pins)
: Configure one or multiple pins on a port to be inputs.void GPIO_setAsInputPinWithPullUpResistor(uint8_t port,uint8_t pins)
: Configure one or multiple pins on a port to be inputs with internal pull resistors connected to 3.3 V.void GPIO_setAsInputPinWithPullDownResistor(uint8_t port,uint8_t pins)
: Configure one or multiple pins on a port to be inputs with internal pull resistors connect to 0 V.
All these functions except GPIO_getInputPinValue
can operate uisng multiple pins at once. To use multiple pins, all desired pin symbols (GPIO_PINm
) should be ‘bitwise or’ed together.
Examples:
Configure P2.1 as an output and set it’s value High:
GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN1 ); // Set P2.1 as an output ... GPIO_setOutputHighOnPin( GPIO_PORT_P2, GPIO_PIN1 ); // Set P2.1 high
Configure P6.1 and P6.3 as inputs and read both values:
uint8_t val1,val2; GPIO_setAsInputPin( 6, GPIO_PIN1 | GPIO_PIN3 ); // Set P6.1,3 to inputs ... val1 = GPIO_getInputPinValue( 6, GPIO_PIN1 ); // Read and store the value of P6.1 val2 = GPIO_getInputPinValue( 6, GPIO_PIN3 ); // Read and store the value of P6.3
Interrupts
A GPIO pin can trigger an interrupt when its value changes: either from low-to-high or high-to-low. These events are known as a rising edge and falling edge, respectively. The pin cannot be configured to trigger an interrupt on both without manually manipulating the configuration after each edge is detected.
GPIO Signal Edges
Each pin interrupt trigger will invoke a single interrupt service routine, or ISR, for the associated port. This implies that if multiple pins within one port are configured to generate interrupts, there must be code to support determining what pin triggered the interrupt.
Enabling Interrupts
Each GPIO pin may have its interrupt capability enabled and disabled using the functions:
void GPIO_enableInterrupt( uint8_t port, uint8_t pins)
void GPIO_disableInterrupt( uint8_t port, uint8_t pins)
Further, selection of the rising or falling edge as the interrupt event may be done through the function:
void GPIO_interruptEdgeSelect( uint8_t port , uint8_t pins , uint8_t edgeSelect )
where uint8_t edgeSelect
is either GPIO_LOW_TO_HIGH_TRANSITION
or GPIO_HIGH_TO_LOW_TRANSITION
.
Each port interrupt, if enabled, must be associated with a function to run when the interrupt is triggered: the ISR. This function is a normal function that takes no inputs and produces no output. The function can be linked, or registered, to the port interrupt through:
void GPIO_registerInterrupt( uint8_t port , <function_name> )
For example, to associate the GPIO Port 5 interrupt with the function void foo(void)
:
GPIO_registerInterrupt(GPIO_PORT_P5,foo);
Interrupt Handling
The ISR function associated with the port will be automatically called when the selected edge is detected on any of the enabled port pins. Within this function, the code must acknowledge the interrupt by clearing the associated flag, or register bit that indicates the interrupt was triggered. If the flag is not cleared, the interrupt will continuously trigger; that is, the function will be immediately called again once it completes.
The interrupt source must be acknowledged using:
void GPIO_clearInterruptFlag( uint8_t port , uint8_t pins )
If multiple pins are enabled as trigger sources, it is necessary to determine which pin triggered the interrupt. This may be done through the function:
uint16_t GPIO_getEnabledInterruptStatus( uint8_t port )
where this function returns a value that is a bitwise-or, |
, of all pins within the specified port that have triggered the interrupt. For example, if pushbuttons on P3.1 and P3.3 were pressed simultaneously, this function would return the value GPIO_PIN1 | GPIO_PIN3
.
Alternate Functions
Each GPIO pin is capable of being internally connected to other module signals. When an alternative function is used, the GPIO pin is controlled directly from module it is connected to. There are up to 6 total signals that may be selected as an alternative function: 3 input and 3 output. These may be selected via the functions:
void GPIO_setAsPeripheralModuleFunctionInputPin( uint8_t port , uint8_t pins , uint8_t mode )
void GPIO_setAsPeripheralModuleFunctionOutputPin( uint8_t port , uint8_t pins , uint8_t mode )
where uint8_t mode
is one of GPIO_PRIMARY_MODULE_FUNCTION
, GPIO_SECONDARY_MODULE_FUNCTION
, or GPIO_TERTIARY_MODULE_FUNCTION
. Issuing one of the above functions will override any previous configuration of the selected pin(s). Likewise, the GPIO pin can be converted back to a normal input or output pin by issuing the corresponding function.
The alternate functions for each pin are listed in the table below. For the MSP432P401R, the Tertiary inputs and outputs are equivalent functions and as such only one tertiary row is listed. Further, selecting input or output mode is not impactful as the module is given control of the pin direction (e.g., P1.0 UCA0STE).
If an output mode alternate function is specified that does not have an associated signal as listed in the table, the pin would be connected to DVSS (ground). If an input pin alternate function is specified that does not have an associated signal as listed in the table, the pin will act like a normal input.
Input Mode |
Output Mode |
In & Out |
|||
---|---|---|---|---|---|
Pin |
Primary |
Secondary |
Primary |
Secondary |
Tertiary |
P1.0 |
UCA0STE |
UCA0STE |
|||
P1.1 |
UCA0CLK |
UCA0CLK |
|||
P1.2 |
UCA0RXD/ UCA0SOMI |
UCA0RXD/ UCA0SOMI |
|||
P1.3 |
UCA0TXD/ UCA0SIMO |
UCA0TXD/ UCA0SIMO |
|||
P1.4 |
UCB0STE |
UCB0STE |
|||
P1.5 |
UCB0CLK |
UCB0CLK |
|||
P1.6 |
UCB0SIMO/ UCB0SDA |
UCB0SIMO/ UCB0SDA |
|||
P1.7 |
UCB0SOMI/ UCB0SCL |
UCB0SOMI/ UCB0SCL |
|||
P2.0 |
UCA1STE |
UCA1STE |
|||
P2.1 |
UCA1CLK |
UCA1CLK |
|||
P2.2 |
UCA1RXD/ |
UCA1RXD/ |
|||
UCA1SOMI |
UCA1SOMI |
||||
P2.3 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