初始化IO口
- void RS485_Init(u32 bound)
- {
- GPIO_InitTypeDef GPIO_InitABC;
- USART_InitTypeDef USART_InitABC;
- //USUART2
- GPIO_InitABC.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3;//GPIOA2与GPIOA3
- GPIO_InitABC.GPIO_Mode=GPIO_Mode_AF;//复用功能
- GPIO_InitABC.GPIO_Speed=GPIO_Speed_100MHz;//速度100MHz
- GPIO_InitABC.GPIO_OType=GPIO_OType_PP;//推挽输出
- GPIO_InitABC.GPIO_PuPd=GPIO_PuPd_UP;//上拉
- GPIO_Init(GPIOA,&GPIO_InitABC);//初始化PA2、PA3
- //PG8推挽输出,495模式控制
- GPIO_InitABC.GPIO_Pin=GPIO_Pin_8;//GPIOG8
- GPIO_InitABC.GPIO_Mode=GPIO_Mode_OUT;//输出
- GPIO_InitABC.GPIO_Speed=GPIO_Speed_100MHz;//速度100MHz
- GPIO_InitABC.GPIO_OType=GPIO_OType_PP;//推挽输出
- GPIO_InitABC.GPIO_PuPd=GPIO_PuPd_UP;//上拉
- GPIO_Init(GPIOG,&GPIO_InitABC);//初始化PG8
- //UUSART2初始化设置
- USART_InitABC.USART_BaudRate=bound;//波特率设置
- USART_InitABC.USART_WordLength=USART_WorldLength_8b;//字长为8为数据格式
- USART_InitABC.USART_StopBits=USART_StopBits_1;//一个停止位
- USART_InitABC.USART_Parity=USART_Parity_No;//无奇偶校验位
- USART_InitABC.USART_HardwareFlowControl=USART_HardwareFlowControl_None;//无硬件数据流
- USART_InitABC.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;//收发模式
- USART_Init(USART2,&USART_InitABC);//初始化串口2
- USART_Cmd(USART2,ENABLE);//使能串口2
- USART_ClearFlag(USART2,USART_FLAG_TC);
- }
|