英文:
Internal Temperature Sensor Reading of STM32 only updating after Reset
问题
我们正在读取STM32-F410RB - NUCLEO 64板的内部温度传感器读数。
问题:
按照程序设置,每隔1秒获取温度传感器的读数,但获取到的是相同的读数。
只有在进行复位后,温度读数才会更新。
当前设置
- Windows 10 64位
- STM32 Nucleo 64 - F410RB
- 使用CubeMX IDE
- 用于串行监控的PuTTy
已完成的STM32 CUBE MX IDE配置
- 系统核心 - 串行线
- 模拟 - ADC1 - 启用温度传感器通道
参数设置 - ADC设置 - 启用扫描转换和连续转换
排名 - 采样时间 - 480周期 - USART2 - 9600波特率
主函数的代码片段
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; // 转为mV
tCelsius = (tCelsius - 500.0) / 10.0; // 转为摄氏度
UART_SEND_TXT(&huart2, "Temperature = ", 0);
UART_SEND_FLT(&huart2, tCelsius, 1);
HAL_Delay(1000);
}
}
请帮忙解决。提前致谢。
英文:
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
Current Setup
- Windows 10 64bit
- STM32 Nucleo 64 - F410RB
- Using CubeMX IDE
- PuTTy for Serial Monitoring
STM32 CUBE MX IDE Configurations Done
- System Core - Serial Wire
- Analog - ADC1 - Enabled Temperature Sensor Channel
Parameter Settings - ADC Setting - Scan Conversion & Continues Conversion Enabled
Rank - Sample Time - 480 Cycles - 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.
答案1
得分: 2
只有一个HAL_ADC_Start
在循环外部。因此,转换只启动一次。
在循环内部,您只是通过HAL_ADC_GetValue
重复接收上次转换的结果。
您需要每次调用HAL_ADC_Start
来启动常规组转换,然后通过HAL_ADC_PollForConversion
等待转换结束,最后通过HAL_ADC_GetValue
获取结果。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论