本帖最后由 lugl4313820 于 2023-2-12 21:11 编辑
【小华HC32F4A0】初识工规级高性能 开发板
【小华HC32F4A0】零代码闪灯
【小华HC32F4A0】RTT 命令行点亮LED灯
【小华HC32F4A0】RTT —UART Hello world
【小华HC32F4A0】RTT OLED
【小华HC32F4A0】RTT HS3003温湿度计
【小华HC32F4A0】RTT OLED温湿计
【小华HC32F4A0】RTT 之 CAN
在上面的基础上,利用CAN与迪文智慧屏结合,创建一个漂亮的温湿度监:
1、在OLED温湿计上面添加CAN的驱动,并把can_dewen.c以及can_dewen.h复制到工程里面
2、修改main.c如下:
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2022, Xiaohua Semiconductor Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-04-28 CDT first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "sensor_renesas_hs300x.h"
#include "ssd1306.h"
#include "can_dewen.h"
/* defined the LED_GREEN pin: PC9 */
#define LED_GREEN_PIN GET_PIN(C, 9)
#include "sensor_renesas_hs300x.h"
#define HS300X_I2C_BUS "i2c1"
int rt_hw_hs300x_port(void)
{
struct rt_sensor_config cfg;
cfg.intf.dev_name = HS300X_I2C_BUS;
cfg.intf.user_data = (void *)HS300X_I2C_ADDR;
rt_hw_hs300x_init("hs300x", &cfg);
return RT_EOK;
}
INIT_ENV_EXPORT(rt_hw_hs300x_port);
int main(void)
{
float humi_f;
float temp_f;
char buf[128] = {0};
can_sample();
ssd1306_Init();
ssd1306_Fill(Black);
ssd1306_UpdateScreen();
/* set LED_GREEN_PIN pin mode to output */
rt_pin_mode(LED_GREEN_PIN, PIN_MODE_OUTPUT);
while (1)
{
hs300x_read_data(&temp_humi_dev,&humi_f,&temp_f);
can_send((uint32_t)(humi_f * 100),(uint32_t)(temp_f*100));
rt_sprintf(buf,"T:%d.%2d",(int)temp_f,(int)(temp_f*100)%100);
ssd1306_SetCursor(10, 0);
ssd1306_WriteString(buf, Font_16x26, White);
rt_sprintf(buf,"H:%d.%2d",(int)humi_f,(int)(humi_f*100)%100);
ssd1306_SetCursor(10, 30);
ssd1306_WriteString(buf, Font_16x26, White);
ssd1306_UpdateScreen();
rt_pin_write(LED_GREEN_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(LED_GREEN_PIN, PIN_LOW);
rt_thread_mdelay(500);
}
}
编译后下载到开发,把迪文智慧屏的CAN_H与CAN_L接入CAN集线器中。重启开发板就可以看到监控界面了。
【小结】得益于RTT移植的通用性,平移项目非常之快速。当然小华的生态也是做得非常之好!
CAN智慧屏温湿度