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.

TMS320F28335: Example given: external interrupts (push buttoms) for Peripheral explorer

Part Number: TMS320F28335
Other Parts Discussed in Thread: C2000WARE

Hi, 

I have been working on the external interrupts of the F28335. I based my code on the example of the control suite folder. However, in that example, interruptions from group one are used. In my code, I have implemented two interrupts, one for each push buttom of the peripheral explorer, which belong to groups 1 and 12. Hope it's useful for all of you. You just have to create a new project and change the main c file with this code:

Some lines are commented because there are different ways of implementing some instruction (i.e., the acknowledgement of the interruption)

//----------------------------------------------------------------------------------------------
// Included Files

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


//----------------------------------------------------------------------------------------------
// Function Prototypes 

__interrupt void xint1_isr(void);
__interrupt void xint2_isr(void);

void delay_loop(void);
void Gpio_select(void);

//----------------------------------------------------------------------------------------------
// Defines
#define DELAY 100L

//----------------------------------------------------------------------------------------------
// Main

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. Initialize 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

    //
    // For this example use the following configuration
    //
    Gpio_select();

    //
    // 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;
    PieVectTable.XINT3 = &xint2_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

    //
    // 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 Group 1 INT4
    PieCtrlRegs.PIEIER12.bit.INTx1 = 1;         // Enable PIE Group 12 INT1

    IER |= M_INT1 | M_INT12;                    // Enable CPU int1 e int12 en una línea
    //IER |= M_INT12;                           // Enable CPU int12
    EINT;                                       // Enable Global Interrupts


    while(1)
    {
    }

}

//----------------------------------------------------------------------------------------------
// delay_loop - Lo podemos usar para los rebotes

void 
delay_loop()
{
    volatile long i;
    for (i = 0; i < 5000000; i++)
    {

    }
}



//----------------------------------------------------------------------------------------------
// Gpio_select -

void 
Gpio_select(void)
{
    EALLOW;
/*
    // Configurando todo a bloque
    GpioCtrlRegs.GPAMUX1.all = 0x00000000;  // All GPIO
    GpioCtrlRegs.GPAMUX2.all = 0x00000000;  // All GPIO
    GpioCtrlRegs.GPAMUX1.all = 0x00000000;  // All GPIO
    GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF;   // All outputs
    GpioCtrlRegs.GPBDIR.all = 0x0000000F;   // All outputs
*/
    // Configurando pin a pin
    GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0;     // Pin 78 como GPIO (GPIO-09)
    GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 0;    // Pin 79 como GPIO (GPIO-11)
    GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;      // GPIO-09 como salida
    GpioCtrlRegs.GPADIR.bit.GPIO11 = 1;     // GPIO-11 como salida

    GpioCtrlRegs.GPBMUX1.bit.GPIO34;        // Pin 46 como GPIO (GPIO-34)
    GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;     // GPIO-34 como salida

    GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0;    // Pin 80 como GPIO (GPIO-49)
    GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1;     // GPIO-49 como salida
    EDIS;

    // Valores iniciales
    GpioDataRegs.GPASET.bit.GPIO9 = 1;
    GpioDataRegs.GPASET.bit.GPIO11 = 1;

    GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
    GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;


    //
    // GPIO17 and GPIO48 are inputs
    //
    EALLOW;
    GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 0;      // GPIO
    GpioCtrlRegs.GPADIR.bit.GPIO17 = 0;       // input
    GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 2;     // Qualification using 6 samples

    GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0;      // GPIO
    GpioCtrlRegs.GPBDIR.bit.GPIO48 = 0;       // input
    GpioCtrlRegs.GPBQSEL2.bit.GPIO48 = 2;     // XINT3 Qual using 6 samples

    //
    // Each sampling window is 510*SYSCLKOUT
    //
    GpioCtrlRegs.GPACTRL.bit.QUALPRD2 = 0xFF;
    GpioCtrlRegs.GPBCTRL.bit.QUALPRD2 = 0xFF;
    EDIS;

    //
    // GPIO0 is XINT1, GPIO1 is XINT3
    //
    EALLOW;
    GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 17;   // Xint1 is GPIO17
    GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL = 16;   // XINT3 is GPIO48
    EDIS;

    //
    // Configure XINT1 y XINT3
    //
    XIntruptRegs.XINT1CR.bit.POLARITY = 0;      // Falling edge interrupt
    XIntruptRegs.XINT3CR.bit.POLARITY = 1;      // Rising edge interrupt

    //
    // Enable XINT1 and XINT3
    //
    XIntruptRegs.XINT1CR.bit.ENABLE = 1;        // Enable Xint1
    XIntruptRegs.XINT3CR.bit.ENABLE = 1;        // Enable XINT3
}


//----------------------------------------------------------------------------------------------
// xint1_isr -

__interrupt void
xint1_isr(void)
{
    //DELAY_US(DELAY);
    // Se hace toggle. Los LED 1 y 2 están  2/3 de tiempo encendidos porque el ciclo se reinicia
    GpioDataRegs.GPATOGGLE.all = 0x00000A00;     // Se hace toggle en dos bits de los 32 posibles (el 9 y el 11)
    GpioDataRegs.GPBTOGGLE.all = 0x00020006;


    //
    // Acknowledge this interrupt to get more from group 1
    //
    //PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}


//----------------------------------------------------------------------------------------------
// xint2_isr -

__interrupt void
xint2_isr(void)
{
    //DELAY_US(DELAY);
    // Se hace toggle. Los LED 1 y 2 están  2/3 de tiempo encendidos porque el ciclo se reinicia
    GpioDataRegs.GPATOGGLE.all = 0x00000A00;     // Se hace toggle en dos bits de los 32 posibles (el 9 y el 11)
    GpioDataRegs.GPBTOGGLE.all = 0x00020006;


    //
    // Acknowledge this interrupt to get more from group 1
    //
    //PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    PieCtrlRegs.PIEACK.bit.ACK12 = 1;
}


//
// End of File
//

  • Hi Pablo,

    What issue are you running into? Are you trying to use interrupts belonging to different groups? I would recommend checking out the updated examples in C2000Ware and looking at the ePWM time interrupt and external examples to understand how to configure multiple interrupts across different groups.

    Regards,

    Ozino