0

We are reading Internal Temperature Sensor reading of STM32-F410RB - NUCLEO 64 Board.

Problem:

Getting the reading of Temperature sensor every 1 second as programmed, but the same readings are got. Only when Reset is done, the Temperature Reading get updated

enter image description here

Current Setup

  1. Windows 10 64bit
  2. STM32 Nucleo 64 - F410RB
  3. Using CubeMX IDE
  4. PuTTy for Serial Monitoring

STM32 CUBE MX IDE Configurations Done

  1. System Core - Serial Wire
  2. Analog - ADC1 - Enabled Temperature Sensor Channel
    Parameter Settings - ADC Setting - Scan Conversion & Continues Conversion Enabled Rank - Sample Time - 480 Cycles
  3. USART2 - 9600 Baud Rate

CODE Snippet of Main

int main(void)
{
  
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_ADC1_Init();
  HAL_ADC_Start(&hadc1);

  while (1)
  {
      uint16_t readValue;
      float tCelsius;
      readValue = HAL_ADC_GetValue(&hadc1);
      tCelsius = ((float)readValue) * 3300.0 / 4095.0; // To mV
      tCelsius = (tCelsius - 500.0) / 10.0; // To degrees C
      UART_SEND_TXT(&huart2, "Temperature = ", 0);
      UART_SEND_FLT(&huart2, tCelsius, 1);
      HAL_Delay(1000);
  }
}

Please kindly help. Thanks in Advance.

Lundin
  • 195,001
  • 40
  • 254
  • 396
Naveen PS
  • 13
  • 5
  • 1
    Sounds like the ADC is incorrectly configured for manually starting each read. For this kind of application you'll want continuous conversion. – Lundin May 29 '23 at 06:34
  • Lundin, Thanks for the prompt reply. I will definitely recheck the config and see. – Naveen PS May 29 '23 at 06:35
  • Possibly you did not configure `MX_ADC1_Init()` for continuous mode? That is generated by CubeMX from the parameters and options you select. ``MX_ADC1_Init()`` should contain `hadc1.Init.ContinuousConvMode = ENABLE` among other things. – Clifford May 29 '23 at 19:17

1 Answers1

2

There is only one HAL_ADC_Start outside the loop. Therefore conversion starts only once.

Inside the loop you just repeatedly receive the last result of the conversion by HAL_ADC_GetValue.

You need to start regular group conversion by calling HAL_ADC_Start each time, then wait conversion to end by HAL_ADC_PollForConversion and, at last, get the result by HAL_ADC_GetValue

AterLux
  • 4,566
  • 2
  • 10
  • 13
  • 1
    A proper HAL which actually works as a hardware abstraction layer would do this for you. Anyway as already mentioned, the OP is just interested in grabbing a number once every second so manually starting a conversion is wrong - they should be using continuous conversion and just grab the last read value. – Lundin May 29 '23 at 12:48