Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/12/03 07:24
Read: times


 
#48136 - RE: c=SBUF; what's going wrong?
Responding to: ???'s previous message
I got the following advice from Keil knowledge base

------------------------------------
QUESTION
I'm using the uVision2 Debugger to simulate my serial interface and I'm having problems receiving characters. My function to receive characters appears as follows:

char getch (void) {
while (!RI);
RI = 0;
return (SBUF);
}

This function always returns a value of zero when I run it in the simulator. It seems to work on the real hardware so why does the uVision2 simulator fail?

ANSWER
This function is potentially unsafe because it resets the RI bit before reading the SBUF register. In the real hardware, this code may work most of the time. However, the RI bit is being cleared too early. The uVision2 debugger always returns 0 in such cases. You should change the function to the following:

char getch (void) {
char ch;

while (!RI);
ch = SBUF;
RI = 0;
return (ch);
}
-----------------------------------------------
I then modified the interrupt code to

void rec(void) interrupt 4 {
while (!RI);
c = SBUF;
RI = 0;
}

The variable c still not follow the value of SBUF !
Anybody have better solution?

Thanks,
David



List of 11 messages in thread
TopicAuthorDate
c=SBUF; what's going wrong?            01/01/70 00:00      
   RE: c=SBUF; what\'s going wrong?            01/01/70 00:00      
      RE: c=SBUF; what\'s going wrong?            01/01/70 00:00      
   RE: c=SBUF; what\'s going wrong?            01/01/70 00:00      
   RE: c=SBUF; what's going wrong?            01/01/70 00:00      
      RE: c=SBUF; what's going wrong?            01/01/70 00:00      
   RE: c=SBUF; what's going wrong?            01/01/70 00:00      
      RE: c=SBUF; what's going wrong?            01/01/70 00:00      
   RE: c=SBUF; what's going wrong?            01/01/70 00:00      
      RE: c=SBUF; what's going wrong?            01/01/70 00:00      
      RE: c=SBUF; what's going wrong?            01/01/70 00:00      

Back to Subject List