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?

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.

  • \$\begingroup\$ If you give me a link to the associated docs, I should be able to take a look tomorrow and help out. \$\endgroup\$ – Kortuk Jun 16 '10 at 22:24
  • \$\begingroup\$ what do you mean by 'proper UART communication'? you don't need clock synchronization between the AVR and the other end of the UART to make it work. I guess maybe if your bit banging the UART on the AVR end which i find unlikely. \$\endgroup\$ – Mark Jun 17 '10 at 3:12
  • \$\begingroup\$ @Mark I mean the TX clock of the AVR has to match the RX clock of the PC within a few % and vice versa, not guaranteed without an XTAL. \$\endgroup\$ – joeforker Jun 17 '10 at 15:21

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...

  • 1
    \$\begingroup\$ Why is this an answer? \$\endgroup\$ – Kortuk Jun 17 '10 at 17:29
  • \$\begingroup\$ I am using an ATtiny2313 which does not have e.g. a PCINTn on the RX pin. So I think the answer is to use AVR054 and go ahead and solder RX to INT0. \$\endgroup\$ – joeforker Jun 17 '10 at 20:19
  • \$\begingroup\$ No, I think you are miss-understanding. \$\endgroup\$ – Kortuk Jun 18 '10 at 3:47
  • \$\begingroup\$ @Kortuk I would be very happy to get another answer, but my answer to my own question is 'go ahead and solder two pins together and use AVR054'. \$\endgroup\$ – joeforker Jun 18 '10 at 12:55
  • \$\begingroup\$ I was asking for links to your datasheet. I will write and answer when I confirm I am not misunderstanding. I do not think you need the cal feature at all. \$\endgroup\$ – Kortuk Jun 27 '10 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.