slightly faster Simple_Serial
lonesock
Posts: 917
Hi, All.
OK, this won't be of too much use to most people, but I noticed that the simple_serial.spin code wasn't overly efficient in the actual sending and receiving of bits. I re-worked it a little, saved a few longs, but most importantly on an 80 MHz system, the speed limit used to be 19200 bps. With the reworked version I can do 31250 bps (but not 38400) on the same system.
Here are the relevant bits:
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
OK, this won't be of too much use to most people, but I noticed that the simple_serial.spin code wasn't overly efficient in the actual sending and receiving of bits. I re-worked it a little, saved a few longs, but most importantly on an 80 MHz system, the speed limit used to be 19200 bps. With the reworked version I can do 31250 bps (but not 38400) on the same system.
Here are the relevant bits:
PUB rx: rxByte | t {{ Receive a byte; blocks caller until byte received. }} if rxOkay dira[noparse][[/noparse]sin]~ ' make rx pin an input t := bitTime >> 1 ' 1/2 a bit waitpeq(inverted & |< sin, |< sin, 0) ' wait for start bit t += cnt ' sync + 1/2 bit repeat 8 waitcnt(t += bitTime) ' wait for middle of bit rxByte += ina[noparse][[/noparse]sin] + rxByte ' sample bit waitcnt(t + bitTime) ' allow for stop bit rxByte := (rxByte >< 8) ^ inverted ' adjust for mode and strip off high bits PUB tx(txByte) | t {{ Transmit a byte; blocks caller until byte transmitted. }} if txOkay txByte := ((txByte | $100) << 2) ^ inverted ' add stop bit, set mode outa[noparse][[/noparse]sout] := !inverted ' set idle state t := cnt ' sync dira[noparse][[/noparse]sout]~~ ' make tx pin an output repeat 10 ' start + eight data bits + stop waitcnt(t += bitTime) ' wait bit time outa[noparse][[/noparse]sout] := (txByte >>= 1) ' output bit (true mode) dira[noparse][[/noparse]sout] := sout <> sin ' release to pull-up/pull-down
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
thanks,
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.