cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152-EVAL USART baud rate is not correct except 9600

xinjin
Associate II
Posted on April 02, 2013 at 17:16

I found it is not correct on STM32L152-EVAL USART baud rate. The clock configuration is set as below. I use printf to show some character such as ''hello world'' on the terminal. It only works with 9600. And the baud rate would be not correct with setting to 115200. I am not sure if the demo board on my hand is broken. Strange.

  *=============================================================================

  *                         System Clock Configuration

  *=============================================================================

  *        System Clock source          | PLL(HSE)

  *-----------------------------------------------------------------------------

  *        SYSCLK                       | 32000000 Hz

  *-----------------------------------------------------------------------------

  *        HCLK                         | 32000000 Hz

  *-----------------------------------------------------------------------------

  *        AHB Prescaler                | 1

  *-----------------------------------------------------------------------------

  *        APB1 Prescaler               | 1

  *-----------------------------------------------------------------------------

  *        APB2 Prescaler               | 1

  *-----------------------------------------------------------------------------

  *        HSE Frequency                | 8000000 Hz

  *-----------------------------------------------------------------------------

  *        PLL DIV                      | 3

  *-----------------------------------------------------------------------------

  *        PLL MUL                      | 12

  *-----------------------------------------------------------------------------

  *        VDD                          | 3.3 V

  *-----------------------------------------------------------------------------

  *        Vcore                        | 1.8 V (Range 1)

  *-----------------------------------------------------------------------------

  *        Flash Latency                | 1 WS

  *-----------------------------------------------------------------------------

  *        SDIO clock (SDIOCLK)         | 48000000 Hz

  *-----------------------------------------------------------------------------

  *        Require 48MHz for USB clock  | Disabled

  *-----------------------------------------------------------------------------

  *=============================================================================

I also use the driver in the library to configure the USART as below:

    USART_InitTypeDef USART_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

/* --------------------------- System Clocks Configuration -----------------*/

/* USART3 clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

/* GPIOC clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

/*-------------------------- GPIO Configuration ----------------------------*/

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Connect USART pins to AF */

GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);

/* USARTx configuration ------------------------------------------------------*/

/* USARTx configured as follow:

 - BaudRate = 9600 baud

 - Word Length = 8 Bits

 - One Stop Bit

 - No parity

 - Hardware flow control disabled (RTS and CTS signals)

 - Receive and transmit enabled

*/

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

        

    /* USART configuration */

    USART_Init(USART3, &USART_InitStructure);

  

    /* Enable USART */

USART_Cmd(USART3, ENABLE);

5 REPLIES 5
Posted on April 02, 2013 at 17:23

Make sure you have the jumper set up right.

Send a continuous stream of characters (0x55 ?), and look at the signal on a scope. Measure the bit times of different baud rates, then conclude if there is a pattern to the issue. Is the clocking wrong, or the signal distorted.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
linas2
Associate II
Posted on April 03, 2013 at 10:10

I had baud rate problem when dealing with STM32F4

all clock values was defined in system_stm32f4xx.c, but in stm32f4xx.h crystal nominal was different,

#if !defined (HSE_VALUE) 
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

when i changed that it worked as it should. Just idea.
Posted on April 03, 2013 at 10:16

But that was more of a math issue, where nothing came out at the correct baud rate, because all computation were based on flawed assumptions (hardware vs software). The issue here is more nuanced, as one baud rate does work, while others do not.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jj2
Associate II
Posted on April 04, 2013 at 16:14

''Issue here is more nuanced, as one baud rate does work,'' - excellent observation & precision use of language.

In > 20 years work w/RS232/485 - have only encountered such signaling rate inconsistencies @ very high baud rates - and this always due to cable/equipment limitations.

Perhaps simple-minded - but is the non-MCU end truly tested/verified @ other baud rates?  (and/or - has it been properly re-configured to the new, test baud rate?)  Sometimes - the remote device may ''default'' into unwanted settings (i.e. hw flow control on) upon simple baud rate setting change - watch for this...

Use of the scope and alternating bit patterns (0x55 or 0xAA) surely is best/fastest means to resolve...

microeval
Associate II
Posted on June 21, 2013 at 13:22

Hi jj.sprague,

I have STM32L152VB(Medium density device:128KB Flash, 16KB RAM) board and i tried USART Example code(from IAR Examples) but nothing is getting in serial terminal. I tried with 115200 and 9600 baud rates. Can you please suggest me the Example code for USART on STM32L152VB board.

Thanks,

Ram.