I've been pulling my hair out trying to figure out why my code just isn't working. ATMEGA2560
Finally I think I've tracked it down to the following issue.
It all goes wrong when I set an interrupt in the code:
UCSR0B |= (1<<UDRIE0); // Enable USART data register empty interrupt
In the simulator I have a breakpoint set in the associated ISR but the code never got there. Instead the code went right back to the beginning (I mean the very beginning).
Single stepping through the disassembly I was shocked to find what happened. After the above instruction that sets the interrupt, the code jumped to this:
00000034 JMP 0x00000000
00000034 is the correct vector address for the interrupt but then it's redirecting the program counter to RESET.
Any idea what could be causing this. The code was compiled with Codevision in Atmel Studio 7.
I found something interesting when I looked in on of the generated files. The next interrupt vector (00000036) has the jump address for my ISR:
00000034 JMP 0x00000000 Jump 00000036 JMP 0x0000024E Jump
My ISR is located at address 0x0000024E which is jumped to by vector 36, but that is the vector for Tx Complete, not UDR empty.
OK, sorted my own problem. I had something wrong in the ISR name. Made a little change and vector 0x34 now jumps to my ISR.