在STM32F070的AD采样期间,被采样电平被拉高到3.3V的问题,求大神赐教

在STM32F070的AD采样期间,被采样电平被拉高到3.3V的问题

// 问题: 在PB1 AD9 引脚输入电平是2.1V , 示波器查看在AD采样期间,
// 输入引脚PB1 的电平被拉高到3.3V, 电平拉高的时间为5us,
// 请哪位大神赐教。谢谢

// 开发环境: 芯片是STM32F070RB ,用STM32Cube_FW_F0_V1.4.0 的STM32F0xx_HAL_Driver,
// Keil mdk uVersion V5.12.0.0
// 没有使用中断
// 单次序列转换模式,软件启动AD 采集。

我的代码如下 :

void HAL_ADC_MspInit(ADC_HandleTypeDef hadc) //, GPIO_TypeDef GPIOx, uint32_t gpio_Pin)
{
GPIO_InitTypeDef GPIO_InitStruct;

__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_ADC1_CLK_ENABLE();
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pin = ADC_IN_BOX_TEMP_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ADC_IN_BOX_TEMP_GPIO_PORT, &GPIO_InitStruct); // PB1 PIN27
}

void HAL_ADC_MspDeInit(ADC_HandleTypeDef hadc) //, GPIO_TypeDef GPIOx, uint32_t gpio_Pin)
{
}


/ ADC handle declaration /
ADC_HandleTypeDef AdcHandle_Box_Temp;
/ ADC channel configuration structure declaration /
ADC_ChannelConfTypeDef sConfig;


Charger_Result AC_ADC_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

/ ADC1 Periph clock enable /
__HAL_RCC_ADC1_CLK_ENABLE();
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pin = ADC_IN_BOX_TEMP_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ADC_IN_BOX_TEMP_GPIO_PORT, &GPIO_InitStruct); // PB1 PIN27

return CHRTN_S_OK;
}


Charger_Result AC_ADC_OneInit(void)
{
//====================== BOX TEMP ============================
AdcHandle_Box_Temp.Instance = ADC1;

AdcHandle_Box_Temp.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;//ADC_CLOCK_ASYNC_DIV1, ADC_CLOCK_SYNC_PCLK_DIV4
AdcHandle_Box_Temp.Init.LowPowerAutoWait = DISABLE;
AdcHandle_Box_Temp.Init.LowPowerAutoPowerOff = DISABLE;
AdcHandle_Box_Temp.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle_Box_Temp.Init.ScanConvMode = ADC_SCAN_ENABLE;
AdcHandle_Box_Temp.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle_Box_Temp.Init.ContinuousConvMode = DISABLE; // 单次转换模式
AdcHandle_Box_Temp.Init.DiscontinuousConvMode = DISABLE; // 单次连续序列转换,否则为断续模式
AdcHandle_Box_Temp.Init.ExternalTrigConv = ADC_SOFTWARE_START;
AdcHandle_Box_Temp.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle_Box_Temp.Init.EOCSelection = ADC_EOC_SEQ_CONV; //ADC_EOC_SINGLE_CONV; //ADC_EOC_SEQ_CONV; // EOC 为序列转换结束
AdcHandle_Box_Temp.Init.DMAContinuousRequests = DISABLE;
AdcHandle_Box_Temp.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; // ADC_OVR_DATA_PRESERVED

/ Initialize ADC peripheral according to the passed parameters /
if (HAL_ADC_Init(&AdcHandle_Box_Temp) != HAL_OK)
{
CHARGER_DEBUG_ERROR(("HAL_ADC_Init(AdcHandle_Box_Temp)\n"));
return CHRTN_E_FAIL;
}

/ # - 2 - Start calibration, AD 校准# /
if (HAL_ADCEx_Calibration_Start(&AdcHandle_Box_Temp) != HAL_OK)
{
CHARGER_DEBUG_ERROR(("HAL_ADCEx_Calibration_Start(AdcHandle_Box_Temp)\n"));
if (HAL_ADC_DeInit(&AdcHandle_Box_Temp) != HAL_OK)
{
CHARGER_DEBUG_ERROR(("HAL_ADC_DeInit(AdcHandle_PWM)\n"));
}
return CHRTN_E_FAIL;
}

/ # - 3 - Channel configuration /
/ Select Channel 0 to be converted /
sConfig.Channel = ADC_IN_BOX_TEMP_AD_CHANNEL;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;// 6us , AD采样和转换完成一次需要6us , AD 时钟14MHZ 时
if (HAL_ADC_ConfigChannel(&AdcHandle_Box_Temp, &sConfig) != HAL_OK)
{
CHARGER_DEBUG_ERROR(("HAL_ADC_ConfigChannel(AdcHandle_Box_Temp)\n"));
if (HAL_ADC_DeInit(&AdcHandle_Box_Temp) != HAL_OK)
{
CHARGER_DEBUG_ERROR(("HAL_ADC_DeInit(AdcHandle_PWM)\n"));
}
return CHRTN_E_FAIL;
}


return CHRTN_S_OK;
}


Charger_Result AC_ADC_OneDeInit(Drv_ADC_Type_t adc_type)
{
if (HAL_ADC_DeInit(&AdcHandle_Box_Temp) != HAL_OK)
{
CHARGER_DEBUG_ERROR(("HAL_ADC_DeInit(AdcHandle_Box_Temp)\n"));
return CHRTN_E_FAIL;
}
return CHRTN_S_OK;
}


//===============================================
// 连续采样N 次,返回N 次的平均值
// 采集次数: get_times
// 返回平均值: pAdc_mv
Charger_BOOL ChargerDrv_ADC_Read_V(Charger_U32 get_times, Charger_U16 *pAdc_mv)
{
Charger_U32 i;
Charger_U16 adc_mv=0;
Charger_U32 adc_all = 0;

ADC_HandleTypeDef *pAdcHandle = &AdcHandle_Box_Temp;
*pAdc_mv = 0;
if (CHRTN_S_OK != AC_ADC_OneInit())
{
printf("AC_ADC_OneInit\n");
return CHARGER_FALSE;
}

for (i=0; i<get_times; i++)
{
if (HAL_OK != HAL_ADC_Start(&AdcHandle_Box_Temp))
{
AC_ADC_OneDeInit();
return CHARGER_FALSE;
}
if (HAL_OK != HAL_ADC_PollForConversion(&AdcHandle_Box_Temp, 1))
{
HAL_ADC_Stop(&AdcHandle_Box_Temp);
AC_ADC_OneDeInit();
return CHARGER_FALSE;
}
adc_mv = HAL_ADC_GetValue(&AdcHandle_Box_Temp);
adc_all += adc_mv;
}
if (HAL_ADC_Stop(&AdcHandle_Box_Temp) != HAL_OK)
{
printf("ERROR: HAL_ADC_Stop\n");
}
AC_ADC_OneDeInit();

adc_all = adc_all/get_times;
*pAdc_mv = (Charger_U16)adc_all;
return CHARGER_TRUE;
}


void main(void)
{
Charger_U16 Adc_mv=0;

AC_ADC_Init();
ChargerDrv_ADC_Read_V(3, &Adc_mv);
}

已邀请:

cnnjjht - 60后IT技术主管

赞同来自:

我的源代码文件

cnnjjht - 60后IT技术主管

赞同来自:

是硬件问题,已解决

夜落ソ离尘

赞同来自:

我也有遇到这个问题,可以方便问下是怎么解决的吗,是硬件的什么问题呢



要回复问题请先登录注册