【FR801xH】富芮坤FR801xH之ADC

发布于:2025-07-08 ⋅ 阅读:(36) ⋅ 点赞:(0)

00. 目录

01. FR801xH概述

在这里插入图片描述

FR801xH 系列芯片是面向SOC(片上系统),易于快速开发的低功耗蓝牙芯片。基于 Freqchip 的蓝牙智能固件和协议栈的支持,完全兼容蓝牙 V5.3(LE 模式)协议。同时用户可以基于芯片内置的 ARM CorteM3 嵌入式 32 位高性能单片机开发各种应用程序。

蓝牙智能固件包括 L2CAP 服务层协议、安全管理器 (SM)、属性协议(ATT)、通用属性配置文件 (GATT)和通用访问配置文件(GAP)。此外,还 支持应用程序配置文件,例如接近度、健康温度计、 心率、血压、血糖、人机界面设备(HID)和 SDK (包括驱动程序、OS-API 等)。SDK 还集成了用于网络应用程序的 SIG Mesh 协议。

采用 Freqchip 的创新技术,将 PMU(锂电池充电 器+LDO)、带 XIP 模式的 QSPI FLASH ROM、 I2C、UART、GPIO、ADC、PWM 集成在一块芯片中,为客户提供:

  • 竞争力的功耗
  • 稳定的蓝牙连接
  • 极低的 BOM 成本

02. FR801xH功能框图

在这里插入图片描述

03.ADC相关类型

位于 components\driver\include\driver_adc.h。

3.1 adc_reference_t

enum adc_reference_t {
    ADC_REFERENCE_INTERNAL = 0x00,
    ADC_REFERENCE_AVDD = 0x20,
};

3.2 adc_internal_ref_t

enum adc_internal_ref_t {
    ADC_INTERNAL_REF_1_2 = 0x00,
    ADC_INTERNAL_REF_1_3 = 0x40,
    ADC_INTERNAL_REF_1_4 = 0x80,
    ADC_INTERNAL_REF_1_5 = 0xc0,
};

3.3 adc_dividor_total_res_t

enum adc_dividor_total_res_t {
    ADC_DIV_TOT_RES_105 = 0x01,
    ADC_DIV_TOT_RES_415 = 0x02,
    ADC_DIV_TOT_RES_7_25K = 0x04,
    ADC_DIV_TOT_RES_30K = 0x08,
};

3.4 adc_dividor_cfg_t

enum adc_dividor_cfg_t {
    ADC_DIV_CFG_1_4 = 0x00,
    ADC_DIV_CFG_1_3 = 0x10,
    ADC_DIV_CFG_1_2 = 0x20,
    ADC_DIV_CFG_2_3 = 0x30,
};

3.5 adc_trans_source_t

enum adc_trans_source_t {
    ADC_TRANS_SOURCE_VBAT,
    ADC_TRANS_SOURCE_PAD,
};

3.6 adc_sample_clk_t

enum adc_sample_clk_t {
    ADC_SAMPLE_CLK_64K_DIV13 = 0x00,
    ADC_SAMPLE_CLK_24M_DIV13 = 0x02,
};

04. ADC相关API

4.1 adc_init

/*********************************************************************
 * @fn      adc_init
 *
 * @brief   initiate ADC with parameters stored in cfg.
 *          The adc module works in low sample rate mode (1K) if more than
 *          one channels are enabled, otherwise higher sample rate (1M) will
 *			be used default.
 *
 * @param   cfg - ADC configurations
 *       
 * @return  None.
 */
void adc_init(struct adc_cfg_t *cfg);
功能:
	初始化 ADC 模块
参数:
	cfg  -  初始化 ADC 的参数,详见 adc_cfg_t 的定义
返回值:
	None

4.2 adc_enable

/*********************************************************************
 * @fn      adc_enable
 *
 * @brief   after adc is initiated, call this function to start AD-convert.
 *          If callback is set a none NULL value, the ADC will work in
 *          interrupt mode. And after indicated length of samples are fetched,
 *          callback will be called to return all these values stored in buffer.
 *          This way can be used in over-sample application.
 *          If callback is NULL, user should call adc_get_result to fetch
 *          value manually.
 *
 * @param   callback    - callback function after all samples have been fetched. 
 *          buffer      - memory pointer to save sample values.
 *          length      - how many samples are needed.
 *       
 * @return  callback should only be set in FIXED channel sample mode, the return
 *          value is false if these configurations mismatch.
 */
bool adc_enable(void (*callback)(uint16_t *, uint32_t), uint16_t *buffer, uint32_t length);
功能:
	ADC 模块初始化之后,就可以调用 adc_enable()进行采样
参数:
	callback  -  如果 callback 不为 NULL,采样结束后就会以回调方式返回采样结果。如果 callback 为 NULL,那么采样结束后就以中断模式返回,采样结果需要调用 adc_get_result()来获取。回调方式只能用于
	fixed channel 采样模式,不然该函数会返回失败
	buffer  -  用于存放采样结果的 buffer
	length  -  需要采样的数据长度
返回值:
	使能的结果,成功或失败。


4.3 adc_disable

/*********************************************************************
 * @fn      adc_disable
 *
 * @brief   disable ongoing AD-convert.
 *
 * @param   None.
 *       
 * @return  None.
 */
void adc_disable(void);
功能:
	停止正在采样的 ADC
参数:
	None
返回值:
	None


4.4 adc_get_result

/*********************************************************************
 * @fn      adc_get_result
 *
 * @brief   get latest converted value, src and channels should match with
 *          configurations set when calling adc_init.
 *
 * @param   src     - @ref adc_trans_source_t.
 *          channels- value of indicated channels are needed, should not contain 
 *                    disabled channel.
 *          buffer  - the sample results will be stored in sequence.
 *       
 * @return  None.
 */
void adc_get_result(enum adc_trans_source_t src, uint8_t channels, uint16_t *buffer);
功能:
	获取最近一次的 ADC 采样结果
参数:
	src  -  ADC 采集的数据源,详见 adc_trans_source_t 定义
	channels  -  ADC 通道
	buffer  -  用于存放采样结果的内存空间,顺序摆放
返回值:
	None

05. 程序示例

示例

#include "driver_adc.h"
#include "os_timer.h"

os_timer_t adc_timer;
void adc_tim_fn(void *arg)
{
    struct adc_cfg_t cfg;
    uint16_t result;
    memset((void *)&cfg, 0, sizeof(cfg));
    cfg.src = ADC_TRANS_SOURCE_PAD;
    cfg.ref_sel = ADC_REFERENCE_AVDD;
    cfg.channels = 0x01;
    cfg.route.pad_to_sample = 1;
    cfg.clk_sel = ADC_SAMPLE_CLK_24M_DIV13;
    cfg.clk_div = 0x3f;
    adc_init(&cfg);
    adc_enable(NULL, NULL, 0);
    adc_get_result(ADC_TRANS_SOURCE_PAD, 0x01, &result);
    adc_disable();
    co_printf("result:%d\r\n", result);
}

void peripheral_demo(void)
{
    co_printf("adc demo\r\n");
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_4, PORTD4_FUNC_ADC0);
    os_timer_init(&adc_timer, adc_tim_fn, NULL);
    os_timer_start(&adc_timer, 1000, 1);
}

运行结果

result:281
result:280
result:282
result:430
result:422
result:417
result:1023
result:1023
result:1023
result:1023
result:1023
result:477
result:387
result:388
result:389
result:339
result:319
result:0
result:0
result:0
result:0
result:0

06. 附录


网站公告

今日签到

点亮在社区的每一天
去签到