Ask for the register several times and only go on if the answer is the same in 2 consecutive tries.
This commit is contained in:
Thomas Göttgens 2022-04-18 22:46:45 +02:00 committed by GitHub
parent cf45e4fce5
commit ed62b6916c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,11 @@
uint8_t oled_probe(byte addr) uint8_t oled_probe(byte addr)
{ {
uint8_t r = 0; uint8_t r = 0;
uint8_t r_prev = 0;
uint8_t c = 0;
uint8_t o_probe = 0; uint8_t o_probe = 0;
do {
r_prev = r;
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
Wire.write(0x00); Wire.write(0x00);
Wire.endTransmission(); Wire.endTransmission();
@ -15,12 +19,15 @@ uint8_t oled_probe(byte addr)
r = Wire.read(); r = Wire.read();
} }
r &= 0x0f; r &= 0x0f;
if (r == 0x08 || r == 0x00) { if (r == 0x08 || r == 0x00) {
o_probe = 2; // SH1106 o_probe = 2; // SH1106
} else if ( r == 0x03 || r == 0x06 || r == 0x07) { } else if ( r == 0x03 || r == 0x06 || r == 0x07) {
o_probe = 1; // SSD1306 o_probe = 1; // SSD1306
} }
DEBUG_MSG("0x%x subtype probed\n", r); c++;
} while ((r != r_prev) && (c < 4));
DEBUG_MSG("0x%x subtype probed in %i tries \n", r, c);
return o_probe; return o_probe;
} }