/*******************************************************************************
** 函数名称 : USART1_GPIO_Configuration
** 函数功能 : 串口1引脚初始化
** 输 入 : 无
** 输 出 : 无
** 返 回 : 无
*******************************************************************************/
void HW_USART1_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1, ENABLE);
/* GPIOA/ USART1 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用开漏输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
//GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
}
/*******************************************************************************
** 函数名称 : USART1_Configuration
** 函数功能 : 串口1初始化配置
** 输 入 : baud 枚举变量,设置波特率
** 输 出 : 无
** 返 回 : 无
*******************************************************************************/
void HW_USART1_Configuration(CAMERA_BAUD baud)
{
unsigned int temp = 0;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* USART1 configuration */
switch(baud){
case BAUD4800: temp = 4800;
break;
case BAUD9600: temp = 9600;
break;
case BAUD19200: temp = 19200;
break;
case BAUD28800: temp = 28800;
break;
case BAUD38400: temp = 38400;
break;
case BAUD57600: temp = 57600;
break;
case BAUD115200: temp = 115200;
break;
default: temp = 19200; /* 默认 19200 */
}
USART_InitStructure.USART_BaudRate = temp;
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;
/* Configure USART1 */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 Receive interrupts */
USART_ClearITPendingBit(USART1,USART1_IRQn);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
}