2018-08-28 04:03 PM
Hi,
I am having issue reading ADC1_IN2/IN15. The value return from HAL_ADC_GetValue(0 is either 0 or close to 0. Others seems fine. I do use exactly same function to read. The results are list below as iSense last 2 value 0 0.
Is there anything specific to those to channels?
Thx
PC1 ------> ADC1_IN2
PB0 ------> ADC1_IN15
vSense 97 92 89 97 111 97
iSense 2357 2417 2312 2370 0 0
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(adcHandle->Instance==ADC1)
{
/* ADC1 clock enable */
HAL_RCC_ADC_CLK_ENABLED++;
if(HAL_RCC_ADC_CLK_ENABLED==1){
__HAL_RCC_ADC_CLK_ENABLE();
}
/**ADC1 GPIO Configuration
PC0 ------> ADC1_IN1
PC1 ------> ADC1_IN2
PC2 ------> ADC1_IN3
PC3 ------> ADC1_IN4
PC4 ------> ADC1_IN13
PA0 ------> ADC1_IN5
PA1 ------> ADC1_IN6
PA2 ------> ADC1_IN7
PA3 ------> ADC1_IN8
PA4 ------> ADC1_IN9
PA5 ------> ADC1_IN10
*** ------> ADC1_IN11
PA7 ------> ADC1_IN12
*** ------> ADC1_IN14
PB0 ------> ADC1_IN15
PB1 ------> ADC1_IN16
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
}
bool stm32_adc::get_adc_data(uint32_t channel, uint32_t *adc_data)
{
/* Variable used to get converted value */
__IO uint16_t uhADCxConvertedValue = 0;
ADC_ChannelConfTypeDef sConfig;
/*##-2- Configure ADC regular channel ######################################*/
sConfig.Channel = channel; /* Sampled channel number */
sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5; /* Sampling time (number of clock cycles unit) */
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
sConfig.Offset = 0; /* Parameter discarded because offset correction is disabled */
if (HAL_ADC_ConfigChannel(m_adc, &sConfig) != HAL_OK)
{
return false;
}
// Run the ADC calibration in single-ended mode
if (HAL_ADCEx_Calibration_Start(m_adc, ADC_SINGLE_ENDED) != HAL_OK)
{
return false;
}
/*##-3- Start the conversion process #######################################*/
if (HAL_ADC_Start(m_adc) != HAL_OK)
{
return false;
}
/*##-4- Wait for the end of conversion #####################################*/
/* For simplicity reasons, this example is just waiting till the end of the
conversion, but application may perform other tasks while conversion
operation is ongoing. */
if (HAL_ADC_PollForConversion(m_adc, 10) != HAL_OK)
{
return false;
}
else
{
/* ADC conversion completed */
/*##-5- Get the converted value of regular channel ########################*/
uhADCxConvertedValue = HAL_ADC_GetValue(m_adc);
}
*adc_data = uhADCxConvertedValue;
return true;
}
Solved! Go to Solution.
2018-08-29 04:46 PM
Got it now, one of the ADG708 chip (input to ADC channel) on our board is not powered. Thx
2018-08-29 04:46 PM
Got it now, one of the ADG708 chip (input to ADC channel) on our board is not powered. Thx