gaoyike7 gaoyike7
关注数: 1 粉丝数: 14 发帖数: 1,542 关注贴吧数: 10
关于stm32f0做的无线温度采集的问题 以下是段用stm32f0做的温度采集的程序,哪位大神能给解释一下,谢谢了! void RCC_Initializations(void) { /* GPIOA Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* GPIOB Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); /* USART1 Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* TIM2 Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); } /** * @brief NVIC(Nested vectored interrupt controller) initializations. * @param None * @retval None */ void NVIC_Initializations(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Enable the TIM2 global Interrupt */// NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //USART1中断初始化 NVIC_Init(&NVIC_InitStructure); } /** * @brief GPIO(General-purpose I/Os) initializations. * @param None * @retval None */ void GPIO_Initializations(void) { GPIO_InitTypeDef GPIO_InitStructure; /* USART1_Tx/Rx Configuration *///USART1 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);// GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //PA9/10 alternate function 串口接9/10 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; //high speed GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//pushpull mode GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//可以没有上拉 GPIO_Init(GPIOA, &GPIO_InitStructure); /* GPIOB Configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;//AM2301接口初始化 温湿度采集接13管脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//output mode GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;//high speed GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//pushpull mode GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//pull up GPIO_Init(GPIOB, &GPIO_InitStructure); } /** * @brief USART1 initializations. * @param None * @retval None */ void USART1_Initialization(void) { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 9600; //波特率9600 USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8位数据位 USART_InitStructure.USART_StopBits = USART_StopBits_1; //1位停止位 USART_InitStructure.USART_Parity = USART_Parity_No; //无奇偶校验 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//收发模式 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//硬件流控制失能 //USART1配置 USART_Init(USART1, &USART_InitStructure);//初始化配置 //USART1使能 USART_Cmd(USART1, ENABLE); } /** * @brief TIM2 initializations. * @param None * @retval None */ void TIM2_Initializations(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Prescaler = 4799; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 10000;//1秒中断一次 //TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //TIM_TimeBaseStructure.TIM_RepetitionCounter = 0xff; /* 中断时间计算公式:T_out = (ARR*(psc+1))/T_clk T_clk=48MHz */ //定时器配置 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //定时器中断使能(更新中断) TIM_ITConfig(TIM2, TIM_IT_Update | TIM_IT_Trigger, ENABLE); //定时器使能 TIM_Cmd(TIM2, ENABLE); //此指令放于点阵初始化中 }
首页 1 2 下一页