This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/MSP-EXP430F5529LP: GPIO interrupt setup for P2_0

Part Number: MSP-EXP430F5529LP

Tool/software: TI-RTOS

I wish to configure a GPIO pin to give an interrupt on a low going square Wave signal from DS3231 RTC chip.

I have started with the gpiointerrupt example and made the following changes. The intention was to use TI-RTOS to setup 1 callback per port interrupt and then use the index value to switch to the appropriate pin action. I added a GPIO pin setting to gpioPinConfigs in MSP_EXP430F5529LP.c and a  GPIO name for the extra pin in MSP_EXP430F5529LP.h.

/*
 *  ======== MSP_EXP430F5529LP.c ========
 *  This file is responsible for setting up the board specific items for the
 *  MSP_EXP430F5529LP board.
 */
GPIO_PinConfig gpioPinConfigs[] = {
    /* Input pins */
    /* MSP_EXP430F5529LP_RTC P2_0 Input with Falling Edge Interrupt*/
    GPIOMSP430_P2_0 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING,
    /* MSP_EXP430F5529LP_S1 */
    GPIOMSP430_P2_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
    /* MSP_EXP430F5529LP_S2 */
    GPIOMSP430_P1_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,

    /* Output pins */
    /* MSP_EXP430F5529LP_LED1 */
    GPIOMSP430_P1_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
    /* MSP_EXP430F5529LP_LED2 */
    GPIOMSP430_P4_7 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
};
.
.
.
/** ============================================================================
 *  @file       MSP_EXP430F5529LP.h
 *
 *  @brief      MSP_EXP430F5529LP Board Specific APIs
 *
 *  The MSP_EXP430F5529LP header file should be included in an application as
 *  follows:
 *  @code
 *  #include <MSP_EXP430F5529LP.h>
 *  @endcode
 *
 *  ============================================================================
 */
/*!
 *  @def    MSP_EXP430F5529LP_GPIOName
 *  @brief  Enum of GPIO names on the MSP_EXP430F5529LP dev board
 *  in ame order as PinConfigs[]
 */
typedef enum MSP_EXP430F5529LP_GPIOName {
	MSP_EXP430F5529LP_RTC = 0, /* port 2 pin 0 */
	MSP_EXP430F5529LP_S1 , /* port 2 pin 1 */
    MSP_EXP430F5529LP_S2, /* port 1 pin 1 */

    MSP_EXP430F5529LP_LED1,
    MSP_EXP430F5529LP_LED2,

    MSP_EXP430F5529LP_GPIOCOUNT
} MSP_EXP430F5529LP_GPIOName;

/* main */

/* variable to be read by GUI Composer */
int count1 = 0;
int count2 = 0;
/* variable to be read by GUI Composer */
//int rtccount = 0;




/*
 *  ======== gpioPortFxn2 ========
 *  Callback function for the Port 2
 *  if index is position in gpioPinConfigs[] then we should get 0 or 1
 */
void gpioPortFxn2(unsigned int index)
{
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED1);

    if (count2++ == 100) {
        count2 = 0;
    }
    System_printf("Port2 Int %d, %d\n", count2 , index);
    System_flush();
}

/*
 *  ======== gpioPortFxn1 ========
 *  Callback function for the GPIO interrupt on Board_BUTTON0.
 *  *  if index is position in gpioPinConfigs[] then we should get 2
 */
void gpioPortFxn1(unsigned int index)
{
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED0);

    if (count1++ == 100) {
        count1 = 0;
    }
    System_printf("Port1 Int %d, %d\n", count1 , index);
    System_flush();
}
/* */
/*
 *  ======== main ========
 */
int main(void)
{
    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();
    Board_initUART();

    /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_ON);

    System_printf("Starting the GPIO Interrupt example\nSystem provider is set"
                  " to SysMin. Halt the target to view any SysMin contents in"
                  " ROV.\n");
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();
    //
    /* install callbacks */
    GPIO_setCallback(MSP_EXP430F5529LP_RTC, gpioPortFxn2);
    GPIO_setCallback(Board_BUTTON0, gpioPortFxn1);
    GPIO_setCallback(Board_BUTTON1, gpioPortFxn2);
    /* Enable interrupts */
    GPIO_enableInt(MSP_EXP430F5529LP_RTC);
    GPIO_enableInt(Board_BUTTON0);
    GPIO_enableInt(Board_BUTTON1);


    /* Start BIOS */
    BIOS_start();

    return (0);
}

With this code the original Button actions trigger an interrupt and I get output to the console from the 2 callback functions.

However the additional GPIO interrupt does not respond. I also note that the P2_0 shows 0v so I wonder if I am missing something in the pin setup?

Starting the GPIO Interrupt example
System provider is set to SysMin. Halt the target to view any SysMin contents in ROV.
Port2 Int 1, 2
Port2 Int 2, 2
Port1 Int 1, 1
Port1 Int 2, 1
Port1 Int 3, 1
Port1 Int 4, 1

I realise I am missing something here. I would welcome any suggestions.

  • Hi,

    First, is there a reason for you to need to use TIRTOS? If not, this is something that can be more easily done by just configuring the appropriate registers (or using driverlib), as you do not seem to actually be making use of any RTOS-specific features.


    As for your current code, you seem to have one of your callbacks applied to 2 pins: MSP_EXP430F5529LP_RTC and Board_BUTTON1. Because of this, I am not sure if your interrupt flag is being cleared properly, in which case you will not see the interrupt get generated correctly. If I am understanding what you are trying to do correctly, I am not sure why you would have 1 callback associated with multiple input pin interrupts.

    Regards,
    Nathan
  • I think I may have resolved this. P2_0 was not generating an interrupt. It is linked to TA1.1. Possibly this timer is being used and has grabbed that pin - perhaps a TI-RTOS guru can confirm or explain that.

    So I moved the input to P2.2 and configured the configuartions like this adding an entry for P2_2

    GPIO_PinConfig gpioPinConfigs[] = {
    /* Input pins */
    /* MSP_EXP430F5529LP_P2_2 */
    GPIOMSP430_P2_2 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING,
    /* MSP_EXP430F5529LP_S1 */
    GPIOMSP430_P2_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
    /* MSP_EXP430F5529LP_S2 */
    GPIOMSP430_P1_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,


    /* Output pins */
    /* MSP_EXP430F5529LP_LED1 */
    GPIOMSP430_P1_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
    /* MSP_EXP430F5529LP_LED2 */
    GPIOMSP430_P4_7 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
    };

    and

    /*!
    * @def MSP_EXP430F5529LP_GPIOName
    * @brief Enum of GPIO names on the MSP_EXP430F5529LP dev board
    */
    typedef enum MSP_EXP430F5529LP_GPIOName {
    MSP_EXP430F5529LP_P2_2 = 0,
    MSP_EXP430F5529LP_S1,
    MSP_EXP430F5529LP_S2,

    MSP_EXP430F5529LP_LED1,
    MSP_EXP430F5529LP_LED2,

    MSP_EXP430F5529LP_GPIOCOUNT
    } MSP_EXP430F5529LP_GPIOName;

    I have 3 callback functions in MAIN linked to each interrupt and a quick test gives this output:

    Port2 Int 1, index 2
    Port2 Int 2, index 2 /*- on board button 2
    Port1 Int 1, index 1
    Port1 Int 2, index 1
    Port1 Int 3, index 1
    Port1 Int 4, index 1 /*- on board button 1
    Prt 2 Int 1, index 0
    Prt 2 Int 2, index 0
    Prt 2 Int 3, index 0 /* test pin for use by RTC SQW

    As I understand it the index value is the position in the GPIOName enumeration and so identifies which pin triggered the interrupt. So the relevant callback should be able to call a SWI or Semaphore for a task.

    I would welcome some confirmation that my assumptions are correct before I go much further - thanks.
    Ted
  • Nathan Thanks for your comment.
    This is a test setup to see if one particular requirement will work in RTOS. The whole project will use RTOS in due course.
    I think it is feasible to have one callback per pin but I suspect that it maybe feasible to have a callback act as a despacher based on the index value. I am just testing to see what can be done. However that is not the issue at the time of posting. I get no interrupt on P2_0. Please see above or below for a not of progress using P2-2.
    Ted
  • I have tested with one shared callback from 3 separate pin interrupts:

    GPIO_setCallback(MSP_EXP430F5529LP_P2_0, gpioPortShared );
    GPIO_setCallback(Board_BUTTON0, gpioPortShared);
    GPIO_setCallback(Board_BUTTON1, gpioPortShared);
    GPIO_enableInt(MSP_EXP430F5529LP_P2_0);
    GPIO_enableInt(Board_BUTTON0);
    GPIO_enableInt(Board_BUTTON1);

    /*
    * ======== gpioPortShared========
    * Shared Callback function for GPIOs
    * if index is position in gpioPinConfigs[] then we should get 0 or 1 or 2
    */
    void gpioPortShared(unsigned int index)
    {
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED1);

    if (count3++ == 100) {
    count3 = 0;
    }
    System_printf("Callback index %d, count: %d\n", index, count3 );
    System_flush();
    }

    This gave an output as follows - all from the same function 'gpioPortShared'

    Callback index 2, count: 1
    Callback index 1, count: 2
    Callback index 1, count: 3
    Callback index 2, count: 4
    Callback index 2, count: 5
    Callback index 0, count: 6
    Callback index 0, count: 7
    Callback index 0, count: 8
    Callback index 0, count: 9
    Callback index 0, count: 10

    As before index 0 is Pin2_2, index 1 is Button0 on P2_1 and index 2 is Button1 on P1_1

    So it can be done. Whether it should be done is another question.
    Ted
  • Hi Ted,

    I do believe that the pin muxing was the reason that you were unable to get Pin2_0. You could verify this by checking the timer configuration in TIRTOS.

    As for using the indexes, I do not see any reason why that wouldn't work or why you should not do that. One thing to consider, though, is if there is a possibility that you will be generating these interrupts at the same time (or almost the same time) as each other. Depending on exactly what you will be trying to do with the interrupts, there could be an issue if the callback needs to be called again while it is still being executed for the previous interrupt. This is the only reason why you might consider using separate callback functions.

    Regards,
    Nathan
  • Nathan
    Thanks - I have reached the same conclusion - although I am not sure which function in TI-RTOS on the 5529LP is using TA1.1. This stage is partly exploretry. What is Feasible v What is Desirable. My intend is to have a per second input and a key pad rather than Buttons so the question of shared Callbacks may not be an issue in any case. Perhaps the concept of a shared calback may be of use to others.
    Cheers
    Ted

**Attention** This is a public forum