748|0

113

帖子

4

TA的资源

一粒金砂(高级)

楼主
 

【瑞萨RA8D1评测】第七篇:AD采样电压串口打印到电脑上 [复制链接]

本帖最后由 eew_cT3H5d 于 2024-8-8 08:13 编辑

本部分采样滑动变阻器模块的电压,将电压数值打印到电脑上,显示当前采样的电压

   

配置ADC使能

 

添加配置ADC模块

 

配置相关adc参数

 

配置相关通道

 

添加函数

 

adc.h文件

#ifndef _ADC_H
#define _ADC_H

#include "hal_data.h"

void ADC_Init(void);
double Read_ADC_Voltage_Value(void);

#endif

adc.c文件

#include <ADC/adc.h>

//ADC转换完成标志位
volatile bool scan_complete_flag = false;

void adc_callback(adc_callback_args_t * p_args)
{
    FSP_PARAMETER_NOT_USED(p_args);
    scan_complete_flag = true;
}

void ADC_Init(void)
{
    fsp_err_t err;
    err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
    err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
    assert(FSP_SUCCESS == err);
}

/* 进行ADC采集,读取ADC数据并转换结果 */
double Read_ADC_Voltage_Value(void)
{
    uint16_t adc_data;
    double a0;

    (void)R_ADC_ScanStart(&g_adc0_ctrl);
    while (!scan_complete_flag) //等待转换完成标志
    {
        ;
    }
    scan_complete_flag = false; //重新清除标志位

    /* 读取通道0数据 */
    R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_0, &adc_data);
    /* ADC原始数据转换为电压值(ADC参考电压为3.3V) */
    a0 = (double)(adc_data*3.3/4095);

    return a0;
}

hal_entry.c函数

/*
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "hal_data.h"

#include "debug_uart3.h"

#include "ADC/adc.h"
fsp_err_t err;

void R_BSP_WarmStart(bsp_warm_start_event_t event);

//extern bsp_leds_t g_bsp_leds;

/*******************************************************************************************************************//**
 * @brief   Blinky example application
 *
 * Blinks all leds at a rate of 1 second using the software delay function provided by the BSP.
 *
 **********************************************************************************************************************/
void hal_entry (void)
{

    Debug_UART3_Init();
    ADC_Init();
    while (1)
    {
        printf("HELLO eeworld !\r\n");
        printf("a0 = %f\r\n", Read_ADC_Voltage_Value());
        R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_SECONDS); //延时1秒
    }
}

/*******************************************************************************************************************//**
 * This function is called at various points during the startup process.  This implementation uses the event that is
 * called right before main() to set up the pins.
 *
 * @param[in]  event    Where at in the start up process the code is currently at
 **********************************************************************************************************************/
void R_BSP_WarmStart (bsp_warm_start_event_t event)
{
    if (BSP_WARM_START_RESET == event)
    {
#if BSP_FEATURE_FLASH_LP_VERSION != 0

        /* Enable reading from data flash. */
        R_FACI_LP->DFLCTL = 1U;

        /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
         * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
#endif
    }

    if (BSP_WARM_START_POST_C == event)
    {
        /* C runtime environment and system clocks are setup. */

        /* Configure pins. */
        R_IOPORT_Open(&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME);
    }
}

编译下载程序

 

点赞 关注

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表