c++ - Why my comparison with an HEX enum fails? -
i seeing weird issue whe comparing hex value stored enum , value read register, have defined chipid follows
enum { bme_280_1_chipid = 0x60, bme_280_2_chipid = 0x58, };
i have snippet of code in driver chip id check
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; }
my 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; }
however, debug shows
bme280 debug: read bme280_chipid 58 expected 60 or 58 bme280 missing!
what's happening?
thanks in advance,
regards!
the solution andriano repetti told
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; }
Comments
Post a Comment