I used a Real Ice system to set one PIC18F14K22 to continuously transmit an 'A' at 1 second intervals. This worked as I can capture the character on my scope. The problem arises when trying to receive this on the second PIC. Both use the same baud rate code and are running at 5V with a common earth. My code is:
BCF TXSTA,BRGH
BCF BAUDCON,BRG16
BCF TXSTA,SYNC
;now have SYNC=0, BRGH=0,BRG16=0
BSF RCSTA,SPEN ;enable serial port
BSF TRISB,RX ;make RX pin an input
BCF RCSTA,CREN
BSF RCSTA,CREN ;enable reception
Loop1
BTFSS PIR1,RCIF ;poll RCIF for high
BRA Loop1
MOVF RCREG,W
NOP
END
I took the PIC that was transmitting the 'A' character and connected it to a Maximite which uses a PIC32MX170 which has a Basic interpreter on board. This received the 'A' . This convinces me that the problem is at the receiving end.
What am I doing wrong when trying to receive a character?
I do not use the 18F series, but in the 16F enhanced series the EUSART seems similar. Are you seeing any errors in the receiver? Can you monitor the IF flag in simulation?
Finally, for the 16F1xxx deivces, one needs to read RCREG twice to be sure to clear it. Of course banking is different for the 18F series.
Thanks for the suggestion John. I tried reading RCREG twice but I still cannot receive a byte.
I don't see any errors in the receiver because nothing is received.
The mystery continues.
I've always had serial problems with PIC18 polling the RXIF , and have resorted to an ISR to read the RCREG and clear the flag. and had to do same with PIC24 , try a faster internal fosc .....