使用SDADC1的0P,SDADC2的0P,SDADC3的0P和1P,SDADC的0P(channel_0)没取得数据
配置如下
SDADC_AINStructTypeDef SDADC_AINStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
uint32_t SDADCTimeout = 0;
/* HADA6017_SDADC APB2 interface clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC1|RCC_APB2Periph_SDADC2|RCC_APB2Periph_SDADC3, ENABLE);
/* PWR APB1 interface clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Enable HADA6017_SDADC analog interface */
PWR_SDADCAnalogCmd(PWR_SDADCAnalog_1|PWR_SDADCAnalog_2|PWR_SDADCAnalog_3, ENABLE);
/* Set the SDADC divider: The SDADC should run @6MHz */
/* If Sysclk is 72MHz, SDADC divider should be 12 */
RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div12);
/* GPIOE Peripheral clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE|RCC_AHBPeriph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
SDADC_VREFSelect(SDADC_VREF_Ext);
//---------------------------//
Delay(5);
/* Enable HADA6017_SDADC */
SDADC_Cmd(SDADC1, ENABLE);
SDADC_Cmd(SDADC2, ENABLE);
SDADC_Cmd(SDADC3, ENABLE);
/* Enter initialization mode */
SDADC_InitModeCmd(SDADC1, ENABLE);
SDADC_InitModeCmd(SDADC2, ENABLE);
SDADC_InitModeCmd(SDADC3, ENABLE);
SDADCTimeout = SDADC_INIT_TIMEOUT;
/* wait for INITRDY flag to be set */
while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == RESET) && (--SDADCTimeout != 0));
if(SDADCTimeout == 0)
{
/* INITRDY flag is not set */
return 1;
}
SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference;//;SDADC_InputMode_SEOffset
SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1;
SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA;
SDADC_AINStructure.SDADC_Offset = 0;
SDADC_AINInit(SDADC1, SDADC_Conf_0, &SDADC_AINStructure);
SDADC_AINInit(SDADC2, SDADC_Conf_0, &SDADC_AINStructure);
SDADC_AINInit(SDADC3, SDADC_Conf_0, &SDADC_AINStructure);
// SDADC_AINInit(SDADC3, SDADC_Conf_1, &SDADC_AINStructure);
SDADC_ChannelConfig(SDADC1, SDADC_Channel_0, SDADC_Conf_0);
SDADC_ChannelConfig(SDADC2, SDADC_Channel_0, SDADC_Conf_0);
SDADC_ChannelConfig(SDADC3, SDADC_Channel_0, SDADC_Conf_0);
SDADC_ChannelConfig(SDADC3, SDADC_Channel_1, SDADC_Conf_0);
/* select channel 0 */
SDADC_InjectedChannelSelect(SDADC1, SDADC_Channel_0);
SDADC_InjectedChannelSelect(SDADC2, SDADC_Channel_0);
SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_0);
SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_1);
/* Select an external trigger */
SDADC_ExternalTrigInjectedConvConfig(SDADC1, SDADC_ExternalTrigInjecConv_T19_CC2);
SDADC_ExternalTrigInjectedConvConfig(SDADC2, SDADC_ExternalTrigInjecConv_T19_CC3);
SDADC_ExternalTrigInjectedConvConfig(SDADC3, SDADC_ExternalTrigInjecConv_T19_CC4);
/* Select rising edge */
SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC1, SDADC_ExternalTrigInjecConvEdge_Rising);
SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC2, SDADC_ExternalTrigInjecConvEdge_Rising);
SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC3, SDADC_ExternalTrigInjecConvEdge_Rising);
/* Exit initialization mode */
SDADC_InitModeCmd(SDADC1, DISABLE);
SDADC_InitModeCmd(SDADC2, DISABLE);
SDADC_InitModeCmd(SDADC3, DISABLE);
/* Enable end of injected conversion interrupt */
SDADC_ITConfig(SDADC1, SDADC_IT_JEOC, ENABLE);
SDADC_ITConfig(SDADC3, SDADC_IT_JEOC, ENABLE);
SDADC_ITConfig(SDADC2, SDADC_IT_JEOC, ENABLE);
/* NVIC Configuration */
NVIC_InitStructure.NVIC_IRQChannel = SDADC1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = SDADC2_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = SDADC3_IRQn;
NVIC_Init(&NVIC_InitStructure);
/* configure calibration to be performed on conf0 */
SDADC_CalibrationSequenceConfig(SDADC1, SDADC_CalibrationSequence_1);
SDADC_CalibrationSequenceConfig(SDADC2, SDADC_CalibrationSequence_1);
SDADC_CalibrationSequenceConfig(SDADC3, SDADC_CalibrationSequence_1);
/* start HADA6017_SDADC Calibration */
SDADC_StartCalibration(SDADC1);
SDADC_StartCalibration(SDADC2);
SDADC_StartCalibration(SDADC3);
/* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */
SDADCTimeout = SDADC_CAL_TIMEOUT;
/* wait for HADA6017_SDADC Calibration process to end */
while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_EOCAL) == RESET) && (--SDADCTimeout != 0));
if(SDADCTimeout == 0)
{
/* EOCAL flag can not set */
return 2;
}
SDADC_SoftwareStartInjectedConv(SDADC3);
中断处理:
if(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_JEOC) != RESET)//SDADC_FLAG_JEOC
{
nAdVal= SDADC_GetInjectedConversionValue(SDADC3, &ChannelIndex);
if(ChannelIndex == 1)
{
adValue[2][ad2cnt]=nAdVal;ad2cnt++;
if(ad2cnt>=para[SAMP_NUM].i1)
{
ad2cnt = 0;dis[31].i1++;
}
}
if(ChannelIndex == 0x10002)
{
adValue[3][ad3cnt]=nAdVal;ad3cnt++;
if(ad3cnt>=para[SAMP_NUM].i1)
{
ad3cnt = 0;
}
}
} |
|
最近在这里也遇到点问题,能沟通下吗。Q1179552873