Skip to main content
Visitor II
August 4, 2009
Question

possible bug in UART lib??

  • August 4, 2009
  • 2 replies
  • 658 views
Posted on August 04, 2009 at 08:05

possible bug in UART lib??

    This topic has been closed for replies.

    2 replies

    rhoek9Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:04

    I’ am having some problems with the UART Baudrate.

    I using the STM8s208RB microcontroller.

    I am cofiguring the UART3 with the STM libs that are provided by STMicroelectronics.

    clock setting; ''high speed internal clock prescaler: 1''. (16MHz)

    Baudrate_UART3 = 38400

    when I check the serial communication an UART3 the baudrate of the send 10 bit messages are almost 10% off, 34598.

    the send messages of the PC and chip that I want to communicate with have both a baudrate of 38450 ~ 38460.

    in the AN2659 bootloader example code they rewrite BRR1 en BRR2 to set correct baudrate - bug in library.

    void SetUARTSpeed(u16 AutobaudPulse)

    {

    u32 BaudRate;

    //compute baudrate

    AutobaudPulse += 20; //correct systematic error (experimental)

    AutobaudPulse /= 7; //pulses ber one bit (sync byte has 7 ones)

    BaudRate = CLK_GetClockFreq() / AutobaudPulse; //calculate baudrate

    //set push-pull on UART_tx pin

    GPIO_Init(UART1_TX_PORT, UART1_TX_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);

    //remove software pull-up on UART_rx pin

    GPIO_Init(UART1_RX_PORT, UART1_RX_PIN, GPIO_MODE_IN_FL_NO_IT);

    //init UART 8-bits, 1 stop bit, even parity

    UART1_Cmd(ENABLE);

    UART1_Init(BaudRate, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

    //to set correct baudrate - bug in library

    UART1->BRR2 = (AutobaudPulse & 0x000F) | ((AutobaudPulse & 0xF000) >> 4);

    UART1->BRR1 = (AutobaudPulse & 0x0FF0) >> 4;

    }//SetUARTSpeed

    //**************************************************************************

    Is it correct that there is a bug in the UART libraries?

    Is there a solution for it?

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:04

    Hi Hoek,

    This is a limitation on the UART3 that consist to configure the fraction and MSB mantissa in one step in the BRR2 register (refer to library), if not the case the UART3_BRR2 register is cleared after the second access, I think that is your case!!!!! This limitation is not available for the UART1.

    When using the library you don't have this issue.

    Just for information, the library used in your code is not the last version you can refer to this link to download the version v1.1.1:

    http://www.st.com/mcu/modules.php?name=mcu&file=familiesdocs&FAM=113

    Regards

    mozra