CODE
/********************************************************************************
************
ADC1_Init (void)
********************************************************************************
************/
void ADC1_ADC2_DualMode_Init (u32 F_Sample)
{ ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE); // Разрешить тактирование ADC1 ADC2
Init_Trigger_ADC1_ADC2 (F_Sample); // Conversion can be triggered by an external event Timer 3 - channel 1
Config_AIN_ADC ();
ADC_DeInit(); // DeInit ADC1
ADC_StructInit(&ADC_InitStructure);
/******************************************************************************/
/* ADCs configuration: dual ADC mode with 15cycles delay */
/******************************************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; // ADC Common configuration
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; // ADC1 regular channel 1 configuration
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Falling; //
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_15Cycles);
ADC_Init(ADC2, &ADC_InitStructure); // Initializes the ADCx peripheral according to the specified parameters
ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_15Cycles);
ADC_Cmd(ADC1, ENABLE); // Enable ADC1
ADC_Cmd(ADC2, ENABLE); // Enables the specified ADC peripheral
} // ADC1_ADC2_DualMode_Init ()
/********************************************************************************
************
ADC_IRQHandler (void) Receiving data via ADC
********************************************************************************
************/
__irq void ADC_IRQHandler(void)
{
if (ADC1->SR & ADC_FLAG_EOC) ADC_Current = (u16)ADC1-> DR; //
if (ADC2->SR & ADC_FLAG_EOC) ADC_Voltage = (u16)ADC2-> DR; //
} // __irq ADC_IRQHandler ()
/********************************************************************************
************
__irq void HardFault_Handler (void)
********************************************************************************
************/
extern INT32U HF_State;
__irq void HardFault_Handler (void)
{
SCB->HFSR |= SCB_HFSR_FORCED_Msk;
} // __irq HardFault_Handler (void)
************
ADC1_Init (void)
********************************************************************************
************/
void ADC1_ADC2_DualMode_Init (u32 F_Sample)
{ ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE); // Разрешить тактирование ADC1 ADC2
Init_Trigger_ADC1_ADC2 (F_Sample); // Conversion can be triggered by an external event Timer 3 - channel 1
Config_AIN_ADC ();
ADC_DeInit(); // DeInit ADC1
ADC_StructInit(&ADC_InitStructure);
/******************************************************************************/
/* ADCs configuration: dual ADC mode with 15cycles delay */
/******************************************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; // ADC Common configuration
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; // ADC1 regular channel 1 configuration
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Falling; //
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_15Cycles);
ADC_Init(ADC2, &ADC_InitStructure); // Initializes the ADCx peripheral according to the specified parameters
ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_15Cycles);
ADC_Cmd(ADC1, ENABLE); // Enable ADC1
ADC_Cmd(ADC2, ENABLE); // Enables the specified ADC peripheral
} // ADC1_ADC2_DualMode_Init ()
/********************************************************************************
************
ADC_IRQHandler (void) Receiving data via ADC
********************************************************************************
************/
__irq void ADC_IRQHandler(void)
{
if (ADC1->SR & ADC_FLAG_EOC) ADC_Current = (u16)ADC1-> DR; //
if (ADC2->SR & ADC_FLAG_EOC) ADC_Voltage = (u16)ADC2-> DR; //
} // __irq ADC_IRQHandler ()
/********************************************************************************
************
__irq void HardFault_Handler (void)
********************************************************************************
************/
extern INT32U HF_State;
__irq void HardFault_Handler (void)
{
SCB->HFSR |= SCB_HFSR_FORCED_Msk;
} // __irq HardFault_Handler (void)