c - Synchronous mode of USART -


i working stm32f103 , want send , receive data synchronous mode of usart2. have question, how can set clock example 10 mhz usart? register?

gpio_inittypedef gpio_initstructure;                      rcc_apb2periphclockcmd( rcc_apb2periph_gpioa | rcc_apb2periph_afio ,enable); rcc_apb1periphclockcmd(rcc_apb1periph_usart2,enable);                                         gpio_initstructure.gpio_pin = gpio_pin_2;                gpio_initstructure.gpio_mode = gpio_mode_af_pp;          gpio_initstructure.gpio_speed = gpio_speed_10mhz;        gpio_init(gpioa, &gpio_initstructure);                    gpio_initstructure.gpio_pin = gpio_pin_3;  gpio_initstructure.gpio_mode = gpio_mode_ipu;                        gpio_init(gpioa, &gpio_initstructure);  gpio_initstructure.gpio_pin = gpio_pin_4;                gpio_initstructure.gpio_mode = gpio_mode_af_pp;          gpio_initstructure.gpio_speed = gpio_speed_10mhz;        gpio_init(gpioa, &gpio_initstructure);  usart_inittypedef usart_initstructure;  usart_clockinittypedef usart_clkinitstructure;                          usart_initstructure.usart_baudrate            = 4390 ;               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_init(usart2, &usart_initstructure);                                usart_itconfig(usart2,usart_it_rxne,enable);                             __nop(); __nop();  usart_clkinitstructure.usart_clock=usart_clock_enable; usart_clkinitstructure.usart_cpol=usart_cpol_low; usart_clkinitstructure.usart_cpha=usart_cpha_2edge; usart_clkinitstructure.usart_lastbit=usart_lastbit_enable; usart_clockinit(usart2, &usart_clkinitstructure);  usart_cmd(usart2, enable); 

you should check example provided in stm32 standard peripheral library (located in stm32f10x_stdperiph_lib_v3.5.0/project/stm32f10x_stdperiph_examples/usart/synchr‌​onous)

the 2 important lines in case are:

usart_clockinitstructure.usart_clock = usart_clock_enable; 

and:

usart_initstructure.usart_baudrate = 115200; 

in code, should replace:

gpio_speed_10mhz 

by:

gpio_speed_50mhz 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -