下面是关于ufun串口1的迷点:
这是我的程序源码
#include
#include "sys.h"
#include
#include
#include "my_uart.h"
#include "delay.h"
//
void RCC_Config(void)
{
ErrorStatus HSEStartUpStatus; //定义结构体
/* RCC system reset(for debug purpose)将外设 RCC寄存器重设为缺省值 */
RCC_DeInit();
/* Enable HSE 设置外部高速晶振(HSE)*/
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready 等待 HSE 起振*/
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer 预取指缓存使能*/
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state 设置代码延时值*/
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK 设置 AHB 时钟(HCLK)*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK 设置高速 AHB 时钟(PCLK2)*/
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/1 设置低速 AHB 时钟(PCLK1)*/
RCC_PCLK1Config(RCC_HCLK_Div1);
/* PLLCLK = 12MHz * 6 = 72 MHz 设置 PLL 时钟源及倍频系数*/
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL 使能或者失能 PLL*/
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready 等待指定的 RCC 标志位设置成功 等待PLL初始化成功*/
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source 设置系统时钟(SYSCLK) 设置PLL为系统时钟源*/
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source 等待PLL成功用作于系统时钟的时钟源*/
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
int main(void)
{
RCC_Config();
delay_init();
Usart_Init();
delay_ms(2000);
printf("初始化完成\n");
while(1)
{
printf("这是相当好的串口通讯方式\n");
delay_ms(1000);
}
#include
#include
#include "my_uart.h"
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#define GETCHAR_PROTOTYPE int fgetc(FILE *f)
#endif /* __GNUC__ */
/**************************************************************/
//程 序 名: USB2Serial_Init
//开 发 者: MingH
//入口参数: 无
//功能说明: USB转串口初始化
//**************************************************************/
void Usart_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* Configure USART1 Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
/* Enable the USARTy */
USART_Cmd(USART1, ENABLE);
}
我手头的两个开发板,最大的区别就是晶振的不同
自己的板子8M外部晶振,而ufun是12M的外部晶振
同样的一份数据,下载到两个不同的开发板上串口打印的数据是不相同的
我自己的时正确的输出,而在ufun上是乱码。
我查了好久的原因,
排除硬件问题:因为ufun跑例程的时候,是正确的。
file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\583685234\QQ\WinTemp\RichOle\9H(X6H0OFG4FI9]1]~RFANR.jpg
file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\583685234\QQ\WinTemp\RichOle\9H(X6H0OFG4FI9]1]~RFANR.jpg