有亿点夸张 2021-04-06 16:35 采纳率: 0%
浏览 21

stm32f103 串口实验

程序没报错,但是在串口调试助手发送数据时,乱码,甚至发不出去

#include "stm32f10x.h"
#include "sys.h"
#include"delay.h"
#include"usart.h"

void My_USART1_Init(void)
{ 
	GPIO_InitTypeDef  GPIO_InitStrue;
	USART_InitTypeDef  USART_InitStrue;
	NVIC_InitTypeDef  NVIC_InitStrue;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//ʹÄÜʱÖÓ
	
	GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
	GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9;
	GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
	GPIO_Init(GPIOA,&GPIO_InitStrue);
	
	GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;
	GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10;
	GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
	GPIO_Init(GPIOA,&GPIO_InitStrue);//IO¿Ú³õʼ»¯

	USART_InitStrue.USART_BaudRate=115200;
  USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
	USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx; 
	USART_InitStrue.USART_Parity=USART_Parity_No;
	USART_InitStrue.USART_StopBits=USART_StopBits_1;
	USART_InitStrue.USART_WordLength=USART_WordLength_8b;
	USART_Init(USART1,&USART_InitStrue);//³õʼ»¯´®¿Ú
	
	USART_Cmd(USART1,ENABLE);//ʹÄÜ´®¿Ú1
	
	USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//¿ªÆô½ÓÊÕÖжÏ
	
	NVIC_InitStrue.NVIC_IRQChannel=USART1_IRQn;
	NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
	NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;
	NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;
	NVIC_Init(&NVIC_InitStrue);//ÖжÏÓÅÏȼ¶ÉèÖÃ
}	

void USART1_IRQHandlerr(void)
{  u8 res;
	if(USART_GetITStatus(USART1,USART_IT_RXNE))
{	
	res=USART_ReceiveData(USART1);
	USART_SendData(USART1,res);
  
  
}
	}
int main(void)
{
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
 My_USART1_Init();
  while (1);
 
}
  • 写回答

1条回答 默认 最新

  • 至纯设计 企业官方账号 2021-04-07 09:42
    关注

    串口助手的波特率要设置115200,8,1,无校验。

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料