目前采用的是F373的芯片,采用的是SDADC_InputMode_SEOffset模式,参考了论坛里的例程,今天刚调通,需要的朋友可以参考一下。
1)我猜测f3函数库中库函数SDADC_InjectedChannelSelect()是有问题的,如图1和图2,SDADC_JCHGR是配置注入组的,SDADC_InjectedChannelSelect使用的是赋值不是或运算,这样如果配置多个通道,后面配置的通道会把之前的覆盖了,导致只能配置一个通道。
2)例程如下:
void SDADC_Configuration(void)
{
SDADC_AINStructTypeDef ADC_AINStructure;
SDADC_InitTypeDef SDADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
int SDADCTimeout=0;
/* Enable clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC1,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_SDADCAnalogCmd(PWR_SDADCAnalog_1,ENABLE);
RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div14);
//===============ADC 输入 端口设置 ==================================================
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
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_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_Init(GPIOE, &GPIO_InitStructure);
SDADC_DeInit(SDADC1);
SDADC_VREFSelect(SDADC_VREF_Ext);
Delay(5);
SDADC_Cmd(SDADC1, ENABLE);
SDADC_InitModeCmd(SDADC1, ENABLE);
while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == RESET));
//SDADC_DeInit(SDADC1);
/* ADC1 configuration ------------------------------------------------------*/
ADC_AINStructure.SDADC_InputMode=SDADC_InputMode_SEOffset;
ADC_AINStructure.SDADC_Gain=SDADC_Gain_1_2;
ADC_AINStructure.SDADC_CommonMode=SDADC_CommonMode_VSSA;
ADC_AINStructure.SDADC_Offset=0;
SDADC_AINInit(SDADC1,SDADC_Conf_0,&ADC_AINStructure);
SDADC_DMAConfig(SDADC1,SDADC_DMATransfer_Injected, ENABLE);
SDADC_ChannelConfig(SDADC1, SDADC_Channel_4, SDADC_Conf_0);
SDADC_ChannelConfig(SDADC1, SDADC_Channel_8, SDADC_Conf_0);
SDADC_InjectedChannelSelect(SDADC1,SDADC_Channel_8|SDADC_Channel_4);//必须这样才可以,分开配置的话后面配置的通道会覆盖前面的。
SDADC_InjectedContinuousModeCmd(SDADC1,ENABLE);
SDADC_InitModeCmd(SDADC1, DISABLE);
SDADC_CalibrationSequenceConfig(SDADC1, SDADC_CalibrationSequence_1);
SDADC_StartCalibration(SDADC1);
/* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */
SDADCTimeout = 4*30720 ;
/* wait for PT100_SDADC Calibration process to end */
while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_EOCAL) == RESET) && (--SDADCTimeout != 0));
if(SDADCTimeout == 0)
{
/* EOCAL flag can not set */
return ;
}
SDADC_SoftwareStartInjectedConv(SDADC1);
}
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE);
DMA_DeInit(DMA2_Channel3); //恢复默认值,这个是必要的
/* DMA channel1 configuration ----------------------------------------------*/
DMA_InitStructure.DMA_PeripheralBaseAddr = SDADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr =(u32) SDADC_RegularConvertedValueTab;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = SDAD_NUM;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // 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_Channel3, &DMA_InitStructure);
NVIC_Configuration();
DMA_ITConfig(DMA2_Channel3, DMA_IT_TC, ENABLE); //DMA通道1传输完成中断
/* Enable DMA channel1 */
DMA_Cmd(DMA2_Channel3, ENABLE);
} |