How to get Interrupts working on MC9S08GB60

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get Interrupts working on MC9S08GB60

551 Views
Ethan01
Contributor I

Hello,

 

I am using MC9S08GB60  and I am attempting to locate some good documentation or even examples that will show me how to use the IRQ interrupt pin (and potentially other sources of interrupts). I am using CW08 V3.1 and I want to be able to program the interrupts using C.

 

I have a basic program written so far for me to test the interrupt and when I enable the IRQ interrupt I don't seem to reach my main program anymore and I don't reach my interrupt subroutine either. However when I disable the interrupt I reach the main and output to the LEDs OK.

 

Here is what I have so far:

Main program:

void main(void)

{

...

IRQSC = 0b0011110;

...

<code that outputs to LEDs to see if I am in the main program>

...

while(1); // infinite loop

}

 

In my Cpu.c file (created by Processor Expert) I have:

#pragma CODE_SEG __SHORT_SEG NON_BANKED
__interrupt void IRQ_Interrupt(void)
{
...

<code that outputs to LEDs to see if I reach the interrupt>

...

while(1); // infinite loop

}
#pragma CODE_SEG DEFAULT

 

In my Cpu.h file (also reacted by Processor Expert) I have:

 

...

__interrupt void IRQ_Interrupt(void);

...

 

and I modified Vectors.c to the following:

void (* const _vect[])() @0xFFCC = {   // Interrupt table
           Cpu_Interrupt,        /* Vector 25 */
           Cpu_Interrupt,        /* Vector 24 */
           Cpu_Interrupt,        /* Vector 23 */
           Cpu_Interrupt,        /* Vector 22 */
           Cpu_Interrupt,        /* Vector 21 */
           Cpu_Interrupt,        /* Vector 20 */
           Cpu_Interrupt,        /* Vector 19 */
           Cpu_Interrupt,        /* Vector 18 */
           Cpu_Interrupt,        /* Vector 17 */
           Cpu_Interrupt,        /* Vector 16 */
           Cpu_Interrupt,        /* Vector 15 */
           Cpu_Interrupt,        /* Vector 14 */
           Cpu_Interrupt,        /* Vector 13 */
           Cpu_Interrupt,        /* Vector 12 */
           Cpu_Interrupt,        /* Vector 11 */
           Cpu_Interrupt,        /* Vector 10 */
           Cpu_Interrupt,        /* Vector 09 */
           Cpu_Interrupt,        /* Vector 08 */
           Cpu_Interrupt,        /* Vector 07 */
           Cpu_Interrupt,        /* Vector 06 */
           Cpu_Interrupt,        /* Vector 05 */
           Cpu_OnClockMonitorInt,        /* Vector 04 */
           Cpu_Interrupt,        /* Vector 03 */
           IRQ_Interrupt,        /* Vector 02 */
           Cpu_SWIInterrupt,/* Vector 01 */
           _EntryPoint            /* Vector 00 */
   };

Labels (1)
0 Kudos
1 Reply

279 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

The seems to be some problems with your basic program structure.  If you were to utilize the new project wizard to create a framwork for your program, you would have the following structure for your main function.

 

You also do not say what is connected to the IRQ input, to activate each interrupt.

 

void main(void) {  // MCU initialisation code here - executed once  EnableInterrupts;  // Global enable    // Other code here - executed once  for( ; ; ) {    __RESET_WATCHDOG();      // Main code loop here - repeatedly executed  } /* loop forever */}

 

So your posted code snippet does not globally enable interrupts,  and the "code that outputs to LEDs to see if I am in the main program" is executed once only, prior to the IRQ signal being activated.  I would suspect that this should be frequently executed.

 

I would also set up the IRQ interrupts, using IRQSC = 0x16;

This assumes that the external signal at the IRQ pin is active low, and ensures that the IRQ interrupt flag is clear.

 

Now for your ISR function -

You do not acknowledge the interrupt, to clear the interrupt flag.  IRQSC = 0x16; would accomplish this.

Your ISR does never exit (unless COP timeout occurs), because of the infinite loop within the ISR.

 

Note that, if the external device is a mechanical switch, the operation may not quite be as intended due to swich contact bounce.  Debounce techniques would need to be employed.

 

Regards,

Mac

 

0 Kudos