OpenEdv-开源电子网

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

串口实验 超级终端上始终显示不了字符串 求指点

[复制链接]

3

主题

22

帖子

0

精华

初级会员

Rank: 2

积分
54
金钱
54
注册时间
2013-10-16
在线时间
0 小时
发表于 2013-10-16 19:49:33 | 显示全部楼层 |阅读模式
#include "stm32f10x.h"
#include "stdio.h"
void RCC_Configuration(void); 
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
int main(void)
{
  unsigned char Buffer[]="work hard";
  u16 i;  
  //SystemInit();  
  RCC_Configuration();
  NVIC_Configuration();
  GPIO_Configuration();
  USART_Configuration();
  printf("\r\n this is a printf demo \r\n");  
for(i=0;Buffer!='\0';i++)
{
USART_SendData(USART1,Buffer);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
}
  while(1)
  {
 
  }
 
}

/*******************************************************************************
* Function Name : Delay
* Description   : Inserts a delay time.
* Input         : nCount: specifies the delay time length.
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)//自己定义的函数
{
  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_10; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
 // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void RCC_Configuration(void)
{
  ErrorStatus HSEStartUpStatus;   
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
 
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1); 
  
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1); 

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */ 
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
}


void NVIC_Configuration(void)
{
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;

USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;//或者设为2位,参看手册
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
// USART_InitStructure.USART_Clock = USART_Clock_Disable;
// USART_InitStructure.USART_CPOL = USART_CPOL_High;
// USART_InitStructure.USART_CPHA = USART_CPHA_1Edge;
// USART_InitStructure.USART_LastBit = USART_LastBit_Enable;
USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);//很容易丢失 勿忘
}

int fputc(int ch, FILE *f)
{
  /* Write a character to the USART */
  USART_SendData(USART1,(u8)ch);

  /* Loop until the end of transmission */
  while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  {
  }
  return ch;
}
用的是3.5的库,感觉程序应该没问题,但是超级终端上显示不了,已经尝试勾选Use MicroLib,依然不行。知道的给指点下吧,纠结好几天了都。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-10-16 22:33:19 | 显示全部楼层
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

39

主题

2026

帖子

1

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
2020
金钱
2020
注册时间
2013-5-1
在线时间
87 小时
发表于 2013-10-16 22:33:51 | 显示全部楼层
连接成功没?硬件有没有问题?  先检查硬件
博观而约取,厚积而薄发。
回复 支持 反对

使用道具 举报

3

主题

22

帖子

0

精华

初级会员

Rank: 2

积分
54
金钱
54
注册时间
2013-10-16
在线时间
0 小时
 楼主| 发表于 2013-10-17 10:10:21 | 显示全部楼层
回复【3楼】745021926:
---------------------------------
硬件要是有问题的话,下载例程上的程序就不会跑了,所以硬件应该是可以的,我就是用的3.5的库,很费解为什么就是不行
回复 支持 反对

使用道具 举报

3

主题

22

帖子

0

精华

初级会员

Rank: 2

积分
54
金钱
54
注册时间
2013-10-16
在线时间
0 小时
 楼主| 发表于 2013-10-17 10:12:45 | 显示全部楼层
回复【2楼】正点原子:
---------------------------------
是准备参考原子哥的例程,可是我还是纳闷为什么上面的程序编译啥的都没问题,软件仿真也OK,但是下到板子里就不行了,跑别人的程序就行。费解
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-7-10 21:55

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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