• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Digital Signal Processors (DSP) » C5000 Ultra Low Power DSP » C5000 Ultra Low Power DSP Forum » Using GPIO for interrupt without using CSL
Share
C5000 Ultra Low Power DSP
  • Forum
  • Announcements
Options
  • Subscribe via RSS
Top 6 Wiki Links
  • C5000 Main Wiki
  • C5000 Software
  • C5515 Boot-Image Programmer
  • CSL (including CSL 3.00)
  • C5000 Connected Audio Framework
  • Porting C5000 Teaching ROM to C5535 eZdsp
  • Forums

    Using GPIO for interrupt without using CSL

    This question is not answered
    MikeH
    Posted by MikeH
    on May 04 2012 06:19 AM
    Guru12675 points

    I have been asked about how to use a GPIO as an interrupt input, without having to use the CSL. Below is one technique I have used successfully. It uses the Spectrum Digital BSL (board support library), which can be downloaded from their website (http://support.spectrumdigital.com/boards/usbstk5515_v2/reva/). 

    The steps for setting up a GPIO line using BSL code are as follows:

    1. Define the GPIO registers in I/O memory (Note: I have added some registers that were not in the BSL). I created file called "gpio.h" and put this code there.

    #define SYS_GPIO_DIR0 *(volatile ioport Uint16*)(0x1c06)
    #define SYS_GPIO_DIR1 *(volatile ioport Uint16*)(0x1c07)
    #define SYS_GPIO_DATAIN0 *(volatile ioport Uint16*)(0x1c08)
    #define SYS_GPIO_DATAIN1 *(volatile ioport Uint16*)(0x1c09)
    #define SYS_GPIO_DATAOUT0 *(volatile ioport Uint16*)(0x1c0a)
    #define SYS_GPIO_DATAOUT1 *(volatile ioport Uint16*)(0x1c0b)
    #define SYS_GPIO_INTEDGE0 *(volatile ioport Uint16*)(0x1c0c)
    #define SYS_GPIO_INTEDGE1 *(volatile ioport Uint16*)(0x1c0d)
    #define SYS_GPIO_INTEN0 *(volatile ioport Uint16*)(0x1c0e)
    #define SYS_GPIO_INTEN1 *(volatile ioport Uint16*)(0x1c0f)
    #define SYS_GPIO_INTFLG0 *(volatile ioport Uint16*)(0x1c10)
    #define SYS_GPIO_INTFLG1 *(volatile ioport Uint16*)(0x1c11)

    2. Next, initialize the GPIO port(s) you want to use. You must initialize

    a) Direction (input for an interrupt),

    b) Enable (temporarily disable the interrupt until you want to use it. Enable it later when ready.)

    c) Rising/Falling Edge Trigger (I use rising edge trigger. Careful! Zero is rising edge, not "1").

    c) Clear any existing interrupt flags.

    void GPIO_init()
    {
    USBSTK5515_GPIO_setDirection(5,0); //Set 5 as input
    USBSTK5515_GPIO_setIntEnable(5,0); //Disable int.
    USBSTK5515_GPIO_setIntEdge(5,0); //Set rising edge
    USBSTK5515_GPIO_clearIntFlag(5); //Clear any existing flags
    }

    Include the following code (from the BSL). I created a file called "gpio.c" and put the code there.


    /* ------------------------------------------------------------------------ *
    * *
    * _GPIO_setIntEdge( number, direction ) *
    * *
    * number <- GPIO# *
    * edge <- 1:Positive Edge Trigger 0:Negative Edge Trigger *
    * *
    * ------------------------------------------------------------------------ */
    Int16 USBSTK5515_GPIO_setIntEdge( Uint16 number, Uint16 edge )
    {

    Uint32 bank_id = ( number >> 4);
    Uint32 pin_id = ( 1 << ( number & 0xF ) );

    if (bank_id == 0)
    if ((edge & 1) == GPIO_INTEDGE_NEG)
    SYS_GPIO_INTEDGE0 &= ~pin_id;
    else
    SYS_GPIO_INTEDGE0 |= pin_id;

    if (bank_id == 1)
    if ((edge & 1) == GPIO_INTEDGE_NEG)
    SYS_GPIO_INTEDGE1 &= ~pin_id;
    else
    SYS_GPIO_INTEDGE1 |= pin_id;

    return 0;
    }

    Int16 USBSTK5515_GPIO_setIntEnable( Uint16 number, Uint16 enable )
    {

    Uint32 bank_id = ( number >> 4);
    Uint32 pin_id = ( 1 << ( number & 0xF ) );

    if (bank_id == 0)
    if ((enable & 1) == GPIO_INT_DISABLE)
    SYS_GPIO_INTEN0 &= ~pin_id;
    else
    SYS_GPIO_INTEN0 |= pin_id;

    if (bank_id == 1)
    if ((enable & 1) == GPIO_INT_DISABLE)
    SYS_GPIO_INTEN1 &= ~pin_id;
    else
    SYS_GPIO_INTEN1 |= pin_id;

    return 0;
    }

    Int16 USBSTK5515_GPIO_clearIntFlag( Uint16 number)
    {

    Uint32 bank_id = ( number >> 4);
    Uint32 pin_id = ( 1 << ( number & 0xF ) );

    if (bank_id == 0) SYS_GPIO_INTFLG0 |= pin_id;

    if (bank_id == 1) SYS_GPIO_INTFLG1 |= pin_id;

    return 0;
    }

    Next, you must create an Interrupt Service Routine which captures the interrupt when it is triggered. To do this, modify the "vector.asm" file by adding the following:

    GPIO: .ivec    _GPIO_Isr ; GPIO Interrupt

    (note the "_" underline before the GPIO_Isr label. This is necessary).

    This points (vectors) the interrupt to a function called "GPIO_Isr" that you include somewhere in your code (put it in "gpio.c"). Here's some example code.

    interrupt void GPIO_Isr(void)
    {
    interrupt_received = true;
    }

    Note how simple the code is in the ISR. Do not include a function call or time consuming code inside the ISR. Just set a simple flag ("interrupt_received") and do the heavy processing in you main code, otherwise you may end up with unexplained behavior.

    Finally, in you "main.c" file, include some of the following:

    a) Make sure the EBSR enables the GPIO line you are using:

    b) Enable the GPIO system interrupt in IER1 (bit 5).

    c) Enable Global Interrupts (another BSL function)

    d) Initialize the GPIO functions (code is from above).

    void main(void)
    {
     ConfigPort(0x5900);           //set EBSR to enable your GPIO pin(s)
     IER1 = 0x0020;                    //enable GPIO system interrupt
    SYS_GlobalIntEnable();    //enable Global interrupt
    GPIO_init();                          //initialize the GPIO pins you want to use
    .
    .
    .

    }

    I hope this helps! It took me literally about 2 weeks to get this working properly since you have to piece together information from several TI documents as well as Spectrum Digital code. I guess TI really wants this to be a challenge for engineers since its not well documented in any one place or application note.

    Code On!

    Thx,

    MikeH

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Theodore Wolff
      Posted by Theodore Wolff
      on May 10 2012 09:53 AM
      Prodigy260 points

      MikeH, thank you very much for contributing this solution for the community!

       ---

      Theodore Wolff, Technical Information Solutions

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use