293 Star 1.6K Fork 381

GVP合宙Luat / LuatOS

 / 详情

[🐛Bug]: 合宙780E 同时使用IIC的0.96寸OLED屏幕,MPU6050,SHT30以及ADC功能,显示几秒后程序会卡死

待办的
创建于  
2024-05-12 15:01

描述一下这个bug / Describe the bug

合宙780E 同时使用IIC的0.96寸OLED屏幕,MPU6050,SHT30以及ADC功能,
功能一切正常,但是显示几秒后(一般十秒以内)

程序会卡死

[2024-05-12 15:01:07.987][000000010.321] E/user.coroutine.resume mpu6xxx.lua:228: attempt to perform arithmetic on a nil value (field 'z')
stack traceback:
mpu6xxx.lua:228: in function 'mpu6xxx.get_accel'
main.lua:77: in function main.lua:51
[2024-05-12 15:01:08.481][000000010.823] E/main Luat:
[2024-05-12 15:01:08.481][000000010.823] E/main mpu6xxx.lua:228: attempt to perform arithmetic on a nil value (field 'z')
stack traceback:
mpu6xxx.lua:228: in function 'mpu6xxx.get_accel'
main.lua:77: in function main.lua:51
[2024-05-12 15:01:08.488][000000010.824] E/main Lua VM exit!! reboot in 15000ms

复现步骤 / To Reproduce

--- 模块功能:u8g2demo
-- @孙江磊 u8g2
-- @Author Dozingfiretruck
-- @lixzh 2021.01.25

-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "u8g2demo"
VERSION = "1.0.1"

log.info("main", PROJECT, VERSION)

-- sys库是标配
_G.sys = require("sys")

--[[
I2C0
I2C0_SCL (5)
I2C0_SDA (4)
]]

--添加硬狗防止程序卡死
wdt.init(9000)--初始化watchdog设置为9s
sys.timerLoopStart(wdt.feed, 3000)--3s喂一次狗
-- 初始化显示屏
local hw_i2c_id,sw_i2c_scl,sw_i2c_sda,spi_id,spi_res,spi_dc,spi_cs = 0,10,11,0,1,10,8
log.info(TAG, "init ssd1306")
u8g2.begin({ic = "ssd1306",direction = 0,mode="i2c_hw",i2c_id=hw_i2c_id,i2c_speed = i2c.FAST}) -- direction 可选0 90 180 270
u8g2.SetFontMode(1)
u8g2.ClearBuffer()
u8g2.SetFont(u8g2.font_opposansm8)
u8g2.DrawUTF8("U8g2+LuatOS", 32, 22)
if u8g2.font_opposansm12_chinese then
u8g2.SetFont(u8g2.font_opposansm12_chinese)
elseif u8g2.font_opposansm10_chinese then
u8g2.SetFont(u8g2.font_opposansm10_chinese)
elseif u8g2.font_sarasa_m12_chinese then
u8g2.SetFont(u8g2.font_sarasa_m12_chinese)
elseif u8g2.font_sarasa_m10_chinese then
u8g2.SetFont(u8g2.font_sarasa_m10_chinese)
else
print("no chinese font")
end
-- 初始化显示屏
--初始化6050
local mpu6xxx = require "mpu6xxx"
i2cid =1
i2c_speed = i2c.FAST

--主流程
sys.taskInit(function()
--初始化部分
-- i2c.send(1, 0x44, string.char(0x2C, 0x06))--温湿度
local addr = 0x44
-- 按实际修改哦
local id = 1
i2c.setup(i2cid, i2c_speed)
local success = mpu6xxx.init(i2cid) -- 初始化,传入i2c_id
if not success then
log.error("MPU initialization failed")
return
end
log.info("i2c", "initial",i2c.setup(id))

while 1 do
    i2c.send(id, addr, string.char(0x2C, 0x06))
    sys.wait(5) -- 5ms
    local data = i2c.recv(id, addr, 6)
    if #data == 6  then
        local _,tval,ccrc,hval,hcrc = pack.unpack(data, ">HbHb")
        local cTemp = ((tval * 175) / 65535.0) - 45
        local humidity = ((hval * 100) / 65535.0)
        log.info( "当前温度:",  cTemp,'单位℃')
        log.info( "当前湿度:", humidity, "单位%")
    end

    local accel = mpu6xxx.get_accel() -- 获取加速度
    if accel then
        log.info("6050accel", "accel.x", accel.x, "accel.y", accel.y, "accel.z", accel.z)
    else
        log.error("Failed to get acceleration")
    end
    local gyro = mpu6xxx.get_gyro() -- 获取陀螺仪
    if gyro then
        log.info("6050gyro", "gyro.x", gyro.x, "gyro.y", gyro.y, "gyro.z", gyro.z)
    else
        log.error("Failed to get gyroscope data")
    end
   

adc.open(0)
adc.open(1)
local adc0 =adc.get(0)
local adc1 =adc.get(1)
log.info("adc1", adc.get(1))
log.info("adc0", adc.get(0))
u8g2.ClearBuffer()
u8g2.DrawUTF8("yuanshen(ma)", 0, 12) --24,42
u8g2.DrawUTF8("qidong(mv)", 0, 24)
u8g2.DrawUTF8("temp", 0, 36)
u8g2.DrawUTF8("shidu", 0, 48)
u8g2.DrawUTF8(  adc0 , 80, 12)
u8g2.DrawUTF8(  adc1 , 80, 24)
u8g2.DrawUTF8(  gyro.x, 80, 48)
u8g2.SendBuffer()
sys.wait(20)
end

end)

-- 主循环, 必须加
sys.run()

如果正常,应该是什么样 / Expected behavior

打印数据都正常,不应该卡死

截图 / Screenshots

输入图片说明

日志 / Logs

[2024-05-12 14:59:49.851][000000021.888] I/user.当前温度: 25.50469 单位℃
[2024-05-12 14:59:49.851][000000021.889] I/user.当前湿度: 42.31784 单位%
[2024-05-12 14:59:49.851][000000021.895] I/user.6050accel accel.x 17.94434 accel.y -257.2021 accel.z 900.6348
[2024-05-12 14:59:49.867][000000021.900] I/user.6050gyro gyro.x 1.361084 gyro.y 1.263428 gyro.z 0.01831055
[2024-05-12 14:59:49.867][000000021.902] I/user.adc1 9
[2024-05-12 14:59:49.867][000000021.903] I/user.adc0 2537
[2024-05-12 14:59:49.952][000000021.983] I/user.当前温度: 25.49134 单位℃
[2024-05-12 14:59:49.952][000000021.984] I/user.当前湿度: 42.34073 单位%
[2024-05-12 14:59:49.952][000000021.990] I/user.6050accel accel.x 39.42871 accel.y -254.8828 accel.z 854.0039
[2024-05-12 14:59:49.967][000000021.996] I/user.6050gyro gyro.x -0.3356934 gyro.y 0.2136230 gyro.z -0.09765625
[2024-05-12 14:59:49.967][000000021.998] I/user.adc1 9
[2024-05-12 14:59:49.967][000000021.999] I/user.adc0 2535
[2024-05-12 14:59:50.051][000000022.079] I/user.当前温度: 25.50469 单位℃
[2024-05-12 14:59:50.051][000000022.080] I/user.当前湿度: 42.34226 单位%
[2024-05-12 14:59:50.051][000000022.086] I/user.6050accel accel.x 35.40039 accel.y -260.0098 accel.z 850.5859
[2024-05-12 14:59:50.067][000000022.091] I/user.6050gyro gyro.x 0.4028320 gyro.y 0.2746582 gyro.z -0.1892090
[2024-05-12 14:59:50.067][000000022.093] I/user.adc1 9
[2024-05-12 14:59:50.067][000000022.095] I/user.adc0 2536
[2024-05-12 14:59:50.136][000000022.174] I/user.当前温度: 25.50469 单位℃
[2024-05-12 14:59:50.136][000000022.175] I/user.当前湿度: 42.36820 单位%
[2024-05-12 14:59:50.136][000000022.181] I/user.6050accel accel.x 31.61621 accel.y -226.8066 accel.z 862.4268
[2024-05-12 14:59:50.152][000000022.187] I/user.6050gyro gyro.x 1.483154 gyro.y 0.2990723 gyro.z -0.1220703
[2024-05-12 14:59:50.152][000000022.189] I/user.adc1 9
[2024-05-12 14:59:50.152][000000022.190] I/user.adc0 2534
[2024-05-12 14:59:50.237][000000022.269] I/user.当前温度: 25.50469 单位℃
[2024-05-12 14:59:50.237][000000022.270] I/user.当前湿度: 42.30411 单位%
[2024-05-12 14:59:50.268][000000022.296] prvI2C_TimerUpCB 272:10,100001,8040d0,0,10000,3208282
[2024-05-12 14:59:50.268][000000022.297] i2c_failed 295:i2c1 从机地址68 传输超时
[2024-05-12 14:59:50.268][000000022.297] D/i2c i2c receive result -13
[2024-05-12 14:59:50.283][000000022.303] E/user.coroutine.resume mpu6xxx.lua:226: attempt to perform arithmetic on a nil value (field 'x')
stack traceback:
mpu6xxx.lua:226: in function 'mpu6xxx.get_accel'
main.lua:77: in function main.lua:51
[2024-05-12 14:59:50.769][000000022.804] E/main Luat:
[2024-05-12 14:59:50.769][000000022.804] E/main mpu6xxx.lua:226: attempt to perform arithmetic on a nil value (field 'x')
stack traceback:
mpu6xxx.lua:226: in function 'mpu6xxx.get_accel'
main.lua:77: in function main.lua:51
[2024-05-12 14:59:50.769][000000022.805] E/main Lua VM exit!! reboot in 15000ms

PACK包版本 / Version

LuatOS-SoC_V1108_EC618_FULL.soc

验证

  • 检查过该问题,之前没有人提过 / Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • 提供了最小可复现工程或详细的复现步骤,确保开发者可以复现 / The provided reproduction is a minimal reproducible example of the bug.
  • 已经提供了完整的报错信息、日志、截图,没有经过删减。

评论 (2)

白泽 创建了任务

i2c_failed 295:i2c1 从机地址68 传输超时 你I2C总线上设备地址0x68的从机工作不正常

事实上是,设备(SHT30温湿度模块)能读到,但是运行几秒后就会通讯失败,但是单独读取这个模块是稳定的,可以一直读取的

alien2017 计划截止日期设置为2024-05-17

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
Lua
1
https://gitee.com/openLuat/LuatOS.git
git@gitee.com:openLuat/LuatOS.git
openLuat
LuatOS
LuatOS

搜索帮助

53164aa7 5694891 3bd8fe86 5694891