SLAAEC8A September 2024 – August 2025
This application uses the TI System Configuration tool (SysConfig) graphical interface to generate the configuration code for the device peripherals. Using a graphical interface to configure the device peripherals streamlines the application prototyping process.
In addition, this application uses
GPIO interrupts on all input pins configured and enabled in the GPIO peripheral in
SysConfig. Based on the GPIO pins configured in SysConfig, the respective GPIO
interrupts must also be manually enabled in the main() portion of
the code using the NVIC_EnableIRQ(); function. After enabling the
interrupts, the main() code waits for an interrupt. This means that
any time one of the input signals changes state, the GPIO interrupt service routine
starts. The main() portion of this code is as follows:
int main(void)
{
SYSCFG_DL_init();
/* Enable GPIO Port A Interrupts */
NVIC_EnableIRQ(GPIO_MULTIPLE_GPIOA_INT_IRQN);
while (1) {
__WFI();
}
}
The following code snippet showcases the GPIO interrupt service routine. There are two switch cases: one for the interrupt types, and one to determine which input channel is selected to be output. The second switch case first checks the select pins to determine the respective states. Depending on those states, the input channel is selected based on the logic truth table (see Figure 1-1). For each individual case, the selected input channel pin is checked, and the output pin is set to match. The code then breaks out of the interrupt service routine, and then returns to wait for another interrupt. In addition, this example code uses pin PA0 on the LP-MSPM0L1306 as the output pin, which turns a red LED on and off based on the output signal.
void GROUP1_IRQHandler(void){
switch (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1)){
case GPIO_MULTIPLE_GPIOA_INT_IIDX:
switch (DL_GPIO_readPins(SELECT_PORT, SELECT_S1_PIN | SELECT_S0_PIN)){
case 0: /* S1 = 0, S0 = 0 */
/* Check Channel 0 and set output to match */
if (DL_GPIO_readPins(INPUT_PORT, INPUT_CHANNEL_0_PIN)){
DL_GPIO_setPins(OUTPUT_PORT, OUTPUT_LED_PIN);
} else {
DL_GPIO_clearPins(OUTPUT_PORT, OUTPUT_LED_PIN);
}
break;
case SELECT_S0_PIN: /* S1 = 0, S0 = 1 */
/* Check Channel 1 and set output to match */
if (DL_GPIO_readPins(INPUT_PORT, INPUT_CHANNEL_1_PIN)){
DL_GPIO_setPins(OUTPUT_PORT, OUTPUT_LED_PIN);
} else {
DL_GPIO_clearPins(OUTPUT_PORT, OUTPUT_LED_PIN);
}
break;
case SELECT_S1_PIN: /* S1 = 1, S0 = 0 */
/* Check Channel 2 and set output to match */
if (DL_GPIO_readPins(INPUT_PORT, INPUT_CHANNEL_2_PIN)){
DL_GPIO_setPins(OUTPUT_PORT, OUTPUT_LED_PIN);
} else {
DL_GPIO_clearPins(OUTPUT_PORT, OUTPUT_LED_PIN);
}
break;
case SELECT_S1_PIN | SELECT_S0_PIN: /* S1 = 1, S0 = 1 */
/* Check Channel 3 and set output to match */
if (DL_GPIO_readPins(INPUT_PORT, INPUT_CHANNEL_3_PIN)){
DL_GPIO_setPins(OUTPUT_PORT, OUTPUT_LED_PIN);
} else {
DL_GPIO_clearPins(OUTPUT_PORT, OUTPUT_LED_PIN);
}
break;
}
break;
}
}