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.

Program For External Interrupt for TMS320F28335

Hi

I want to configure GPIO52 as external interrupt. I have written the program for it but it is going to the isr. Can anyone help me what is wrong with the program.

interrupt void xint4_isr(void);
volatile Uint32 Xint4Count;

Uint32 LoopCount=0;
Uint32 j=0,i=0;;

void main(void)
{

InitSysCtrl();

DINT;


InitPieCtrl();


IER = 0x0000;
IFR = 0x0000;


InitPieVectTable();

/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.XINT4 = &xint4_isr;
EDIS; // This is needed to disable write to EALLOW protected registers


Xint4Count = 0; 
LoopCount = 0; 



PieCtrlRegs.PIEIER12.bit.INTx2 = 1; // Enable PIE Gropu 1 INT4
IER |= M_INT4; // Enable CPU int1
EINT;

EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO52 = 0; // GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO52 = 0; // input
GpioCtrlRegs.GPBQSEL2.bit.GPIO52 = 0; 

EDIS;

EALLOW;
GpioIntRegs.GPIOXINT4SEL.bit.GPIOSEL = 0x00000014; 

EDIS;


XIntruptRegs.XINT4CR.bit.POLARITY = 0; // Falling edge interrupt


XIntruptRegs.XINT4CR.bit.ENABLE = 1; // Enable Xint4

for(;;)
{

LoopCount++;

}


}


interrupt void xint4_isr(void)

{
Xint4Count++;
i++;
// Acknowledge this interrupt to get more from group 12
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12;
}

In this program LoopCount is being incremented but the main program is not being interrupted and thus i is not being incremented. Program is not giving any error when it is compiled.

Please help me with the program. 

Thanks.

  • Hi Arun,

    Check the attached code for XINT for GPIO52 which is triggered by GPIO0. There might be some minor errors; correct them if you find any.

    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    // Prototype statements for functions found within this file.
    interrupt void xint1_isr(void);
    
    Uint32 LoopCount;
    
    #define DELAY 35.700L
    
    void main(void)
    {
    
    
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2833x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP2833x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();  // Skipped for this example
    
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
       DINT;
    
    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the DSP2833x_PieCtrl.c file.
       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).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
    // This function is found in DSP2833x_PieVect.c.
       InitPieVectTable();
    
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
       EALLOW;	// This is needed to write to EALLOW protected registers
       PieVectTable.XINT1 = &xint1_isr;
       EDIS;   // This is needed to disable write to EALLOW protected registers
    
    // Step 4. Initialize all the Device Peripherals:
    // This function is found in DSP2833x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
    
    // Step 5. User specific code, enable interrupts:
    
    // Clear the counters
       LoopCount = 0;  // Count times through idle loop
    
    // Enable Xint1 and XINT2 in the PIE: Group 1 interrupt 4 & 5
    // Enable int1 which is connected to WAKEINT:
       PieCtrlRegs.PIECTRL.bit.ENPIE = 1;          // Enable the PIE block
       PieCtrlRegs.PIEIER1.bit.INTx4 = 1;          // Enable PIE Gropu 1 INT4
       IER |= M_INT1;                              // Enable CPU int1
       EINT;                                       // Enable Global Interrupts
    
    // GPIO30 & GPIO31 are outputs, start GPIO30 high and GPIO31 low
       EALLOW;
       GpioDataRegs.GPASET.bit.GPIO0 = 1;         // Load the output latch
       GpioCtrlRegs.GPAMUX2.bit.GPIO0 = 0;        // GPIO
       GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;         // output
    
    
    // GPIO35 inputs
       EALLOW;
       GpioCtrlRegs.GPBMUX2.bit.GPIO52 = 0;         // GPIO
       GpioCtrlRegs.GPBDIR.bit.GPIO52 = 0;          // input
       GpioCtrlRegs.GPBQSEL2.bit.GPIO52 = 0;        // Xint1 Synch to SYSCLKOUT only
       
       EDIS;
    
    // GPIO0 is XINT1, GPIO1 is XINT2
       EALLOW;
       GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 52;   // Xint1 is GPIO52
    
       EDIS;
    
    // Configure XINT1
       XIntruptRegs.XINT1CR.bit.POLARITY = 0;      // Falling edge interrupt
      
    // Enable XINT1 
       XIntruptRegs.XINT1CR.bit.ENABLE = 1;        // Enable Xint1
      
    
    // GPIO34 will go low inside each interrupt.  Monitor this on a scope
       EALLOW;
       GpioCtrlRegs.GPBMUX1.bit.GPIO0= 0;        // GPIO
       GpioCtrlRegs.GPBDIR.bit.GPIO0 = 1;         // output
       EDIS;
    
    // Step 6. IDLE loop:
       for(;;)
       {
          
          // Trigger XINT1
          GpioDataRegs.GPBSET.bit.GPIO0 = 1;   // GPIO34 is high
          GpioDataRegs.GPACLEAR.bit.GPIO0 = 1; // Lower GPIO30, trigger Xint1
          
         
    
       }
    
    
    }
    
    
    // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
    	// If local ISRs are used, reassign vector addresses in vector table as
        // shown in Step 5
    
    interrupt void xint1_isr(void)
    {
    	GpioDataRegs.GPBCLEAR.bit.GPIO0 = 1;   // GPIO34 is low
    	Xint1Count++;
    
    	// Acknowledge this interrupt to get more from group 1
    	PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }
    
    

    Regards,

    Gautam

  • Sir

    Your Attached program is not working.

    GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 52;

    GPIOSEL is 5 bit register and 52 is a 6 bit word.

    As per the datasheet Xint1 and Xint2 can be used by GPIO0-31

    Xint4,Xint5,Xint6,Xint7 can be used by GPIO32-63

    I have configured the GPIO 52 as XINT4 but it is not going in the isr.

    Thanks

  • As per the datasheet Xint1 and Xint2 can be used by GPIO0-31

    Xint4,Xint5,Xint6,Xint7 can be used by GPIO32-63

    That is exactly what I was talking about. That code was just a rough format not tested by me! Ok, as XINT4 its not working... So I hope you might've made respective changes in PIE and XIntruptRegs. Can you please attach the modified version of my code? Once I get some free time, will check it out.

    Regards,

    Gautam

  • Sir,

    I have written the modified program in above only. Please tell what is wrong with the code. Program is not giving any error when my code is compiled but on runtime it is not going into isr when interrupt is given on GPIO 52

  • Arun, in the above code:

    IER |= M_INT4

    You have to enable INT12 and not INT4. Try modifying the same and revert.

    Regards,

    Gautam

  • Thank you Sir, Now the interrupt is working. But I want that isr should be executed on high to low transition only. But in the above program  isr is being executed in high to low transition and it is being executed again and again till it is in low state.

    Please tell me the changes so that isr gets executed only at high to low transition.  

  • But in the above program  isr is being executed in high to low transition and it is being executed again and again till it is in low state.

    This is because of noise. What you can try is increase the QUALPRD value; for eg:

    GpioCtrlRegs.GPBCTRL.bit.QUALPRD1 = 0xFF;    //Sampling period = 510 x Tsysclockout

    Do let me know whether this solves your query or not.

    Regards,

    Gautam

  • No sir it is not working.

    The Problem is still the same. How i can configure it as edge trigger. Please tell me the changes in the program.