Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
[第二期 空气质量分析仪]第2周作业
发布于 2019-09-06 22:59:20 浏览:851
订阅该版
任务1:完成温湿度应用模块 ```static rt_thread_t temp_humi_thread = RT_NULL;//线程控制块 static void temp_humi_thread_entry(void* parameter) { while (1) { rt_kprintf("temp_humi_thread running: "); //read humidity g_humidity = aht10_read_humidity(dev); rt_kprintf("humidity:%d.%d%%; ", (int)g_humidity, (int)(g_humidity * 10) % 10); //read temperature g_temperature = aht10_read_temperature(dev); rt_kprintf("temperature:%d.%d℃;
", (int)g_temperature, (int)(g_temperature * 10) % 10); rt_thread_delay(500); } } void temp_humi_init(void) { const char *i2c_bus_name = "i2c2"; dev = aht10_init(i2c_bus_name); if(dev == RT_NULL) { rt_kprintf("The sensor initializes failure
"); } // 创建动态线程 temp_humi_thread = rt_thread_create("temp_humi_thread", //线程名字,在shell里面可以看到 temp_humi_thread_entry, //线程入口函数 RT_NULL, //线程入口函数参数 512, //线程栈大小 3, //线程的优先级 20); //线程时间片 if (temp_humi_thread != RT_NULL) rt_thread_startup(temp_humi_thread); //启动线程 else return; } ``` 任务2:PM2.5传感器驱动 ```static rt_thread_t pm2_5_thread = RT_NULL;//线程控制块 static void pm2_5_thread_entry(void* parameter) { uint8_t VoutH = 0, VoutL = 0; uint8_t VrefH = 0, VrefL = 0; uint8_t Checksum = 0; //Vout = (VoutH * 256 + VoutL) / 1024 * 5V; //Sensitivity = 0.35V/(0.1mg/m^3) = 0.0035V/(ug/m^3) //ratio = 5 / (1024 * 0.0035) float ratio = 5 / (1024 * 0.0035); while(1) { if (g_UART_FrameFlag == 0) return; rt_kprintf("pm2_5_thread running: "); VoutH = g_UART_FrameBuf[1]; VoutL = g_UART_FrameBuf[2]; VrefH = g_UART_FrameBuf[3]; VrefL = g_UART_FrameBuf[4]; Checksum = g_UART_FrameBuf[5]; if (Checksum == (VoutH + VoutL + VrefH + VrefL)) { g_pm2_5 = (VoutH * 256 + VoutL) * ratio; rt_kprintf("pm2.5:%dug/m^3;
", (int)g_pm2_5); } rt_thread_delay(500); } } void pm2_5_init(void) { //init // 创建动态线程 pm2_5_thread = rt_thread_create("pm2_5_thread", //线程名字,在shell里面可以看到 pm2_5_thread_entry, //线程入口函数 RT_NULL, //线程入口函数参数 512, //线程栈大小 4, //线程的优先级 20); //线程时间片 if (pm2_5_thread != RT_NULL) rt_thread_startup(pm2_5_thread); //启动线程 else return; } ``` 实验结果:  没有买甲醛模块,任务3没有做。 中间遇到个小问题,pm2_5_thread的优先级低于temp_humi_thread的优先级或两者优先级相同时,temp_humi_thread打印消息会打断pm2_5_thread的消息,将pm2_5_thread设为高于temp_humi_thread优先级时就正常了,还没找到是什么原因。
查看更多
1
个回答
默认排序
按发布时间排序
撰写答案
登录
注册新账号
关注者
0
被浏览
851
关于作者
CCXX
这家伙很懒,什么也没写!
提问
4
回答
4
被采纳
0
关注TA
发私信
相关问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RT-thred的stm32h723对应bsp包CubeMX添加其他外设报错
2
RT-Thread中的time溢出问题,时间戳溢出,解决方法
3
ART-PI使用env驱动ETH网卡,pc和板子可以ping通
4
SystemView线程名字不显示
5
只用网页也能跑RT-Smart 无门槛腾讯Cloud studio + smart-build快速构建
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
UART
ESP8266
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
ulog
SFUD
msh
C++_cpp
MicroPython
本月问答贡献
RTT_逍遥
9
个答案
2
次被采纳
三世执戟
8
个答案
1
次被采纳
KunYi
8
个答案
1
次被采纳
winfeng
2
个答案
1
次被采纳
YZRD
2
个答案
1
次被采纳
本月文章贡献
catcatbing
2
篇文章
5
次点赞
swet123
1
篇文章
4
次点赞
Days
1
篇文章
4
次点赞
YZRD
1
篇文章
2
次点赞
阳光的掌控者
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部