PIC16F15354 UART

Thread Starter

Missio2468

Joined Mar 18, 2022
69
I am using PIC16F15354 UART for serial Communication. Uart Works as it should be. I send a data (Let's say A) through realterm software and My PIC returns with data P and if other data is send then it should return data B. when the device is powered on I get the data correctly.(That means if I send A, I recieve P). But immediately if I send the data C(other than A) after first byte sent. I still recieve the previous message that is P.Now if I resend the data B one more time, I recieve the data B.
Can anyone help me to figure where the problem is??
 

cmartinez

Joined Jan 17, 2007
8,253
Most likely it's a programming issue. You'd have to share the code for us to try and help you trace the problem.

Also, make sure that the PCB's traces are clean and there's no short circuit that could cause crosstalk between Tx and Rx
 

geekoftheweek

Joined Oct 6, 2013
1,216
Code:
void UART_send_char(char bt){
    while(PIR3bits.TX1IF == 0){}  // hold the program till TX buffer is free
    TXREG = bt; //Load the transmitter buffer with the received value
        __delay_ms(0.2);
    while(TX1STAbits.TRMT == 0);
    PIE3bits.TX1IE = 0;
}
I didn't quite make if through the whole program, but this section caught my eye...
Maybe it's in an area I didn't look but I didn't see anywhere that PIR3bits.TXIF is being cleared.
I would do something like
Code:
void UART_send_char(char bt){
    while(PIR3bits.TX1IF == 0){}  // hold the program till TX buffer is free

    PIR3bits.TXIF = 0;  //  clear interrupt before reloading TXREG

    TXREG = bt; //Load the transmitter buffer with the received value
        __delay_ms(0.2);
    while(TX1STAbits.TRMT == 0);
    PIE3bits.TX1IE = 0;
}
 
Top