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.

External Interrupt help



New to microcontrollers and some C programming experience. Going through the tutorial training and I'm stuck on interrupts.  What I'm doing is going pass what the training is providing and trying to use a GPIO input to fire off an interrupt... not making any headway.  All I was trying to do is toggle a output... not happening... any advice?

25FEB2013: got it to work with the following changes in RED.

//###########################################################################
//
// FILE: ExternalInterrupt.c
//
// TITLE:  Delfino TMS320x2833x External Interrupt.
//

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

// external function prototypes
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
extern void InitCpuTimers(void);
extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.
void Gpio_select(void);
interrupt void xint5_isr(void); interrupt void xint2_isr(void);
interrupt void cpu_timer0_isr(void);

// Global variables for this example
volatile Uint32 Xint1Count;

#define DELAY 35.700L

void main(void)
{
   int counter=0;        // binary counter for digital output
   
//Initialize System Control:
   InitSysCtrl();
   
//Clear all interrupts and initialize PIE vector table:
   DINT;    // Disable CPU interrupts

// Initialize PIE control registers to their default state.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt Service Routines (ISR).
   InitPieVectTable();

// Interrupts used, re-mapped to ISR functions.
   EALLOW;    
      PieVectTable.TINT0 = &cpu_timer0_isr;
      PieVectTable.XINT5 = &xint5_isr;  PieVectTable.XINT2 = &xint2_isr;
   EDIS;
 
 // Clear the counters
   Xint1Count = 0;
       
 // Initialize CpuTimers  
   InitCpuTimers();    
    
        ConfigCpuTimer(&CpuTimer0,150,100000); // setting CPU- Timer0 at 500 milliseconds

// Enable Interrupts
        PieCtrlRegs.PIECTRL.bit.ENPIE = 1;             // Enable the PIE block
        PieCtrlRegs.PIEIER1.bit.INTx7 = 1;          // Enable PIE Group 1 INT7
        PieCtrlRegs.PIEIER2.bit.INTx5 = 1;    PieCtrlRegs.PIEIER1.bit.INTx5 = 1;     
           IER |= M_INT1;     IER |=  0x0003;  
           EINT;                                       // Enable Global Interrupts
           ERTM;      

 // start timer0

CpuTimer0Regs.TCR.bit.TSS = 0;    // start timer0

//Initalize GPIO:
// InitGpio();  
   Gpio_select();
   
//Configure & Enable interrupts:        
// Configure XINTx
   XIntruptRegs.XINT5CR.bit.POLARITY = 1;     XIntruptRegs.XINT2CR.bit.POLARITY = 1;   // Rising edge interrupt

// Enable XINTx
   XIntruptRegs.XINT5CR.bit.ENABLE = 1;      XIntruptRegs.XINT2CR.bit.ENABLE = 1;     

// IDLE loop:
   while(1)
   {
     counter++;
        if(counter&1) GpioDataRegs.GPASET.bit.GPIO5 = 1;
            else GpioDataRegs.GPACLEAR.bit.GPIO5 = 1;
        if(counter&2) GpioDataRegs.GPASET.bit.GPIO7 = 1;
            else GpioDataRegs.GPACLEAR.bit.GPIO7 = 1;
        if(counter&4) GpioDataRegs.GPASET.bit.GPIO9 = 1;
            else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
        if(counter&8) GpioDataRegs.GPASET.bit.GPIO11 = 1;
            else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

      while(CpuTimer0.InterruptCount == 0);
              CpuTimer0.InterruptCount = 0;
   }
}

void Gpio_select(void)
{
    EALLOW;
//Set all GPIO as I/O
    GpioCtrlRegs.GPAMUX1.all = 0;
    GpioCtrlRegs.GPAMUX2.all = 0;
    GpioCtrlRegs.GPBMUX1.all = 0;
    GpioCtrlRegs.GPBMUX2.all = 0;
    GpioCtrlRegs.GPCMUX1.all = 0;
    GpioCtrlRegs.GPCMUX2.all = 0;
//GROUPA
    GpioCtrlRegs.GPADIR.all = 0;        // GPIO0-31 as inputs
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;    // LED on GPIO5
    GpioCtrlRegs.GPADIR.bit.GPIO7 = 1;    // LED on GPIO7
    GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;    // LED on GPIO9
    GpioCtrlRegs.GPADIR.bit.GPIO11 = 1;    // LED on GPIO11
    
    GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;    // SETTING GPIO1 WITH INTERNAL PULLUP
    GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 0;   // Xint2 Synch to SYSCLKOUT only
    GpioIntRegs.GPIOXINT5SEL.bit.GPIOSEL = 1;       GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 1;
//GROUPB                 
    GpioCtrlRegs.GPBDIR.all = 0;        // GPIO63-32 as inputs
    GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1;    // peripheral explorer: LED LD1 at GPIO49
//GROUPC     
    GpioCtrlRegs.GPCDIR.all = 0;        // GPIO63-32 as inputs
   EDIS;
}

interrupt void cpu_timer0_isr(void)
{
     CpuTimer0.InterruptCount++;

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

interrupt void xint5_isr(void)  interrupt void xint2_isr(void)
{
    GpioDataRegs.GPBTOGGLE.bit.GPIO49 = 1;

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}