RT-Thread / RT-Thread/rt-thread
[Bug] stm32_adc_get_vref ()接口返回的是dc->Instance->DR并不是参考电压,导致rt_adc_voltage无法正常计算出采集的电压
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
RT-Thread Version
master
Hardware Type/Architectures
stm32f4x
Develop Toolchain
GCC
Describe the bug
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
static rt_adc_device_t dev_;
rt_uint16_t bat_v;
rt_int16_t v;
static void thread_(void *param)
{
while (1)
{
v = rt_adc_voltage(dev_, 8);
bat_v = v / 10 * 110;
rt_kprintf("rt_adc_voltage: %d\n", v);
rt_kprintf("bat_v: %d(mV)\n", bat_v);
rt_thread_mdelay(1000);
}
}
void app_battery_init(void)
{
rt_err_t ret;
dev_ = (rt_adc_device_t)rt_device_find("adc2");
if (!dev_)
goto exit;
ret = rt_adc_enable(dev_, 8);
rt_kprintf("rt_adc_enable ret: %d\n", ret);
rt_thread_t t = rt_thread_create("bat_thread", thread_, RT_NULL, 2048, 25, 20);
if (!t)
goto exit;
rt_thread_startup(t);
return;
exit:
rt_kprintf("error\n");
return;
}
Other additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the STM32 implementation of stm32_adc_get_vref() and the rt_adc_voltage() path used by the stm32f4x ADC2 channel 8 example. Check whether the value returned as the reference voltage is actually the ADC data register value, then reproduce the calculation with the provided application and confirm that rt_adc_voltage reports the expected sampled voltage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100