新闻动态
资质荣誉
联系我们
在keil上串口实现printf遇到的问题
发布时间:2021-08-02 08:00:31 来源:大电流电感厂家 查看: 次
问题是这样的,当我不对rcc初始化,只开启RCC_APB2PeriphclockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);串口能打印,但是我对rcc初始化后,keil上的USART窗口打印什么都没打印。还有另一个问题,打印ABCD。。。的那个循环在串口上只能打印出ACD。。。就是别的都能打印就是第二个字符打印不了
#include "STM32f10x.h"
#include "stdio.h"
/*************************************************************
¿âº¯Êý°æ
*************************************************************/
void USART_Configuration(void);
void GPIO_Configuration(void);
void RCC_Configuration(void);
//½ÓÊÜÊý¾Ý
int fputc(int ch,FILE *f)
{
USART_SendData(USART1,(u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
return ch;
}
//·¢ËÍÊý¾Ý
int GetKey(void)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE)==SET);
return ((int) USART_ReceiveData(USART1));
}
int main(void)
{
u8 i,data = 'A';
RCC_Configuration();
USART_Configuration();
GPIO_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
for(i=0; i<20; i++)
{
USART_SendData(USART1,data);
data++;
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
USART_CleaRFlag(USART1,USART_FLAG_TC);
}
printf("\n\thello world!");
//add your code here
return 0;
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
USART_InitStructure.USART_BaudRate = 9600;
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_Tx | USART_Mode_Rx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //GPIOÔÚ×÷Ϊ¸´Óù¦ÄÜÊä³öʱ£¬Ö»Äܸ´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //×ö¸´Óù¦ÄÜÊäÈëʱ£¬²»ÄÜΪģÄâÊäÈ룬˫Ïò¸´ÓÃʱֻÄܸ¡¿ÕÊäÈë
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //ÕâÀïÑ¡Ôñ¸¡¿ÕÊäÈë
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
FlagStatus Status;
RCC_DeInit();//ȱʡ
RCC_HSEConfig(RCC_HSE_ON);//Ñ¡ÔñÍⲿ¸ßËÙʱÖÓ
HSEStartUpStatus = RCC_WaitForHSEStartUp();
while(HSEStartUpStatus != SUCCESS);//µÈ´ýHSEÎȶ¨
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//ÉèÖÃHSE9±¶Æµ
RCC_PLLCmd(ENABLE);//ʹÄÜ¿ªÆôPLL
Status = RCC_GetFlagStatus(RCC_FLAG_PLLRDY);
while(Status == RESET);//µÈ´ýPLL¹¤×÷
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//ÉèÖÃPLLΪϵͳʱÖÓ
while(RCC_GetSYSCLKSource()!=0x80);//ÅжÏPLLÊÇ·ñΪϵͳʱÖÓ
/*******************************/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
}
#include "STM32f10x.h"
#include "stdio.h"
/*************************************************************
¿âº¯Êý°æ
*************************************************************/
void USART_Configuration(void);
void GPIO_Configuration(void);
void RCC_Configuration(void);
//½ÓÊÜÊý¾Ý
int fputc(int ch,FILE *f)
{
USART_SendData(USART1,(u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
return ch;
}
//·¢ËÍÊý¾Ý
int GetKey(void)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE)==SET);
return ((int) USART_ReceiveData(USART1));
}
int main(void)
{
u8 i,data = 'A';
RCC_Configuration();
USART_Configuration();
GPIO_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
for(i=0; i<20; i++)
{
USART_SendData(USART1,data);
data++;
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
USART_CleaRFlag(USART1,USART_FLAG_TC);
}
printf("\n\thello world!");
//add your code here
return 0;
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
USART_InitStructure.USART_BaudRate = 9600;
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_Tx | USART_Mode_Rx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //GPIOÔÚ×÷Ϊ¸´Óù¦ÄÜÊä³öʱ£¬Ö»Äܸ´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //×ö¸´Óù¦ÄÜÊäÈëʱ£¬²»ÄÜΪģÄâÊäÈ룬˫Ïò¸´ÓÃʱֻÄܸ¡¿ÕÊäÈë
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //ÕâÀïÑ¡Ôñ¸¡¿ÕÊäÈë
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
FlagStatus Status;
RCC_DeInit();//ȱʡ
RCC_HSEConfig(RCC_HSE_ON);//Ñ¡ÔñÍⲿ¸ßËÙʱÖÓ
HSEStartUpStatus = RCC_WaitForHSEStartUp();
while(HSEStartUpStatus != SUCCESS);//µÈ´ýHSEÎȶ¨
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//ÉèÖÃHSE9±¶Æµ
RCC_PLLCmd(ENABLE);//ʹÄÜ¿ªÆôPLL
Status = RCC_GetFlagStatus(RCC_FLAG_PLLRDY);
while(Status == RESET);//µÈ´ýPLL¹¤×÷
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//ÉèÖÃPLLΪϵͳʱÖÓ
while(RCC_GetSYSCLKSource()!=0x80);//ÅжÏPLLÊÇ·ñΪϵͳʱÖÓ
/*******************************/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
}
应该是RCC的配置问题吧
串口的波特率和打印机要一致,否则会出错
时钟不要你专门配置,在启动文件中自动调用SystenInit这个函数来初始化时钟,修改这个函数来修改你要达到的时钟频率,在配置串口或GPIO只要打开他们的时钟就行了
逆变器制作过程及调试方法该机具有以下特点:1.SPWM的驱动核心采用了单片机SPWM芯片,TDS2285,所以,SPWM驱动部分相对纯硬件来讲,比较简单,制作完成后要调试的东西很少,所以,比较容易成功。2.所有的PCB全部采
LDO低压差线性稳压器LDO是一种微功耗的低压差线性稳压器,它通常具有极低的自有噪声和较高的电源抑制比PSRR(Power Supply Rejection Ratio)。LDO是新一代的集成电路稳压器,它与三端稳压器最大
[开关电源]3525输出异常,烧MOS管等 本帖最后由 piaoyiliu03 于 2015-6-5 09:26 编辑 输出总是烧MOS管与输出电阻R13与R14,查了,好久都找不出什么原因,请帮忙分析,谢谢,变压器初级7圈,次级9圈芯片电源要加滤波电容。 R5、R6用22k变得沒作用。 图小看不清6 本帖最后由 zyj9490 于 2015-6-7 14:01 编辑 有三个问题,1,漏感能量耗散RC网络取值有问题,2)10欧的功率是否合适,3),D5
上一条:TL432 击穿 下一条:[逆变器]VD是如何续流的?