UDP receiving packets inside TImer Routine

G'Day all,

I am trying to use a 10second timer routine to issue an NTP request and then check 10seconds later for a received packet and process it.

I want to sned the request and check in the same timer routine which I will expand out later. If the packet has been received I then flag for a resend on the next timer function call.

However the code hangs after the first tx of the NTP packet! Does UDP calls work inside a simple timer routine?


Does UDP calls work inside a simple timer routine?


edit: Conditionally on your code and hardware, but since you shared neither with us, it is difficult to tell. If you have a memory card in the microSD slot, remove it for the test. How does the UdpNtpClient code in the ethernet examples work?

More info....

  • IDE is v1.0
  • board is standard Duemilanova
  • code is NTP demo code which works fine outside of timer routine
  • Timer library is MSTimer2 from Aduino web site
  • Enternet board is off the shelf Wiznet with NO SD fitted


I left the code running overnight with the UDP code commented out and a 1second timer tick, lots of serial debugging, code is ticking over every second. To reduce SRAM usage comments are using the Serial.println(F("comment")); so I cant see a RAM issue. Timer code works with no perceived issues.

NTP code works fine outside of timer routine as per NTP example, but I'm trying to schedule stuff to do based on fixed time quantums so running full speed in a loop is not ideal for the task at hand, I might change the logic to use the timer solely as a counter and then simple state logic to send UDP requests and monitor receives outside of the timer ISR and inside loop().

Any thoughts on issues that might arise are welcome, I'll Keep you updated.

Is teh timer routine you refer to an interupt? I just wondered as receiving an ethnet packet presumably uses an interupt, and therefore are you trying to interupt during an interupt which doesn't work and just loses everything?

Only a suggestion/guess as I have seen references to not using serial print commands in interupt routines.


IDE v1.0 had a bug in the ethernet library that caused problems. May I suggest upgrading to v1.0.1.

BTW, the ethernet library does not use an interrupt. It is a polling type device.