野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10898|回复: 8

F4——uart4 发送与接收无效内附配置代码

[复制链接]
发表于 2016-10-10 08:58:33 | 显示全部楼层 |阅读模式
  GPIO_InitTypeDef                 GPIO_InitStructure;
  USART_InitTypeDef         USART_InitStructure;
//        DMA_InitTypeDef     DMA_InitStructure;
  NVIC_InitTypeDef                 NVIC_InitStructure;
       
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOF | RCC_APB1Periph_UART4, ENABLE);       
       
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,                GPIO_AF_UART4);
  GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,                GPIO_AF_UART4);
       
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
       
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
       
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_Init(GPIOF, &GPIO_InitStructure);
       
  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;
  USART_Init(UART4, &USART_InitStructure);
       
  USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);       
       
  USART_Cmd(UART4, ENABLE);

//--------------------------------------

        USART_SendData(UART4,0xAA); //示波器观察过没数据输出
        while( USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET);//会卡在这里 ,但DR里是没数据。



回复

使用道具 举报

发表于 2016-10-10 09:01:55 | 显示全部楼层
这代码只能是我才会帮你看了了,我用板子实验下先。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-10-10 09:03:42 | 显示全部楼层
fire 发表于 2016-10-10 09:01
这代码只能是我才会帮你看了了,我用板子实验下先。

3Q
**********************
回复 支持 反对

使用道具 举报

发表于 2016-10-10 09:09:27 | 显示全部楼层
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOF | RCC_APB1Periph_UART4, ENABLE);        


APB的时钟怎么能用AHB函数开
回复 支持 反对

使用道具 举报

发表于 2016-10-10 09:17:09 | 显示全部楼层
时钟明显开错了,GPIO的时钟是AHB总线,UART4的时钟是APB1
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-10-10 09:19:10 | 显示全部楼层
flyleaf 发表于 2016-10-10 09:09
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOF | RCC_APB1Periph_UART4, ENABLE); ...


粗心了,感谢。
回复 支持 反对

使用道具 举报

发表于 2016-10-10 09:30:47 | 显示全部楼层
用的GPIO0是 PC10和 PC11 ,例程已经在挑战者上面测试好。
UART—UART4接发.7z (347.59 KB, 下载次数: 38)
1.png
回复 支持 反对

使用道具 举报

发表于 2016-10-10 09:39:32 | 显示全部楼层
666666666666
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-10-10 10:03:30 | 显示全部楼层
fire 发表于 2016-10-10 09:30
用的GPIO0是 PC10和 PC11 ,例程已经在挑战者上面测试好。

3Q
***************************
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-20 23:12 , Processed in 0.036430 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表