Ok, I'm getting crashes that SEEM to be interrupt related. Without posting a pile of code, it is difficult to even know what to ask here, but I'll try. I'm willing to post everything, but that seems excessive.
Ok, here's the hardware. ATMega1284P running at 8 Mhz. AVR Dragon using JTAG
I'm building up the user interface for my project, and at the moment, it is all that is coded.
I have one rotary encoder using INT0 and INT1.
I have 7 push-buttons (including the one in the encoder) running into a 74HC165 shift register. The I/0 for the shift register is on Port D. I only mention the Port because INT0 and INT1 are also on Port D, in case by some wierd chance that is relevant to my trouble. The state of these buttons is retrieved by polling. On each iteration through the main() while loop, I run the code for the shift register, and return a byte with the button states.
I have an HD44780 type LCD running off an I2C expander. The I2C code, and LCD code is all my own.
In its current form, if working properly, the encoder should cycle through the alphabet and write the current character on the screen
The buttons should write the name of the button at a unique portion of the screen respective to each button. This is all just to test the functionality of the input system.
Ok, I did the encoder code first. It runs flawlessly on its own.
I did the push-button code next. It runs flawlessly with interrupts disabled.
If I try and have everything enabled, I get one of two results (usually)
If I don't touch the encoder, the buttons work fine. Until I turn the encoder. Then either the encoder works, but not the buttons, or everything locks up completely.
If I tun the encoder first, again, either it works, or crashes, but the buttons don't work.
So it seems that when the first interrupt is triggered, that's when things go awry.
Every variable that the ISRs reference are volatile (I think. I'm open to having missed something at this point).
Ok, here is maybe a clue. If I debug, with no breakpoints, literally every time I pause the session, it pauses in my I2C function who's sole purpose is to wait for the TWINT flag to clear. The only I2C device i'm using is the I/O expander for the LCD. Granted, since there is a screen update of some kind every while(1) iteration, and since most of my LCD functions will trigger multiple calls to this wait function, I'd expect my app to spend alot of time there.
But it never pauses anywhere else. Ever. So I'm wondering if somehow the TWCR register is being corrupted when I use interrupts.
Use of compiler optimization one way or the other seems to not matter.
I'm completely stumped here.
<edit>
Forgot to mention. I tried disabling interrupts just when the Wait for TWINT function to is running. No dice.