打印

连个简单的串口都没调通,实在很受伤!

[复制链接]
982|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wang168506|  楼主 | 2014-2-28 10:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
基本GPIO及USART3配置如下(PC10,PC11),主函数基本没啥东西,就简单发送个0x11,时钟、IO模式、USART时钟及配置,都没有问题了,请问大家到底还差到哪,哪里被我忘掉了?
void USART_GPIO_ConFig(void)
{
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);         //USART3 GPIO RCC Enable
  /* Connect PXx to USARTx_Tx*/
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
   /* Connect PXx to USARTx_Rx*/
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin = GPIO_PinSource10;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* Configure USART Rx as alternate function  */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Pin = GPIO_PinSource11;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* USART configuration */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //USART3 RCC Enable  
  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(USART3, &USART_InitStructure);
  /* Enable USART */
  USART_Cmd(USART3, ENABLE);
  




}




int main()
{
  int i;
  USART_GPIO_ConFig();

//  printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
  while(1)
  {
  USART_SendData(USART3, 0x11);
  for(i=0;i<1000;i++)
                {
                }
  }

return 0;
}   

相关帖子

沙发
luofeng2g| | 2014-2-28 11:09 | 只看该作者
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);         //USART3 GPIO RCC Enable  USART3时钟没看到
USART Rx配置的Pin_10应配置为输入模式。

使用特权

评论回复
板凳
qbasicljx| | 2014-2-28 11:24 | 只看该作者
总线时钟 调了吗?

使用特权

评论回复
地板
diweo| | 2014-2-28 20:07 | 只看该作者
你的函数库版本不是3.5?
另外,RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);         //USART3 GPIO RCC Enable  好像不对吧。。。。

使用特权

评论回复
5
airwill| | 2014-3-1 12:34 | 只看该作者
不要受伤, STM32 的外设功能很强大, 调试确实比较费力, 静心看外设的设置吧.
化伤痛为力量吧

使用特权

评论回复
6
wang168506|  楼主 | 2014-3-7 09:22 | 只看该作者
diweo 发表于 2014-2-28 20:07
你的函数库版本不是3.5?
另外,RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);         //USART3 ...

对的额

使用特权

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

本版积分规则

57

主题

811

帖子

5

粉丝