interrupts are not to be messed with
I came across an interesting bug while working with one of my students today. His AVR would continuously reset unless interrupts were switched off, but he needed them on for his project. This might seem pretty baffling (it was to me for a few minutes), but if you sit down and think about the code from an assembly perspective it should be obvious what was going on. Try and work it out!
————-
Not sure?
When compilers generate an interrupt table, they fill all of the unused vectors with something equivalent to
rjmp 0x0000 ; jump to reset vector
This protects the interrupt table from being filled with random data and causing random jumps (which can do bad things to your hardware). Unfortunately, if you enable interrupts and then trigger one without writing a handler (ie overriding this vector), you cause a chip reset. It turns out that the student had a timer interrupt firing very quickly and hadn’t written a handler for it.
Just goes to show that some assembly knowledge is useful, even for high level programmers.