cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with external interrupt

Patriks
Senior
Posted on July 27, 2014 at 10:01

Hello,

This question is propably really basic, but I hope to get any advice, a link to a tutorial or even a sample code which helps me to solve my problem.

I am really new in this buisness. The possibilities of the SPC56 controller familiy are huge but as a beginner their complexity confuses me. My setting is a SPC56xL Discovery Kit and the SPC5 Studio in combination with the High Tec C compiler. What I want to do is normally very simple. One of the LEDs (e.g. LED D5 on Pin A0) should be controlled by the button S2 on Pin G8. Therefore, my idea was to use an interrupt triggered by the button S2. I set up a small project, using the OSAL-HAL component.

But I really have no idea how and where i should implement this functionality in my C code. All what I have done so far is configuring an interrupt vector, but I am even not sure if i did this in the correct way. The main questions for me are:

-) What is the correct way to configure an interrupt vector?

-) How is the connection between the interrupt vector and the corresponding interrupt source made?

-) And finally, where and how to define the interrupt function to toggle my LED?

I would be really grateful for any help.

Best regards,

Patrik

1 ACCEPTED SOLUTION

Accepted Solutions
Patriks
Senior
Posted on August 14, 2014 at 12:45

Hello,

Finally, I solved my problem. I just forgot to set the interrupt enable bit for the corresponding pad.

Best regards,

Patrik

View solution in original post

5 REPLIES 5
Erwan YVIN
ST Employee
Posted on July 29, 2014 at 17:00

Hello Patrik ,

1)  there are some examples in low level driver (example : ADC)

how to define an IRQ Handler

you can use OSAL_IRQ_HANDLER

OSAL_IRQ_HANDLER(SPC5_ADC0_WD_HANDLER) {

  uint32_t isr;

  OSAL_IRQ_PROLOGUE();

  isr = ADCD1.adc_tagp->WTISR.R;

  ADCD1.adc_tagp->WTISR.R = isr;

  adc_lld_serve_interrupt(&ADCD1, isr);

  OSAL_IRQ_EPILOGUE();

}

in your case , 

You can use External INTERRUPT In SIUL chapter 48

and the convenient EIRQ[X] chapter 48.4

you should use vector41 , vector42, vector 43 or vector 44

41 0x0290 16 SIU External IRQ_0 SIUL

42 0x02A0 16 SIU External IRQ_1 SIUL

43 0x02B0 16 SIU External IRQ_2 SIUL

44 0x02C0 16 SIU External IRQ_3 SIUL

2) for mapping you should use IO Settings and set your good port/function in the good mode

    chap 4 from the convenient table ''function summary''

3) 

in your IRQ handler you should have :

if (palReadPad(PORT_D, PD_BUTTON1) == 0) {

      palTogglePad(PORT_D, PD_LED5);

    }

   Best regards

      Erwan

Patriks
Senior
Posted on August 07, 2014 at 15:16

Hello Erwan,

Thanks for your help, but there are still some open questions for me. What I understand now is how I have to define the IRQ Handler. I adapted your code example that pressing the button S2 on the eval board should activate LED7.

OSAL_IRQ_HANDLER(BUTTON1){

    OSAL_IRQ_PROLOGUE();

        

if

(palReadPad(PORT_G,PG_BUTTON_S2)==0){ 

            palClearPad(PORT_G,PA_LED7); //LED is connected to +3,3V

        } 

        OSAL_IRQ_EPILOGUE();

}

For testing purpose, I put the handler in the main function in main.c .

But still, I am not sure about definition and configuration of the interrupt vector. The button S2 is connected to the Pin G[8], means EIRQ(21). I understand that vector41 to vector44 are the vectors for external interrupts which means all together 32 possible external interrupts. Because button S2 is connected to G[8] the corresponding interrupt vector is vector43 (EIRQ[16:23]).

Therefore, i defined vector 43 in main.c

#define BUTTON1 vector43

I used the Application Configuration to define the pin G[8] as an input and defined the name PG_BUTTON_S2. According to the product manual, a PADSEL initilization is not required when using the pin as an input. The pin with the LED is defined as a push-pull output.

Do you know what I did wrong? It is not working and debugging the code shows, that the IRQ Handler is never reached.

Best regards,

Patrik

Patriks
Senior
Posted on August 13, 2014 at 13:55

Since the last time I write in this forum, I was trying many times to solve my interrupt issue. In the mean time, I was even able to use the PIT module to generate a periodic interrupt and let the LED of the discovery board toggle. I have to say that I changed to a smaller board - the SPC560D discovery board because of a hardware problem.

Using the PIT module works really fine, but still I am not able to use the external interrupt. Debbuging the program shows me, that the interrupt flag is set when pressing the button. But because of an unknown reason, the interrupt handler is never executed. I really don´t understand this because i did everything as I did to use the timer interrupt. Has anybody an idea what could be the reason for that or what I maybe forget to configure?

Thanks,

Patrik

Patriks
Senior
Posted on August 14, 2014 at 12:45

Hello,

Finally, I solved my problem. I just forgot to set the interrupt enable bit for the corresponding pad.

Best regards,

Patrik

Erwan YVIN
ST Employee
Posted on August 14, 2014 at 14:13

Hello Patrik ,

it is a good news 😉

Anyway , we will add in the new release of Application repository a ''test application'' relative ''how to use correctly the EIRQ''.

           Best regards

                             Erwan