下面是我的配置代码:
sta
tic void GPIO_USART1_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOUSART1, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOUSART1, GPIO_PinSource10, GPIO_AF_1);
/* GPIO_PIN9 - gt; USART1-TX GPIO_PIN10 - gt; USART1-RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOUSART1, amp;GPIO_InitStructure);
}
void USART1_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_USART1_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
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_Rx | USART_Mode_Tx;
USART_Init(USART1, amp;USART_InitStructure);
USART_Cmd(USART1, ENABLE);//ʹÄÜ´®¿Ú1
}
void UART1_send_byte(uint8_t byte)
{
while(!((USART1- gt;ISR) amp;(1ISR) amp;(1ISR amp; (1CR |= (uint32_t)0x00000001;
/* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */
RCC- gt;CFGR amp;= (uint32_t)0xF8FFB80C;
/* Reset HSEON, CSSON and PLLON bits */
RCC- gt;CR amp;= (uint32_t)0xFEF6FFFF;
/* Reset HSEBYP bit */
RCC- gt;CR amp;= (uint32_t)0xFFFBFFFF;
/* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
RCC- gt;CFGR amp;= (uint32_t)0xFFC0FFFF;
/* Reset PREDIV1[3:0] bits */
RCC- gt;CFGR2 amp;= (uint32_t)0xFFFFFFF0;
/* Reset USARTSW[1:0], I2CSW, CECSW and ADCSW bits */
RCC- gt;CFGR3 amp;= (uint32_t)0xFFFFFEAC;
/* Reset HSI14 bit */
RCC- gt;CR2 amp;= (uint32_t)0xFFFFFFFE;
/* Disable all interrupts */
RCC- gt;CIR = 0x00000000;
/* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */
SetSysClock();
}
static void SetSysClock(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
/* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/
/* Enable HSE */
RCC- gt;CR |= ((uint32_t)RCC_CR_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC- gt;CR amp; RCC_CR_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) amp; amp; (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC- gt;CR amp; RCC_CR_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* Enable Prefetch Buffer */
FLASH- gt;ACR |= FLASH_ACR_PRFTBE;
FLASH- gt;ACR |= (uint32_t)FLASH_ACR_LATENCY;
/* HCLK = SYSCLK */
RCC- gt;CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
/* PCLK = HCLK */
RCC- gt;CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1;
/* PLL configuration: = HSE * 4 = 40 MHz */
RCC- gt;CFGR amp;= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
RCC- gt;CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL4);
/* Enable PLL */
RCC- gt;CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */
while((RCC- gt;CR amp; RCC_CR_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC- gt;CFGR amp;= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
RCC- gt;CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC- gt;CFGR amp; (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
{
}
}
else
{ /* If HSE fails to start-up, the application will have wrong clock
configuration. User can add here some code to deal with this error */
}
}
调了两天了,一直找不到问题,