瑞萨FPB-RA6E2开发板概述
RA6E2快速原型开发板配备了R7FA6E2BB3CFM微控制器,是专门用于各种应用原型开发的评估板。它具有内置的SEGGER J-Link™仿真器电路,因此您无需额外工具即可编写/调试程序。此外,通过Arduino Uno和Pmod™接口,包括对微控制器所有引脚的标准和通孔访问等,它具有很高的可扩展性。

按照上图进行Oled接线,使用模拟方式实现IIC了。使用P100和P101引脚作为IIC的时钟和数据线,使用P000作为ADC转换输入引脚:

在oled.h文件中进行如下修改:
#define OLED_SCL_Set() R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_00, BSP_IO_LEVEL_HIGH)
#define OLED_SCL_Clr() R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_00, BSP_IO_LEVEL_LOW)
#define OLED_SDA_Clr() R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_01, BSP_IO_LEVEL_LOW)
#define OLED_SDA_Set() R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_01, BSP_IO_LEVEL_HIGH)
删除部分应用于其他芯片的代码,在主函数中调用:
OLED_Init();
while\(1\)
\{ OLED\_ShowChinese\(0,0,0,16,1\);
OLED\_ShowChinese\(18,0,1,16,1\);
OLED\_ShowChinese\(36,0,2,16,1\);
OLED\_ShowChinese\(54,0,3,16,1\);
OLED\_ShowChinese\(72,0,4,16,1\);
OLED\_ShowChinese\(90,0,5,16,1\);
OLED\_ShowChinese\(108,0,6,16,1\);
OLED\_Refresh\(\); \}
最后终于调出OLED显示界面如下:

接下来配置ADC转换,外接一个光传感器输出模拟电压,可以测试光照度:

配置扫描通道:

在合适位置插入代码:
void ADC_Init(void)
{fsp_err_t err;
err = R_ADC_Open(&g_adc0_ctrl, &g_adc0_cfg);
err = R_ADC_ScanCfg(&g_adc0_ctrl, &g_adc0_channel_cfg);
assert(FSP_SUCCESS == err);}
uint16_t Read_ADC_Voltage_Value(void)
{
uint16_t adc_data;
adc_status_t adc_status;
double a0;
(void)R_ADC_ScanStart(&g_adc0_ctrl);
//while (FSP_SUCCESS ==R_ADC_StatusGet (&g_adc0_ctrl, &adc_status)) {;}
R_ADC_Read(&g_adc0_ctrl, ADC_CHANNEL_0, &adc_data);
a0 = (double)(adc_data*3.3/4095);
return adc_data;
}
为了在OLED上显示较为稳定的数据,将ADC转换结果进行平均滤波:
OLED_Init();
ADC\_Init\(\);
while(1)
\{ OLED\_ShowChinese\(0,0,0,16,1\);
OLED\_ShowChinese\(18,0,1,16,1\);
OLED\_ShowChinese\(36,0,2,16,1\);
OLED\_ShowChinese\(54,0,3,16,1\);
OLED\_ShowChinese\(72,0,4,16,1\);
for\(count=0;count<16;count\+\+\)
\{adcresult\+=Read\_ADC\_Voltage\_Value\(\);\}
adcresult=adcresult/16;
OLED\_ShowNum\(8,16,adcresult,8,16,1\);
OLED\_Refresh\(\);\}
最后给出调试结果:
