2017-04-14 80 views
0

我看到磨片將存儲到一個枚舉和讀取寄存器值的十六進制值一個奇怪的問題,我已經定義我的CHIPID如下爲什麼我與HEX枚舉的比較失敗?

enum { 
    BME_280_1_CHIPID = 0x60, 
    BME_280_2_CHIPID = 0x58, 
}; 

我有此代碼段在我的司機在芯片ID是檢查

uint8_t id = read8(BME280_REGISTER_CHIPID); 
    if ((id != BME_280_2_CHIPID) || (id != BME_280_1_CHIPID)){ 

    #ifdef DEBUG 
     uint8_t value = read8(BME280_REGISTER_CHIPID); 
     debugPrint("BME280 DEBUG: read BME280_CHIPID "); 
     debugPrint(value,HEX); 
     debugPrint(" expected "); 
     debugPrint(BME_280_1_CHIPID,HEX); 
     debugPrint(" or "); 
     debugPrintLn(BME_280_2_CHIPID,HEX); 
    #endif 
     return false; 
    } 

我read8()funtion是

uint8_t Adafruit_BME280::read8(byte reg) 
{ 
    uint8_t value; 
    Wire1.beginTransmission((uint8_t)_i2caddr); 
    Wire1.write((uint8_t)reg); 
    Wire1.endTransmission(); 
    Wire1.requestFrom((uint8_t)_i2caddr, (byte)1); 
    value = Wire1.read(); 

    return value; 
} 

然而,調試顯示

BME280 DEBUG: read BME280_CHIPID 58 expected 60 or 58 
BME280 MISSING! 

發生了什麼事?

在此先感謝,

問候!

+5

注:!'值= ||一值!= b'。除非'a == b',否則其中一個肯定是'true'。將其更改爲'&&'。 –

+0

@AdrianoRepetti'a == b','value'永遠不會改變 – ndarkness

+0

@ndarkness不,其中一個值是0x60(96),另一個是0x58(94)。所有的數字都不等於其中的一個。例如,'BME_280_1_CHIPID!= BME_280_2_CHIPID'。 – molbdnilo

回答

1

爲Andriano Repetti解決方案告訴

uint8_t id = read8(BME280_REGISTER_CHIPID); 
    if ((id != BME_280_2_CHIPID) && (id != BME_280_1_CHIPID)){ 

    #ifdef DEBUG 
     uint8_t value = read8(BME280_REGISTER_CHIPID); 
     debugPrint("BME280 DEBUG: read BME280_CHIPID "); 
     debugPrint(value,HEX); 
     debugPrint(" expected "); 
     debugPrint(BME_280_1_CHIPID,HEX); 
     debugPrint(" or "); 
     debugPrintLn(BME_280_2_CHIPID,HEX); 
    #endif 
     return false; 
    }