USART3 的问题大家帮看一下 接收不到数据

2019-07-20 04:17发布

void My_USART3_Init(void)
{
GPIO_InitTypeDef  GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);

GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_USART3);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate=115200;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;

USART_Init(USART3,&USART_InitStructure);
USART_Cmd(USART3 ,ENABLE);
  
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);

NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);


}

void USART3_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART3,USART_IT_RXNE)){

res=USART_ReceiveData(USART3);
USART_SendData(USART3,res);
}

}
int main(void)
{
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
My_USART3_Init();
while(1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
13条回答
xibeizhanlang
1楼-- · 2019-07-21 02:20
if(USART_GetITStatus(USART3,USART_IT_RXNE) )将这个改成  if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
董董
2楼-- · 2019-07-21 06:05
 精彩回答 2  元偷偷看……
董董
3楼-- · 2019-07-21 08:29
xuyaqi 发表于 2016-4-27 09:37
对com3有问题的把工程发上来让我帮你。

麻烦你帮我看看,谢谢
xuyaqi
4楼-- · 2019-07-21 13:58
下载一半停了.jpg 下载一半停了,发我邮箱吧xuyaqi029@163.com
独家记忆·
5楼-- · 2019-07-21 15:23
 精彩回答 2  元偷偷看……
qhq8001
6楼-- · 2019-07-21 17:14
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//使能USART3时钟


应该为:RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);     时钟错了吧

一周热门 更多>