So...
This has been bugging me (hah) for a WHILE.
And it has been super annoying to deal with.
I am using an ATTiny 1627, Arduino IDE 2.0 rc9 (this happens across various RCs), the latest megaTinyCore 2.5.11.
I have no idea if the issue is with Arduino IDE, megaTinyCore, or somewhere else.
I used to encounter issues like that as well still using Arduinos, so I assume it is not megaTinyCore, or the bug is copied over if it is used in the same serial stuff.
Bug:
If you use the serial output with anything beyond 16 bits, you're in for a treat.
Mind you, "value" and "data" are being declared earlier in the code as an "unsigned long" (32 bits).
#ifdef DEBUG
Serial.println(data, BIN);
Serial.flush();
//Output: 11111111111111111100000100100101
for(int i = 31; i >= 0; i--)
{
if(bytesRaw[i])
{
Serial.print("1");
}
else
{
Serial.print("0");
}
}
Serial.println();
Serial.flush();
//Output: 00000000000100101100000100100101
#endif
How the variables are populated:
bool bit = analogRead(PINCALDATA) > 50;
[...]
if(bit)
{
value |= (1 << bytePos);
}
bytesRaw[bytePos] = bit;
bytePos++;
if(bytePos == 24)
{
data = value;
value = 0;
bytePos = 0;
[Resetting stuff etc...]
I have zero idea what is going on here. But you can imagine my surprise trying to debug a piece of code where bits are set to 1 which I am actually not setting in the code (as my bytePos limit is at 24).
Yes, value is reset to "0" during that reset phase.
I have had this with other code snippets doing similar things.
The serial output will just screw me over, and I don't know why.
Again, zero idea what is going on here, but I am merely leaving this here in case someone has the same issue, starts to question his or her sanity, and then stumbles upon this.
That said, I have no idea where this topic is best put. So please move this however you see fit.