| 
 
| 大家好,本人之前一直用的是STM32F系列的,这次用L系列的,由于L系列库函数没有 TIM_CtrlPWMOutputs(TIM2, ENABLE);函数,且寄存器也不一样和F系列的,求解! 代码如下:
 void AD_Config_Init(void)
 {
 ADC_InitTypeDef  ADC_InitStructure;
 GPIO_InitTypeDef GPIO_InitStructure;
 
 /* Enable the HSI oscillator */
 RCC_HSICmd(ENABLE);
 
 /* Enable GPIOB clock */
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
 
 /* Configure PB.12 (ADC Channel18) in analog mode */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_4 | GPIO_Pin_5;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
 GPIO_Init(GPIOC, &GPIO_InitStructure);
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
 GPIO_Init(GPIOE, &GPIO_InitStructure);
 
 /* Check that HSI oscillator is ready */
 while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
 
 /* Enable ADC1 clock */
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
 /* ADC1 configuration */
 ADC_InitStructure.ADC_ScanConvMode = ENABLE;
 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//DISABLE;//ENABLE;
 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConv_T2_CC2;//ADC_ExternalTrigConvEdge_None;//ADC_ExternalTrigConv_T2_CC3;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_NbrOfConversion = 8;
 ADC_Init(ADC1, &ADC_InitStructure);
 
 /* ADC1 regular channel18 configuration */
 ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_4Cycles); //ADC_SampleTime_4Cycles
 ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 2, ADC_SampleTime_4Cycles);
 ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 3, ADC_SampleTime_4Cycles);
 ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 4, ADC_SampleTime_4Cycles);
 ADC_RegularChannelConfig(ADC1, ADC_Channel_22, 5, ADC_SampleTime_4Cycles);
 ADC_RegularChannelConfig(ADC1, ADC_Channel_23, 6, ADC_SampleTime_4Cycles);
 ADC_RegularChannelConfig(ADC1, ADC_Channel_24, 7, ADC_SampleTime_4Cycles);
 ADC_RegularChannelConfig(ADC1, ADC_Channel_25, 8, ADC_SampleTime_4Cycles);
 
 /* Enable the request after last transfer for DMA Circular mode */
 ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
 
 /* Enable ADC1 DMA */
 ADC_DMACmd(ADC1, ENABLE);
 
 /* Enable ADC1 */
 ADC_Cmd(ADC1, ENABLE);
 
 /* Wait until the ADC1 is ready */
 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
 {
 }
 
 /* Start ADC1 Software Conversion */
 ADC_SoftwareStartConv(ADC1);
 //  ADC_StartCalibration(ADC1);
 //  ADC1->CR2 |= (uint32_t)0x00000004;
 
 }
 
 void TIME2_Init( uint16_t frq_cj)
 {
 TIM_TimeBaseInitTypeDef   TIM_TimeBaseStructure;
 TIM_OCInitTypeDef         TIM_OCInitStructure;
 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
 TIM_DeInit(TIM2);
 
 TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
 TIM_TimeBaseStructure.TIM_Period = frq_cj;
 TIM_TimeBaseStructure.TIM_Prescaler = 0;//零分频,设置定期为1/72us
 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = frq_cj;//0x2BF2;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
 TIM_OC1Init(TIM2, &TIM_OCInitStructure);
 //   TIM_CtrlPWMOutputs(TIM2, ENABLE);
 //   TIM2->BDTR |= ((u16)0x8000);
 
 TIM_SelectOnePulseMode(TIM2, TIM_OPMode_Single);//TIM_OPMode_Repetitive);
 
 TIM_Cmd(TIM2, ENABLE);
 }
 
 
 
 
 | 
 |