MC9S08AW16 SCI RDRF can not be cleared

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

MC9S08AW16 SCI RDRF can not be cleared

2,549 Views
JerryBJ
Contributor I
Hi,
I am using MC9S08AW16 for a project, and CW5.1 IDE. I create my project under MC9S08AW32 and change PRM for RAM 0x100 to 0x46F, ROM start from 0xC000.
 
Since I need a SCI communication, I set SCI1 as 1200-9-E-1 format, initialize code as below.
 SCI1BDH=change_2.iuch[0];
 SCI1BDL=change_2.iuch[1];                                    
 /* SCI1C1: LOOPS=0,SCISWAI=0,Rsrc=0,M=1,WAKE=0,ILT=0,PE=1,PT=0 */
 SCI1C1=0B00010010;                                     
 /* SCI1C2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=0,RE=1,RWU=0,SBK=0 */
 SCI1C2=0B00100100;                                     
 /* SCI1C3: R8=0,T8=0,TXDIR=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */
  SCI1C3 = 0x0f;         
 SCI1S2=0;
When I send a single charactor from PC COM to my AW16, the SCI Rx interrupts runs well, and I receive correct data, but the flag RDRF flag can not be cleared. I wrote my ISR as below:
 
interrupt void SCI1_rx(void)
{
 uchar i,data0;
 data0=SCI1S1; 
 data0=SCI1D;

\\\ more codes followed....
}

Most strange is, when I am string at address 0x3C(SCI1S1 register) in the memory window of Hi-Wave debugger, RDRF can be cleared, but if this address is hidden in the window, it can not be cleared.

Is this a CW bug or do I have anything incorrect in my project? Thanks in advance.

jerry

Labels (1)
0 Kudos
Reply
4 Replies

425 Views
Sampson
Contributor I
You also have to be careful how you read the SCI1SR register especially if you don't make use of the data that you read, as in your code snippet.   Some compilers especially with optimization turned on will see that data0 is not used after you read SCI1SR.  They will optimize out this step and your compiled code will only contain the read of the SCI1 data register.  Sometimes making data0 volatile will help.  You could also test the value of SCI1SR to see if RDRF is actually set and that the error flags are not set.
0 Kudos
Reply

425 Views
bigmac
Specialist III
Hello Jerry,
 
Refer to the EB642 document attached.
 
You have also observed the spurious clearing of the RDRF flag when the debugger operation reads the registers associated with the flag clearing sequence.  To prevent this the debugger should not display these register values.
 
Regards,
Mac
 
0 Kudos
Reply

425 Views
JerryBJ
Contributor I
Thank both of you very much.
I read R8 before SCI1D, and now it works well. :smileyvery-happy:
0 Kudos
Reply

425 Views
Geezer
Contributor I
I believe you can't clear your flag because you haven't finished reading your data [which is now 9 bits.] The 9th bit is in the SCI1C3 register. You may need to read it first, I don't remember...

Al
0 Kudos
Reply