找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2618|回复: 0
打印 上一主题 下一主题
收起左侧

这STM32程序逻辑有问题吗,串口调试助手接收不到数据,使用虚拟串口的

[复制链接]
跳转到指定楼层
楼主



单片机源程序如下:
  1. #ifndef __USART_H
  2. #define __USART_H
  3. #include "stm32f10x.h"

  4. static void NVIC_Configuration(void)
  5. {
  6.     NVIC_InitTypeDef NVIC_InitStructure;
  7.     NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
  8.      NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  9.      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
  10.      NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
  11.      NVIC_Init(&NVIC_InitStructure);
  12. }

  13. void USART_Config(void)
  14. {
  15.        GPIO_InitTypeDef GPIO_InitStructure;
  16.         USART_InitTypeDef USART_InitStructure;
  17.         
  18.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  19.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
  20.         
  21.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
  22.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
  23.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
  24.         GPIO_Init(GPIOA,&GPIO_InitStructure);
  25.         
  26.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
  27.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
  28.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
  29.         GPIO_Init(GPIOA,&GPIO_InitStructure);
  30.         
  31.         USART_InitStructure.USART_BaudRate=9600;
  32.         USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
  33.         USART_InitStructure.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
  34.         USART_InitStructure.USART_Parity=USART_Parity_No;
  35.         USART_InitStructure.USART_StopBits=USART_StopBits_1;
  36.         USART_InitStructure.USART_WordLength=USART_WordLength_8b;
  37.         USART_Init(USART1,&USART_InitStructure);
  38.         USART_Cmd(USART1,ENABLE);
  39.         
  40.         USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
  41.         
  42.        NVIC_Configuration();
  43.         USART_Cmd(USART1,ENABLE);
  44. }

  45. void usart_sendbyte(USART_TypeDef* pUSARTx,uint8_t ch)
  46. {
  47. USART_SendData(pUSARTx,ch);
  48. while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TXE)==RESET);
  49. }
  50. void usart_sendstring(USART_TypeDef* pUSARTx,char *str)
  51. {
  52. unsigned int k=0;
  53. do{
  54.    usart_sendbyte(pUSARTx,*(str+k));
  55.   k++;
  56. }while(*(str+k)!='\0');
  57. while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  58. {
  59. }
  60. }
  61. void USART1_IRQHandler(void)
  62. {
  63.         uint8_t ucTemp;
  64.         
  65.    if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)
  66.      {
  67.       ucTemp= USART_ReceiveData(USART1);
  68.      USART_SendData(USART1,ucTemp);  
  69.      }
  70. }
  71. #endif


  72. #include "stm32f10x.h"
  73. #include "usart.h"
  74. int main()
  75. {
  76. USART_Config();
  77. while(1)
  78. {
  79. usart_sendstring(USART1,"THIS");
  80. }
  81. }
复制代码





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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