ADC1을 설정하고 ADC를 읽어오다가 내부 온도 센서나 BAT 값을 읽어보려고 설정을 하였지만 값을 제대로 읽어오지 못하였습니다. 왜 안될까 고민하다가 데이터 시트를 펼쳤습니다.
!!!???
In addition, there are 5 internal dedicated channels
– The internal reference voltage (VREFINT), connected to ADC3
– The internal temperature sensor (VSENSE), connected to ADC3
– The VBAT monitoring channel (VBAT/4), connected to ADC3
The ADCs are connected to 5 internal analog inputs:
– the internal temperature sensor (VSENSE) is connected to ADC3 VINP/VINN[18]
– the internal reference voltage (VREFINT) is connected to ADC3 VINP/VINN[19]
– the VBAT monitoring channel (VBAT/4) is connected to ADC3 VINP/VINN[17]
ADC3에서 사용가능하네요.(항상 느끼는 거지만 게으름이 사람을 힘들게 할 때가 많네요. 하지만 사람은 망각의 동물이라고 내일되면 다시 잊어버리고 새롭게 삽질을 시작할 것 입니다. 나는 닭이니까...)
값 확인
DEBUGPRINT("%d\r\n", Get_InternalTemperture());
온도값 읽어오기
#define VDDA_APPLI ((uint32_t)3300)
int32_t Get_InternalTemperture(void)
{
int32_t RAW_Temp;
HAL_ADC_PollForConversion(&AdcHandle3, 1000);
RAW_Temp = HAL_ADC_GetValue(&AdcHandle3);
return __HAL_ADC_CALC_TEMPERATURE(VDDA_APPLI, RAW_Temp, LL_ADC_RESOLUTION_16B);
}
ADC3 설정
void ADC3_Init(void)
{
/* ADC Periph clock enable */
__HAL_RCC_ADC3_CLK_ENABLE();
/* ADC Periph interface clock configuration */
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_CLKP);
/*##-1- Configure the ADC peripheral #######################################*/
AdcHandle3.Instance = ADC3;
if (HAL_ADC_DeInit(&AdcHandle3) != HAL_OK){
/* ADC de-initialization Error */
}
AdcHandle3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2; /* Asynchronous clock mode, input ADC clock divided by 2*/
AdcHandle3.Init.Resolution = ADC_RESOLUTION_16B; /* 16-bit resolution for converted data */
AdcHandle3.Init.ScanConvMode = ENABLE;//DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
AdcHandle3.Init.EOCSelection = ADC_EOC_SINGLE_CONV; /* EOC flag picked-up to indicate conversion end */
AdcHandle3.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
AdcHandle3.Init.ContinuousConvMode = ENABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
AdcHandle3.Init.NbrOfConversion = ADC_CONVERTED_DATA_BUFFER_SIZE3; /* Parameter discarded because sequencer is disabled */
AdcHandle3.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
AdcHandle3.Init.NbrOfDiscConversion = 1; /* Parameter discarded because sequencer is disabled */
AdcHandle3.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */
AdcHandle3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
AdcHandle3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR; /* Regular Conversion data stored in DR register only */
AdcHandle3.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
AdcHandle3.Init.OversamplingMode = DISABLE; /* No oversampling */
if (HAL_ADC_Init(&AdcHandle3) != HAL_OK){
}
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&AdcHandle3, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK){
}
/*##-2- Configure ADC regular channel ######################################*/
sConfig.SamplingTime = ADC_SAMPLETIME_64CYCLES_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 */
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; /* Sampled channel number */
sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
if (HAL_ADC_ConfigChannel(&AdcHandle3, &sConfig) != HAL_OK){;}
HAL_ADC_Start(&AdcHandle3);
}
'초보의 아웅다웅 설계하기 > STM32' 카테고리의 다른 글
STM32 PID 제어 (0) | 2020.01.16 |
---|---|
STM32H750 ReadProtection, BrownOutReset 설정 (0) | 2020.01.08 |
STM32H750 내부 Flash 사용하기 (0) | 2019.12.28 |
STM32F723 UART LL_DRIVER 예제 (0) | 2019.11.17 |
STM32H743 LL_Driver Timer (0) | 2019.11.10 |