Can we execute a funtion inside timer1 isr by disabling and enabling it.

Dear guru’s,

Hardware used
cpu =mega2560 R3
ide =arduino
pheripheral= w5100 shield
sensors dht22

project details:- Hobby project temperature/humidity logger

I am checking for ethernet clients continuously inside timer1_isr. I have set the timer1 in Overflow capture interrupt mode for 2 sec ovf period. I disable the timer1_isr before processing the client’s and then re_enabling the isr using defined macros.

#define enable_timer1     TIMSK1 |=  (1 << OCIE1A); TCNT1=0;
#define disable_timer1    TIMSK1 &= ~(1 << OCIE1A); TCNT1=0;

void scan_clients()
{
  disabling timer1_interrupt;
  checking_ethernet clients request and processing request;
  enabling_timer1_interupt;
}

isr_timer1(ovf)
{
scan_clients();

}
loop()
{
  i2c_display ();
delay(2000);
}

I need your expert answers on whether we can execute a function inside timer1 16bit by disabling the the timer1 _isr and executing the code and then re-enabling the timer_isr;

Problem is sometimes loop () code just hangs but timer1_isr keeps working

When in an ISR, interrupts are disabled (so not sure what you depend on for client detection) and you should not do anything that takes a long time

Why don’t you just check for clients in the main loop and get rid of the delay ?

[quotes]When in an ISR, interrupts are disabled (so not sure what you depend on for client detection) and you should not do anything that takes a long time

Why don't you just check for clients in the main loop and get rid of the delay ?[/quotes]

Ok. thanks for your reply.

cleared ....