极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8900|回复: 0

sdp600压力传感器 i2c 使用

[复制链接]
发表于 2014-6-21 18:43:12 | 显示全部楼层 |阅读模式
本帖最后由 sem599 于 2014-6-21 18:49 编辑

求助各位。 看俺的代码写的对不对
SDP600 是微压差传感器。
i2C地址是0x40, 软复位指令是0xfe  测量指令是0xf1
高手看看我的i2c读取指令对不对。

#include <Wire.h>
// copy to sdp600 @ 0x40
// this code firstly reset the sensor by commend 0xfe
// secondly commend it to measure 0xf1

#define ADDR 0b01000000
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
  
void loop()
{
  
  int val = 0;
  //reset
  Wire.beginTransmission(ADDR);
  Wire.write(0b11111110);//soft reset 0xfe
  Wire.endTransmission();
  delay(500);
  
  //measure
  Wire.beginTransmission(ADDR);
  Wire.write(0b11110001);//triger sensor to measure hF1
  Wire.endTransmission();
     
  digitalWrite(13, LOW);
  delay(500);
   
  Wire.beginTransmission(ADDR);
  
  delay(500);

  Wire.requestFrom(ADDR, 3); // 3byte every time   
  
    byte a = Wire.read();
    byte b = Wire.read();
    byte c = Wire.read();

  Serial.println(a, BIN);
  Serial.println(b, BIN);
  Serial.println(c, BIN);
  
  Wire.endTransmission();
   
   val= (a<<8) + b;
  
  Serial.println(val);
  digitalWrite(13, HIGH);
  delay(1000);
   
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 21:47 , Processed in 0.046049 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表