I could not find a way to check the Rx shift register... so what I did was add 4 null bytes to the end of everything I was sending to the PIC from the PC.. and when the pic trims this 4 null bytes.. the PC will still receive the relevant data.. "Vitaliy" wrote in message news:043401c74c6b$92e65a10$6f02a8c0@WS11... > jtroxas wrote: >> hello.. >> I am doing a serial communication and doing a loopback test through a PIC >> most of the times the last two or four bytes of a message is not being >> sent back to the sending computer from the PIC... > > Which PIC are you using? > >> the computer pulls down a pin to 0volts to tell the PIC that a >> transmission is over and up to tell the PIC that its about to initiate a >> transmission.. The PIC signal a clear to send message by raising another >> pin to 5 volts... >> >> when the PIC has sent a reply it pulls down this other pin to low and >> disables Transmit Interrupt... > > Why are you using handshaking lines? > > Why are you using interrupts for transmit? > >> the problem I think is the timing when raising and lowering the said >> pins. >> when the pins are lowered while some data is still in the PIC's hardware >> buffer.. Some of the last 4 bytes are being lost.. maybe 2 when received >> and 2 when transmitting.. I got an idea of checking TXSTA register's TRMT >> bit to check whether the shift register is empty or not before sending a >> "message sent" signal to the computer and disabling interrupt so as not >> to >> loose the last data sitting on the transmit buffer.. >> >> on the other hand.. Is there a way to check the PIC's Receiving Shift >> register if it has data or currently shifting data.. I would like to >> avoid >> waiting or delay code if it can be avoided... > > To check if there's data in the RCREG, you need to check the RCIF bit in > PIR1. > > The most straightforward way of implementing what you're doing, is to > enable > Rx interrupt, and in the ISR put the byte you received into the TXREG > (without enabling the Tx interrupt). > > Best regards, > > Vitaliy > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist