打印

STM32串口设置时为什么一定要打开对应GPIO的时钟才能工作?

[复制链接]
5703|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yzhu|  楼主 | 2009-5-31 14:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

设置代码如下:

void UART_Configuration(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 USART_InitTypeDef USART_InitStructure;
 /* Enable USART1 and GPIOA clocks */
 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_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
 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);
 /* USARTx configuration --------------------------------------------------*/
 /* USARTx configured as follow:
        - BaudRate = 115200 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 = 115200;
 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;
  
 /* Configure the USART1 */ 
 USART_Init(USART1, &USART_InitStructure);
 /* Enable the USART1 */
 USART_Cmd(USART1, ENABLE);
}


没有红色部分时,串口就没有输出。
请问这是什么原因?
沙发
McuPlayer| | 2009-5-31 15:12 | 只看该作者

这对设计是非常有用的

不用的模块关闭,耗电只有静态电流,占比90%以上的动态功耗不会有。
ST这也是为系统设计提供了更多的灵活选择。

使用特权

评论回复
板凳
香水城| | 2009-5-31 18:22 | 只看该作者

为了降低功耗,STM32使用了时钟门控技术(Clock Gating)

请看我的博客:
相关链接:http://blog.**/STM32/215446/message.aspx

使用特权

评论回复
地板
yzhu|  楼主 | 2009-5-31 20:05 | 只看该作者

可是我已经使能了USART1的时钟了呀。

但这样不行
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
还得是
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);

使用特权

评论回复
5
香水城| | 2009-5-31 21:49 | 只看该作者

USART1模块是借用GPIO的端口实现输入输出

使能了USART1模块并不能自动地使能对应的输入输出端口。

使用特权

评论回复
6
bhsdlmj| | 2009-6-1 14:56 | 只看该作者

楼上各位解释的过于简单,并且并没有道破本质!

使用特权

评论回复
7
brotherwen| | 2009-6-2 08:51 | 只看该作者

确实是没有道破本质

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_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
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);
//不妨一试
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

29

主题

66

帖子

0

粉丝