Electronic – How to calibrate an AVR’s RC oscillator using the UART

avruart

I would like to set my AVR's OSCCAL for proper RS-232 communication using the other end's transmission as the calibration clock, without having to solder the RX pin to a timer pin. Is there firmware to do this?


edit
I wound up writing my own synchronization routine and soldering the RX pin to the ICP (input capture) unit. When the ICP pin changes, TIMER1's value is copied into a register and an interrupt fires.

The code uses an ADCPM-inspired search technique. OSCCAL is incremented or decremented by 1 initially. Each time OSCCAL needs to move in the same direction again it moves twice as far, when it switches direction it starts over at 1. http://code.google.com/p/pwmsign/source/browse/synch.c

All that trouble, and I discovered the perfect OSCCAL was only 1 off from the factory setting.

Best Answer

Clearly I'm looking for the Atmel-provided datasheet, AVR054: Run-time calibration of the internal RC oscillator. I think it could be adapted to PC-to-AVR communication without too much trouble...