| 续前【RA-Eco-RA4E2-64PIN-V1.0开发板试用】2、第一个程序运行rasc.exe打开上次位置项目,在Stacks项中 点击Stacks->New Stack->Connectivity -> UART (r_sci_uart)。
r_sci_uart配置如下;
中断回调
在bsp中设置heap为0x2000
保存并生成配置,在keil中用microlib
在Stacks项中 点击Stacks->New Stack->Analog-> ADC(r_adc)。选择0,5通道。
选择p0,p5引脚。中断回调
增加代码
fsp_err_t err = FSP_SUCCESS;
unsigned char send_buff[100];
volatile bool uart_send_complete_flag = false;
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 user_uart_callback (uart_callback_args_t * p_args)
{
if(p_args->event == UART_EVENT_TX_COMPLETE)
{
uart_send_complete_flag = true;
}
}
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 ch;
}
在/*TODO:add your own code here */下增加:
err = R_SCI_UART_Open(&g_uart0_ctrl, &g_uart0_cfg);
assert(FSP_SUCCESS == err);
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
assert(FSP_SUCCESS == err);
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);
double a0,a5;
uint16_t adc_data1=0;
uint16_t adc_data2=0;
在while(1)中增加
/*
Enable scan triggering from ELC events. */
(void) R_ADC_ScanStart(&g_adc0_ctrl);
scan_complete_flag = false;
while (!scan_complete_flag)
{
/* Wait for callback to set flag. */
}
err =R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_0, &adc_data1);
assert(FSP_SUCCESS == err);
a0=(adc_data1/4095.0)*3.3;
err =R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_5, &adc_data1);
assert(FSP_SUCCESS == err);
a5=(adc_data1/4095.0)*3.3;
R_BSP_SoftwareDelay (20, BSP_DELAY_UNITS_MILLISECONDS);
printf("a0: %f\\n", a0);
printf("a5: %f\\n", a5);
/* USER CODE BEGIN 2 */
printf("cpuclkfeq = %d\n", 48000000);
printf("DWT->CYCCNT: %d", DWT->CYCCNT);
/* USER CODE END 2 */
printf("[app info led off]");
printf("[app info led on]");
编译:
linking...
Program Size: Code=8562 RO-data=1322 RW-data=8 ZI-data=10164
FromELF: creating hex file...
After Build - User command #1: cmd /c "start "Renesas" /w cmd /c ""E:\lst\ra0e1-20240827154516\123\ra4e2\FSP_Project\rasc_launcher.bat" "E:\lst\ra0e1-20240827154516\123\ra4e2\FSP_Project\rasc_version.txt" -nosplash --launcher.suppressErrors --gensmartbundle --compiler ARMv6 --devicefamily ra "E:\lst\ra0e1-20240827154516\123\ra4e2\FSP_Project\configuration.xml" "E:\lst\ra0e1-20240827154516\123\ra4e2\FSP_Project\Objects\FSP_Project.axf" 2> "%TEMP%\rasc_stderr.out"""
".\Objects\FSP_Project.axf" - 0 Error(s), 50 Warning(s).
Build Time Elapsed: 00:00:30
下生成FSP_Project.hex文件。Renesas Flash Programmer下载重新设boot引脚reset com 口printf输出:
a0: 1.545641
a5: 3.098535
[app info led off][app info led on]a0: 1.971941
a5: 3.138828
[app info led off][app info led on]
com:
达到预期状态。 |