|
在网上搜了一下,有这方面的提问(8 i9 _/ v8 m9 [$ U c7 W. e1 m- a8 U , t' y- c5 O( q$ d% b! I, @ 在2010-7-5 16:11:34 有提到过 一下为原帖 文字 1 q4 U) W+ J* ` USART3映射方式2(映射到PD8,PD9)时,要先开启AFIO功能,再初始化相关外设后,USART才有效。( ~' T( p4 O9 j 以下代码是正确的: 9 a& {) J: y* w2 G( @, L% t' F6 S u32 backRcc = RCC->APB2ENR & (RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO);//read status of rcc_gpiob & rcc_afio( C- E& p2 P4 G! Q7 T# [ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);1 N3 H/ i* B5 ~ g- H! U GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); /* Configure USART3 Tx (PD.8) as alternate function push-pull */) C$ j. g+ g8 o( O GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8;/ ?# G! ]& D7 D, f& z$ u GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure USART3 Rx (PD.9) as input Up */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOD, &GPIO_InitStructure);* _3 Q; v- R* f" J4 U7 A* } if(!backRcc) {9 v9 }" {$ {# A/ t: V: z RCC->APB2ENR &= ~backRcc; //restore 6 @0 D9 t1 a) a, S$ s( B- b8 e } 初始化USART等。。。 若去掉 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);) Z$ l% H0 X6 L) U . x T3 K4 b1 B$ w% m- L8 R 不正常! ' J! ?9 ~0 p; u0 r' `# E7 v; ?- j5 n )% `; ]) k! V8 W . [1 k5 [- V" u$ ~ 根据上述还是没有解决这个问题 (其他口的重映射验证都是OK的),所以又开了一下此贴,希望得到大家的帮助 ,本人代码如下 //重映射成功的 方式1 #ifdef DEFINE_UART_MAP_PORT_3 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE); ]1 J& W( U* B' x RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); ! ]8 j5 ^3 E p1 J GPIO_PinRemapConfig(GPIO_PartialRemap_USART3 ,ENABLE); // GPIO_FullRemap_USART3 /* Configure USART3 Tx (PC10) as alternate function push-pull */* Z. Z- X9 }% ^) F k1 i8 H GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;4 ^) b8 g$ q$ P7 E' o( Y GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;6 G/ X& l! ~) M GPIO_Init(GPIOC, &GPIO_InitStructure);1 o X2 [, D. X; ?+ ~& a7 b R4 R /* Configure USART3 Rx (PC11) as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;& M1 D, A3 h/ }- E* n GPIO_Init(GPIOC, &GPIO_InitStructure); #endif 7 ~$ b! n C5 z5 I' ] # C: l+ K! z' \. }5 | //方式2 重映射失败 8 ~. {$ q: Z4 o" s4 P) q4 l #ifdef DEFINE_UART_MAP_3. B& T6 \" W) d( p& ]0 p : v, U2 d' |& K' x$ D( W% } * _6 s" O8 Y' y/ D RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); $ }& H2 L% f& g RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 , ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO , ENABLE);/ }/ U+ D3 _2 u- u5 E) c6 ~3 m) g6 e GPIO_PinRemapConfig(GPIO_FullRemap_USART3 ,ENABLE); // GPIO_FullRemap_USART3, t0 U) B" S+ a /* Configure USART3 Tx (PD9) as alternate function push-pull */: a9 L' {: v: G; ^ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;: b+ E. q |5 k# n- `6 H; d! | GPIO_Init(GPIOD, &GPIO_InitStructure);- s; \% F6 E+ j. U, @1 V ! p* U1 t$ s7 P5 s9 J /* Configure USART3 Rx (PD8) as input floating */( }" T/ }( T4 J: g& g! U+ g: _ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;. v+ `- i8 S5 c2 R; }' {3 t GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;. ]. \8 B6 I$ l5 h GPIO_Init(GPIOD, &GPIO_InitStructure); #endif/ d8 M( Y: ~" y* v 附图为keil寄存器值 |
微信公众号
手机版
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2
RE:stm32 USART3 映射方式2