AnsweredAssumed Answered

Can't increase USART Baud above 130Kbps?

Question asked by kureigu on Sep 29, 2014
Latest reply on Sep 30, 2014 by kureigu
Hi all,

I've been getting familiar with the RCC stuff on the STM32L152 (STMrecently152L-Discovery), but I'm struggling to push the baud rate of my USART transmission beyond 130Kbaud.

I've set up the SysClk to use the PLL, after dividing the HSI down to 12MHz (16MHz*3/4). That's far faster than the default 2MHz it was running on before so seems to me like it should be plenty headroom for the USART to be able to up its speed. What I'm seeing though when I set the Baud to > 130Kbps though is the actual Baud rate dropping to near 200bps on the scope.

I'm not sure if there's a stage of configuration I'm missing, but I think I've been looking at it so long I wouldn't even be able to spot it now.

I know my clock config is working okay in terms of the SYSCLK, because setting up my MCO pin using the SYSCLK will output the expected 12MHz.

RCC_MCOConfig(RCC_MCOSource_SYSCLK,RCC_MCODiv_1);



Clock configuration:
01./* Configure the clocks as required */
02.void Clock_cfg(void){
03.     
04.     
05. // Enable HSI //
06. RCC_HSICmd(ENABLE);
07.     
08. // Enable Prefetch Buffer //
09. FLASH_PrefetchBufferCmd(ENABLE);
10. 
11. // Flash 0 wait state //
12. FLASH_SetLatency(FLASH_Latency_0);
13.             
14. // HCLK = SYSCLK // HCLK derived from SCLK
15. RCC_HCLKConfig(RCC_SYSCLK_Div1);      
16.     
17. // APB1 Clock
18. RCC_PCLK1Config(RCC_HCLK_Div1);
19.     
20. // APB2 Clock
21. RCC_PCLK2Config(RCC_HCLK_Div1);
22.     
23. // Set PLL clock as HSI*8/4 = 16MHz/2
24. RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_3, RCC_PLLDiv_4);
25.     
26. // Enable PLL
27. RCC_PLLCmd(ENABLE);
28.     
29. // Wait til PLL is ready
30. while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
31.     
32. // SysClk/AHB clock config // Set from PLL Clock
33. RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
34.     
35. // Wait till PLL is used as system clock source
36. while(RCC_GetSYSCLKSource() != 0x0C);
37.     
38. 
39.     
40.}


USART config:
01.// Configure pin for USART TX
02.GPIO_IS.GPIO_Pin = USART_TX;                // Configure pin   
03.GPIO_IS.GPIO_Mode = GPIO_Mode_AF;                   // Set as output                       
04.GPIO_IS.GPIO_OType = GPIO_OType_PP;             // Push/pull
05.GPIO_IS.GPIO_Speed = GPIO_Speed_40MHz;      // 40MHz clk
06.GPIO_IS.GPIO_PuPd = GPIO_PuPd_UP;                 // Pull-up
07.GPIO_Init(USART_PORT, &GPIO_IS);   
08. 
09.// Configure alternate functions
10.GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);   // PA2 - USART2_TX
11. 
12.// Configure USART
13.USART_IS.USART_BaudRate = 140000;
14.USART_IS.USART_WordLength = USART_WordLength_8b;
15.USART_IS.USART_StopBits = USART_StopBits_2;
16.USART_IS.USART_Parity = USART_Parity_No;
17.USART_IS.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
18.USART_IS.USART_Mode = USART_Mode_Tx;
19.//Apply structure
20.USART_Init(USART2, &USART_IS);
21. 
22.// Enable USART
23.USART_Cmd(USART2, ENABLE);


Any advice or ideas would be very welcome!

Outcomes