I am trying to set up a communication with the EUSART of the pic16F18877 but sofar no succes. After receiving some comments I made some changes to the RxChar() function.
From the computer I am sending 0xFE05 to the controller by means of a usb to ttl interface (USB To RS232 TTL PL2303HX). A serial monitor in between shows no errors. The send char is going out correctly. On the micro controller side I keep receiving frame errors time after time.
Still trying to make the EUSART working. Sofar without succes. To find out where the problem comes from I returned to the Original hex file (code in basic) to reduce the possible error sources. The Original program is written for the pic16F887A and after programming the PIC16F877A the serial communication operates correctly. The serial communication for the PIC16F877A must be in a library since I can not find it in the basic code. Only the port and baud definitions are given.
This above makes me believe that the problem must be somewhere in the settings or code of my project with the PIC16F18877. But sofar I have no clue. Any assistance in how to proceed is welcome.
fosc = 20.000000
void UART_Init(void)
{
RC1STAbits.SPEN = 0; // begin of setup disable serial port.
// transmitter
TX1STAbits.TXEN = 1; // continues transmit enable bit
TX1STAbits.TX9 = 0; // 8 bit transmission
TX1STAbits.SYNC = 0; // asynchronous operation
ANSELCbits.ANSC6 = 0; // digital
TRISCbits.TRISC6 = 0; // output
// receiver
RC1STAbits.CREN = 1; // continues receive enable bit
RC1STAbits.RX9 = 0;
// there is only one sync
ANSELCbits.ANSC7 = 0; // digital
TRISCbits.TRISC7 = 1; // input
// baudrate.
TX1STAbits.BRGH = 1;
BAUD1CONbits.BRG16 = 1;
SPBRG = 520; // baudrate 9600
RC1STAbits.SPEN = 1; // end of setup enable serial port
}
void UART_TxChar(uchar ch)
{
while(TXIF==0);
TXREG=ch;
}
uchar UART_RxChar()
{
uchar Discard;
while(1){
while(RCIF==0); // Wait till the data is received
if (RCSTAbits.FERR)
{
Discard = RCREG; Read the register and wait for the next byte
break;
}
if (RCSTAbits.OERR)
{
RCSTAbits.CREN = 0;
break;
}
return RCREG; // Return the received data to calling function
}
}
0
? You should not do that. And you haven't shown how all this is used \$\endgroup\$