- //---LIN配置
- static void lin_init(void)
- {
- //初始化
- //时钟设置
- NVIC_InitTypeDef NVIC_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- USART_ClockInitTypeDef USART_ClockInitqlt;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- //---USART2串口配置
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //开启中断
- NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PREEMPTION_PRIORITY_LIN_UART_RX;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_SUB_PRIORITY_LIN_UART_RX;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- USART_InitStructure.USART_BaudRate = LIN_BAUDRATE;
- 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(USART2, &USART_InitStructure);
- USART_ClockInitqlt.USART_Clock= USART_Clock_Disable;
- USART_ClockInitqlt.USART_CPOL = USART_CPOL_Low;
- USART_ClockInitqlt.USART_CPHA = USART_CPHA_2Edge;
- USART_ClockInitqlt.USART_LastBit = USART_LastBit_Disable;//
- USART_ClockInit(USART2,&USART_ClockInitqlt);
- USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
- USART_ITConfig(USART2,USART_IT_TXE,DISABLE);
-
- USART_Cmd(USART2, ENABLE);
- }
|