Hello group,
I have an interesting (read frustrating) situation where I am sending some known data via USART from 1 PIC16F887 device to another, but the data received is corrupted. As this is a test set-up I am processing no other instructions. Both devices share the exact same initialization code (below) one is set to TX only and the other RX only. Baud=9600, Internal 4Mhz clk,
An example of the corrupted data is below:
Sending (in hex) AA, 55, AA, 00
Receiving (hex) D6, A9, D6, 80
(Bin) 10101010 .01010101 .10101010 .00000000
(Bin) 11010110 .10101001 .11010110 .10000000
Other data sent is corrupted in a similar way (MSB=1 & Lower nibble damaged). other "new" devices have been tested and I can observe the correct data being sent on the oscilloscope. There is some redundant code with bank switching - please ignore -
any help appreciated,
Dan.
; 1) ENABLE THE TRANSMITTER
BANKSEL TXSTA ; Select Bank 1
BSF TXSTA,TXEN ; enables TX of the EUSART.
BCF TXSTA,SYNC ; configures EUSART for async
BANKSEL RCSTA ; Select Bank 0
BSF RCSTA,SPEN ; auto config TX & RX I/O pins
; 2) ENABLE THE RECEIVER
BANKSEL RCSTA ; Select Bank 1
BSF RCSTA,CREN ; enable the RX of the EUSART
; 3) Set the Baude Rate
BANKSEL SPBRG ; Select Bank1
MOVLW D'25' ; Load Baud register with d25 (19hex)
MOVWF SPBRG ; Register in BANK1
BANKSEL TXSTA ; Bank1 Selected
BSF TXSTA,BRGH ; Set BRGH = H.Speed Baud
BANKSEL PORTA ; Set back to Bank0 for main:
RETURN ; before exiting the set-up routine
**** sample of RX test code ****
BTFSS PIR1,RCIF ; Poll RX flag for character in buffer
GOTO $-1 ; Continue polling for the RX data
MOVF RCREG,W ; Extract char from buffer to WREG
MOVWF CharRX ; Move to variable location
**** sample of RX test code ****
MOVLW H'55'
MOVWF Var1 ; Load data for TX into variable
BTFSS PIR1,TXIF; TXIF=1 [ready to accept data] TXIF=0 [busy]
GOTO $-1 ; Branch always to previous cmd line [poll flag]
MOVF Var1,W ; Move variable into the WREG [Var1=55]
MOVWF TXREG