USART Framing Error

Page: 12 > Showing page 1 of 2
Author
Tom Myers
Super Member
  • Total Posts : 444
  • Reward points : 0
  • Joined: 2003/11/07 12:37:50
  • Status: offline
2008/05/20 07:48:58 (permalink)
0

USART Framing Error

Hi,
 
I am using a 18F87J50 with the internal clock (default to 4 MHz). I am using the USART library in C18. The USART set-up is as follows:
 

 //configure USART
 Open1USART(  USART_TX_INT_OFF  &
                     USART_RX_INT_ON  &
                     USART_ASYNCH_MODE &
                     USART_EIGHT_BIT  &
                     USART_CONT_RX  &
                     USART_BRGH_HIGH,
                     25 );                                   //9600,n,8,1 - for a 4 MHz Osc.
 

 
I am analysing the serial Tx line using the microchip serial analyser, with the software set to 9600 baud.
 
While the data looks right, it reports framing errors and displays the data something like:
 
61[Err] 54 [Err] 67 [Err] ..... where [Err] represents framing errors.
 
I have tried tuning the internal osc with the osctune register, as follows:
 

   OSCTUNE = tuneReg;
   Nop();

 
I right a value into tuneReg via the DMCI slider at run time and even when I go through the full range of tuning values, I still get framing errors (full range 1 - 63).
 
Any thoughts?
 
Regards,
Tom
 
 
#1

21 Replies Related Threads

    jgmartinez
    Super Member
    • Total Posts : 537
    • Reward points : 0
    • Joined: 2007/06/28 06:13:39
    • Location: Madrid, Spain.
    • Status: offline
    RE: USART Framing Error 2008/05/20 07:57:36 (permalink)
    0
    Internal oscillator is not stable and acuracy for high data rate transmission. There are some threads about this matter, chek them.

    Juan Pablo
    EA4CIV
    #2
    Tom Myers
    Super Member
    • Total Posts : 444
    • Reward points : 0
    • Joined: 2003/11/07 12:37:50
    • Status: offline
    RE: USART Framing Error 2008/05/20 09:18:51 (permalink)
    0
    Same problem persists with external clock.
     
    Regards,
    Tom
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/05/20 15:57:31 (permalink)
    0
    Hi Tom, at times a "fine tune" (+/- 1) of BRG value can help in these cases...

    GENOVA :D :D ! GODO
    #4
    Tom Myers
    Super Member
    • Total Posts : 444
    • Reward points : 0
    • Joined: 2003/11/07 12:37:50
    • Status: offline
    RE: USART Framing Error 2008/05/20 23:10:17 (permalink)
    0
    Hi Dario,
     
    I have observed the changes from BRG = 10 through to 30 with +1 increments. Even though at the extremeties the framing error ceases, the data is garbage. I have also tried it at multiples i.e. 50, 100 etc..
     
    On the scope the baud rate looks to be correct approx. 9600 KHz period between successive bits when BRG = 25.
     
    I have used the USART many many times, but never on a J series PIC nor on a device with multiple USARTS.
     
    I am very scepticle of the clock settings on this device, however, the baud rate looks right? [:@]
     
    Isn't a framing error caused by a misplaced stop bit? If so, why would this become independant of the rest of the packet i.e. in inter bit timing looks correct, surely the stop bit should follow correctly? (although I haven't scoped it! Smile).
     
    Argggghhhhhhhh .......
     
    Regards,
    Tom
    #5
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/05/21 01:36:25 (permalink)
    0
    Well, definitely strange Smile

    Yeah, the framing error is that one.
    What about Erratas? And... baudUSART() ?

    GENOVA :D :D ! GODO
    #6
    Tom Myers
    Super Member
    • Total Posts : 444
    • Reward points : 0
    • Joined: 2003/11/07 12:37:50
    • Status: offline
    RE: USART Framing Error 2008/05/21 02:07:15 (permalink)
    0
    Dario,
     
    I had checked the errata and there is nothing on this.
     
     
    Should BaudUSART() be used as well as the Open1USART( config ) function?
     
    Regards,
    Tom
    #7
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/05/21 03:34:41 (permalink)
    0
    Yes, it completes the settings.

    GENOVA :D :D ! GODO
    #8
    tunelabguy
    Super Member
    • Total Posts : 1712
    • Reward points : 0
    • Joined: 2005/04/03 08:30:19
    • Location: Hopkins, MN USA
    • Status: offline
    RE: USART Framing Error 2008/05/21 04:15:25 (permalink)
    0
    Just a wild guess, but have you checked your polarity? The TX output pin is usually inverted through a MAX232 or other similar RS-232 interface chip, which inverts the polarity. On the TX pin the start bit should be low and the stop bit should be high. On the RS-232 end, the start bit is high and the stop bit is low. Are you using such a chip?

    Robert Scott
    Hopkins, MN
     
    #9
    Tom Myers
    Super Member
    • Total Posts : 444
    • Reward points : 0
    • Joined: 2003/11/07 12:37:50
    • Status: offline
    RE: USART Framing Error 2008/05/21 05:08:51 (permalink)
    0
    Hi,
     
    Both very interesting points.
     
    1) I will try the BaudUSART() - although I have never used this in any previous applications.
     
    2) I am not using any level translating IC. I am working at 3.3V on the PIC and the device which I am talking to also uses 3.3V - I wonder could this be the problem?
     
    I have placed the PIC Serial Analyzer in parallel to may PIC and this communicates with the device perfectly.
     
    Regards,
    Tom
    #10
    Tom Myers
    Super Member
    • Total Posts : 444
    • Reward points : 0
    • Joined: 2003/11/07 12:37:50
    • Status: offline
    RE: USART Framing Error 2008/05/21 09:18:48 (permalink)
    0
    Hi,
     
    I have been looking through the .c files associated with USART and USART.h - in these files definitions are tested and depending on the outcome various registers set.
     
    For example:
     

     
    #if defined (EAUSART_V6)|| defined (EAUSART_V7) || defined (EAUSART_V8) || defined (EAUSART_V9) || defined (EAUSART_V10)  || defined (EAUSART_V10)
     

     
    Where are these definitions made? I have looked in the .h files associated with my processor i.e. p18f87j50.h and they are not contained in there?
     
    Where are they? Should the programmer conciously define them? I have never done so in the past - maybe I have just been fortunate!
     
    Regards,
    Tom
    #11
    Tom Myers
    Super Member
    • Total Posts : 444
    • Reward points : 0
    • Joined: 2003/11/07 12:37:50
    • Status: offline
    RE: USART Framing Error 2008/05/21 10:30:32 (permalink)
    0
    FIXED ......................
     
    Thanks for all your help guys. It was a partial effort in the end. It seems like it was the clock idle state!
     
    With the addition of:
     

      baud1USART( BAUD_IDLE_CLK_LOW &
        BAUD_8_BIT_RATE  &
        BAUD_WAKEUP_OFF  &
        BAUD_AUTO_OFF  );

     
    Which I have never used before SmileSmile (my luck has run out!). With BAUD_IDLE_CLK_HIGH I got framing errors and with it set as above, things are running perfectly!
     
    Thank you and regards.
     
    Tom
    #12
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/05/21 10:37:26 (permalink)
    0
    Hi Tom, I can see those EAUSART_ things in a "pconfig.h" file into MCC18 include folder...

    GENOVA :D :D ! GODO
    #13
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/05/21 10:39:04 (permalink)
    0
    ORIGINAL: Tom Myers

    With the addition of:


     baud1USART( BAUD_IDLE_CLK_LOW &
       BAUD_8_BIT_RATE  &
       BAUD_WAKEUP_OFF  &
       BAUD_AUTO_OFF  );




    Well, very good then Smile

    GENOVA :D :D ! GODO
    #14
    tunelabguy
    Super Member
    • Total Posts : 1712
    • Reward points : 0
    • Joined: 2005/04/03 08:30:19
    • Location: Hopkins, MN USA
    • Status: offline
    RE: USART Framing Error 2008/05/21 12:40:11 (permalink)
    0
    ORIGINAL: Tom Myers
    ..It seems like it was the clock idle state!

    With the addition of:


     baud1USART( BAUD_IDLE_CLK_LOW &
       BAUD_8_BIT_RATE  &
       BAUD_WAKEUP_OFF  &
       BAUD_AUTO_OFF  );


    Ah, so it was polarity after all! I didn't realize that these PIC18F devices had the ability to flip polarity, but now that you brought this to light, I see that the BAUDCON register has two bits called RXDTP and TXCKP, which set the polarity of the transmit and receive pins. That must be what your BAUD_IDLE_CLK_LOW setting does. If you were using a 16F series part, then you would have been stuck with IDLE_CLK_HIGH as the only choice.

    Robert Scott
    Hopkins, MN
     
    #15
    vloki
    Jo, alla!
    • Total Posts : 6755
    • Reward points : 0
    • Joined: 2007/10/15 00:51:49
    • Location: Germany
    • Status: offline
    RE: USART Framing Error 2008/05/21 13:18:10 (permalink)
    0
    ORIGINAL: Tom Myers

    FIXED ......................

    Thanks for all your help guys. It was a partial effort in the end. It seems like it was the clock idle state!

    With the addition of:


    baud1USART( BAUD_IDLE_CLK_LOW &
    BAUD_8_BIT_RATE  &
    BAUD_WAKEUP_OFF  &
    BAUD_AUTO_OFF  );


    Which I have never used before SmileSmile (my luck has run out!). With BAUD_IDLE_CLK_HIGH I got framing errors and with it set as above, things are running perfectly!

    Thank you and regards.

    Tom

    IMO you are a lucky guy - each time i was using this baudUSART() i got crazy gringringrin

    Now i hope that I know why this hapened and would suggest to use it this way:
    (edit: in asyncronous mode)

    baud1USART( BAUD_IDLE_RX_PIN_STATE_HIGH &
                    BAUD_IDLE_TX_PIN_STATE_HIGH

                    BAUD_8_BIT_RATE  &
                    BAUD_WAKEUP_OFF  &
                    BAUD_AUTO_OFF  );

    Don't know it causes problems with PIC18F87J50 but it seems more save to me defining
    both bits.
    (see bad documentation of baudUSART() function ?)
    post edited by vloki - 2008/05/21 13:20:58

    Uffbasse !
    #16
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/05/21 13:43:52 (permalink)
    0
    In fact I thought about you Vloki grin

    GENOVA :D :D ! GODO
    #17
    Malin Dixon
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2007/07/17 14:38:34
    • Location: 0
    • Status: offline
    RE: USART Framing Error 2008/06/14 01:24:01 (permalink)
    0
    I don't know what bit C18 uses to decide that there is space to transmit another byte, but there could be a problem if it uses TRMT bit, as this can result in the stop bit being too short so the next byte can be transmitted early.

    http://forum.microchip.com/tm.aspx?m=289304&mpage=1&key=&#290815


    #18
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USART Framing Error 2008/06/16 02:50:02 (permalink)
    0
    Yes, BusyUSART() uses TRMT:

    char BusyUSART(void)
    {
      if(!TXSTAbits.TRMT)  // Is the transmit shift register empty
        return 1;          // No, return FALSE
      return 0;            // Return TRUE
    }


    (and putsUSART() relies on that on top)

    GENOVA :D :D ! GODO
    #19
    moiska
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2013/12/02 23:03:25
    • Location: 0
    • Status: offline
    RE: USART Framing Error 2013/12/02 23:36:49 (permalink)
    0
    数据手册介绍:使用高波特率(BRGH = 1)或16 位BRG 有利于减小波特率误差,或者在快速振荡频率条件下实现低波特率。 
      
    我使用PIC18F4525,我遇到接收字符错误和帧错误(向PIC18F4525发送03h,RCREG收到:0Ah   FERR=1),此时我使用内部振荡器模块,工作频率32MHz(4x8MHz)。 
    考虑是否速度过高,因此我改用16MHz(4x4MHz),然而现象依旧。
     
    我也试过利用OSCTUN 降低或频率,RCREG收到数据有变,但FERR=1始终存在。
     
    最后,我取消使用PLL,直接使用FOSC=8MHz,问题得到解决。 

    因此,我认为,可能内部振荡器模块输出频率存在误差,这个误差是可以允许的,但经过PLL 4倍频以后,误差被放大就超出了允许的限度。 
    还好,8MHz对我的工作完全胜任。 

    ;-----------------------------------------
    ;OSCCON:振荡器控制寄存器 //0100 q000 //0100 q000 //uuuu uuqu 
    ; //IDLEN //IRCF2 //IRCF1 //IRCF0 //OSTS //IOFS //SCS1 //SCS0 
              MOVLW B'11111010' 
              MOVWF OSCCON 
    ;-----------------------------------------ok
    ;OSCTUNE:振荡器调节寄存器 //00-0 0000 //00-0 0000 //uu-u uuuu 
    ; //INTSRC //PLLEN(1) //— //TUN4 //TUN3 //TUN2 //TUN1 //TUN0 
             MOVLW B'10000000' 
             MOVWF OSCTUNE 
    ;---------------------------------------------------------------- 
             movlw 0xc0 ;  set tris bits for Tx and RX 
             iorwf TRISC,F 
    ;------------------------------------------------ 
    ;BAUDCON //01-0 0-00 //01-0 0-00 //--uu uuuu 
    ; //ABDOVF //RCIDL //— //SCKP //BRG16 //— //WUE //ABDEN 
             bsf BAUDCON,BRG16 ;bit 3 BRG16:16 位波特率发生器位 ; 1=使用16 位波特率发生器 ; 0=使用8 位波特率发生器 
             ...... 
            TBLRD*+ ; read into TABLAT and increment 
            MOVF TABLAT,W ; get data 
            MOVWF SPBRGH 
            TBLRD*+ ; read into TABLAT and increment 
            MOVF TABLAT,W ; get data 
            MOVWF SPBRG;L 
             ...... 
    SetupSerial01: 
    ;------------------------------------------------ 
    ;TXSTA //0000 0010 //0000 0010 //uuuu uuuu 
              movlw B'01000110';=B'00100100' 
              movwf TXSTA 
    ;------------------------------------------------ 
    ;RCSTA //0000 000x //0000 000x //uuuu uuuu 
              movlw B'11000000' ;=B'10010000' 
              movwf RCSTA 
             ......
     

    pink
    post edited by moiska - 2013/12/02 23:59:09
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5