Yuqiang Wang e1498cabc9 SDK build (#47) пре 8 месеци
..
.settings 4795f3d206 更新fsp为2.2.0 пре 9 месеци
board 4795f3d206 更新fsp为2.2.0 пре 9 месеци
figures 539cd344e1 增加示例的FSP配置描述 пре 1 година
packages 4795f3d206 更新fsp为2.2.0 пре 9 месеци
rzn 0e9a0dfdbd fix iar link source пре 9 месеци
rzn_cfg 0e9a0dfdbd fix iar link source пре 9 месеци
rzn_gen 0e9a0dfdbd fix iar link source пре 9 месеци
script 4795f3d206 更新fsp为2.2.0 пре 9 месеци
src f4bde77e2a 修复gpt 使用pwm 框架 以及其他示例中hal_entry 中的 主循环内容 пре 1 година
.api_xml c8d6781221 upload sample project(i2c adc factory) пре 1 година
.config 4795f3d206 更新fsp为2.2.0 пре 9 месеци
.cproject 4795f3d206 更新fsp为2.2.0 пре 9 месеци
.gitignore 43669c1c97 Fixed some known issues пре 1 година
.project c8d6781221 upload sample project(i2c adc factory) пре 1 година
.secure_azone c8d6781221 upload sample project(i2c adc factory) пре 1 година
.secure_rzone 4795f3d206 更新fsp为2.2.0 пре 9 месеци
.secure_xml 4795f3d206 更新fsp为2.2.0 пре 9 месеци
Kconfig 4795f3d206 更新fsp为2.2.0 пре 9 месеци
README.md e1498cabc9 SDK build (#47) пре 8 месеци
README_zh.md e1498cabc9 SDK build (#47) пре 8 месеци
SConscript 0e9a0dfdbd fix iar link source пре 9 месеци
SConstruct c8d6781221 upload sample project(i2c adc factory) пре 1 година
buildinfo.ipcf 0e9a0dfdbd fix iar link source пре 9 месеци
buildinfo.json 4795f3d206 更新fsp为2.2.0 пре 9 месеци
configuration.xml 4795f3d206 更新fsp为2.2.0 пре 9 месеци
envsetup.sh c8d6781221 upload sample project(i2c adc factory) пре 1 година
mklinks.bat c8d6781221 upload sample project(i2c adc factory) пре 1 година
mklinks.sh c8d6781221 upload sample project(i2c adc factory) пре 1 година
ozone_scons.jdebug 384e7a31df 修复scons固件无法运行的问题,添加ozone调试脚本 пре 1 година
project.ewd 0e9a0dfdbd fix iar link source пре 9 месеци
project.ewp 0e9a0dfdbd fix iar link source пре 9 месеци
project.ewt 0e9a0dfdbd fix iar link source пре 9 месеци
project.eww c8d6781221 upload sample project(i2c adc factory) пре 1 година
rtconfig.h 4795f3d206 更新fsp为2.2.0 пре 9 месеци
rtconfig.py 384e7a31df 修复scons固件无法运行的问题,添加ozone调试脚本 пре 1 година
rzn_cfg.txt 4795f3d206 更新fsp为2.2.0 пре 9 месеци
template.ewd 0e9a0dfdbd fix iar link source пре 9 месеци
template.ewp 0e9a0dfdbd fix iar link source пре 9 месеци
template.eww c8d6781221 upload sample project(i2c adc factory) пре 1 година

README.md

ADC Driver Usage Instructions

English | 中文

Introduction

This example demonstrates how to use the RT-Thread ADC framework on the EtherKit to collect analog signals via ADC and perform digital signal conversion. The main content includes the following:

Hardware Description

image-20241126100528305

As shown in the schematic above, the EtherKit provides an 8-channel analog input interface, which is connected to the MCU's ADC channels 0, 1, 2, and 3 for ADC0 and ADC1. (Note: The voltage range for the Analog Input is 0 to 1.8V.)

FSP Configuration Instructions

  • Step 1: Open FSP and import the XML configuration file (or directly click the FSP link file in RT-Thread Studio).
  • Step 2: Create a new r_adc stack, configure the ADC device, and select the channels to be used.

image-20241204164135500

  • Step 3: Save and click "Generate Project". The generated code will be saved in hal_data.c.

ENV Configuration

Use the env tool to enable ADC0 peripheral:

image-20241126100628534

Example Code Description

The ADC source code is located in /projects/etherkit_driver_adc/src/hal_entry.c. The macros used are defined as follows:

image-20241126100746019

The specific function is to sample the analog voltage from ADC0 channel 0 every 1000ms and perform a conversion. The code is as follows:

static int adc_vol_sample()
{
    rt_adc_device_t adc_dev;
    rt_uint32_t value, vol;
    rt_err_t ret = RT_EOK;
    /* Find the device */
    adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
    if (adc_dev == RT_NULL)
    {
        rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
        return RT_ERROR;
    }
    /* Enable the device */
    ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
    /* Read the sampled value */
    value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
    rt_kprintf("The value is :%d \n", value);
    /* Convert to corresponding voltage */
    vol = value * REFER_VOLTAGE / CONVERT_BITS;
    rt_kprintf("The voltage is :%d.%02d \n", vol / 100, vol % 100);
    /* Disable the channel */
    ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
    return ret;
}

In the example, the while loop calls adc_vol_sample every 1000ms.

Compilation & Download

  • RT-Thread Studio: In RT-Thread Studio’s package manager, download the EtherKit resource package, create a new project, and compile it.
  • IAR: First, double-click mklinks.bat to create symbolic links between RT-Thread and the libraries folder. Then, use the Env tool to generate the IAR project. Finally, double-click project.eww to open the IAR project and compile it.

After compilation, connect the development board’s JLink interface to the PC and download the firmware to the development board.

Run Effect

The effect when using ADC0 channel 0 to sample a 1.8V voltage is shown below:

image-20241126100845961

Notes

The ADC voltage input tolerance for the R9A07G084M08GBG chip is 1.8V.