你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32 USART发送数据

[复制链接]
xufengjuan 提问时间:2011-11-26 16:19 /
 
这是我的初始化函数,但是之后调用USART_SendData(USART6, (u8)(printf_buf)),用示波器看串口的TX没有数据发出去,也用串口调试助手试过,都没有数据,这是怎么回事?请大家看看,我用的是STM32F207的mcu
void Printf_Init(void)
{
#ifdef __DEBUG_PRINT
 GPIO_InitTypeDef  GPIO_InitStructure;
 USART_InitTypeDef USART_InitStructure;
 USART_ClockInitTypeDef USART_ClockInitStructure;
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6);
  GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6) ;
 
  GPIO_InitStructure.GPIO_Pin = GPIO_PinSource7;
  GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_ResetBits(GPIOC, GPIO_PinSource6);
  GPIO_InitStructure.GPIO_Pin = GPIO_PinSource6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
    USART_ClockInitStructure.USART_CPOL    = USART_CPOL_Low;
    USART_ClockInitStructure.USART_CPHA    = USART_CPHA_2Edge;
    USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
    USART_ClockInitStructure.USART_Clock   = USART_Clock_Disable;
    USART_ClockInit(USART6, &USART_ClockInitStructure);
 
   USART_InitStructure.USART_BaudRate            = 9600;
   USART_InitStructure.USART_WordLength          = USART_WordLength_8b;
   USART_InitStructure.USART_StopBits            = USART_StopBits_1;
   USART_InitStructure.USART_Parity              = USART_Parity_No;
   USART_InitStructure.USART_Mode                = USART_Mode_Tx;
   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
   
 
   USART_Init(USART6, &USART_InitStructure);
   USART_Cmd(USART6, ENABLE);  //enable USART6
#ifdef STM32_PRINT_USE_DMA
 /* enable DMA clock */
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
#endif
#endif
}
收藏 评论2 发布时间:2011-11-26 16:19

举报

2个回答
火雷达 回答时间:2011-11-27 09:56:08

RE:STM32 USART发送数据

1、建议用STM32官方的串口程序测试一下硬件,如果硬件确定没有问题的话,再把程序移植到你的自己的程序里面。
2、因为STM32比较复杂,刚刚入手的话,可能会有很的地方没有注意到,忘记配置,所以多多参考STM32的例程。
xufengjuan 回答时间:2011-11-28 11:16:52

回复:STM32 USART发送数据

回复第 2 楼 于2011-11-27 01:56:08发表:
1、建议用STM32官方的串口程序测试一下硬件,如果硬件确定没有问题的话,再把程序移植到你的自己的程序里面。
2、因为STM32比较复杂,刚刚入手的话,可能会有很的地方没有注意到,忘记配置,所以多多参考STM32的例程。
发现了一个错误,我把 GPIO_Pin写成GPIO_PinSoure 了,笨啊!
 

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版