程序如下:
调试卡在了程序中加粗一句,求助!
谢谢各路大神!!!
#include <
STM32f4xx.h>
#include <stdio.h>
void RCC_Configura
tion(void); //ʱÖÓÅäÖÃ
void USART1_Configuration(void); //´®¿Ú1ÅäÖÃ
int main(void)
{
uint16_t i = 0;
RCC_Configuration();
USART1_Configuration();
//USART1_NVIC_Configuration();
//DMA_Configuration();
//DMA_NVIC_Configuration();
while(1)
{
if(USART_GetFlagStatus(USART1,USART_IT_RXNE) == SET)
{
USART_SendData(USART1,USART_ReceiveData(USART1));
for(i = 0;i < 500;i++);
}
}
}
/*ʱÖÓ*/
void RCC_Configuration(void) //ʱÖÓÅäÖÃ
{
ErrorStatus HSEStartUp; //ö¾ÙÐͱäÁ¿£¬½ÓÊÜHSEÆðÕñ·µ»ØÖµ
RCC_DeInit(); //ȱʡRCC¼Ä´æÆ÷
RCC_HSEConfig(RCC_HSE_ON); //¿ªÆôHSE,HSE=8M
HSEStartUp = RCC_WaitForHSEStartUp(); //µÈ´ýHSEÆðÕñ
if(HSEStartUp == SUCCESS) //ÆðÕñ³É¹¦
{
RCC_PLLConfig(RCC_PLLSource_HSE,4,288,4,8); //VCOIN=4M,VCOOUT=288M,PLL=72M,others=36M
RCC_HCLKConfig(RCC_SYSCLK_Div1); //AHB=SYSCLK 72M
RCC_PCLK1Config(RCC_HCLK_Div2); //CLK1=AHB/2 36M
RCC_PCLK2Config(RCC_HCLK_Div2); //CLK2=AHB/2 36M
/*ÑÓʱFLASH 2¸öÖÜÆÚ£¬Ê¹ÄÜÔ¤¶Á»º´æ£¨±ØÐëµÄ£©*/
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(ENABLE);
RCC_PLLCmd(ENABLE); //ʹÄÜPLL
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //µÈ´ýPLL¾ÍÐ÷
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //Ñ¡ÔñPLLΪSYSCLK
while(RCC_GetSYSCLKSource() != 0x08); //µÈ´ýϵͳʱÖÓ¾ÍÐ÷
}
}
/*´®¿Ú1*/
void USART1_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //³õʼ»¯GPIO½á¹¹Ìå
USART_InitTypeDef USART_InitStructure; //³õʼ»¯USART½á¹¹Ìå
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //ʹÄÜGPIOAʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); //ʹÄÜUSART1ʱÖÓ
/*ÅäÖÃUSART1µÄGPIO*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //Ñ¡ÖйܽÅ9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸´Óù¦ÄÜ
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //I/O¿Ú×î¸ß· תƵÂÊ50MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀ µç×è
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //¿ªÂ©Êä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //ÎÞÉÏÏÂÀ µç×è
GPIO_Init(GPIOA,&GPIO_InitStructure);
/*ÅäÖÃUSART1µÄģʽ*/
USART_InitStructure.USART_BaudRate = 9600; //²¨ÌØÂÊΪ9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //×Ö³¤Îª8bit
USART_InitStructure.USART_StopBits = USART_StopBits_1; //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);
//USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //ʹÄÜUSART1½ÓÊܼĴæÆ÷·Ç¿Õʱ²úÉúÖжÏ
USART_Cmd(USART1,ENABLE); //ʹÄÜ´®¿Ú1
//USART_ClearFlag(USART1,USART_FLAG_TC);
}
三、你的芯片问题,可以是坏的
四、仿真器的影响
一周热门 更多>