UART Receiver Framing Error

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
Hello sir,
I'm receiving "UART Receiver Framing error" and some characters are working fine but some are not….my right hand keys are working fine but left hand keys are displaying different characters…if i press a key then "y" is displaying in terminal how can i solve this problem?

I’m using pic18f4550 and using external 20Mhz crystal and my project settings are below and schematic:

PLL Prescaler Selection:
Divide by 5(20MHz oscillator input)

System Clock Postscaler Selection:
[Primary Oscillator Src: /1][96 MHz PLL Src: /2]

USB Clock Selection (used in full-Speed USB mode onl…
USB clock source comes from the 96 MHz PLL divided by 2

Oscillator Selection
HS oscillator, PLL enabled (HSPLL)?

Thanks
 

Attachments

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
Thanks AlbertHall for your response.
I'm using baud rate 9600 in program and also into real terminal.
what will you recommend?

C:
void main() {
ADCON1=0x0F;

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);

  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      UART1_Write(uart_rd);       // and send data via UART
    }
  }
}
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
9,826
How accurately does UART1_Init set the baud rate? Look at the actual register values and use the datasheet to calculate the baud rate for those values.

Have you ensured that the number of data bits and stop bits match between the terminal and the PIC?
 

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
I did not calculate baud rate just put that value as it is. what register should i look?...you mean I have to set data bit and stop bit in program also?
 

hexreader

Joined Apr 16, 2011
404
Alternatively....

Zip up your whole project folder and post the zip file here. This way I can see all of your settings as well as your code.

I will be happy to check it all out for you.

No need to check registers - as mikroC compiler will do the hard work as long as your project settings are correct.
 

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
Yup, there are registers you have to write to to set up the serial port. You need to down load the reference manual for the chip and go thru it.
Thanks noweare

According to datasheet I'm calculating baud rate by using below formula.
X = ((FOSC/Desired Baud Rate)/64) – 1

Now I changed my program like below but not working:
C:
ADCON1=0x0F;
SYNC_bit=0;
BRGH_bit=0;
BRG16_bit=0;

             //SPBRG = 129;

  UART1_Init(9766);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);

  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      UART1_Write(uart_rd);       // and send data via UART
    }
  }
 
Last edited by a moderator:

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
Alternatively....

Zip up your whole project folder and post the zip file here. This way I can see all of your settings as well as your code.

I will be happy to check it all out for you.

No need to check registers - as mikroC compiler will do the hard work as long as your project settings are correct.
Thanks hexreader here is my project.
 

Attachments

hexreader

Joined Apr 16, 2011
404
Absolutely nothing wrong with your code or your settings.

Accurate 9600 baud is going out on RC6 as shown in scope print below:
NewFile1.png

Now check your terminal settings on PC "real terminal". You should select 9600 baud, 8 data bits, 1 stop bit, no parity, no flow control.

Schematic looks good as far as I can tell.

Good luck...
 
Last edited:

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
Thanks hexreader for your time to check my prj.
I have checked my serial cable and shorting the T1/T2 out and R1/R2 in the level shifter. Its working fine in terminal. now what should I do?

my real terminal settings are
Baud rate: 9600
1 stop bits
8 data bits
no parity
hardware flow none
 

hexreader

Joined Apr 16, 2011
404
Connect the cable from PC to your board making sure that Tx goes to Rx, Rx goes to Tx and common goes to common

All looks good to me, so all I can think of is that the cable has a problem
 

JohnInTX

Joined Jun 26, 2012
4,064
Hmmm.. You should also check the errata for the chip. This is an old one and they have a lot of bugs, many in the USART. I didn't see any that would account for your framing error on the PC but number 19 is interesting. Keep in mind that not all silicon errors get to the errata in a timely manner.
http://ww1.microchip.com/downloads/en/DeviceDoc/80478a.pdf

Just for grins, reset your clock to EC at 20mhz and recalculate the baud settings for that. Sometimes the PLL can be problematic when running at high speeds.
 
Last edited:

Thread Starter

Omais Ahmed

Joined Oct 4, 2015
35
thanks alot both of you hexreader and johnInTX

it's working. :)

I changed my program...there's no hardware issue.
C:
TRISC7_bit  = 1;          /* RC7(RX) configured as i/p                   */
TRISC6_bit  = 1;          /* RC6(TX) configured as o/p                   */
TXSTA   = 0X20;       /* Transmission Enable(TXEN=1,SYNC=0,BRGH=1)   */
RCSTA   = 0X90;       /* Rception Enable (SPEN=1,CREN=1)             */
BAUDCON = 0x40;       /* Baudrate control Register                   */
SPBRG   = 0X4D;       /* 9600 brgh=0 */


                                
  //UART1_Init(9600);
  Delay_ms(2000);                  // Wait for UART module to stabilize

  UART1_Write_Text("Start");
  UART1_Write(10);
  UART1_Write(13);

  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     // read the received data,
      UART1_Write(uart_rd);       // and send data via UART
    }
  }
 
Last edited by a moderator:
Top