I am having the weirdest problem with an array initialization, and nothing I've tried has solved it. I have a global uint8_t array declared and initialized at the same time like so:
uint8_t registers[] = { 0x00, 0xA0, 0x64, 0x32, 0x00, 0xA0, 0x64, 0x32, 0x00, 0xA0, 0x64, 0x32, 0x00, 0xA0, 0x64, 0x32, 0x00, 0x64, 0x32, 0x06, 0xE0, 0x06, 0xE0 };
And then later, I have a series of assignments and comparisons to translate bit fields into distinct control variables, like so:
void applyRegisterConfig() { redMode = registers[0x00] & 0x07; redInvert = registers[0x00] & 0x08; redBrightMin = registers[0x01] & 0x0F; redBrightMax = (registers[0x01] & 0xF0) >> 4; redPeriod = registers[0x02]; redSquare = registers[0x03] & 0x7F; . . . }
But the behavior is not as expected. The rest of the code does not modify either the registers array contents or any of the red... or other control variables, but for example redMode does not contain zero even though it is being assigned registers[0] & 0x07 (which should be zero as far as I can tell.
Further testing by direct comparison shows that this condition matches, and redMode is set to 1:
if (registers[0x00] == 255) { redMode = 1; }
This makes no sense at all to me. What would be causing the initialized variable to be 255 instead of 0? I'm using the ATTiny44, so I have ~4K of program space and I'm using a little more than half. The full code is available here for inspection:
https://github.com/jrowberg/keyglove/blob/master/module_code/kgm_feedback/kgm_feedback.c
It's an ATTiny44-powered I2C slave for a unique RGB/vibe/piezo feedback module. This is the only roadblock I've come across so far, but I can't figure it out for anything.