RT-Thread / RT-Thread/rt-thread

[Bug] stm32_adc_get_vref ()接口返回的是dc->Instance->DR并不是参考电压,导致rt_adc_voltage无法正常计算出采集的电压

Open
#10,498 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.