OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4222|回复: 3

战舰stm32的板子USART2的问题

[复制链接]

23

主题

95

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
207
金钱
207
注册时间
2013-2-19
在线时间
0 小时
发表于 2013-2-28 17:22:27 | 显示全部楼层 |阅读模式
今天设置USART2,少了下面这段就怎么也没发打印出来,不知道是什么原因,请正点大哥指点下,谢谢。。。

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //LED4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);

完整
程序代码:

#include "stm32f10x.h"
#include "platform_config.h"
#include "stm32f10x_usart.h"
#include "misc.h"

void USART2_Config(void);
void GPIO_Configuration(void);
void Delay(vu32 Time);


unsigned char TxBuf2[50] = "0123456789";

int main(void)
{
int i, RX_status = 0;

SystemInit();
GPIO_Configuration();
USART2_Config();

for( i = 0; TxBuf2 != '\0'; i++) {
USART_SendData(USART2 , TxBuf2);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}


while (1)
{
for( i = 0; TxBuf2 != '\0'; i++) {
USART_SendData(USART2 , TxBuf2);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}

}
}


void USART2_Config(void)
{
USART_InitTypeDef USART_InitStructure;
    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;

USART_Init(USART2, &USART_InitStructure); 
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
}


void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE);
        /* 如果将下面这段去掉串口将没有输出 */   
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //LED4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);  
      /******************结束*************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;         
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  
GPIO_Init(GPIOA, &GPIO_InitStructure);   

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;        
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   
GPIO_Init(GPIOA, &GPIO_InitStructure);       

}


void Delay(vu32 Time)
{
for(; Time != 0; Time--);
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval : None
  */
void assert_failed(uint8_t* file, uint32_t line)
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif




www.wxx3g.com
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

230

主题

1950

帖子

10

精华

论坛元老

Rank: 8Rank: 8

积分
4562
金钱
4562
注册时间
2010-12-14
在线时间
32 小时
发表于 2013-2-28 17:28:35 | 显示全部楼层
      /* 如果将下面这段去掉串口将没有输出 */   
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //LED4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);  
      /******************结束*************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;         
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //加上这行。。。。。。

GPIO_Init(GPIOA, &GPIO_InitStructure);   

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;        
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   
GPIO_Init(GPIOA, &GPIO_InitStructure);       
我是开源电子网?网站管理员,对网站有任何问题,请与我联系!QQ:389063473Email:389063473@qq.com
回复 支持 反对

使用道具 举报

23

主题

95

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
207
金钱
207
注册时间
2013-2-19
在线时间
0 小时
 楼主| 发表于 2013-2-28 17:33:43 | 显示全部楼层
感谢群里的童鞋帮忙。。。
原来是GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;没有设置
www.wxx3g.com
回复 支持 反对

使用道具 举报

0

主题

41

帖子

0

精华

初级会员

Rank: 2

积分
139
金钱
139
注册时间
2014-1-11
在线时间
23 小时
发表于 2016-6-19 19:56:55 | 显示全部楼层
很好的,有参考价值.
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-12 17:51

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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