Skip to content

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

@juzhango

Description

@juzhango

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions