野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11704|回复: 2

大家帮忙看看这个程序有什么问题

[复制链接]
发表于 2016-11-23 12:31:00 | 显示全部楼层 |阅读模式
为什么串口输出不对
  1. #include "stm32f10x.h"
  2. #include "bsp_usart1.h"
  3. #include "bsp_led.h"  
  4. #include "bsp_can.h"
  5. void delay_ms(u16 time);
  6. void HMISends(char *buf1);
  7. void HMISendb(u8 buf);
  8. char  buf[64];
  9. char buff[64];
  10. void RCC_Config(void);
  11. void USARTx_Config(void);

  12. int main(void)
  13. {       
  14.         /* USART1 config */
  15.         USARTx_Config();
  16.           RCC_Config();  
  17.        
  18.         /* LED config */
  19. //        LED_GPIO_Config();       
  20.        
  21. //        printf( "\r\n Õa¸öò»¸öCAN£¨»Ø»·Ä£ê½oíÖD¶Ïģ꽣©2aêÔ3ìDò...... \r\n" );
  22.        
  23. //        USER_CAN_Init();       
  24. //        delay_ms(300);
  25.         sprintf(buf,"n0.val=1");
  26.                                 HMISends(buf);
  27.                                 HMISendb(0xff);
  28. //        printf( "\r\n CAN »Ø»·2aêÔ3õê¼»ˉ3é1|...... \r\n" );
  29.        
  30. //        USER_CAN_Test();
  31. //        delay_ms(300);
  32. sprintf(buf,"n0.val=66666");
  33.                                 HMISends(buf);
  34.                                 HMISendb(0xff);       
  35. //        printf( "\r\n CAN »Ø»·2aêÔ3é1|...... \r\n" );
  36.        
  37.        
  38.         while (1)
  39.         {
  40.         sprintf(buf,"n0.val=6666");
  41.                                 HMISends(buf);
  42.                                 HMISendb(0xff);       
  43.         }
  44. }
  45. void delay_ms(u16 time)     
  46. {   
  47.   u16 i=0;   
  48.   while(time--)     
  49.   {   
  50.     i=12000;   
  51.     while(i--);   
  52.   }   
  53. }
  54. void HMISends(char *buf1)                  //???????
  55. {
  56.         u8 i=0;
  57.         while(1)
  58.         {
  59.          if(buf1[i]!=0)
  60.                  {
  61.                         USART_SendData(USART1,buf1[i]);  //??????
  62.                         while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){};//??????
  63.                          i++;
  64.                 }
  65.          else
  66.          return ;

  67.                 }
  68.         }
  69. void HMISendb(u8 k)                         //??????
  70. {                 
  71.         u8 i;
  72.          for(i=0;i<3;i++)
  73.          {
  74.          if(k!=0)
  75.                  {
  76.                         USART_SendData(USART1,k);  //??????
  77.                         while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET){};//??????
  78.                 }
  79.          else
  80.          return ;

  81.          }
  82. }
  83. void RCC_Config(void)
  84. {
  85.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
  86.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1,ENABLE);
  87. }
  88. void USARTx_Config(void)
  89. {
  90.         GPIO_InitTypeDef GPIO_InitStructure;
  91.         USART_InitTypeDef USART_InitStructure;
  92.        
  93.         /* config USART1 clock */
  94.         macUSART_APBxClock_FUN(macUSART_CLK, ENABLE);
  95.         macUSART_GPIO_APBxClock_FUN(macUSART_GPIO_CLK, ENABLE);
  96.                
  97.         /* USART1 GPIO config */
  98.         /* Configure USART1 Tx (PA.09) as alternate function push-pull */
  99.         GPIO_InitStructure.GPIO_Pin =  macUSART_TX_PIN;
  100.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  101.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  102.         GPIO_Init(macUSART_TX_PORT, &GPIO_InitStructure);   
  103.         /* Configure USART1 Rx (PA.10) as input floating */
  104.         GPIO_InitStructure.GPIO_Pin = macUSART_RX_PIN;
  105.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  106.         GPIO_Init(macUSART_RX_PORT, &GPIO_InitStructure);       
  107.                        
  108.         /* USART1 mode config */
  109.         USART_InitStructure.USART_BaudRate = macUSART_BAUD_RATE;
  110.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  111.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  112.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  113.         USART_InitStructure.USART_Mode =USART_Mode_Rx | USART_Mode_Tx;
  114.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  115.        
  116.         USART_Init(macUSARTx, &USART_InitStructure);
  117.         USART_Cmd(macUSARTx, ENABLE);
  118.        
  119. }

复制代码


回复

使用道具 举报

发表于 2016-11-23 16:24:59 | 显示全部楼层
实验现象呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-11-24 10:37:00 | 显示全部楼层

输出printf里边的内容
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-7-2 15:49 , Processed in 0.023921 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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