2011-07-29 05:10 AM
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-usart2011-07-29 08:56 AM
The 24 MHz VL Discovery has NO problem outputting at 460800 baud into a USB-to-CMOS Serial dongle.
a) Check your serial port supports the rate. Most internal/motherboard ones don't. b) Attach a scope and verify the bit/baud clocking is what you expect. c) RS232 driver chips often filter >1Mbaud. void RCC_Configuration(void); void GPIO_Configuration(void); void USART_Configuration(void); void RCC_Configuration(void) { ErrorStatus HSEStartUpStatus; /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if (HSEStartUpStatus == SUCCESS) { #if 0 // VL Does not require /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 0 wait state */ FLASH_SetLatency(FLASH_Latency_0); #endif /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div1); /* ADCCLK = PCLK2/4 */ RCC_ADCCLKConfig(RCC_PCLK2_Div4); /* PLLCLK = 8MHz * 3 = 24 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08); } } void USART_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* Configure USART Tx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // PA.09 USART1.TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // PA.10 USART1.RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART resources configuration (Clock, GPIO pins and USART registers) ----*/ /* USART configured as follow: - BaudRate = 460800 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 = 460800; 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; /* Enable UART clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* USART configuration */ USART_Init(USART1, &USART_InitStructure); /* Enable the USART1 */ USART_Cmd(USART1, ENABLE); } int main(void) { char str[] = ''Welcome to wherever you are...''; char *s; RCC_Configuration(); USART_Configuration(); /* Infinite loop */ while(1) { s = str; while(*s) { while((USART1->SR & 0x40)==0); USART1->DR = *s++; } } /* does not exit - kind of important */ return(1); }