2.2 Calibration Protocol

The basic concept is that the programming tool generates the calibration clock (C-clock) and the device uses this as a reference to calibrate its internal RC oscillator. When the device has completed the calibration it signals “OK” to the tool on the TDO line.

Prior to initiating the calibration, the exact frequency of the calibration clock signal must be measured and provided to the calibration firmware. The signal should have a nominal frequency of approximately 32 kHz.

The XMEGA device should enable its internal pull-up resistor on the TDI line, and the programming tool should enable a pull-up resistor on the TDO line. Unfortunately, the programming tool is in many cases behind level converters, so the device should set the TDO line high to ensure that noise is unlikely to corrupt the calibration.

The calibration procedure consists of the following steps:

  1. The tool writes the calibration firmware into the device and releases the Reset line.
  2. The JTAG disable bit in the MCUCSR register on the device is written to one.
  3. The calibration clock is applied on the TDI line by the programming tool.
  4. When the device detects the calibration clock, a binary search is used to find an RC32KCAL value that meets the accuracy criterion. If calibration fails, the TDO line is set low and program flow goes to step 7.
  5. The oscillator calibration bytes are written to EEPROM.
  6. TDO line is toggled 8 times/4 cycles by the device. The toggling of the TDO line is performed on the falling edge of the clock on the TDI line (C-clock), but 5 to 10 CPU cycles delayed.
  7. JTAG interface is re-enabled and the device goes into an infinite loop.
  8. If the device does not have an EESAVE fuse, the tool must read back the calibration bytes from EEPROM, for later restoring when the calibration firmware has been erased from the Flash. If the device have an EESAVE fuse, this fuse can be set so that erasing the Flash does not also erase the EEPROM.
Note: Please note that it is necessary to copy the calibration byte from EEPROM or FLASH to the calibration register at run-time. A routine for this must therefore be implemented in the final firmware.