瑞萨RL78/F22 MCU基于e2studio开发环境创建触摸应用样例工程

chq123 2026-01-15 12:01 阅读数 1239 #科创经济
文章标签 瑞萨RL78F22MCU

目 录

01 概述
02 瑞萨RL78/F22 Target Board简介
03 基于e²studio创建触摸应用样例工程

–在e²studio中创建新工程

–在Smart Configurator中为新工程添加驱动程序

–使用QE for Capacitive Touch开发触摸应用

–添加应用代码实现LED闪烁

1

概述

本文包含以下主要内容:

瑞萨RL78/F22 Target Board简介

基于e²studio创建触摸样例工程

使用QE for Capacitive Touch开发触摸应用

触摸和LED闪烁演示

本文基于以下开发环境

软件运行环境

73efde9a-f0fe-11f0-92de-92fbcf53809c.png

硬件运行环境

2

瑞萨RL78/F22 Target Board简介

瑞萨RL78/F22 target board

(RTK7F125FPC01000BJ)

74a1ce2a-f0fe-11f0-92de-92fbcf53809c.png

硬件运行环境搭建

硬件连接框图

757c08ba-f0fe-11f0-92de-92fbcf53809c.png

3

基于e²studio创建触摸样例工程

在e²studio中创建RL78新工程

打开e²studio设定workspace后在菜单栏点击[File]新建RL78新工程。

新建工程名称:

RL78F22_TB_TOUCH_SAMPLE

75e66e08-f0fe-11f0-92de-92fbcf53809c.png7649fc70-f0fe-11f0-92de-92fbcf53809c.png

选择Toolchain

V1.15.01

选择目标器件

R7F122GG4xFB

76a331fa-f0fe-11f0-92de-92fbcf53809c.png

选择仿真器

E2 Lite(RL78)。

选择Use Smart configurator

勾选。

76fb804e-f0fe-11f0-92de-92fbcf53809c.png

完成新工程创建

点击Finish。

77622d58-f0fe-11f0-92de-92fbcf53809c.png

在Smart Configurator中为新工程添加驱动程序

RL78新工程创建完成后,默认打开Smart Configurator的Overview选项卡。

781a552c-f0fe-11f0-92de-92fbcf53809c.png

Smart Configurator设定

Clocks选项卡

设定VDD Setting

本例为2.7V ≤ VDD ≤ 5.5V。

787e8ab0-f0fe-11f0-92de-92fbcf53809c.png

System选项卡

按照下图进行设定

78e551dc-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

r_bsp设定

保持默认。

794aa3c0-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

点击

79ae0e56-f0fe-11f0-92de-92fbcf53809c.png

按钮。

在New Component对话框中选择Capacitive Sensing Unit driver.(r_ctsu)。

7a026622-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

r_ctsu设定

根据实际电路设定触摸通道:

勾选TSCAP;

勾选TS2;

勾选TS3;

按下图所示:

7a59b620-f0fe-11f0-92de-92fbcf53809c.png7aae2e58-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

点击

79ae0e56-f0fe-11f0-92de-92fbcf53809c.png

按钮。

在New Component对话框中选择Touch Middleware.(rm_touch)。

7b5c648c-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

rm_touch设定

按下图所示:

7bc197a8-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

点击

79ae0e56-f0fe-11f0-92de-92fbcf53809c.png

按钮。

在New Component对话框中选择Ports。

7c7b3852-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

Ports设定

用于驱动Test LED;

按下图所示:

7cd1e8fa-f0fe-11f0-92de-92fbcf53809c.png7d273b52-f0fe-11f0-92de-92fbcf53809c.png

Components选项卡

确认r_bsp。

Initialization of peripheral functions by Code Generator/Smart Configurator;

Enable;

点击

7d807532-f0fe-11f0-92de-92fbcf53809c.png

生成驱动程序。

7ddb9bf6-f0fe-11f0-92de-92fbcf53809c.png

确认驱动程序的添加

点击

7e300e70-f0fe-11f0-92de-92fbcf53809c.png

编译工程。

7e86582a-f0fe-11f0-92de-92fbcf53809c.png

使用QE for Capacitive Touch开发触摸应用

在e²studio中打开QE For Capacitive touch

7edddbb8-f0fe-11f0-92de-92fbcf53809c.png

Preparation

工程设定

7f34d030-f0fe-11f0-92de-92fbcf53809c.png

建立配置

7f9f28c2-f0fe-11f0-92de-92fbcf53809c.png

建立配置

在画布中添加Button

80103b16-f0fe-11f0-92de-92fbcf53809c.png

建立配置

为Button设定触摸通道和阻尼电阻(Button00/TS02/560ohm,Button01/TS03/560ohm)。

80786dbc-f0fe-11f0-92de-92fbcf53809c.png

建立配置

点击Create完成设定。

80e31e46-f0fe-11f0-92de-92fbcf53809c.png

Tuning

调优(Tuning)前的准备工作

点击

814b41a6-f0fe-11f0-92de-92fbcf53809c.png

旁边的

819f1f24-f0fe-11f0-92de-92fbcf53809c.png

在下拉菜单中选择Debug Configuration。

81f6ca1c-f0fe-11f0-92de-92fbcf53809c.png

双击对话框左侧的RL78F22_TB_TOUCH_SAMPLE_HardwareDebug后,在对话框右侧Debugger选项卡的Connection Settings标签页确认目标板供电方式为仿真器供电方式,点击Close关闭。

825fda70-f0fe-11f0-92de-92fbcf53809c.png

将E2 Lite连接PC以及RL78/F22 target board的CN3。

使用长45mmx宽25mmx厚2mm的亚克力板(用户自行准备)覆盖住电极区域。

注意:禁止手指直接触摸电极,否则会导致短路或者测量不正确。

82cce98a-f0fe-11f0-92de-92fbcf53809c.png

连接方法选择Emulator。

833ab622-f0fe-11f0-92de-92fbcf53809c.png

进行自动调优(Tuning)

点击Start Tuning按钮,在弹出的对话框中,设定3.3V供电电压后,点击OK。

83a570b6-f0fe-11f0-92de-92fbcf53809c.png

按步骤显示自动调优(Tuning)对话框,如寄生电容测量,偏置电流调整等无需用户操作的步骤。

83fbca2e-f0fe-11f0-92de-92fbcf53809c.png

进入需要用户参与的灵敏度测量步骤

用户需要使用正常压力按压触摸按键并保持,然后按下PC键盘上的任意键,生成默认的阈值,完成调优(Tuning)。

844fa82e-f0fe-11f0-92de-92fbcf53809c.png

在弹出的对话框中,显示阈值/溢出信息/警告错误信息,用户点击Continue the Tuning Process按钮完成。

84a5d794-f0fe-11f0-92de-92fbcf53809c.png

自动调优(Tuning)完成后,点击Display Tuning Result按钮,显示自动调优(Tuning)的结果,包括寄生电容值、驱动频率、阈值、扫描时间等。

84fe333a-f0fe-11f0-92de-92fbcf53809c.png

输出自动调优(Tuning)产生的参数文件

点击Output Parameter Files

856a01e6-f0fe-11f0-92de-92fbcf53809c.png

Coding

输出Sample Code

点击Show Sample按钮,在弹出的对话框中,点击Output to a file,点击OK关闭。

85d11444-f0fe-11f0-92de-92fbcf53809c.png

在工程目录下检查新生成的参数文件和Sample Code文件。

在qe_touch_config.c中检查的按键阈值(threshold)等参数。

86427058-f0fe-11f0-92de-92fbcf53809c.png

在main.c中添加qe_touch_main()的声明和调用

点击

7e300e70-f0fe-11f0-92de-92fbcf53809c.png

编译工程,并运行程序。

86eea242-f0fe-11f0-92de-92fbcf53809c.png

Monitoring

确认连接方式为Emulator

点击Show Views

8744976a-f0fe-11f0-92de-92fbcf53809c.png

在Board Monitor中,点击Enable Monitoring ,并在各个监控窗口中设定需要监控的Touch I/F。

87addcf2-f0fe-11f0-92de-92fbcf53809c.png

按下触摸按键,即可在各个图形化窗口中进行Monitoring以及触摸参数调整。

881a0b2a-f0fe-11f0-92de-92fbcf53809c.png

添加应用代码实现LED闪烁

应用代码添加

在qe_genqe_touch_sample.c中

LED1和LED2的宏定义

左右滑动查看完整内容

#defineLED1    (P6_bit.no6)
#defineLED2    (P6_bit.no7)


#defineLED_OFF   (1U)
#defineLED_ON   (0U)
88752f78-f0fe-11f0-92de-92fbcf53809c.png

在qe_genqe_touch_sample.c中

按下触摸按键后点亮LED1和LED2。

左右滑动查看完整内容

/*TODO:Add your own code here. */
switch(button_status)
{
caseCONFIG01_MASK_BUTTON00:
LED1 = LED_ON;
break;
caseCONFIG01_MASK_BUTTON01:         
LED2 = LED_ON;         
break;
case(CONFIG01_MASK_BUTTON00 | CONFIG01_MASK_BUTTON01):         
LED1 = LED_ON;         
LED2 = LED_ON;         
break;
 default:        
 LED1 = LED_OFF;        
 LED2 = LED_OFF;        
 break;  
 }
88e09d9e-f0fe-11f0-92de-92fbcf53809c.png

编译运行后,按下触摸按键Touch Button1点亮LED1。

893bf1d0-f0fe-11f0-92de-92fbcf53809c.png

编译运行后,按下触摸按键Touch Button2点亮LED2。

8997949a-f0fe-11f0-92de-92fbcf53809c.png

热门