標(biāo)題: STM32F030c8t6單片機讀取內(nèi)部溫度傳感器值不正確? [打印本頁]

作者: killalljp    時間: 2019-3-11 13:32
標(biāo)題: STM32F030c8t6單片機讀取內(nèi)部溫度傳感器值不正確?
這個是初始化代碼

得到的溫度值都是偏大 譬如室溫是25攝氏度得到的值是65?

哪位大神有成功代碼參考參考?
  1. /* Temperature sensor calibration value address */
  2. #define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7B8))
  3. #define VDD_CALIB ((uint32_t) (3300))
  4. #define VDD_APPLI ((uint32_t) (3000))
  5. #define AVG_SLOPE ((uint32_t) (5336)) //AVG_SLOPE in ADC conversion step (@3.3V)/°C multiplied by 1000 for precision on the division
  6. int32_t temperature; /* will contain the temperature in degrees Celsius */
  7. temperature = ((uint32_t) *TEMP30_CAL_ADDR - ((uint32_t) ADC1->DR * VDD_APPLI / VDD_CALIB)) * 1000;
  8. temperature = (temperature / AVG_SLOPE) + 30;
復(fù)制代碼
這個是參考手冊里的源碼
  1. static void MX_ADC_Init(void)
  2. {

  3.   ADC_ChannelConfTypeDef sConfig;

  4.   /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */
  5.   hadc.Instance = ADC1;
  6.   hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  7.   hadc.Init.Resolution = ADC_RESOLUTION_12B;
  8.   
  9.   hadc.Init.SamplingTimeCommon = ADC_SAMPLETIME_239CYCLES_5;
  10.   
  11.   hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  12.   hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  13.   hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  14.   hadc.Init.LowPowerAutoWait = DISABLE;
  15.   hadc.Init.LowPowerAutoPowerOff = DISABLE;
  16.   hadc.Init.ContinuousConvMode = DISABLE;
  17.   hadc.Init.DiscontinuousConvMode = ENABLE;
  18.   hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  19.   hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  20.   hadc.Init.DMAContinuousRequests = DISABLE;
  21.   hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  22.   /* Initialize ADC peripheral according to the passed parameters */
  23.   if (HAL_ADC_Init(&hadc) != HAL_OK)
  24.   {
  25.     _Error_Handler(__FILE__, __LINE__);
  26.   }

  27.   /* 校正ADC */
  28.   if(HAL_ADCEx_Calibration_Start(&hadc) != HAL_OK)
  29.   {
  30.     _Error_Handler(__FILE__, __LINE__);
  31.   }
  32.   
  33.   /**Configure for the selected ADC regular channel 16 to be converted.*/
  34.   sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
  35.   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  36.   {
  37.     _Error_Handler(__FILE__, __LINE__);
  38.   }
  39. }
復(fù)制代碼


作者: Angle145    時間: 2019-3-11 20:44
1.芯片內(nèi)部溫度本來就比室溫高,2.內(nèi)部溫度傳感器是低精度的,一般此溫度是用來監(jiān)測芯片內(nèi)部溫度變化(做參考)而不是它精確的溫度




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1