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

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.