??? 04/28/04 12:46 Read: times |
#69376 - RE: Lock up of serial port 2 receive side Responding to: ???'s previous message |
hi,
Michael, you said: I always clear RI after reading SBUF. For me, it has no differentcy. Let examine some cases: - byte A comes to SBUF and RI is set. You read SBUF, then clear RI. If byte B comes to SBUF between read-clear commands then you lost byte B (it is in UART but you cleared its RI and so do not know that the new byte come). If byte B comes before you read SBUF then you lost byte A. Only if byte B comes after RI has been cleared, then you obtain both bytes A and B (byte B is read at next interrupt). - byte A comes to SBUF and RI is set. Kevan clears RI and then reads SBUF. If byte B comes to SBUF between clear-read commands then he losts byte A but obtains byte B twice (second B is read at next interrupt). If byte B comes before he reads SBUF then byte A is lost. So what is difference? Both way do not avoid reception failure. Only one thing I see useful is that with your way it is possible to detect such failure by packet size which will be smaller than expected one. From other side, Kevan`s way has less latency than yours and so it decreases such failure possibility. Really, your code is: JB RI,ISR_UART_GET ;... ISR_UART_GET: MOV A,SBUF CLR RI while his is: JBC RI,ISR_UART_GET ;... ISR_UART_GET: MOV A,SBUF So your way increases a chance of failure (at time when you clear RI, Kevan has already done all job). Now another interest issue I need to indicate: some (most) Atmel/Temic products has errata about JBC used with SCON: On C51, when using JBC instruction on any bit of SCON register, if RB8 bit changes from "1" to "0" during JBC the "0" is lost and RB8 keeps "1". It is why I avoid to use JBC at this place. Regards, Oleg |