View previous topic :: View next topic |
Author |
Message |
pavelustinov
Joined: 09 Mar 2013 Posts: 20
|
Main function knows, if it was an interrupt |
Posted: Fri Apr 12, 2013 6:23 am |
|
|
Hello everybody!
I use interrupt in my program like this
Code: | #INT_EXT
void ext_isr(void)
{
}
void main()
{
} |
In interrupt function I save settings to EEPROM.
How can main function know, if it was an interrupt?
Main function must read settings from EEPROM once, because read it every second is a bad idea.
Maybe something like a global variable? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Apr 12, 2013 8:07 am |
|
|
Code: |
int1 flag=0; //gobal inited to zero
#INT_EXT
void ext_isr(void)
{
flag=1;
}
void main()
{
if (flag) { write_eeprom(whatever); flag=0; }
}
|
NEVER write_eeprom inside an ISR - takes too much time
Last edited by asmboy on Fri Apr 12, 2013 11:21 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Apr 12, 2013 8:09 am |
|
|
general comment...
normally, you'll set a 'flag' within the ISR to tell 'main' that an 'action' has been done (if done within the ISR), or to be done by 'main'.
common practice is to just set 'flags', maybe write a byte or read 'registers' inside the ISR. Never try to do printf(...), math operations, etc. inside the ISR.
ISRs need to be small and fast! Let 'main' look at the flags and act accordingly.
hth
jay |
|
|
|