Browse Source

Code for SI7021 with BRZO (not working)

fastled
Xose Pérez 6 years ago
parent
commit
7f872f43a8
2 changed files with 15 additions and 6 deletions
  1. +2
    -2
      code/espurna/config/sensors.h
  2. +13
    -4
      code/espurna/sensors/SI7021Sensor.h

+ 2
- 2
code/espurna/config/sensors.h View File

@ -274,13 +274,13 @@
#endif #endif
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Internal power montior
// Internal power monitor
// Enable support by passing ADC_VCC_ENABLED=1 build flag // Enable support by passing ADC_VCC_ENABLED=1 build flag
// Do not enable this if using the analog GPIO for any other thing // Do not enable this if using the analog GPIO for any other thing
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
#ifndef ADC_VCC_ENABLED #ifndef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 1
#define ADC_VCC_ENABLED 1
#endif #endif
#if ADC_VCC_ENABLED #if ADC_VCC_ENABLED


+ 13
- 4
code/espurna/sensors/SI7021Sensor.h View File

@ -79,7 +79,7 @@ class SI7021Sensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String name() { String name() {
char buffer[20];
char buffer[25];
snprintf(buffer, sizeof(buffer), "%s @ I2C (0x%02X)", chipAsString().c_str(), _address); snprintf(buffer, sizeof(buffer), "%s @ I2C (0x%02X)", chipAsString().c_str(), _address);
return String(buffer); return String(buffer);
} }
@ -131,6 +131,9 @@ class SI7021Sensor : public BaseSensor {
unsigned char bytes = (command == 0xE0) ? 2 : 3; unsigned char bytes = (command == 0xE0) ? 2 : 3;
#if I2C_USE_BRZO #if I2C_USE_BRZO
uint8_t buffer[2] = {command, 0x00};
brzo_i2c_start_transaction(_address, SI7021_SCL_FREQUENCY);
brzo_i2c_write(buffer, 1, false);
#else #else
Wire.beginTransmission(_address); Wire.beginTransmission(_address);
Wire.write(command); Wire.write(command);
@ -144,11 +147,16 @@ class SI7021Sensor : public BaseSensor {
while (millis() - start < 50) delay(1); while (millis() - start < 50) delay(1);
#if I2C_USE_BRZO #if I2C_USE_BRZO
unsigned int msb = 0;
unsigned int lsb = 0;
brzo_i2c_read(buffer, 2, false);
brzo_i2c_end_transaction();
unsigned int msb = buffer[0];
unsigned int lsb = buffer[1];
#else #else
Wire.requestFrom(_address, bytes); Wire.requestFrom(_address, bytes);
if (Wire.available() != bytes) return 100;
if (Wire.available() != bytes) {
_error = SENSOR_ERROR_CRC;
return 0;
}
unsigned int msb = Wire.read(); unsigned int msb = Wire.read();
unsigned int lsb = Wire.read(); unsigned int lsb = Wire.read();
#endif #endif
@ -159,6 +167,7 @@ class SI7021Sensor : public BaseSensor {
unsigned int value = (msb << 8) | lsb; unsigned int value = (msb << 8) | lsb;
_error = SENSOR_ERROR_OK;
return value; return value;
} }


Loading…
Cancel
Save