-
-
Save schinken/0c626f245e1d4e20dd65589b2d1cb4ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
const int I2C_ADDR = 0x50; | |
void dumpEEPROM(bool dumpAsCode = false) | |
{ | |
for (int i = 0; i < 256; i++) { | |
const byte eepromByte = readByte(I2C_ADDR, i); | |
if (dumpAsCode) | |
{ | |
Serial.print(F("writeByte(I2C_ADDR, 0x")); printHex(i, 2); | |
Serial.print(F(", 0x")); printHex(eepromByte, 2); | |
Serial.print(F(");\n")); | |
} | |
else | |
{ | |
printHex(eepromByte, 2); | |
Serial.print(" "); | |
if ((i + 1) % 16 == 0) | |
Serial.println(); | |
} | |
} | |
Serial.println(); | |
} | |
void MODeeprom() { | |
Serial.println("\n...Flashing EEPROM...\n"); | |
// Change the Ω order to continuity -> Ohms (09 - 07; the default is 07 - 09) | |
writeByte(I2C_ADDR, 0x8F, 0x09); | |
writeByte(I2C_ADDR, 0x9F, 0x07); | |
// Change the V order to DC->AC (normally 0x4->0x5) | |
writeByte(I2C_ADDR, 0x8E, 0x05); | |
writeByte(I2C_ADDR, 0x9E, 0x04); | |
// Make 2A range DC->AC instead of AC->DC | |
writeByte(I2C_ADDR, 0x87, 0x1C); // Dotless DC A, default 0x17 for AC A | |
writeByte(I2C_ADDR, 0x97, 0x16); // Dot DC A | |
writeByte(I2C_ADDR, 0xA7, 0x1D); // Dotless AC A, default 0x16 for DC A | |
writeByte(I2C_ADDR, 0xB7, 0x17); // Dot AC A | |
// !!!! Copy bytes from 0x50 and 0x51 (locations of 2A calibration data) to locations 0x56 and 0x57 (2000A / dotless 2A calibration data) | |
writeByte(I2C_ADDR, 0x56, 0x2D); | |
writeByte(I2C_ADDR, 0x57, 0x7E); | |
// Make 20A range DC->AC instead of AC->DC | |
writeByte(I2C_ADDR, 0x8B, 0x18); | |
writeByte(I2C_ADDR, 0x9B, 0x19); | |
// Make 100A range DC->AC instead of AC->DC | |
writeByte(I2C_ADDR, 0x8D, 0x1A); | |
writeByte(I2C_ADDR, 0x9D, 0x1B); | |
// Set V order: V(DC) - V(DC mV) - V(AC) - V(AC mV) | |
writeByte(I2C_ADDR, 0x8E, (byte) 0x03); | |
writeByte(I2C_ADDR, 0x9E, (byte) 0x05); | |
writeByte(I2C_ADDR, 0xAE, (byte) 0x04); | |
writeByte(I2C_ADDR, 0xBE, (byte) 0x06); | |
// ---------------------------------------------------------- // | |
// Expand 100A range to 1000A - only DM1106 chip | |
writeByte(I2C_ADDR, 0x07, 0x10); // normally 0xE8 | |
writeByte(I2C_ADDR, 0x08, 0x27); // normally 0x03 | |
// ---------------------------------------------------------- // | |
// Add NCV field level range | |
writeByte(I2C_ADDR, 0x9C, 0x02); // normally 0x00 | |
writeByte(I2C_ADDR, 0xAC, 0x00); // normally 0x00 | |
// ---------------------------------------------------------- // | |
// Backlight does not turn off | |
writeByte(I2C_ADDR, 0xFC, (byte) 0x00); | |
// ---------------------------------------------------------- // | |
// 10000 counts = 0x2710 | |
// Upper switch point 9999 = 0x270F | |
writeByte(I2C_ADDR, 0x12, 0x0F); | |
writeByte(I2C_ADDR, 0x13, 0x27); | |
// Lower switch point 980 = 0x03D4 (default 190) | |
writeByte(I2C_ADDR, 0x14, 0xD4); | |
writeByte(I2C_ADDR, 0x15, 0x03); | |
} | |
void setup() { | |
Serial.begin(115200); | |
Wire.begin(); | |
Serial.println(F("Starting in...")); | |
countdownDelay(7); | |
Serial.println(F("EEPROM before mod:")); | |
dumpEEPROM(true); | |
Serial.println(F("-------------------")); | |
delay(10); | |
dumpEEPROM(); | |
delay(10); | |
if (0) // Enable/disable modding | |
{ | |
Serial.println(F("Flashing the mods in...")); | |
countdownDelay(5); | |
MODeeprom(); | |
delay(10); | |
Serial.println(F("EEPROM after mod:")); | |
dumpEEPROM(); | |
} | |
} | |
void loop() {} | |
void writeByte(int i2cAddr, unsigned int addr, byte data) { | |
Wire.beginTransmission(i2cAddr); | |
Wire.write(addr); | |
Wire.write(data); | |
Wire.endTransmission(); | |
delay(5); | |
} | |
byte readByte(int i2cAddr, unsigned int addr) { | |
byte data = 0x00; | |
Wire.beginTransmission(i2cAddr); | |
Wire.write(addr); | |
Wire.endTransmission(); | |
Wire.requestFrom(i2cAddr, 1); | |
while (!Wire.available()) ; | |
data = Wire.read(); | |
return data; | |
} | |
void printHex(int num, int precision) { | |
char tmp[16]; | |
char format[128]; | |
sprintf(format, "%%.%dX", precision); | |
sprintf(tmp, format, num); | |
Serial.print(tmp); | |
} | |
void countdownDelay(int seconds) | |
{ | |
for (int i = seconds; i >= 1; --i) | |
{ | |
Serial.println(i); | |
delay(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment