Page 1 of 1

how to set up interrupt vector programmatically

Posted: Fri Jan 25, 2008 6:00 pm
by MaxAnarki
how to set up interrupt vector programmatically ?

for example, it is easy to define interrupt vector at the compile time like this, using winavr lib:

ISR(INT0_vect)
{
}

but I need select INT0_vect or INT1_vect... etc programmatically, depending on some conditions..

What is the easiest way ?

Thanks a lot

Posted: Tue Jan 29, 2008 1:07 pm
by christian
Since the interrupt vector is in flash memory, it's hard to modify it from your code. I would recommend that you define ISRs for INT0 AND INT1 and call your routine from either one.

Posted: Tue Jan 29, 2008 1:42 pm
by MaxAnarki
If disengage from that problem and use winavr lib's functions for writing to flash memory, how to write in C lang correct piece of code to define interrupt handler and how to correctly program vector table ?

Posted: Tue Jan 29, 2008 1:49 pm
by christian
The vector table consists of relative jump instructions. You must compute the correct rjmp instruction and write it to the vector table slot.

Please note that flash memory can only be programmed page-wise. You must read the entire page, modify the vector and write back the page. Also, some AVRs require that you run code which modifies the main flash memory from the boot loader section. And finally: While programming the flash memory, the CPU may be halted.

Posted: Tue Jan 29, 2008 2:12 pm
by MaxAnarki
As I understand the CPU during working uses RAM. Vector table is loaded from flash to RAM isn't it ? It is convenient to me to modify the RAM only after my software is started.

Posted: Tue Jan 29, 2008 7:34 pm
by christian
This is not correct. The vector table is in flash memory.