MAX_CLOCK_ERROR vs. better xtal?

Boards with 8-bit 8MHz AVR MCU like ATmega328 and ATmega32u4 normally require LMIC MAX_CLOCK_ERROR to be set to a value higher than 0.
Some of these boards are Arduino Pro Mini and Adafruit/BSFrance LoRa32u4.

My assumption was that this is related to the relatively low clock speed (combined with 8-bit architecture) but maybe a resonator could play a role here as well.

There are two popular makes of Arduino Pro Mini available on AliExpress:

  • The Simple (blue PCB) uses a resonator.
  • RobotDyn (black PCB) uses a crystal.

It would be interesting to test if the RobotDyn can work with a lower MAX_CLOCK_ERROR than The Simple.

What also plays a role if setting MAX_CLOCK_ERROR (and what value) is needed is how fast or slow events are handled in the OnEvent() event handler. This is relevant also for faster 32-bit MCU’s.

While the event handler code should be as short and fast as possible, the Arduino framework does not provide simple alternatives like multitasking to spin off longer running tasks, where the OS can schedule different tasks based on their priority (to prevent that longer running code impacts proper LMIC timing).
So if event handler code takes longer time to do its work (e.g. printing to serial port), it may be necessary to set/increase MAX_CLOCK_ERROR or else receive windows could be missed causing failure of downlinks (including joins).

1 Like