STM32F103ZE USART baud rate over 115200
- July 29, 2011
- 1 reply
- 917 views
Hi,
I have a
little problem
with setting
a custom
speed on the
STM32
above
115200th
The problem occurs
both when
using the
init
or
manual configuration
(manual
calculation
of values ??for
the registry
BRR)
.
There is no problem
with different
transmissions
9600
, 28800
until
115200th
After
this value,
the terminal
is silent.
Only
by using the
library function
to initialize the
USART
to the terminal
reached
some
wrong information.
With
manual configuration
did not
reach
above the
115200th
Overall,
I must
dispel
USART
to
1Mb
, because
I make
the
servo
controller
which
is at
such a
speed
that
communicates with the
interface.
I would add
that I am using
win 7
and
the
terminal
v1.9b
.
Once
I tested the
speed
, eg
256 000
for
ATMega32
and
worked
without a problem
.
&sharpinclude ''stm32f10x.h''
&sharpinclude ''stm32f10x_conf.h''
void
RCC_Conf(
void
)
;
int
main(
)
{
RCC_Conf(
)
;
uint16_t
zmienna=
0
;
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(
RCC_APB2Periph_USART1|
RCC_APB2Periph_GPIOA, ENABLE)
;
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin
=
GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode
=
GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed
=
GPIO_Speed_50MHz;
GPIO_Init(
GPIOA,&
GPIO_InitStructure)
;
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin
=
GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode
=
GPIO_Mode_IN_FLOATING;
GPIO_Init(
GPIOA,&
GPIO_InitStructure)
;
USART_ClockInitTypeDef USART_ClockInitStructure;
USART_ClockInitStructure.USART_Clock
=
USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL
=
USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA
=
USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit
=
USART_LastBit_Disable;
USART_ClockInit(
USART1,&
USART_ClockInitStructure)
;
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;
uint32_t
tmp;
tmp=
USART1-
>
CR1;
tmp|
=
USART_InitStructure.USART_WordLength
|
USART_InitStructure.USART_Parity
|
USART_InitStructure.USART_Mode
;
USART1-
>
CR1=
tmp;
tmp=
USART1-
>
CR2;
tmp|
=
USART_InitStructure.USART_StopBits
;
USART1-
>
CR2=
tmp;
tmp=
USART1-
>
CR3;
tmp|
=
USART_InitStructure.USART_HardwareFlowControl
;
USART1-
>
CR3=
tmp;
USART1-
>
BRR=
(
uint16_t
)
0x9c4
;
/* Enable USART1 */
USART_Cmd(
USART1, ENABLE)
;
while
(
1
)
{
while
(
USART_GetFlagStatus(
USART1, USART_FLAG_TXE)
==
RESET)
{
}
USART_SendData(
USART1,0xA2
)
;
while
(
USART_GetFlagStatus(
USART1, USART_FLAG_RXNE)
==
RESET)
{
}
zmienna=
USART_ReceiveData(
USART1)
;
}
return
0
;
}
void
RCC_Conf(
void
)
{
ErrorStatus HSEStartStatus;
//reset ustawie? RCC
RCC_DeInit(
)
;
//W??cz HSE
RCC_HSEConfig(
RCC_HSE_ON)
;
//Czekaj a? HSE b?dzie gotowy
HSEStartStatus=
RCC_WaitForHSEStartUp(
)
;
if
(
HSEStartStatus==
SUCCESS)
{
FLASH_PrefetchBufferCmd(
FLASH_PrefetchBuffer_Enable)
;
//zwloka dla pamieci Flash
FLASH_SetLatency(
FLASH_Latency_2)
;
//HCLK = SYSCLK
RCC_HCLKConfig(
RCC_SYSCLK_Div1)
;
//PCLK2 = HCLK
RCC_PCLK2Config(
RCC_HCLK_Div1)
;
//PCLK1 = HCLK/2
RCC_PCLK1Config(
RCC_HCLK_Div2)
;
//PLLCLK = 8MHz * 9 = 72MHz
RCC_PLLConfig(
RCC_PLLSource_HSE_Div1, RCC_PLLMul_9)
;
//W??cz PLL
RCC_PLLCmd(
ENABLE)
;
//Czekaj a? PLL poprawnie si? uruchomi
while
(
RCC_GetFlagStatus(
RCC_FLAG_PLLRDY)
==
RESET)
{
}
//PLL b?dzie zrodlem sygnalu zegarowego
RCC_SYSCLKConfig(
RCC_SYSCLKSource_PLLCLK)
;
while
(
RCC_GetSYSCLKSource(
)
!
=
0x08
)
{
}
}
}
#stm32-usart