博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SHT30 Linux标准 i2c-dev 读取程序
阅读量:4674 次
发布时间:2019-06-09

本文共 1375 字,大约阅读时间需要 4 分钟。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define I2C_DEV "/dev/i2c-2" int main(void){ int tmp75Fd; int ret; unsigned char slaveAddr = 0x45; unsigned char buf[8] = {0}; // 打开设备 tmp75Fd = open(I2C_DEV, O_RDWR); if ( tmp75Fd < 0 ){ printf("faile to open the i2c bus: %s.\n", I2C_DEV); return -1; } // 设置7位地址 if ( ioctl(tmp75Fd, I2C_TENBIT, 0) < 0) { printf("faile to set bits.\n"); return -1; } // 强制设置地址 //if ( ioctl(tmp75Fd, I2C_SLAVE, 0x4c) < 0 ) { if ( ioctl(tmp75Fd, I2C_SLAVE_FORCE, slaveAddr) < 0 ) { perror("faile to set address.\n"); return -1; } while ( 1 ) { // 配置tmp75控制器 buf[0] = 0x2C; buf[1] = 0x0D; if ( write(tmp75Fd, buf, 2) != 2 ) { perror("faile to write config.\n"); return -1; } //buf[0] = 0xE0; //buf[1] = 0x00; //if ( write(tmp75Fd, buf, 2) != 2 ) { // perror("faile to write config.\n"); // return -1; //} buf[0] = 0; buf[1] = 0; if ( read(tmp75Fd, buf, 8) != 8 ) { perror("faile to read back configure data.\n"); return -1; } printf("tmp75 configure: 0x%x.0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x \n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7] ); usleep(500000); } // 貌似是多余的 close(tmp75Fd); return 0; }

转载于:https://www.cnblogs.com/chenfulin5/p/8809846.html

你可能感兴趣的文章
BlockingQueue深入解析
查看>>
Push rejected: Push master to origin/master was rejected by remote(IDEA、MAC、GIT)
查看>>
最强整理Mac IDEA 常用快捷键
查看>>
LeetCode(Java版)因为用上了MD所有删掉了以前的帖子
查看>>
阻止冒泡(例:a标签上面绝对定位的文字标签【×】
查看>>
清除浮动的方法
查看>>
前言、Mysql简介
查看>>
第一次个人编程作业
查看>>
第一次博客作业
查看>>
第一次团队展示
查看>>
第一次结对编程作业
查看>>
Python的isinstance()函数
查看>>
Windows安装Pygame
查看>>
python报错: _tkinter.TclError: couldn't recognize data in image file
查看>>
Python正则表达式
查看>>
python中的迭代器
查看>>
HTML 样式表
查看>>
poj-1274-The Perfect Shall
查看>>
urlEncodeComponent
查看>>
@media 适配兼容
查看>>