uart源代码程序下进去 打印乱码

2019-07-21 02:16发布

小弟只把USart1 改为uart5 其他没变,但是通过串口打印字符都是乱码,怎么办
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
11条回答
ZRAINZ
1楼-- · 2019-07-21 06:13
问题终于找到了,是改为25M时, #define HSE_VALUE    ((uint32_t)25000000)也需要改。谢谢大家
joe_knight
2楼-- · 2019-07-21 09:59
 精彩回答 2  元偷偷看……
ZRAINZ
3楼-- · 2019-07-21 15:06
回复【2楼】joe_knight:
---------------------------------
int main(void)
{ u8 a[5] = {1,2,3,4,5};
  u8  i=0;

   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
My_UART5_Init();
delay_init(168);
while(1)
{
for(i=0;i<5;i++)
{USART_SendData(UART5,a);}
delay_ms(1000);
}

}
ZRAINZ
4楼-- · 2019-07-21 19:31
void My_UART5_Init(void)
{
GPIO_InitTypeDef  GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);//????USART1?±??
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);

GPIO_PinAFConfig(GPIOC,GPIO_PinSource12,GPIO_AF_UART5);


 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource2,GPIO_AF_UART5);
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

USART_InitStructure.USART_BaudRate=115200;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;

USART_Init(UART5,&USART_InitStructure);
USART_Cmd(UART5 ,ENABLE);
  
USART_ITConfig(UART5,USART_IT_RXNE,ENABLE);

NVIC_InitStructure.NVIC_IRQChannel=UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);


}

void UART5_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(UART5,USART_IT_RXNE)){

res=USART_ReceiveData(UART5);
USART_SendData(UART5,res);
}

}
joe_knight
5楼-- · 2019-07-22 01:09
PC端串口调试助手上显示乱码?应该勾选上16进制显示
ZRAINZ
6楼-- · 2019-07-22 03:59
回复【5楼】joe_knight:
---------------------------------
勾了,我那个程序其实发的就是12345,但是显示的是FE FE 什么的

一周热门 更多>