RA生态之基于 DTC 的多通道 ADC 采集
Posted 衾许°
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RA生态之基于 DTC 的多通道 ADC 采集相关的知识,希望对你有一定的参考价值。
配置ADC:Stacks->New Stack-> Analog -> ADC Driver on r_adc
配置ADC:Stacks->New Stack->Transfer-> Transfer Driver on r_dtc
堆栈设置
示例代码:
#include "hal_data.h"
#include <stdio.h>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;/******************************************************************/
/*串口重定向*/
int fputc(int ch, FILE *f)
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 0;
/*串口回调函数*///函数功能把串口接收到的数据存到
void user_uart_callback (uart_callback_args_t * p_args)
/*如果串口发送数据完成*/
if(p_args->event == UART_EVENT_TX_COMPLETE)
uart_send_complete_flag = true;
/******************************************************************/
uint16_t adc_result_buffer[3];
void adc_callback(adc_callback_args_t *p_args)
if( p_args->event == ADC_EVENT_SCAN_COMPLETE)
err = R_DTC_Reset( &g_transfer0_ctrl,(void*)&R_ADC0->ADDR[0],&adc_result_buffer[0],1 );
if( FSP_SUCCESS != err )
__BKPT(1);
void hal_entry(void)
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);
g_transfer0_cfg.p_info->p_src = (void*)&R_ADC0->ADDR[0];
g_transfer0_cfg.p_info->p_dest = &adc_result_buffer[0];
err = R_DTC_Open(&g_transfer0_ctrl, &g_transfer0_cfg);
assert(FSP_SUCCESS == err);
err = R_DTC_Enable(&g_transfer0_ctrl);
assert(FSP_SUCCESS == err);
while(1)
err = R_ADC_ScanStart(&g_adc0_ctrl);
assert(FSP_SUCCESS == err);
printf("adc[0]_v=%f\\r\\n",(float)adc_result_buffer[0]/4095*3.3);
printf("adc[1]_v=%f\\r\\n",(float)adc_result_buffer[1]/4095*3.3);
printf("adc[2]_v=%f\\r\\n",(float)adc_result_buffer[2]/4095*3.3);
R_BSP_SoftwareDelay(1000, BSP_DELAY_UNITS_MILLISECONDS);
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
例程现象:比如你拿根杜邦线接P000,P000adc采集到的电压值就会串口打印出来
以上是关于RA生态之基于 DTC 的多通道 ADC 采集的主要内容,如果未能解决你的问题,请参考以下文章