Problems creating a simple ISR

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

Problems creating a simple ISR

Jump to solution
2,896 Views
BFarner
Contributor I
Using CodeWarrior 5.7.0 with an MC9S12DT256, I'm having trouble creating a simple timer interrupt. When running the following code under all three memory models, I get ILLEGAL_BP error and execution halts before the ISR ever runs. What do I need to do to get an ISR working?


#include       /* common defines and macros */
#include      /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dt256b"

void tim_init (void) {
 TIE = 0x01;    // Enable Tim Ch. 0
 TSCR1 = 0x80;   // Enable Timer module
 TSCR2 = 0x80;
 TC0 = 0x0080;
}

void main(void) {
  /* put your own code here */
 
 
  DDRA = 0xFF;
  PORTA = 0x00;
 
  EnableInterrupts;
 
  tim_init();
  for(;;) {} /* wait forever */
  /* please make sure that you never leave this function */
}

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt 8 void tim_ch0_vector(void) {
  PORTA = 0x55;
  TFLG2 = 0x80;
}
#pragma CODE_SEG DEFAULT
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
886 Views
J2MEJediMaster
Specialist I
I'm not quite sure about using the ISR function declaration to set the interrupt vector number. I'd rather see:

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void tim_ch0_vector(void) {
PORTA = 0x55;
TFLG2 = 0x80;
}
#pragma CODE_SEG DEFAULT

You're also not adding the final ingredient to the mix, which is to plug the interrupt's address into the interrupt vector table. If you're using the CW stationery, this table is located in the file vector.c. In that file, do the following:

1) Declare your ISR

extern void near tim_ch0_vector(void); // Declare code of ISR to be somewhere else

2) Add address to vector table in vector.c

const tIsrFunc_vec[] @0xFF80 = {

UnimplementedISR, // vector 63
UnimplementedISR, // vector 62
...
UnimplementedISR, // vector 9
tim_ch0_vector(), // vector 8 // Where the processor is to go for this int
UnimplementedISR, // vector 7
...


Good luck!

---Tom

View solution in original post

0 Kudos
Reply
2 Replies
887 Views
J2MEJediMaster
Specialist I
I'm not quite sure about using the ISR function declaration to set the interrupt vector number. I'd rather see:

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void tim_ch0_vector(void) {
PORTA = 0x55;
TFLG2 = 0x80;
}
#pragma CODE_SEG DEFAULT

You're also not adding the final ingredient to the mix, which is to plug the interrupt's address into the interrupt vector table. If you're using the CW stationery, this table is located in the file vector.c. In that file, do the following:

1) Declare your ISR

extern void near tim_ch0_vector(void); // Declare code of ISR to be somewhere else

2) Add address to vector table in vector.c

const tIsrFunc_vec[] @0xFF80 = {

UnimplementedISR, // vector 63
UnimplementedISR, // vector 62
...
UnimplementedISR, // vector 9
tim_ch0_vector(), // vector 8 // Where the processor is to go for this int
UnimplementedISR, // vector 7
...


Good luck!

---Tom
0 Kudos
Reply
886 Views
bigmac
Specialist III

Hello,

Using the ISR function declaration to set the interrupt vector number appears to be valid for the 9S08 (see AN2616 page 53) - but not sure about the 9S12.  The method avoids the need to modify the .PRM file with the vector information.

Regards,
Mac