打印

串口初始化的问题

[复制链接]
1746|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
su27meng|  楼主 | 2011-8-3 14:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在进行串口2的初始化过程中出现了非常奇怪的问题,在进行串口初始化时,当我仅仅完成GPIO的初始化后(执行到斜体字所示位置时,串口就不断的发出0x00),发觉串口会不断的发出0x00。这是什么原因,如何消除?
void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef  GPIO_InitStructure;
USART_ClockInitTypeDef  USART_ClockInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
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;
/* Configure the USART2 synchronous paramters */
USART_ClockInit(USART2, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 38400;
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_Tx | USART_Mode_Rx ;
USART_Init(USART2, &USART_InitStructure);
    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//使能USART接收中断
  
USART_Cmd(USART2, ENABLE);
}
沙发
su27meng|  楼主 | 2011-8-3 14:44 | 只看该作者

串口初始化

在进行串口2的初始化过程中出现了非常奇怪的问题,在进行串口初始化时,当我仅仅完成GPIO的初始化后(执行到斜体字所示位置时,串口就不断的发出0x00),发觉串口会不断的发出0x00。这是什么原因,如何消除?
void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef  GPIO_InitStructure;
USART_ClockInitTypeDef  USART_ClockInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
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;
/* Configure the USART2 synchronous paramters */
USART_ClockInit(USART2, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 38400;
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_Tx | USART_Mode_Rx ;
USART_Init(USART2, &USART_InitStructure);
    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//使能USART接收中断
  
USART_Cmd(USART2, ENABLE);
}

使用特权

评论回复
板凳
香水城| | 2011-8-3 14:52 | 只看该作者
不可能出现这样的问题,除非你没有正确地复位系统。

使用特权

评论回复
地板
su27meng|  楼主 | 2011-8-4 10:54 | 只看该作者
不知道您说的正确的复位系统是怎么样操作的,希望您能清楚的解释一下,谢谢。

使用特权

评论回复
5
香水城| | 2011-8-4 11:15 | 只看该作者
不知道您说的正确的复位系统是怎么样操作的,希望您能清楚的解释一下,谢谢。
su27meng 发表于 2011-8-4 10:54


简单地说,“正确的复位系统”就是在复位引脚上有足够长时间的低电平。

使用特权

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

本版积分规则

0

主题

5

帖子

0

粉丝