Nagaraju Boya

NOT RETURNING FROM INTERRUPT

Discussion created by Nagaraju Boya on Jan 4, 2012
Latest reply on Jan 5, 2012 by Nagaraju Boya

Hello everyone,

 

I am using a Minidragon plus2 with mixed C & assembly as shown in the book:
"Learning C by example" & have seemingly run into the max C code limit.

Using Codewarrior 5.1 with PE USB MULTILINK.

 

My code is as follows

 

The problem PC is jumping to ISR and after completing ISR, control is looping back to again ISR.

 

control is not retruning from interrupt.

 

I have seen stack frame in sigle step everything seems stacking.

 

Can someone please look the code and tell where is the problem in code.

 

Memory model is "banked".

 

#include <hidef.h>      /* common defines and macros */
//#include "derivative.h"      /* derivative-specific definitions */
#include "hcs12def.h"      /* common defines and macros */

 

 

//-------------------------------------------------------------------------------------------------------------------------------------------------
#pragma CODE_SEG NON_BANKED
//-------------------------------------------------------------------------------------------------------------------------------------------------
interrupt 20 void  SCI1_Isr (void)
{
 volatile unsigned char scicr2,scisr1;
 static unsigned char RxCnt=0;
 unsigned int i;
 scisr1 = SCI0SR1;
 scicr2 = SCI0CR2;
 
  i = SCI0DRL;

//transmit

 SCI0DRL = i;  //TRANSMIT 1
 
     PTM |= 0x10; //glowing led
    
    PTM |= 0x08; //glowing led
    
    PTM |= 0x20; //glowing led
}
//------------------------------------------------------------------------------------------------------------------------------------------------
#pragma CODE_SEG DEFAULT
//------------------------------------------------------------------------------------------------------------------------------------------------

 

#pragma CODE_SEG NON_BANKED
void main(void) {
  /* put your own code here */
  int ix;
  long ltmp;  

  unsigned int i;
  
    // initalize PLL - reset default is Oscillator clock
    // 8 MHz oscillator, PLL freq = 48 MHz, 24 MHz bus,
    //  divide by 16 for timer of 2/3 usec tic
    PLLCTL &= 0xBF;     // Turn off PLL so can change freq
    SYNR = 0x02;        // set PLL/ Bus freq to 48/ 24 MHz
    REFDV = 0x00;
    PLLCTL |= 0x40;     // Turn on PLL
    // wait for PLL lock
    while (!(CRGFLG & 0x08));   
    CLKSEL = 0x80;      // select PLL as clock

    // wait for clock transition to finish
    for (ix = 0; ix < 60; ix++);
 
 DDRM |= 0xFC;    // port M - all outputs, full drive by default  //CONNECTED TO LEDS
 DDRS &= 0xF2;    // configure transmitter pin as output and receiver pin as inputs
  
  //INITIALIZE SCI
 
    SCI0BDH = 0x00;
 // Set up SCI (rs232): SCI BR reg= BusFreq(=24MHz)/16/baudrate
    SCI0BDL = (unsigned char)(1500000/115200);  //emb edited
    ltmp = (150000000/115200) - ((long)SCI0BDL*100);
    if(ltmp > 50) {
        SCI0BDL++;   // round up
    }
    SCI0CR1 =  0x00;
    //SCI0CR2 = 0x24;   // TIE=0,RIE = 1; TE=0,RE =1  FROM ORIGINAL CODE
 //SCI0CR2 = 0x2c;     /* Transmit enable, read enable */ //WITH NO INTERRUPTS  0x24 is not working because transmit is disabled (may be)
 SCI0CR2 = 0xfc; ////0x24;
 
 asm cli;  //enable interrupts
 
 SCI0DRL = 0x31;  //TRANSMIT 1
 
 while(!(SCI0SR1 & 0x40)){ }
 
//RECEIVE

    while(!(SCI0SR1 & 0x20)){  }    //wait for reception
 i = SCI0DRL;

//transmit

 SCI0DRL = i;  //TRANSMIT 1
 
 while(!(SCI0SR1 & 0x40)){ } //wait to transmit
 
   //off 4,5,6 leds on ms2 board
     PTM |= 0x10;
     PTM|= 0x08; // PTM |= 0x08;
        PTM |= 0x20;
 

while(1)
 {
    //off 4,5,6 leds on ms2 board
    PTM &= ~0x10;  //bit4 LED5
   
    PTM &= ~0x08;  //bit3 LED4
   
    PTM &= ~0x20;  //bit5 LED6
   
   
    for(i = 0;i<=50000;i++) { }
   
    for(i = 0;i<=50000;i++) { }
      
    for(i = 0;i<=50000;i++) { }
   
    for(i = 0;i<=50000;i++) { }
   
  //ON 4,5,6 leds on ms2 board
    PTM |= 0x10;
   
    PTM |= 0x08;
   
    PTM |= 0x20;
   
    for(i = 0;i<=50000;i++) { }
   
    for(i = 0;i<=50000;i++) { }
      
    for(i = 0;i<=50000;i++) { }
   
    for(i = 0;i<=50000;i++) { }

 }
}

#pragma CODE_SEG DEFAULT

 

 

Thanks,

Embitel

Outcomes