猿问

AM2320 传感器:CRC 不匹配,来自传感器的 CRC(0)

注意:代码是在 windows 10 中交叉编译的。


代码:


package main


import (

    "fmt"

    "io"

    "log"

    "net/http"


    aosong "github.com/d2r2/go-aosong"

    i2c "github.com/d2r2/go-i2c"

)


const i2CAddress = 0x5c

const i2CBus = 1


// Server struct

type Server struct {

    Sensor *aosong.Sensor

    I2C    *i2c.I2C

}

func main() {

        var err error

    s := Server{Sensor: aosong.NewSensor(aosong.AM2320)}

    s.I2C, err = i2c.NewI2C(i2CAddress, i2CBus)

    if err != nil {

        log.Printf(err.Error())

    }

    fmt.Println(s.Sensor.ReadRelativeHumidityAndTemperature(s.I2C))

    defer s.I2C.Close()

}

调试信息:


2019-02-12T10:29:19.692 [     i2c] DEBUG  Write 3 hex bytes: [030004]

2019-02-12T10:29:19.697 [     i2c] DEBUG  Read 8 hex bytes: [0304012500d92045]

2019-02-12T10:29:19.698 [     i2c] DEBUG  Read 8 hex bytes: [0000000000000000]

CRCs doesn't match: CRC from sensor(0) != calculated CRC(6912).

知道为什么来自传感器的 CRC 为 0 吗?


我能够使用 python 脚本读取具有相同地址的同一总线上的传感器。


繁华开满天机
浏览 120回答 1
1回答

翻翻过去那场雪

库本身似乎有问题,它进行了两次读取,但由于未发送读取代码,因此值变为 0,如日志中所示:2019-02-12T10:29:19.692 [     i2c] DEBUG  Write 3 hex bytes: [030004]2019-02-12T10:29:19.697 [     i2c] DEBUG  Read 8 hex bytes: [0304012500d92045] (first read that was ignored)2019-02-12T10:29:19.698 [     i2c] DEBUG  Read 8 hex bytes: [0000000000000000] (second one that came a 0)CRCs doesn't match: CRC from sensor(0) != calculated CRC(6912)
随时随地看视频慕课网APP

相关分类

Go
我要回答