刚刚点灯完毕,现在来实现RA4E2的串口打印功能,先打开原理图,我们看到
串口使用的是P109和P110两个IO口,然后我们来进行配置
先打开
RA4E2_UART
下一步
随便选一个
配置好串口9,选择通道9
中断函数改名如下
生成代码,然后打开keil,开始编写串口函数
#include "hal_data.h"
#include "stdio.h"
void R_BSP_WarmStart(bsp_warm_start_event_t event);
extern bsp_leds_t g_bsp_leds;
fsp_err_t err = FSP_SUCCESS;
unsigned char send_buff[100];
volatile bool uart_send_complete_flag = false;
void uart_user_callback (uart_callback_args_t * p_args)
{
switch (p_args->event)
{
case UART_EVENT_RX_CHAR:
{
/* 把串口接收的数据发送回去 */
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&(p_args->data), 1);
break;
}
case UART_EVENT_TX_COMPLETE:
{
uart_send_complete_flag = true;
break;
}
default:
break;
}
}
#if defined GNUC && !defined clang
int _write(int fd, char *pBuffer, int size); //防止编译器警告
int _write(int fd, char *pBuffer, int size)
{
(void)fd;
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)pBuffer, (uint32_t)size);
while(uart_send_complete_flag == false);
uart_send_complete_flag = false;
return size;
}
#else
int fputc(int ch, FILE *f)
{
(void)f;
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&ch, 1);
while(uart_send_complete_flag == false);
uart_send_complete_flag = false;
return ch;
}
#endif
下面是主函数
void hal_entry (void)
{
#if BSP_TZ_SECURE_BUILD
R_BSP_NonSecureEnter();
#endif
const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS;
const uint32_t freq_in_hz = 2;
const uint32_t delay = bsp_delay_units / freq_in_hz;
bsp_leds_t leds = g_bsp_leds;
err = R_SCI_UART_Open(&g_uart9_ctrl, &g_uart9_cfg);
assert(FSP_SUCCESS == err);
unsigned char buff[]="RA E2STUDIO";
uint8_t buff_len = strlen(buff);
err = R_SCI_UART_Write(&g_uart9_ctrl, buff, buff_len);
if(FSP_SUCCESS != err) __BKPT();
while(uart_send_complete_flag == false){}
uart_send_complete_flag = false;
printf("欢迎使用瑞萨电子\r\n");
printf("RA4E2 M33\r\n");
printf("串口测试\r\n");
while(1)
{
printf("瑞萨串口—每500毫秒打印一次\r\n");
R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS);
}
}
连接上位机串口助手
测试正常,至此串口调通!!!!!