本帖最后由 caihong001 于 2015-11-8 18:16 编辑
在用STM32F103R8T6做红外接收,红外接收管型号是1838,接收管输出引脚接的是UART2的RXD(PA.3)
初始化部分:
uint8_t usart2_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
// Enable USART2 clocks
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
// Enable GPIOA clocks
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE);
USART_InitStructure.USART_BaudRate = 115200;
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_Cmd(USART2, ENABLE);
/* Set the USART2 prescaler */
USART_SetPrescaler(USART2, 0x1);
/* Configure the USART2 IrDA mode */
USART_IrDAConfig(USART2, USART_IrDAMode_Normal);
/* Enable the USART2 IrDA mode */
USART_IrDACmd(USART2, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(IrDA_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(IrDA_PORT, &GPIO_InitStructure);
/*开启USART3的接收和发送完成中断*/
USART_ITConfig(IrDA, USART_IT_TC, DISABLE);
USART_ITConfig(IrDA, USART_IT_RXNE, ENABLE);
}
按遥控,能进USART2中断,但按一次键每次收到三十多个0
配置有问题吗?都是按例程改的。
还有硬件电路上的接法是不是有问题,我尝试过在红外输出脚加一上拉电阻也不行.
|