Ok here is a working code without unions and stuff. Corrected some things and it works as it should:
void ReadData(long Start, long Stop) {
char result[3];
word counter = 0;
long address;
byte str5;
union ByteToLong addr;
byte str1 = (Start & 0x0F);
byte str2 = (Start & 0xF0) >> 4;
byte str3 = (Start & 0xF00) >> 8;
//byte str4 = (Start & 0xF000) >> 12;
byte str4 = (Start >> 12) & 0x0F;
if (Start & 0xF0000) {
//str5 = (Start & 0xF0000) >> 16;
str5 = (Start >> 16) & 0x0F;
}
else {
str5 = 0x00;
}
for (byte a = str5; a <= 0x0F; a++) {
for (byte b = str4; b <= 0x0F; b++) {
for (byte c = str3; c <= 0x0F; c++) {
for (byte d = str2; d <= 0x0F; d++) {
for (byte e = str1; e <= 0x0F; e+=2) {
counter++;
address = ((unsigned long) a << 16) | ((unsigned long) b << 12) | (c << 8) | (d << 4) | e;
//sprintf(result, "%04X",(char*) GetWord(address));
print_hex(GetWord(address), 16);
if (counter == ((Stop - Start)/2)) goto out;
}
Serial.println();
}
}
}
}
out:
Serial.println();
return;
}
The only problem is the leading "0" in hex numbers. I read words and where there is a 0 like a 081F it displays like 81F! Any work around this? print_hex() is really slow on that! Something faster would be great!
Thanx guys