element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Safe and Sound
  • Challenges & Projects
  • Design Challenges
  • Safe and Sound
  • More
  • Cancel
Safe and Sound
Blog Safe and Sound Wearables- Hearing Guard System #8: TI-RTOS Enable Button HWI
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jomoenginer
  • Date Created: 14 Apr 2017 8:23 AM Date Created
  • Views 691 views
  • Likes 4 likes
  • Comments 3 comments
  • msp432_launchpad
  • safe & sound
  • msp432 ti-rtos hwi
Related
Recommended

Safe and Sound Wearables- Hearing Guard System #8: TI-RTOS Enable Button HWI

jomoenginer
jomoenginer
14 Apr 2017

TI-RTOS - HWI Button Presses

 

For my Hearing Guard System, I intend to use multiple menus to allow the user to set items such as Db Threshold, View Alerts, Connect to Base Unit, and so.  This required user input and at this time, the on board Buttons on the MSP432 seemed to be the best option.  I plan to look at using the touch pads on the Sharp LCD, but the Buttons were easy to implement which allowed me to proceed with configuring the menus.

To enable the push Buttons (SW1, SW2) on the MSP432 from TI-RTOS is fairly simple and most of the dirty work has already been implemented in TI-RTOS. There are multiple options for handling the MSP432 Button presses including creating a Task to poll for the presses, Software Interrupt, or Hardware Interrupt.  For my purposes, I wanted the Button presses to be Event Driven where the Button presses are handled only when the they are pressed, so I opted for a Hardware Interrupt option.  As a reference, there is an GPIO Interrupt example in the MSP432 TI-RTOS package.

 

     TI-RTOS MSP432 GPIO Interrupt example:

          gpiointerrupt_MSP_EXP432P401R_TI

 

This example contained exactly what I was looking for, so I just incorporated the code into my project.

 

The first thing is to ensure the GPIO.h and Board.h header files are included:

/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>


/* Example/Board Header files */
#"Board.h"

 

 

Then in the main function, add the GPIO Init method to enable the GPIO devices.

    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();
    Board_initUART();

 

 

To handle the Button press events, callback methods are required for each Button. These callback methods will be called but the Interrupt handler when a Button event occurs.  These will be defined later.

    /* install Button callback */
    GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);

 

 

To ensure the Interrupts are registered for the Buttons, a call to GPIO_enableInt is required.

    /* Enable interrupts */
    GPIO_enableInt(Board_BUTTON0);

 

 

To handle the second Button interrupt, (Button1), in the example an if statement was added to check for input pins for Button0 and Button1 in which case Interrupts will be enabled for Button1 if it exists.

    /*
     *  If more than one input pin is available for your device, interrupts
     *  will be enabled on Board_BUTTON1.
     */
    if (Board_BUTTON0 != Board_BUTTON1) {
        /* install Button callback */
        GPIO_setCallback(Board_BUTTON1, gpioButtonFxn1);
        GPIO_enableInt(Board_BUTTON1);
    }

 

Now, the only thing to do is to create the Callback methods to handle the button press events.  In the example, when Button0 is pressed, Board_LED0 (LED1) is toggled.

/*
 *  ======== gpioButtonFxn0 ========
 *  Callback function for the GPIO interrupt on Board_BUTTON0.
 */
void gpioButtonFxn0(unsigned int index)
{
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED0);


    if (count++ == 100) {
        count = 0;
    }
}

 

 

If Button1 is pressed, Board_LED0 (LED2: Red) is toggled.

/*
 *  ======== gpioButtonFxn1 ========
 *  Callback function for the GPIO interrupt on Board_BUTTON1.
 *  This may not be used for all boards.
 */
void gpioButtonFxn1(unsigned int index)
{
    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_LED1);


    if (count++ == 100) {
        count = 0;
    }
}

 

From here, the callback methods can be changed to perform the routine required for an project.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • jomoenginer
    jomoenginer over 8 years ago in reply to Jan Cumps +1
    Jan, The intent of the post was to show the basic method of getting the button press events from an Interrupt using the TI-RTOS API rather than using a task which polls the for the presses. This is why…
  • DAB
    DAB over 8 years ago +1
    Nice post. It is a good start to build upon. DAB
  • DAB
    DAB over 8 years ago

    Nice post.

     

    It is a good start to build upon.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jomoenginer
    jomoenginer over 8 years ago in reply to Jan Cumps

    Jan,

     

    The intent of the post was to show the basic method of getting the button press events from an Interrupt using the TI-RTOS API rather than using a task which polls the for the presses. This is why I referenced the example code.

     

    This basic framework was pretty much what I was looking for, but as is written, intermittent multiple presses will be experienced if no debounce code is added as you have mentioned. This can be implemented by adding a clockHandle for each button.

     

    I'll look at updating the post with the Debounce code. 

     

    Thanks,

     

    Jon

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago

    Nice.

    A few design comments. Your code is demo, but when using it for something else than flashing an LED:

    With interrupt mode, you'll have to introduce some debounce logic.

    Interrupt handler should be as short as possible and should yield back as fast as achievable

    There's a timer function in TI-RTOS that uses one of the hardware timers and can let the controller do other things while waiting. I've used it in one of my projects and then forgot which one image I'll have to look it up...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube