|
|
|
|
@ -32,20 +32,20 @@
|
|
|
|
|
*/
|
|
|
|
|
static void RCC_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
//下面是给各模块开启时钟
|
|
|
|
|
//启动GPIO
|
|
|
|
|
//下面是给各模块开启时钟
|
|
|
|
|
//启动GPIO
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | \
|
|
|
|
|
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | \
|
|
|
|
|
RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOG,
|
|
|
|
|
ENABLE);
|
|
|
|
|
|
|
|
|
|
//启动AFIO
|
|
|
|
|
//启动AFIO
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
|
|
|
|
//启动USART1时钟
|
|
|
|
|
//启动USART1时钟
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
|
|
|
|
//启动USART2时钟
|
|
|
|
|
//启动USART2时钟
|
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
|
|
|
|
//启动DMA时钟
|
|
|
|
|
//启动DMA时钟
|
|
|
|
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
|
|
|
|
/* Enable ADC1 and GPIOC clock */
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
|
|
|
|
@ -95,13 +95,13 @@ static void GPIO_Configuration(void)
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* USART1_TX */
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* USART1_RX */
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
|
|
|
|
@ -118,7 +118,7 @@ static void GPIO_Configuration(void)
|
|
|
|
|
void USART1_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
USART_InitTypeDef USART_InitStructure;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USART_InitStructure.USART_BaudRate = 115200;
|
|
|
|
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
|
|
|
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
|
|
|
|
@ -126,14 +126,14 @@ void USART1_Configuration(void)
|
|
|
|
|
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
|
|
|
|
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
|
|
|
|
USART_Init(USART1, &USART_InitStructure);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USART_Cmd(USART1, ENABLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* IWDG_Configuration
|
|
|
|
|
*/
|
|
|
|
|
static void IWDG_Configuration(void)
|
|
|
|
|
static void IWDG_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
|
|
|
|
|
IWDG_SetPrescaler(IWDG_Prescaler_64);
|
|
|
|
|
@ -161,12 +161,12 @@ int fputc(int ch, FILE *f)
|
|
|
|
|
|
|
|
|
|
int fgetc(FILE *f)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(!(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (USART_ReceiveData(USART1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|