Here you can see a dump of two variables which both have the value 105.
The sketch uses a rather flexible dump function that works on the first 64k of RAM, FLASH and EEPROM,
but don't get distracted by that additional complexity of the code.
float 0204: 00 00 D2 42 '..ÒB'
long 0200: 69 00 00 00 'i...'
typedef byte (*accessFunction)(const byte *adr);
void dumpGen(const byte* adr, int len, accessFunction accs, const __FlashStringHelper* pfx, bool withAdr = true, int suppHex = -1);
void dumpR(const void* adr, int len, const __FlashStringHelper* pfx = NULL);
void dumpF(const void* adr, int len, const __FlashStringHelper* pfx = NULL);
void dumpE(const void* adr, int len, const __FlashStringHelper* pfx = NULL);
float tfValue = 105;
long tlValue = 105;
void setup() {
Serial.begin(115200);
dumpR(&tfValue, sizeof(tfValue), F("float "));
dumpR(&tlValue, sizeof(tlValue), F("long "));
}
void loop() {}
byte accRAM(const byte *adr) {
return *adr;
}
byte accPGM(const byte *adr) {
return pgm_read_byte_near(adr);
}
byte accEEPROM(const byte *adr) {
return eeprom_read_byte(adr);
}
void dumpGen(const byte* adr, int len, accessFunction accs, const __FlashStringHelper* pfx, bool withAdr, int suppHex) {
byte idx;
byte blanks;
if (len) {
for (; len > 0; len -= 16, adr += 16) {
Serial.print(pfx);
if (withAdr) {
phAdr(adr);
}
for (idx = 0; idx < 16; idx++) {
if (idx < len ) {
byte curr = (*accs)(adr + idx);
if (suppHex < 0 || suppHex != curr) {
phByte(curr);
} else {
Serial.write('.');
Serial.write('.');
}
blanks = 1;
} else {
blanks = 3;
}
while (blanks--) {
Serial.write(' ');
}
}
Serial.write('\'');
for (idx = 0; (idx < 16) && (idx < len); idx++) {
byte curr = (*accs)(adr + idx);
Serial.write(curr < 0x20 || (suppHex >= 0 && curr == suppHex) ? '.' : curr);
}
Serial.write('\'');
Serial.println();
}
}
}
void dumpR(const void* adr, int len, const __FlashStringHelper* pfx) {
dumpGen((const byte*)adr, len, accRAM, pfx);
}
void dumpF(const void* adr, int len, const __FlashStringHelper* pfx) {
dumpGen((const byte*)adr, len, accPGM, pfx);
}
void dumpE(const void* adr, int len, const __FlashStringHelper* pfx) {
dumpGen((const byte*)adr, len, accEEPROM, pfx);
}
void phByte(byte value) {
if (value < 16) {
Serial.write('0');
}
Serial.print(value, HEX);
}
void phAdr(const byte* adr) {
phByte((byte)(((uint16_t)adr) >> 8));
phByte((uint16_t)adr);
Serial.write(':');
Serial.write(' ');
}