si7210 sensor data read

fabi1415
Posts: 1
Joined: Tue Oct 22, 2024 12:08 pm

si7210 sensor data read

Postby fabi1415 » Tue Oct 22, 2024 12:22 pm

Can someone help me. I always receive the same value.

Code: Select all

#include <Wire.h>
#include <Arduino.h>


#define reg_chip 0xC0
#define reg_hByte 0xC1
#define reg_lByte 0xC2
#define otp_data_addr 0xE2
#define SLAVEaddr 0x30


void initializeSensor() {
 
    Wire.beginTransmission(SLAVEaddr);
    Wire.write(0xC9); 
    Wire.endTransmission(false);
    delay(100);
}
void setreg() {
 
    Wire.beginTransmission(SLAVEaddr);
    Wire.write(0x04); 
    Wire.endTransmission(false);
    Wire.write(0x01); 
    delay(1);
}


void setup()
{
    Serial.begin(115200);
  Wire.begin(21,22);
  delay(1000);;
  initializeSensor();
//--------------------------------------------------
  // iwc address scanner
  byte error, address;
  for (address = 1; address < 127; address++)
  {
    Wire.beginTransmission(address);
    delay(100);
    error = Wire.endTransmission();
    delay(1);

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
    }
  }
//--------------------------------------------------

  // Read ChipID
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x04);
  Wire.write(0x01);
  Wire.write(reg_hByte);
  Wire.endTransmission();
  byte result = Wire.endTransmission();

  delay(100);

  Wire.requestFrom(SLAVEaddr, 1);
  delay(100); 
  byte chipID = Wire.read() >> 4;
  delay(100);
  Serial.print("ChipID: ");
  Serial.println(chipID, DEC);
  
}

void loop()
{
  int16_t field;
  float result;
  float scale = 204.7f;

  // Read high byte
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x04);
  Wire.write(0x01);

  Wire.write(reg_hByte);
  Wire.endTransmission(false);
  delay(100);

  Wire.requestFrom(SLAVEaddr, 1);
  delay(1);
  byte highByte = Wire.read();
  delay(100);


  // read low byte
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x04);
  Wire.write(0x01);
  Wire.write(reg_lByte);
  Wire.endTransmission(false);
  delay(100);
 
  Wire.requestFrom(SLAVEaddr, 1);
  delay(1);
  byte lowByte = Wire.read();
  delay(100);



  field = ((highByte & 0x7F) << 8) | lowByte;
  field -= 16384;

  result = (256*highByte+lowByte -16384)* (0.00125);
  Serial.println(result);

  delay(1000);
}


output:

Code: Select all

[  1129][E][Wire.cpp:416] beginTransmission(): Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing...
I2C device found at address 0x30  !
ChipID: 0
-20.48
-20.48
-20.48
-20.48
-20.48
-20.4
8

Who is online

Users browsing this forum: iParcelBox, jjsch-dev and 99 guests