SCI recieve interrupt problem

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

SCI recieve interrupt problem

Jump to solution
900 Views
bassplayer142
Contributor I

I am currently using a minidragon board with a MC9S12DG256 chip (HCS12).  I am trying to get an interrupt executed when some other unit sends anything through the serial port.  I have set the interrupt to take what information was recieved and send it back but I get three outputs instead.  Here the hex input is the 0x34 and the output is the following 6 hex numbers. 

 

 

 

{34}

 

{E1}{01}{3E}

 

 

The Following is the code I used and is shortened for simplicity.  Be aware that I have set up the clock and the baud rate to 9600 and they both work because without interrupts they work beautifully.

 

 

 

 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg256.h>     /* derivative information */
#include <math.h>

 

#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"

 

 

 

 

void interrupt 20 handler(){ 
     perint();

 

}

 

 

 

void main(void) {
      clkinit();
      delay();
      initsciint();   

 

      EnableInterrupts;        
while(1){}

 

}

 

 

 

void perint(void){
 
  datain = inchar0();
  outchar0(datain);
}

 

void initsciint(void){  
    SCI0CR1 = 0x40;  //setup sci port0  interrupts
    SCI0CR2 = 0x2C;
    SCI0BDH = 0x00;
    SCI0BDL = 0x9C;
}

 

void clkinit(void){  //set up eclock 24MHz

 

    SYNR = 0x02;  
    REFDV = 0x01;
    CLKSEL = 0x00;
    PLLCTL = 0xF1;
    delay();
    CLKSEL = 0x80;
}

 

Thanks for any help!

Labels (1)
Tags (1)
0 Kudos
1 Solution
378 Views
itisravi
Contributor II
#pragma CODE_SEG __NEAR_SEG NON_BANKEDinterrupt 20 void SCI0_ISR(void){      /*i'm assuming that we are here due to RDRF.Check for other flags if you want to*/    (void)SCI0SR1;  //dummy read to clear interruput    if(index>24)index=0; //my static variable for buffer index    BufferRx[index++]=SCI0DRL;//copy byte    return;}#pragma CODE_SEG DEFAULT

 This seems to work fine for me.May be you need to place the ISR in the non banked segment like i did. Also, try using  pre define macros  in your initsciint(). Makes it more readable. Example:

SCI0CR2 |= (SCI0CR2_TE_MASK | SCI0CR2_RE_MASK | SCI0CR2_RIE_MASK); /* Enable transmitter, Enable receiver, Enable receiver interrupt */

 

These macros can be found in the header file of your MCU derivative.

 

View solution in original post

0 Kudos
1 Reply
379 Views
itisravi
Contributor II
#pragma CODE_SEG __NEAR_SEG NON_BANKEDinterrupt 20 void SCI0_ISR(void){      /*i'm assuming that we are here due to RDRF.Check for other flags if you want to*/    (void)SCI0SR1;  //dummy read to clear interruput    if(index>24)index=0; //my static variable for buffer index    BufferRx[index++]=SCI0DRL;//copy byte    return;}#pragma CODE_SEG DEFAULT

 This seems to work fine for me.May be you need to place the ISR in the non banked segment like i did. Also, try using  pre define macros  in your initsciint(). Makes it more readable. Example:

SCI0CR2 |= (SCI0CR2_TE_MASK | SCI0CR2_RE_MASK | SCI0CR2_RIE_MASK); /* Enable transmitter, Enable receiver, Enable receiver interrupt */

 

These macros can be found in the header file of your MCU derivative.

 

0 Kudos