
1.概述
本篇文章主要介绍如何使用e2studio对瑞萨进行DTC配置,并且对多通道ADC进行采集。
2.硬件准备
首先需要准备一个开发板,这里我准备的是芯片型号 R7FA2L1AB2DFL 的开发板。
3.新建工程

4.工程模板

5.保存工程路径

6.芯片配置
本文中使用R7FA2L1AB2DFL来进行演示。

7
7.工程模板选择

8.ADC配置
点击Stacks->New Stack->Driver->Analog -> ADC Driver on r_adc。

9.ADC属性配置



10.DTC配置
点击Stacks->New Stack->Driver->Transfer-> Transfer Driver on r_dtc。

11.DTC属性配置

12.设置e2studio堆栈

13.e2studio的重定向printf设置

C++ 构建->设置->GNU ARM Cross C Linker->Miscellaneous去掉Other linker flags中的 “--specs=rdimon.specs”

14.UART配置
点击Stacks->New Stack->Driver->Connectivity -> UART Driver on r_sci_uart。

15.UART属性配置
配置串口,用于打印数据。

16.printf输出重定向到串口
打印最常用的方法是printf,所以要解决的问题是将printf的输出重定向到串口,然后通过串口将数据发送出去。
注意一定要加上头文件#include
#ifdef __GNUC__ //串口重定向
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
if(FSP_SUCCESS != err) __BKPT();
while(uart_send_complete_flag == false){}
uart_send_complete_flag = false;
return ch;
}
int _write(int fd,char *pBuffer,int size)
{
for(int i=0;i;i++)>
17.代码
#include "hal_data.h"
#include
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER
fsp_err_t err = FSP_SUCCESS;
unsigned char send_buff[100];
volatile bool uart_send_complete_flag = false;
void user_uart_callback (uart_callback_args_t * p_args)
{
if(p_args->event == UART_EVENT_TX_COMPLETE)
{
uart_send_complete_flag = true;
}
}
#ifdef __GNUC__ //串口重定向
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
err = R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&ch, 1);
if(FSP_SUCCESS != err) __BKPT();
while(uart_send_complete_flag == false){}
uart_send_complete_flag = false;
return ch;
}
int _write(int fd,char *pBuffer,int size)
{
for(int i=0;ievent == ADC_EVENT_SCAN_COMPLETE )
{
err = R_DTC_Reset( &g_transfer0_ctrl,
(void*)&R_ADC0->ADDR[0], // reset source address
&adc_result_buffer[0], // reset destination address
1 ); // reset block size
if( FSP_SUCCESS != err )
{
__BKPT(1);
}
}
}
void hal_entry(void)
{
/* TODO: add your own code here */
err = R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg);
assert(FSP_SUCCESS == err);
adc_status_t adc_status;
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
assert(FSP_SUCCESS == err);
err = R_ADC_StatusGet (&g_adc0_ctrl, &adc_status);
assert(FSP_SUCCESS == err);
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);
// Source is first ADC result register
g_transfer0_cfg.p_info->p_src = (void*)&R_ADC0->ADDR[0];
// Destination is results buffer
g_transfer0_cfg.p_info->p_dest = &adc_result_buffer[0];
/* Open the transfer instance with initial configuration. */
err = R_DTC_Open(&g_transfer0_ctrl, &g_transfer0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Enable the DTC to handle incoming transfer requests. */
err = R_DTC_Enable(&g_transfer0_ctrl);
assert(FSP_SUCCESS == err);
while(1)
{
/* In software trigger mode, start a scan by calling R_ADC_ScanStart(). In other modes, enable external
* triggers by calling R_ADC_ScanStart(). */
err = R_ADC_ScanStart(&g_adc0_ctrl);
assert(FSP_SUCCESS == err);
printf("adc[0]_v=%f\n",(float)adc_result_buffer[0]/4095*3.3);
printf("adc[1]_v=%f\n",(float)adc_result_buffer[1]/4095*3.3);
printf("adc[2]_v=%f\n",(float)adc_result_buffer[2]/4095*3.3);
R_BSP_SoftwareDelay(1000, BSP_DELAY_UNITS_MILLISECONDS); // NOLINT100->160
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
};i++)>
18.多通道ADC采集通过DTC传输例程
现在设置3个ADC通道的输入电压如下所示。
ADC通道 | 管脚 |
输入电压 |
AN0 |
P000 |
GND(0V) |
AN1 | P001 | VCC(3.3V) |
AN2 | P002 | 1.5V |
19.演示效果
通过串口打印出的数据如下所示。

原创:By RA_Billy Xiao
原文标题:瑞萨e2studio----基于DTC的多通道ADC采集
文章出处:【微信公众号:RA生态工作室】欢迎添加关注!文章转载请注明出处。
-
mcu
+关注
关注
146文章
17400浏览量
353250 -
ARM
+关注
关注
134文章
9193浏览量
370169 -
嵌入式
+关注
关注
5097文章
19228浏览量
308788 -
开发板
+关注
关注
25文章
5167浏览量
98591
发布评论请先 登录
相关推荐
【瑞萨RA2L1入门学习】2. PWM呼吸灯
【瑞萨RA2L1入门学习】1. 点亮LED
【瑞萨RA2L1入门学习】+ MacOS安装e2studio
瑞萨e2 studio中Reality AI组件的使用方法

瑞萨e2studio(1)----瑞萨芯片之搭建FSP环境
瑞萨e2studio----SPI速率解析

评论