void ADC_Configuration(void) { ADC_InitTypeDef ADC_InitStructure; ADC_StructInit(&ADC_InitStructure); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_Init(ADC2, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1 , ADC_SampleTime_239Cycles5); ADC_ITConfig(ADC1, ADC_IT_EOC, DISABLE); /* ADC2 regular channels configuration */ ADC_RegularChannelConfig(ADC2, ADC_Channel_4, 1, ADC_SampleTime_239Cycles5); ADC_ITConfig(ADC2, ADC_IT_EOC, DISABLE); /* Enable ADC1 DMA */ //ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1,2 */ ADC_Cmd(ADC1, ENABLE); ADC_Cmd(ADC2, ENABLE); /* Enable ADC1,2 reset calibaration register */ /* Check the end of ADC1,2 reset calibration register */ ADC_ResetCalibration(ADC1); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_ResetCalibration(ADC2); while(ADC_GetResetCalibrationStatus(ADC2)); /* Start ADC1,2 calibaration */ /* Check the end of ADC1,2 calibration */ ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC2); while(ADC_GetCalibrationStatus(ADC2)); /* Start ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); ADC_SoftwareStartConvCmd(ADC2, ENABLE); }
void initial_adc_dma_for_mosfet_test(void) { DMA_InitTypeDef DMA_InitStructure; // Set the TIM1 Trgo as the ADC trigger ADC1->CFGR1 |= ADC_ExternalTrigConvEdge_Rising; ADC1->CFGR1 &= ~ADC_ExternalTrigConv_T1_CC4; ADC1->CFGR1 |= ADC_ExternalTrigConv_T1_TRGO; ADC_ITConfig(ADC1, ADC_IT_EOSEQ, DISABLE); // Continuous mode // When tim1 update trigger the convert ADC_ContinuousModeCmd(ADC1, ENABLE); // Reconfig ADC DMA buffer DMA_DeInit(DMA1_Channel1); ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_OneShot); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)adc_buffer_for_mosfet_test; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 50; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); DMA_Cmd(DMA1_Channel1, ENABLE); }
void adc_init_analog_watchdog (void) { NVIC_InitTypeDef NVIC_InitStructure; //Set up interruts ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); // [..] A typical configuration Analog Watchdog is done following these steps : // (#) the ADC guarded channel(s) is (are) selected using the // ADC_AnalogWatchdogSingleChannelConfig() function. //Setup single channel function for ADC Channel 4, ADC_BATT_I ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_AnalogWatchdog_Channel_4); // (#) The Analog watchdog lower and higher threshold are configured using the // ADC_AnalogWatchdogThresholdsConfig() function. ADC_AnalogWatchdogThresholdsConfig(ADC1, I_BATT_TO_ADC(0.1), I_BATT_TO_ADC(0) ); // (#) The Analog watchdog is enabled and configured to enable the check, on one // or more channels, using the ADC_AnalogWatchdogCmd() function. ADC_AnalogWatchdogCmd(ADC1, ENABLE); // (#) Enable the analog watchdog on the selected channel using // ADC_AnalogWatchdogSingleChannelCmd() function ADC_AnalogWatchdogSingleChannelCmd(ADC1, ENABLE); /* Enable and set ADC1_COMP Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = ADC1_COMP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
/** * @brief Configure ADC and Analog watchdog * @param None * @retval None */ static void ADC_Config(void) { /* Enable ADC1 clock */ CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE); /* Initialise and configure ADC1 */ ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2); ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 Channel 3 */ ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE); /* Calculate Threshold data value*/ HighThresholdData = (uint16_t)(((uint32_t)HIGH_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ; LowThresholdData = (uint16_t)(((uint32_t)LOW_THRESHOLD_VOLTAGE * 1000) / (uint32_t)ADC_RATIO) ; /* Configure Analog Watchdog selected channel and Thresholds */ ADC_AnalogWatchdogConfig(ADC1, ADC_AnalogWatchdogSelection_Channel3, HighThresholdData, LowThresholdData); /* Enable Analog watchdog ADC1 Interrupt */ ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); /* Enable Interrupts */ enableInterrupts(); /* Start ADC1 Conversion using Software trigger*/ ADC_SoftwareStartConv(ADC1); }
/******************************************************************************* * Function Name : SVPWM_InjectedConvConfig * Description : This function configure ADC1 for 3 shunt current * reading and temperature and voltage feedbcak after a * calibration of the three utilized ADC Channels * Input : None * Output : None * Return : None *******************************************************************************/ void SVPWM_InjectedConvConfig(void) { /* ADC1 Injected conversions configuration */ ADC_InjectedSequencerLengthConfig(ADC1,2); ADC_InjectedSequencerLengthConfig(ADC2,2); ADC_InjectedChannelConfig(ADC1, PHASE_B_ADC_CHANNEL,1,SAMPLING_TIME_CK); ADC_InjectedChannelConfig(ADC1, BUS_VOLT_FDBK_CHANNEL,2,SAMPLING_TIME_CK); /* ADC1 Injected conversions trigger is TIM1 TRGO */ ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_TRGO); ADC_ExternalTrigInjectedConvCmd(ADC2,ENABLE); /* Bus voltage protection initialization*/ ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleInjecEnable); ADC_AnalogWatchdogSingleChannelConfig(ADC1,BUS_VOLT_FDBK_CHANNEL); ADC_AnalogWatchdogThresholdsConfig(ADC1, OVERVOLTAGE_THRESHOLD>>3,0x00); /* ADC1 Injected group of conversions end and Analog Watchdog interrupts enabling */ ADC_ITConfig(ADC1, ADC_IT_JEOC | ADC_IT_AWD, ENABLE); /* ADC2 Injected conversions configuration */ ADC_InjectedSequencerLengthConfig(ADC2,2); ADC_InjectedChannelConfig(ADC2, PHASE_A_ADC_CHANNEL, 1,SAMPLING_TIME_CK); ADC_InjectedChannelConfig(ADC2, TEMP_FDBK_CHANNEL, 2,SAMPLING_TIME_CK); }
static void AD_Reset() { ADC_InitTypeDef ADC_InitStructure; ADC_DeInit(ADC1); /* ADC configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegInjecSimult; //ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_ExternalTrigConvCmd(ADC1, ENABLE); ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5); ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* enable and calibrate ADCs */ ADC_Enable(ADC1); }
/** * @brief ADC configuration. * @param None * @retval None */ void ADC_Config(void) { /* ADC1 Peripheral clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* Channel 18 or 31 are already configured in Analog mode using GPIO registers */ /* ADC1 Configuration */ ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); #ifdef USE_STM32L152D_EVAL /* ADC1 regular channel 31 configuration for STM32L152D*/ ADC_RegularChannelConfig(ADC1, ADC_Channel_31, 1, ADC_SampleTime_384Cycles); #elif USE_STM32L152_EVAL /* ADC1 regular channel 18 configuration for STM32L152*/ ADC_RegularChannelConfig(ADC1, ADC_Channel_18, 1, ADC_SampleTime_384Cycles); #endif /* Enable EOC interrupt */ ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); }
int main(void) { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_InitStructure; ADC_InitTypeDef ADC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); TIM_TimeBaseStructInit(&TIM_InitStructure); TIM_InitStructure.TIM_Prescaler = 10000; TIM_InitStructure.TIM_Period = 100; TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_InitStructure); TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_55Cycles5); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); ADC_ExternalTrigConvCmd(ADC1, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); ADC_Cmd(ADC1, ENABLE); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); TIM_Cmd(TIM3, ENABLE); if (SysTick_Config(SystemCoreClock / 1000)) while (1); while(1); }
void adc_init(void) { ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_1); ADC_VrefintCmd(ENABLE); ADC_SamplingTimeConfig(ADC1,ADC_Group_SlowChannels,ADC_SamplingTime_4Cycles); ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE); ADC_Cmd(ADC1,ENABLE); };
extern "C" void ADC_IRQHandler() { // Assume interrupt comes from analog watchdog ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); ADC_ITConfig(ADC1, ADC_IT_AWD, DISABLE); // No longer need this interrupt // Do something... DAC_data_handler = panic_sound; }
/************************************************************************************** Func: ADC模拟狗配置 Time: 2014-6-18 Ver.: V1.0 Note; **************************************************************************************/ void ADC_WatchdogConfig(void) { NVIC_ADC1_2_Configuration(); //设置模拟狗相关 ADC_AnalogWatchdogSingleChannelConfig(ADC1,ADC_Channel_15); //设置模拟狗相关 ADC_AnalogWatchdogThresholdsConfig(ADC1,0xf,0);//设置模拟狗相关 ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleRegEnable); //设置模拟狗相关 ADC_ITConfig(ADC1,ADC_IT_AWD,DISABLE); //设置模拟狗相关 }
/** @brief Stops conversion engine. */ void Analog::stop() { // Disable external triggering ADC_ExternalTrigConvCmd(_base, DISABLE); //Disable the interrupt ADC_ITConfig(_base , ADC_IT_EOC , DISABLE); //Disable the ADC ADC_Cmd(_base, DISABLE); }
/** * @brief Change thresholds for light sensor readings * * This function reconfigures the analog watchdog thresholds. */ void setAdcThresholds(uint32_t high, uint32_t low){ ADC_AnalogWatchdogThresholdsConfig(ADC1, high, low); ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_10); ADC_ClearFlag(ADC1, ADC_FLAG_AWD); ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable); ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* Configure LED GPIO Pin ------------------------------------------------- */ STM_EVAL_LEDInit(LED1); /* ADC1 Configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel14 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5); /* Configure high and low analog watchdog thresholds */ ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0B00, 0x0300); /* Configure channel14 as the single analog watchdog guarded channel */ ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_14); /* Enable analog watchdog on one regular channel */ ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable); /* Enable AWD interupt */ ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); while (1) { } }
int main(void) { //Enable clocks RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //Configure PA0, PA1 and PA2 as analog inputs G.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2; G.GPIO_Mode = GPIO_Mode_AN; G.GPIO_OType = GPIO_OType_PP; G.GPIO_PuPd = GPIO_PuPd_NOPULL; G.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOA, &G); //Configure ADC in 12bit mode with upward scanning A.ADC_ContinuousConvMode = DISABLE; A.ADC_DataAlign = ADC_DataAlign_Right; A.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; A.ADC_Resolution = ADC_Resolution_12b; A.ADC_ScanDirection = ADC_ScanDirection_Upward; ADC_Init(ADC1, &A); ADC_Cmd(ADC1, ENABLE); //Enable end of conversion interrupt ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); //Enable ADC1 interrupt N.NVIC_IRQChannel = ADC1_COMP_IRQn; N.NVIC_IRQChannelPriority = 1; N.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&N); //Configure the channels to be converted, in this case C0, C1 and //C2, corresponding to PA0, PA1 and PA2 respectively ADC_ChannelConfig(ADC1, ADC_Channel_0, ADC_SampleTime_239_5Cycles); ADC_ChannelConfig(ADC1, ADC_Channel_1, ADC_SampleTime_239_5Cycles); ADC_ChannelConfig(ADC1, ADC_Channel_2, ADC_SampleTime_239_5Cycles); //Wait for the ADC to be ready! while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)); while(1) { //Start conversion ADC_StartOfConversion(ADC1); //Wait for conversion while(!Converted); //Reset converted flag (placement of breakpoint! Converted = 0; } }
/************************************************************************************** Func: ADC中断函数 Time: 2014-6-18 Ver.: V1.0 Note; **************************************************************************************/ void ADC1_2_IRQHandler(void) //模拟狗相关 { ADC_ITConfig(ADC1,ADC_IT_AWD,DISABLE); if(SET == ADC_GetFlagStatus(ADC1,ADC_FLAG_AWD)) { ADC_ClearFlag(ADC1,ADC_FLAG_AWD); ADC_ClearITPendingBit(ADC1,ADC_IT_AWD); if(Tos_TaskGetState(TOUCH_Tos_TaskID)==_TTS_Stop)Tos_TaskRecover(TOUCH_Tos_TaskID); else Tos_TaskTimeout(TOUCH_Tos_TaskID,10);//防止在任务没有挂起就发生dma发送中断了 } }
//定时器触发的ADC配置 void adc_tim_trig_config(uint32_t period, uint32_t prescaler) { ADC_CommonInitTypeDef ADC_CommonInitStructure; ADC_InitTypeDef ADC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); gpio_an_no_init(GPIOC, GPIO_Pin_5); ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式 ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; //两个采样阶段之间的延迟5个时钟 ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //DMA失能 ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4; //ADCCLK=PCLK2/4=84/4=21Mhz ADC_CommonInit(&ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; //12位模式 ADC_InitStructure.ADC_ScanConvMode = DISABLE; //关闭扫描模式 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //关闭连续转换 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; //外部触发上升沿 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //右对齐 ADC_InitStructure.ADC_NbrOfConversion = 1; //规则序列中有1个转换 ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_84Cycles ); //设置通道5采样顺序为1, 采样时间为84个周期 ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); ADC_Cmd(ADC1, ENABLE); nvic_config(ADC_IRQn, 2); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseStructure.TIM_Period = period-1; TIM_TimeBaseStructure.TIM_Prescaler = prescaler-1; TIM_TimeBaseStructure.TIM_ClockDivision = 0; 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_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_Pulse = period/2; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_Cmd(TIM2, ENABLE); TIM_InternalClockConfig(TIM2); TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); TIM_UpdateDisableConfig(TIM2, DISABLE); }
// // Boost_HW_SetInterrupts() // void Boost_HW_SetInterrupts(void) { //Desliga o HRTIM1 e ADC1 como fonte de interrupcao: NVIC_DisableIRQ(HRTIM1_TIMB_IRQn); NVIC_DisableIRQ(ADC1_2_IRQn); //Aciona interupcao por reset (ela que sera o trigger para disparar //a conversao A/D) HRTIM_ITConfig(HRTIM1, 0x01, HRTIM_TIM_IT_RST, ENABLE); //Aciona a interrupcao do ADC: ADC_ITConfig(ADC1, ADC_IT_EOC,ENABLE); }
/** * @brief ADC1 channel11 configuration * @param None * @retval None */ void ADC_Config(void) { ADC_InitTypeDef ADC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* ADC1 Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* Configure ADC Channel11 as analog input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure); /* ADC1 DeInit */ ADC_DeInit(ADC1); ADC_StructInit(&ADC_InitStructure); /* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits */ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; ADC_Init(ADC1, &ADC_InitStructure); /* Convert the ADC1 Channel 1 with 239.5 Cycles as sampling time */ ADC_ChannelConfig(ADC1, ADC_Channel_11 , ADC_SampleTime_239_5Cycles); /* Enable End Of Conversion interupt */ ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* Configure and enable ADC1 interrupt */ NVIC_InitStructure.NVIC_IRQChannel = ADC1_COMP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* ADC1 Start Conversion */ ADC_StartOfConversion(ADC1); }
void enable_ADC_watchdog(uint16_t low, uint16_t high) { ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_0); ADC_AnalogWatchdogThresholdsConfig(ADC1, high, low); ADC_ClearFlag(ADC1, ADC_FLAG_AWD); ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable); ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); NVIC_InitTypeDef NVIC_InitStructure = {0}; NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
void adc_init_injected(int use_trigger, int trigger){ //Confiure pins PA0[AN1], PA1[AN2] for analog input operation RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_InitTypeDef myGPIO; GPIO_StructInit(&myGPIO); myGPIO.GPIO_Pin=(GPIO_Pin_1|GPIO_Pin_0); myGPIO.GPIO_Mode=GPIO_Mode_AN; GPIO_Init(GPIOA,&myGPIO); //Configure ADC RCC_ADCCLKConfig(RCC_ADC12PLLCLK_OFF); RCC_AHBPeriphClockCmd(RCC_AHBENR_ADC12EN,ENABLE); ADC_CommonInitTypeDef myADC_Comm; ADC_CommonStructInit(&myADC_Comm); myADC_Comm.ADC_Clock=ADC_Clock_SynClkModeDiv1; ADC_CommonInit(ADC1,&myADC_Comm); ADC_VoltageRegulatorCmd(ADC1,ENABLE); /*Initial calibration*/ ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1) != RESET); ADC_GetCalibrationValue(ADC1); ADC_InjectedInitTypeDef myADC; ADC_InjectedStructInit(&myADC); myADC.ADC_ExternalTrigInjecEventEdge= (use_trigger) ? ADC_ExternalTrigInjecEventEdge_RisingEdge : ADC_ExternalTrigInjecEventEdge_None; //Connect timer with adc myADC.ADC_ExternalTrigInjecConvEvent=trigger;//Start convertion on TIM2_OTRIG myADC.ADC_NbrOfInjecChannel=2; myADC.ADC_InjecSequence1=ADC_InjectedChannel_1; myADC.ADC_InjecSequence2=ADC_InjectedChannel_1; myADC.ADC_InjecSequence3=ADC_InjectedChannel_1; myADC.ADC_InjecSequence4=ADC_InjectedChannel_2; ADC_InjectedInit(ADC1,&myADC); ADC_InjectedChannelSampleTimeConfig(ADC1,ADC_InjectedChannel_1,ADC_SampleTime_7Cycles5); ADC_InjectedChannelSampleTimeConfig(ADC1,ADC_InjectedChannel_2,ADC_SampleTime_7Cycles5); // ADC_ITConfig(ADC1, ADC_IT_JEOS, ENABLE); NVIC_EnableIRQ(ADC1_IRQn); /* wait for ADRDY */ ADC_Cmd(ADC1,ENABLE); while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY)); }
/** * @brief Set up analog input and ADC to read values from light sensor * * This function configures GPIO PC0 as an analog input connected to an * ADC. It also enables an analog watchdog interrupt that fires each time the * digital value is less then LIGHT_THRESHOLD_LOW or higher than LIGHT_THRESHOLD_HIGH. * * (LIGHT_THRESHOLD_LOW and LIGHT_THRESHOLD_HIGH are defined in lightsensor.h) * * You must define an interrupt handler (ADC_IRQHandler) to handle * these interrupts. */ void initAdc() { GPIO_InitTypeDef GPIO_initStructre; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN,ENABLE); GPIO_initStructre.GPIO_Pin = GPIO_Pin_0; GPIO_initStructre.GPIO_Mode = GPIO_Mode_AN; GPIO_initStructre.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC,&GPIO_initStructre); /* Common ADC Initialization */ ADC_CommonInitTypeDef adc_common; ADC_CommonStructInit(&adc_common); adc_common.ADC_Prescaler = ADC_Prescaler_Div8; ADC_CommonInit(&adc_common); /* ADC Initialization */ ADC_InitTypeDef adc; ADC_StructInit(&adc); adc.ADC_Resolution = ADC_Resolution_12b; adc.ADC_ContinuousConvMode = ENABLE; ADC_Init(ADC1, &adc); ADC_Cmd(ADC1,ENABLE); ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_480Cycles); /* Use an analog watchdog to trigger interrupt on given thresholds */ ADC_AnalogWatchdogThresholdsConfig(ADC1, LIGHT_THRESHOLD_HIGH, LIGHT_THRESHOLD_LOW); ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_10); ADC_ClearFlag(ADC1, ADC_FLAG_AWD); ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable); ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); NVIC_InitTypeDef NVIC_InitStructure; /* Configure and enable ADC interrupt */ NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); ADC_SoftwareStartConv(ADC1); }
/** * @brief Configure ADC peripheral * @param None * @retval None */ static void ADC_Config(void) { /* Initialise and configure ADC1 */ ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2); ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 Channel 3 */ ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE); /* Enable End of conversion ADC1 Interrupt */ ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* Start ADC1 Conversion using Software trigger*/ ADC_SoftwareStartConv(ADC1); }
static void RAY12_ADC_Init (void) { // for ADC GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* Configure PC.00 (ADC Channel10) as analog input -------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); ADC_InitTypeDef ADC_InitStructure; /* ADC1 Configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // ADC1 在独立模式 ADC_InitStructure.ADC_ScanConvMode = DISABLE; // ENABLE-ADC多通道扫描, DISABLE-ADC单通道扫描 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // ENABLE--ADC连续转化模式 DISABLE--ADC单次转化模式 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // 由软件触发 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; // 数据向右对齐 ADC_InitStructure.ADC_NbrOfChannel = 1; // 连续转化1个AD通道值 ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel10 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_13Cycles5); /* Enable AWD interupt */ ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); }
void ADC_Config(void) { ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_7; 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_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure); /* ADC Common Init **********************************************************/ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC1 Init ****************************************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = DISABLE; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); ALL_EM_OFF; }
void init_ADC(){ GPIO_InitTypeDef gpioinitADC; #if defined(CX_10_RED_BOARD) gpioinitADC.GPIO_Pin = GPIO_Pin_2; #endif #if defined(CX_10_BLUE_BOARD) gpioinitADC.GPIO_Pin = GPIO_Pin_7; //-5 #endif gpioinitADC.GPIO_Mode = GPIO_Mode_AN; gpioinitADC.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &gpioinitADC); ADC_InitTypeDef ADC_InitStructure; ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; ADC_Init (ADC1, &ADC_InitStructure); #if defined(CX_10_RED_BOARD) ADC_ChannelConfig (ADC1, ADC_Channel_2, ADC_SampleTime_239_5Cycles); #endif #if defined(CX_10_BLUE_BOARD) ADC_ChannelConfig (ADC1, ADC_Channel_7, ADC_SampleTime_239_5Cycles); #endif ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = ADC1_COMP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 4; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); ADC_GetCalibrationFactor(ADC1); ADC_Cmd (ADC1, ENABLE); while (!ADC_GetFlagStatus (ADC1, ADC_FLAG_ADEN)); }
void SVPWM_3ShuntCurrentReadingCalibration(void) { static u16 bIndex; /* ADC1 Injected group of conversions end interrupt disabling */ ADC_ITConfig(ADC1, ADC_IT_JEOC, DISABLE); hPhaseAOffset=0; hPhaseBOffset=0; hPhaseCOffset=0; /* ADC1 Injected conversions trigger is given by software and enabled */ ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None); ADC_ExternalTrigInjectedConvCmd(ADC1,ENABLE); /* ADC1 Injected conversions configuration */ ADC_InjectedSequencerLengthConfig(ADC1,3); ADC_InjectedChannelConfig(ADC1, PHASE_A_ADC_CHANNEL,1,SAMPLING_TIME_CK); ADC_InjectedChannelConfig(ADC1, PHASE_B_ADC_CHANNEL,2,SAMPLING_TIME_CK); ADC_InjectedChannelConfig(ADC1, PHASE_C_ADC_CHANNEL,3,SAMPLING_TIME_CK); /* Clear the ADC1 JEOC pending flag */ ADC_ClearFlag(ADC1, ADC_FLAG_JEOC); ADC_SoftwareStartInjectedConvCmd(ADC1,ENABLE); /* ADC Channel used for current reading are read in order to get zero currents ADC values*/ for(bIndex=0; bIndex <NB_CONVERSIONS; bIndex++) { while(!ADC_GetFlagStatus(ADC1,ADC_FLAG_JEOC)) { } hPhaseAOffset += (ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_1)>>3); hPhaseBOffset += (ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_2)>>3); hPhaseCOffset += (ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_3)>>3); /* Clear the ADC1 JEOC pending flag */ ADC_ClearFlag(ADC1, ADC_FLAG_JEOC); ADC_SoftwareStartInjectedConvCmd(ADC1,ENABLE); } SVPWM_InjectedConvConfig( ); }
void Vibro_Process( void *pvParameters ) // { while(1) { if( xVibro_Semaphore != NULL) { if( xSemaphoreTake( xVibro_Semaphore, portMAX_DELAY ) == pdTRUE ) { ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); vTaskDelay(500); Set_Random_Color(); //vTaskDelay(1500); ADC_ClearITPendingBit(ADC1, ADC_IT_AWD); ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE); //xSemaphoreGive(xVibro_Semaphore); //taskYIELD(); } } } }
/** * @brief Configures the ADC. * @param None * @retval None */ void ADC_Configuration(void) { ADC_InitTypeDef ADC_InitStructure; // Structure to initialize the ADC // Common config ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // Conversion on PWM rising edge only ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; // Timer 1 CC1 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 8; ADC_DeInit( ADC1 ); //Set ADC registers to default values ADC_Init( ADC1, &ADC_InitStructure ); // Channels config // Refer to SignalsRouting.png for the ranks ADC_RegularChannelConfig( ADC1, ADC_Channel_8, 2, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_9, 1, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_10, 8, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_11, 7, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_12, 3, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_13, 4, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_14, 6, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig( ADC1, ADC_Channel_15, 5, ADC_SampleTime_1Cycles5); // Enable End Of Conversion interrupt ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); // Start transferts ADC_ExternalTrigConvCmd( ADC1, ENABLE ); // Enable ADC1 external trigger ADC_DMACmd( ADC1, ENABLE ); //Enable ADC1 DMA ADC_Cmd( ADC1, ENABLE ); //Enable ADC1 // Calibrate ADC1 ADC_ResetCalibration( ADC1 ); while ( ADC_GetResetCalibrationStatus(ADC1) ) {} //Check the end of ADC1 reset calibration register ADC_StartCalibration( ADC1 ); while ( ADC_GetCalibrationStatus(ADC1) ) {} //Check the end of ADC1 calibration }
/** * @brief Main program * @param None * @retval : None */ int main(void) { /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC1ConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 1; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* DMA2 channel5 configuration ----------------------------------------------*/ DMA_DeInit(DMA2_Channel5); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC3_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC3ConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 1; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA2_Channel5, &DMA_InitStructure); /* Enable DMA2 channel5 */ DMA_Cmd(DMA2_Channel5, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_28Cycles5); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* ADC2 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC2, &ADC_InitStructure); /* ADC2 regular channels configuration */ ADC_RegularChannelConfig(ADC2, ADC_Channel_13, 1, ADC_SampleTime_28Cycles5); /* Enable ADC2 EOC interupt */ ADC_ITConfig(ADC2, ADC_IT_EOC, ENABLE); /* ADC3 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC3, &ADC_InitStructure); /* ADC3 regular channel14 configuration */ ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 1, ADC_SampleTime_28Cycles5); /* Enable ADC3 DMA */ ADC_DMACmd(ADC3, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Enable ADC2 */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC2 reset calibaration register */ ADC_ResetCalibration(ADC2); /* Check the end of ADC2 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC2)); /* Start ADC2 calibaration */ ADC_StartCalibration(ADC2); /* Check the end of ADC2 calibration */ while(ADC_GetCalibrationStatus(ADC2)); /* Enable ADC3 */ ADC_Cmd(ADC3, ENABLE); /* Enable ADC3 reset calibaration register */ ADC_ResetCalibration(ADC3); /* Check the end of ADC3 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC3)); /* Start ADC3 calibaration */ ADC_StartCalibration(ADC3); /* Check the end of ADC3 calibration */ while(ADC_GetCalibrationStatus(ADC3)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* Start ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC2, ENABLE); /* Start ADC3 Software Conversion */ ADC_SoftwareStartConvCmd(ADC3, ENABLE); while (1) { } }