2017-03-08 02:36 AM
hi
first i look here
but there is no usart driver.
this is my schematic
according to schematic i use pa2 and pa3 as usart.
please tell me if there is any library to init usart and use it.
if there is not .
datasheet give me something but its hard to understand . what to do?
first
Alternate function selection
/* This sequence select AF2 for GPIOA5, 8 and 9. This can be easily adapted
with another port by changing all GPIOA references by another GPIO port,and the alternate function number can be changed by replacing 0x02 foreach pin by the targeted alternate function in the 2 last code lines. *//* (1) Enable the peripheral clock of GPIOA */
/* (2) Select alternate function mode on GPIOA pin 5, 8 and 9 */
/* (3) Select AF2 on PA5 in AFRL for TIM2_CH1 */
/* (4) Select AF2 on PA8 and PA9 in AFRH for TIM1_CH1 and TIM1_CH2 */
RCC->
AHBENR|
=
RCC_AHBENR_GPIOAEN;
/* (1) */
GPIOA->
MODER=
(
GPIOA->
MODER&
~
(
GPIO_MODER_MODER5|
GPIO_MODER_MODER8|
GPIO_MODER_MODER9)
)
|
GPIO_MODER_MODER5_1|
GPIO_MODER_MODER8_1|
GPIO_MODER_MODER9_1;
/* (2) */
GPIOA->
AFR[
0
]
|
=
0x02
<<
(
5
*
4
)
;
/* (3) */
GPIOA->
AFR[
1
]
|
=
0x02
|
(
0x02
<<
(
(
9
-
8
)
*
4
)
)
;
/* (4) */
???????????????
?
?
?
?
?
?
?
?
?
?
?
?
?
but line 3 and line 4 is so hard to get . why 5*4 why ((9-8)*4)) :!
please somebody help me
#stm32 #stm32-f02017-03-08 06:26 AM
Hi
ansari.navid
,What you are sharing is a snippet code available in the reference manual of your product.
It is based on direct access to register.
In the package
, you have a set of ready to use examples.More other advanced examples that are well described and allow you to use USART based on a given STM32 board are available in the
package.You can also generate your own example thanks to the
.-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.