Part Number: LAUNCHXL-CC2640R2
Tool/software: TI-RTOS
I'm trying to configure a GPIO to cause an interrupt, as the input goes from high to low. I'm using the GPIO-driver, but whether I try to configure it static with the config arrays or dynamic in run-time, I can't get it right.
1. Underneath you can see my code for the static configuration, int the following order: 1. BoardGpioInitTable, 2. gpioCallbackFunctions, 3. gpioPinConfigs
1. BoardGpioInitTable:
const PIN_Config BoardGpioInitTable[] = {
CC2640R2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
CC2640R2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
CC2640R2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
CC2640R2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
CC2640R2_LAUNCHXL_DIO22 | PIN_INPUT_EN | PIN_IRQ_NEGEDGE | PIN_HYSTERESIS, /* !!! MY CONFIG !!! */
CC2640R2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */
CC2640R2_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */
CC2640R2_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */
CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */
CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */
CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */
PIN_TERMINATE
};
2. gpioCallbackFunctions:
GPIO_CallbackFxn gpioCallbackFunctions[] = {
NULL, /* !!! MY CONFIG !!! */
NULL, /* Button 1 */
NULL, /* Button 2 */
NULL, /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
NULL, /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
};
3. gpioPinConfigs:
GPIO_PinConfig gpioPinConfigs[] = {
/* Input pins */
GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* !!! MY CONFIG !!! */
GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 1 */
GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 2 */
GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
/* Output pins */
GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */
GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */
GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG, /* TMP116_EN */
/* SPI Flash CSN */
GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG,
/* SD CS */
GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,
/* Sharp Display - GPIO configurations will be done in the Display files */
GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */
GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */
GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /*LCD enable */
};
As far as I understand, the Board_init does setup the configuration table for all IOs, and any IOs that isn't stated in the BoardGpioInitTable will be set to default values. Later on, when the GPIO_init is called, the previous IO table is copied to the configArray, and the pins are reconfigured if they haven't been "ORed" with the "GPIO_DO_NOT_CONFIG"-macro in the gpioPinConfigs-table. The callback functions for the interrupt-pins are stated in the gpioCallbackFunctions, respectively to the BaordGpioInitTable's order of the pins. I've done it dynamic, with the following line:
GPIO_setCallback(Board_DIO22, DIO22_intFxn);
When I do it this way, the program goes in exception-mode, after I try to configure the callback function dynamic.
2. Underneath you can see the default static tables, as I try to configure the IOs dynamic.
1. BoardGpioInitTable:
const PIN_Config BoardGpioInitTable[] = {
CC2640R2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
CC2640R2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
CC2640R2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
CC2640R2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
CC2640R2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */
CC2640R2_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */
CC2640R2_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */
CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */
CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */
CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */
PIN_TERMINATE
};
2. gpioCallbackFunctions:
GPIO_CallbackFxn gpioCallbackFunctions[] = {
NULL, /* Button 1 */
NULL, /* Button 2 */
NULL, /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
NULL, /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
};
3. gpioPinConfigs:
GPIO_PinConfig gpioPinConfigs[] = {
/* Input pins */
GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 1 */
GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 2 */
GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
/* Output pins */
GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */
GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */
GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG, /* TMP116_EN */
/* SPI Flash CSN */
GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG,
/* SD CS */
GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,
/* Sharp Display - GPIO configurations will be done in the Display files */
GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */
GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */
GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /*LCD enable */
};
Underneath you can see my dynamic configuration, that is done after I've called the Board_init and the GPIO_init:
/* Configure the button pin */ GPIO_setConfig(Board_DIO22, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING); /* install Button callback */ GPIO_setCallback(Board_DIO22, DIO22_intFxn); /* Enable interrupts */ GPIO_enableInt(Board_DIO22);
When I do it this way, the code runs, but doesn't interrupt on falling nor rising edges.
I've tried to debug the code, and see how the DIO22-configuration-register changes through the configuration, with the GPIO_getConfig()-fxn, as written below:
GPIO_getConfig(Board_DIO22, &testDIO22); // testDIO22 = 00100001000000110010111101011000b GPIO_setConfig(Board_DIO22, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING); GPIO_getConfig(Board_DIO22, &testDIO22); // testDIO22 =00100000000000000010111101011000b
I see that the 5 lower bits are not "10110 = 22", as I'd expect. The upper 16 pins are right though, according to my dynamic configuration settings. I don't understand why bit 29 = '1' though.
I've tried to look up other posts, but with no luck. Neither have I found an answer in the driver-manuals. So my questions are:
1. How to configure GPIOs static
2. How to configure GPIOs dynamic