打印

USART 串口实验 软件调试时USART1接收到字符串了 但是在超级终端显示不了

[复制链接]
1828|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tangzhao_01|  楼主 | 2013-10-15 21:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//#include "stm32f10x_lib.h"
#include "stm32f10x.h"
#include "stdio.h"
extern void SystemInit(void);
void NVIC_Configuration(void);
//void delay_ms(u16 nms);
void GPIO_Configuration(void);
void USART_Configuration(void);
int main(void)
{       
  unsigned char Buffer[]="i need you";
  u16 i;                                         
  SystemInit();  
  //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
  NVIC_Configuration();
  GPIO_Configuration();
  USART_Configuration();
  printf("\r\n this is a printf demo \r\n");         
                for(i=0;Buffer[i]!='\0';i++)
                {
                        USART_SendData(USART1,Buffer[i]);
                        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 delay_ms(u16 nms)
//{
// u32 temp;
// nms=0;
// SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);        //选择外部时钟  HCLK/8
// //fac_us=SystemCoreClock/8000000;        //为系统时钟的1/8
// nms=SystemCoreClock/8000;//非ucos下,代表每个ms需要的systick时钟数
//  
// SysTick->LOAD = 9000*nms; //输入的nms即为延时多少ms
// SysTick->VAL=0X00;//清空计数器
// SysTick->CTRL=0X01;//使能,减到零是无动作,采用外部时钟源
// do
// {
//  temp=SysTick->CTRL;//读取当前倒计数值
// }while((temp&0x01)&&(!(temp&(1<<16))));//等待时间到达
//    SysTick->CTRL=0x00; //关闭计数器
//    SysTick->VAL =0X00; //清空计数器
//}

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;
}
软件调试,全速运行能在USART1窗口中看到输出,但是超级终端上就是看不到?纠结几天了,遇到过的给指导下吧
沙发
tangzhao_01|  楼主 | 2013-10-16 14:00 | 只看该作者
明白的给指点一二啊。。。。。补充下:用的是3.5的库,USE  MicroLib 已经勾选了,超级终端还是看不到

使用特权

评论回复
板凳
jjjkkk00| | 2013-10-17 14:10 | 只看该作者
硬件连接有没有接触不好?
用示波器看先电平转换芯片MAX232等等出来的信号。

使用特权

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

本版积分规则

8

主题

45

帖子

1

粉丝