Problem with SCI in MC9S12P

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

Problem with SCI in MC9S12P

1,691 Views
Mishup
Contributor I

Hi everyone,

 

I'm trying to make SCI communication between uC and computer but I have a problem with receiving data using interrupt.

My SCI configuration:

  /* SCIBD: IREN=0,TNP1=0,TNP0=0,SBR12=0,SBR11=0,SBR10=0,SBR9=0,SBR8=0,SBR7=0,SBR6=0,SBR5=0,SBR4=1,SBR3=1,SBR2=0,SBR1=0,SBR0=0 */  SCIBD = 24U;                              /* SCICR1: LOOPS=0,SCISWAI=0,Rsrc=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */  SCICR1 = 0U;                                        /* SCISR2: AMAP=1 */  SCISR2 |= (unsigned char)128U;       /* Switch to the alternative register set */  /* SCIASR1: RXEDGIF=1,BERRV=0,BERRIF=1,BKDIF=1 */  SCIASR1 = 131U;                      /* Clear interrupt flags */  /* SCIACR1: RXEDGIE=0,BERRIE=0,BKDIE=0 */  SCIACR1 = 0U;                                        /* SCIACR2: BERRM1=0,BERRM0=0,BKDFE=0 */  SCIACR2 = 0U;                                        /* SCISR2: AMAP=0 */  SCISR2 &= (unsigned char)~(unsigned char)128U; /* Switch to the normal register set */  /* SCICR2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=1,RE=0,RWU=0,SBK=0 */  SCICR2 = 40U; 

 And this is how I try to handle an interrupt: 

  if(SCISR1 & 0x20)   {             SCISR1 ;    //SCICR2_RIE = 0;       recv_block();   }

 But program doesn't get into this section. I can see, when sending byte from computer, that RDRF flag is set, but condition never is considered as true - flag is immediately cleared. Sometimes program doesn't even get  into a interrupt procedure. 

 

Could you tell me what do I do wrong? I'll be grateful for eny help. 

 

Best regards,

Michal

Labels (1)
0 Kudos
Reply
4 Replies

1,457 Views
Mishup
Contributor I

Hi!

 

It seemed that it was just debugger reading SCISR1 and RDRF flag by itself. But I have another problem. Currently when I send several bytes from terminal in pc I receive only the last byte in uC. 

 

Interrupt handling:

__interrupt void isrVsci(void){  /* Write your interrupt code here ... */   if(SCISR1 & 0x20)  {   SCICR2_RIE = 0;    recv_block();  }}

 and recv_block() funkction:

void recv_block()  {  byte i = 0;     SCISR1;  SCICR2;     bt_rx_buffer[i++] = SCIDRL ;  while(SCISR1 & 0x20)   {SCISR1 ; SCICR2; bt_rx_buffer[i++] = SCIDRL ;      }    SCICR2_RIE = 1;    return; }

 

I know that something is wrong (if wasn't i would work properly), but I cannot see what.

Please help me.

 

Best regards,

Michal

0 Kudos
Reply

1,457 Views
Mishup
Contributor I

I discovered that overrun flag is being set while handling an interrupt. But baud rate, parity, etc. of connection are everywhere (in btm112 module, sci registers, com properties) the same  - 19200, 8-bit data, no parity, one stop bit. Did I miss something?

 

Best regards,

Michal

0 Kudos
Reply

1,456 Views
kef
Specialist I

Overrun flag set means that your code is too slow to read SCI data register on time, before new SCI byte is received. Disabling interrupts for too long, high other interrupts load also may cause this.

0 Kudos
Reply

1,456 Views
Mishup
Contributor I

Thank you for your reply, but there is no other interrupt handling procedures serviced in my program. So nothing seems to slow down my reception routine. But I'll try to find if there is something that make all gone wrong. 

 

I'll be grateful, If someone have any idea.

 

Best regards,

Michal

0 Kudos
Reply