[CCC DEV] Software serial question

Adam Sampson ats at offog.org
Wed Jun 16 17:42:50 BST 2010


Matt Jadud <jadudm at gmail.com> writes:

> There's a few changes in ffi.c (specifically, the C-side of the
> software serial call). I'm getting... mangled results, and wondered if
> anyone could take a look.

I would suggest applying an oscilloscope to the problem at this point --
you can compare the serial waveform you're generating with the nice
clean one the AVR produces, and check that the timings are correct.

The timings will certainly be a bit off because your bit timings will
actually be _delay_us plus however long the code between the delays will
take (which will vary). I'm also not sure offhand of how accurate
_delay_us is; I think it's fairly approximate anyway. Rather than using
software delays, I'd suggest setting up one of the AVR's timers to tick
at (some multiple of) the serial bit rate, and shifting out a bit in the
interrupt handler -- assuming you can find a spare timer!

An alternative is to write some assembler code to do it -- it'll only be
a few instructions, and then you can count cycles to get the delays
exact. There's some similar code in my AVR-based frequency counter that
you could crib from:
  http://offog.org/darcs/misccode/avr/freqcount.c

-- 
Adam Sampson <ats at offog.org>                         <http://offog.org/>




More information about the developers mailing list