金牌会员
 
- 积分
- 1050
- 金钱
- 1050
- 注册时间
- 2016-5-13
- 在线时间
- 111 小时
|
发表于 2016-8-9 13:12:12
|
显示全部楼层
[mw_shl_code=c,true]/* USART4 */
#define UART4_GPIO_TX GPIO_Pin_10
#define UART4_GPIO_RX GPIO_Pin_11
#define UART4_GPIO GPIOC
#define USART_BAUD_RATE 115200
// --------------------------------------------------------- //
// 函数名称:USART4HardwareInit
// 函数说明: 串口4初始化
// 输入参数: 无
// 输出参数: 无
// 返回值: 无
// 历史记录:
// <作者> <时间> <修改记录>
// --------------------------------------------------------- //
void USART4HardwareInit(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/*开USART1时钟*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
/*开GPIOA时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
/* Configure USART1 Tx (PC.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = UART4_GPIO_TX;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(UART4_GPIO, &GPIO_InitStructure);
/* Configure USART1 Rx (PC.11) as input floating */
GPIO_InitStructure.GPIO_Pin = UART4_GPIO_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(UART4_GPIO, &GPIO_InitStructure);
//串口1配置 8位数据位 1为停止位 DMA发送模式 中断接收模式
USART_InitStructure.USART_BaudRate = USART_BAUD_RATE;
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(UART4, &USART_InitStructure);
//使能串口1
USART_Cmd(UART4, ENABLE);
//打开接收完成中断
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
//清除发送完成中断
USART_ClearFlag(UART4, USART_FLAG_TC);
}
[/mw_shl_code] |
|