打印
[STM32L1]

stm32l151 的串口3 总是输出乱码啊!

[复制链接]
1303|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hekai123|  楼主 | 2013-11-28 17:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
串口3 的配置如下:使用输出时总是乱码!哪位路过的大神,能否帮我解决下啊!谢谢!
void bsp_uart_config(void)
{
        USART_InitTypeDef USART_InitStructure;
       
        GPIO_InitTypeDef GPIO_InitStructure;
       
//  RCC_APB2PeriphClockCmd(USARTx_CLK, ENABLE);
   RCC_APB1PeriphClockCmd(USARTx_CLK, ENABLE);          //允许串口3时钟
   RCC_AHBPeriphClockCmd(USARTx_RX_GPIO_CLK, ENABLE);  //允许gpio时钟
       
          /* Connect PXx to USARTx_Tx */
  GPIO_PinAFConfig(USARTx_TX_GPIO_PORT, USARTx_TX_SOURCE, USARTx_TX_AF);

  /* Connect PXx to USARTx_Rx */
  GPIO_PinAFConfig(USARTx_RX_GPIO_PORT, USARTx_RX_SOURCE, USARTx_RX_AF);
  
   /* Configure USART1 Tx (PA.09) as alternate function push-pull */
   GPIO_InitStructure.GPIO_Pin = USARTx_TX_PIN;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;                //我加上去的
   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;                 //我加上去的
   GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStructure);
  
   GPIO_InitStructure.GPIO_Pin = USARTx_RX_PIN;
   GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStructure);
         
         USART_DeInit(USARTx);
  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_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  
  /* Configure USART1 */
  USART_Init(USARTx, &USART_InitStructure);
  
  /* Initialize variables for data transmission */
  
  /* Enable USART1 */
  USART_Cmd(USARTx, ENABLE);
}
沙发
122541325| | 2013-12-4 16:45 | 只看该作者
波特率设置对了么?

使用特权

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

本版积分规则

2

主题

2

帖子

0

粉丝