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.

interrupt lm4f120

hi, sorry for my posts, i'm trying to configure an ssi transmission by pressing a button, how can i do for handle an interrupt on PB5?a part of the code i wrote is the following:

GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5);    //pulsante
    GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_RISING_EDGE);
    GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_5);
    IntEnable(GPIO_PORTB_BASE);


    IntMasterEnable();

    SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,
            SSI_MODE_MASTER, 5000, 16);

    SSIEnable(SSI0_BASE);
    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
    GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_2);


    while(1)
    {
        
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
        GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_2);
        {    int i; //int j;



            if (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5)) {

                GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);

                for (i = 0; i < 200000; i++) {

                }


                GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);

                SSIDataPut(SSI0_BASE, 0x0002);
                while(SSIBusy(SSI0_BASE)){}




            }
        }

    }
}

void Miointerrupt(void)

{    int i;



    if (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5)) {

        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
        for (i = 0; i < 20000; i++) {



        }

        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
        SSIDataPut(SSI0_BASE, 0xf0f0);
        while(SSIBusy(SSI0_BASE)){}

        GPIOPinIntClear(GPIO_PORTB_BASE, GPIO_PIN_5);
    }
}

i don't understand how handle interrupts....

thanks!

  • Giuseppe Giancola1 said:
    IntEnable(GPIO_PORTB_BASE);

    You have an invalid parameter here, it would need to be INT_GPIOB. This is defined in inc/hw_ints.h. Also, do you define the interrupt handler in the startup file? If not, you would need to use GPIOIntRegister (which takes the base address as it's parameter) - then you would not need to IntEnable(), as it is done by GPIOIntRegister.

    Then another point, you have not one, but two idling loops in your interrupt handler. You will want to consider eliminating those.

    I hope this helps you get one step forward with your efforts.

  • thanks veikko,

    I defined Miointerrupt in startup_ccs.c at //GPIO Port B raw, is it ok?

    then, if I use the interrupt, can I write the while(1){} and then configure the interrupt function out of the main?

    i mean...this:


    #include "driverlib/pin_map.h"
    #include "driverlib/primo.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/gpio.h"
    #include "driverlib/ssi.h"

    //*****************************************************************************
    void Miointerrupt(void);

    int main()

    {
        MAP_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
        //
        // Enable Peripheral Clocks
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
     
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);


      

        //
        // Enable port PB7 for GPIOOutput
        //

        MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);        // PB7 reset


        //
        // Enable port PA4 for SSI0 SSI0RX
        //
        MAP_GPIOPinConfigure(GPIO_PA4_SSI0RX);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_4);

        //
        // Enable port PA3 for SSI0 SSI0FSS
        //
        MAP_GPIOPinConfigure(GPIO_PA3_SSI0FSS);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_3);

        //
        // Enable port PA2 for SSI0 SSI0CLK
        //
        MAP_GPIOPinConfigure(GPIO_PA2_SSI0CLK);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2);

        //
        // Enable port PA5 for SSI0 SSI0TX
        //
        MAP_GPIOPinConfigure(GPIO_PA5_SSI0TX);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5);

        // configurazione interrupt PB5

        GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5);    //pulsante
        GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_RISING_EDGE);
        GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_5);
        IntEnable(INT_GPIOB);


        IntMasterEnable();

        SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,
                SSI_MODE_MASTER, 5000, 16);

        SSIEnable(SSI0_BASE);
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
        GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_2);


        while(1)
        {

            GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
            GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_2);
         
    }

    void Miointerrupt(void)

    {    int i;



        if (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5)) {

            GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
            for (i = 0; i < 20000; i++) {

            }

            GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
            SSIDataPut(SSI0_BASE, 0xf0f0);
            while(SSIBusy(SSI0_BASE)){}

            GPIOPinIntClear(GPIO_PORTB_BASE, GPIO_PIN_5);
        }
    }

  • I'm sorry but frankly I don't understand what you're asking. What I do see - as you said yourself - that you don't fully seem to understand the interrupt functionality and the perks of dealing with them. 

    I would suggest that for now, you skip the interrupts altogether and instead just poll for the button status in the main loop. When you have everything else working, you can then move the handling to interrupts gradually.

  • ok, thanks for your help

    this is the clean code without interrupt that sends 16bit    f0f5 on ssi0:

    #include "driverlib/pin_map.h"
    #include "driverlib/primo.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/gpio.h"
    #include "driverlib/ssi.h"

    //*****************************************************************************
    void Miointerrupt(void);

    int main()

    {
        MAP_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
        //
        // Enable Peripheral Clocks
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
      
      
        MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7); // PB7 come reset
        MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5);    // PB5 in

        //
        // Enable port PA4 for SSI0 SSI0RX
        //
        MAP_GPIOPinConfigure(GPIO_PA4_SSI0RX);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_4);

        //
        // Enable port PA3 for SSI0 SSI0FSS
        //
        MAP_GPIOPinConfigure(GPIO_PA3_SSI0FSS);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_3);

        //
        // Enable port PA2 for SSI0 SSI0CLK
        //
        MAP_GPIOPinConfigure(GPIO_PA2_SSI0CLK);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2);

        //
        // Enable port PA5 for SSI0 SSI0TX
        //
        MAP_GPIOPinConfigure(GPIO_PA5_SSI0TX);
        MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5);


        SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,
                SSI_MODE_MASTER, 5000, 16);

        SSIEnable(SSI0_BASE);

        int check;
        check=0;

        while(1)
        {
           
            if(check==100000)
            check=0;

            GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
            GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_PIN_2);
            {int i; //int j;



                if (check==0 && GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5)) {

                    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0); //reset0

                    for (i = 0; i < 200000; i++) {;

                }


                    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);//reset1

                    SSIDataPut(SSI0_BASE, 0xf0f5);
                    while(SSIBusy(SSI0_BASE)){}




                }
                check++;
            }
        }
    }