sem599 发表于 2014-6-21 18:54:33

sdp600压力传感器 i2c 使用

我首发在电子区的求助
sdp600压力传感器 i2c 使用
http://www.geek-workshop.com/thread-10154-1-1.html

求助各位。 看俺的代码写的对不对
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);
   
}

男子汉、 发表于 2014-7-23 11:00:02

地址不是0x80吗?楼主读出来没,我读的时候,时不时有0XFFFF
页: [1]
查看完整版本: sdp600压力传感器 i2c 使用