Firefly开源社区

标题: 添加AHT10温湿度传感器无法通讯 [打印本页]

作者: kiswih    时间: 2019-10-29 11:00
标题: 添加AHT10温湿度传感器无法通讯
本帖最后由 kiswih 于 2019-10-29 11:01 编辑

使用AHT10温湿度传感器接入在AIO-3399C(AI)的I2C7号通道,设备寄存器地址是0x38,但是我调用i2c_master_send函数时返回-6(没有设备)错误,请问各位大神我应该如何正确使用呢?
DTS配置如下:
  1. &i2c7 {
  2.      status = "okay";

  3.      aht10: aht10@38 {
  4.               status = "okay";
  5.               compatible = "thinary,aht10";
  6.               reg = <0x38>;
  7.       };
  8. };
复制代码

驱动代码:
  1. static AHT10_R writeandread(const const char *cmd, size_t cmdsize, uint8_t *buffer, int readsize)
  2. {
  3.     int rtn;
  4.     struct i2c_client *client = this_client;
  5.     if (!client)
  6.         return AHT10_BAD;

  7.     rtn = i2c_master_send(client, cmd, cmdsize); //返回-6
  8.     if (rtn != cmdsize)
  9.     {
  10.         printk("ERROR sending command %d\n", rtn);
  11.         return AHT10_WRITE_FAILED;
  12.     }

  13.     if (readsize > 0)
  14.     {
  15.         mdelay(100);
  16.         rtn = i2c_master_recv(client, buffer, readsize);
  17.         if (rtn < readsize)
  18.             return AHT10_READ_FAILED;
  19.     }
  20.     return AHT10_OK;
  21. }
复制代码









欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) Powered by Discuz! X3.1