/* ------------ ADC1~ADC2 reguler channel configuration ----------------- */
ADC_InitStructure.ADC_Mode = ADC_Mode_RegInjecSimult; /* »ìºÏͬ²½¹æÔò+ͬ²½×¢Èëģʽ */
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; /* DISABLE */
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = NUM_OF_REG_CHANNEL;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Init(ADC2, &ADC_InitStructure);
ADC_EXT_TRIG_ENABLE(ADC2); /* adc2¹æÔòͨµÀÍⲿ´¥·¢ */
/* Regular ChannelÉèÖòɼ¯Ë³ÐòºÍʱ¼ä.ÉèÖóÉË«adcºó,dmaÓÃ32bit´«Êä,µÍ16bitÊÇadc1ͨµÀ,¸ß16bitÊÇadc2ͨµÀ */
ADC_RegularChannelConfig(ADC1, CH5_RESERVED, 1, ADC_SampleTime_13Cycles5);//0
ADC_RegularChannelConfig(ADC1, CH6_VREF_1_65, 2, ADC_SampleTime_13Cycles5);// 2
ADC_RegularChannelConfig(ADC1, CH12_BAT_IN, 3, ADC_SampleTime_13Cycles5);// 4
ADC_RegularChannelConfig(ADC1, CH13_15VAD, 4, ADC_SampleTime_13Cycles5);//6
ADC_RegularChannelConfig(ADC1, CH14_RIGHT_BUS_CURRENT, 5, ADC_SampleTime_13Cycles5);//8
ADC_RegularChannelConfig(ADC1, CH15_LEFT_BUS_CURRENT, 6, ADC_SampleTime_13Cycles5);//10
/* Regular Channel */
ADC_RegularChannelConfig(ADC2, CH15_LEFT_BUS_CURRENT,1, ADC_SampleTime_13Cycles5);// 1
ADC_RegularChannelConfig(ADC2, CH5_RESERVED, 2, ADC_SampleTime_13Cycles5);// 3
ADC_RegularChannelConfig(ADC2, CH6_VREF_1_65, 3, ADC_SampleTime_13Cycles5);//5
ADC_RegularChannelConfig(ADC2, CH12_BAT_IN, 4, ADC_SampleTime_13Cycles5);//7
ADC_RegularChannelConfig(ADC2, CH13_15VAD, 5, ADC_SampleTime_13Cycles5);//9
ADC_RegularChannelConfig(ADC2, CH14_RIGHT_BUS_CURRENT,6, ADC_SampleTime_13Cycles5);//11
/* ÔÙ´ÎÅäÖÃadc1ºÍadc2µÄ×¢Èëת»»¹æÔò.Èç¹ûת»»Ìõ¼þΪTIM8CC4,Ôòµ±cc4²úÉúʱ,adc1
* ½«´¥·¢,¶øadc2»á±»×÷ΪslaveÆô¶¯×ª»».ÕâÀïµÄͨµÀ¿ÉÒÔÓÃÀ´²âÁ¿ÏàµçÁ÷.
*/
/* Injected Channel×¢ÈëͨµÀ×î¶à4¸ö,²Î¿¼jsqr¼Ä´æÆ÷ */
ADC_InjectedSequencerLengthConfig(ADC1, NUM_OF_INJ_CHANNEL);
ADC_InjectedChannelConfig(ADC1, CH3_RESERVED, 1, ADC_SampleTime_13Cycles5);
ADC_InjectedChannelConfig(ADC1, CH4_RESERVED, 2, ADC_SampleTime_13Cycles5);
ADC_InjectedChannelConfig(ADC1, CH10_RESERVED, 3, ADC_SampleTime_13Cycles5);
ADC_InjectedChannelConfig(ADC1, CH11_RESERVED, 4, ADC_SampleTime_13Cycles5);
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4);
ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE);
/* ---------------------- ADC2 configuration ------------------------------- */
/* Injected Channel */
ADC_InjectedSequencerLengthConfig(ADC2, NUM_OF_INJ_CHANNEL);
ADC_InjectedChannelConfig(ADC2, CH11_RESERVED, 1, ADC_SampleTime_13Cycles5);
ADC_InjectedChannelConfig(ADC2, CH10_RESERVED, 2, ADC_SampleTime_13Cycles5);
ADC_InjectedChannelConfig(ADC2, CH4_RESERVED, 3, ADC_SampleTime_13Cycles5);
ADC_InjectedChannelConfig(ADC2, CH3_RESERVED, 4, ADC_SampleTime_13Cycles5);
ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_None); //GDоƬÐè¼ÓÕâ¾ä»°£¬STÄܼæÈÝ
ADC_ExternalTrigInjectedConvCmd(ADC2, ENABLE);
/* ------------------------------------------------------------------------- */
/**
* ADC1
*/
/* Enable ADC1 DMA */
ADC_DMA_ENABLE(ADC1);
/* Enable ADC1 */
ADC_ENABLE(ADC1);
/* Enable ADC1 reset calibaration register */
ADC_RST_CAL(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GET_RST_CAL_STATUS(ADC1));
/* Start ADC1 calibaration */
ADC_START_CAL(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GET_CAL_STATUS(ADC1));
/* Enable ADC2 */
ADC_ENABLE(ADC2);
ADC_RST_CAL(ADC2);
while(ADC_GET_RST_CAL_STATUS(ADC2));
ADC_START_CAL(ADC2);
while(ADC_GET_CAL_STATUS(ADC2));
/**
* DMA1 channel1 deinitialize
*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DISABLE(DMA1_Channel1);
DMA1_Channel1->CCR = 0;
DMA1_Channel1->CNDTR = 0;
DMA1_Channel1->CMAR = 0;
DMA1_Channel1->CPAR = 0;
CLR_IT_FLAG(DMA1, Channel1);
/**
* DMA1 channel1 configuration
*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&g_adc12_value[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = NUM_OF_REG_CHANNEL; /* ָʾDMAʹÓöàÉÙ¸öÊý¾Ý,²»Äܳ¬¹ýÊý×é´óС.µ¥Î»ÊÇDMA_MemoryDataSize */
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; /* ÕâÊÇADC2ʹÓÃDMAµÄÒªÇó.low 16bit=adc1,high 16bit=adc2 */
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; /* normal=Ö»´«ËÍÒ»´Î */
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);