串口通信大家都很熟悉,一边发送一边接收,但有些产品应用时会发现硬件接口不够了,或者线不够了,这是就可能用到单线通信了,一条线实现半双工通信,研究了很久终于搞好了,记录见附件
/* Enabe HalfDuplex mode for USART2 */ USART_HalfDuplexCmd(USART1, ENABLE);// CR3_HDSEL=1
USART_LINCmd((USART1, DISABLE);// CR2_LINEN=0 USART_ClockInitTypeDef USART_ClockInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; // CR2_CLKEN=0 USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; USART_ClockInit(USART2, &USART_ClockInitStructure); USART_SmartCardCmd(USART1, DISABLE); // CR3_SCEN=0 USART_IrDACmd(USART1, DISABLE); // CR3_IREN=0
|