John Walshe wrote: > > I'm using an '876 with the onboard UART talking to an RF IC and a software > UART(swuart) talking to the PC. On the PC I cobbled together a Visual C(++) > application which sends commands to the PIC. However the PC talks too fast > for the PIC to both grab the command data and do something with it. Although > the shortest command is only four bytes long they come so fast on the tail > of each other that the swuart misses part of the second byte and I get a > garbled command. I don't think you can ever guarantee how the PC will send your data, especially time wise. You didn't say what baud rate you are using, but I normally use 19200 and have no problems. I use these 2 subroutines a lot for RS232 in/out. ; ; ---------------------------- ; RECEIVE CHARACTER FROM RS232 ; ---------------------------- ; This routine does not return until a character is received. ; Receive btfss PIR1,RCIF ; (5) check for received data goto Receive ; movf RCREG,W return ; ; ------------------------------------ ; WAIT UNTIL RS232 IS FINISHED SENDING ; ------------------------------------ ; TransWt movwf TXREG bsf STATUS,RP0 Wt_TX btfss TXSTA,TRMT ; (1) transmission is complete if hi goto Wt_TX ; clrf STATUS ; RAM Page 0 return If you are expecting 4 bytes from the PC then perhaps... movlw Buffer movwf FSR Rx_Loop call Receive movwf INDF incf FSR movlw Buffer + d'4' xorwf FSR,W btfss STATUS,Z goto Rx_Loop call TransWt ; sends 0 byte back to ACK ; do something with data Sending that buffer back again... movlw Buffer movwf FSR Tx_Loop movf INDF,W call TransWt ; guarantees byte is sent incf FSR movlw Buffer + d'4' xorwf FSR,W btfss STATUS,Z goto Tx_Loop Basically make sure that your processing speed is OK with the baud rate and vice versa. -- Best regards Tony mICros http://www.bubblesoftonline.com mailto:sales@bubblesoftonline.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu