RCC_APB2PeriphClockCmd(RCC_APB2ENR_LPUART1, ENABLE);
LPUART_StructInit(&LPUART_InitStructure);
LPUART_InitStructure.LPUART_BaudRate = LPUART_Baudrate_9600;
LPUART_InitStructure.LPUART_WordLength = LPUART_WordLength_8b;
LPUART_InitStructure.LPUART_StopBits = LPUART_StopBits_1;
LPUART_InitStructure.LPUART_Parity = LPUART_Parity_No;
LPUART_InitStructure.LPUART_Clock_Source = 0; /* 0:LSE 1:LSI 2:PCLK */
LPUART_InitStructure.LPUART_MDU_Value = 0x952;
LPUART_InitStructure.LPUART_NEDET_Source = LPUART_NegativeDectect_Source1;
LPUART_InitStructure.LPUART_RecvEventCfg = LPUART_RecvEvent_OneByte_Complete;
LPUART_Init(LPUART1, &LPUART_InitStructure);
LPUART_ITConfig(LPUART1, LPUART_LPUCON_RXIE, ENABLE);
LPUART_Cmd(LPUART1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOC, ENABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource0, GPIO_AF_2);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_2);
引脚复用参考如下:
Adc使用 三个连接滑动变阻器的口如下:
代码配置如下:
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_PRESCARE = ADC_PCLK2_PRESCARE_16;
ADC_InitStructure.ADC_Mode = ADC_Mode_Continue;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC1_ExternalTrigConv_T3_CC3;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 0, ADC_Samctl_240_5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_Samctl_240_5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_Samctl_240_5);
IRM模块配置:
引脚复用情况:
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7); // IR out
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); // UART1_RX
服用配置后使用A9口发送,A10口作为接收
使用UART1寄存器值作为发送数据值
static uint8_t IRM_Count = 0x01;
if (IRM_Count < 0xFF) IRM_Count ++;
else {
IRM_Count = 0x01;
}
// printf("\r\n IRM Send data : 0x%x\n", IRM_Count);
UART_SendData(UART1, IRM_Count);
while(UART_GetFlagStatus(UART1, UART_FLAG_TXEPT) == RESET);
使用UART1中断接收
void UART1_IRQHandler(void)
{
uint32_t ValueRec = 0;
if(UART_GetITStatus(UART1, UART_IT_RXIEN) != RESET)
{
ValueRec = UART_ReceiveData(UART1);
printf("\r\n IRM_RecvHandler Recv Data : 0x%x\n", ValueRec);
UART_ClearITPendingBit(UART1, UART_IT_RXIEN);
LCD_DisplayNumber2(4, '0' + (ValueRec / 10), 0);
LCD_DisplayNumber2(5, '0' + (ValueRec % 10), 0);
}
}
左边两位显示ADC值转化为等分的3.3V分压,右边部分显示的IRM周期发送的递增值,后接受到的数据
最后RTC模块配置后时间显示效果
☝长按图片,扫码申请☝