Shop OBEX P1 Docs P2 Docs Learn Events
Rxtime using SimpleSerial — Parallax Forums

Rxtime using SimpleSerial

M. K. BorriM. K. Borri Posts: 279
edited 2007-04-16 15:46 in Propeller 1
'' Only works at 9600bps and below
'' still better than nothing [noparse]:)[/noparse]

PUB rxtime(timeout) | t, b, timer

t~
b~
timer~

'' Receive a byte; blocks program until byte received
if started
' dira[noparse][[/noparse]sin]~ ' make rx pin an input

if (timeout == -1)
waitpeq(inverted & |< sin, |< sin, 0)
{
if (inverted)
repeat
while ina[noparse][[/noparse]sin] == 0
else
repeat
while ina[noparse][[/noparse]sin] == 1
}

else
if (inverted)
repeat
if (++timer == timeout)
return -1
while ina[noparse][[/noparse]sin] == 0
else
repeat
if (++timer == timeout)
return -1
while ina[noparse][[/noparse]sin] == 1
t := cnt + bitTime >> 1 ' sync + 1/2 bit
repeat 8
waitcnt(t += bitTime) ' wait for middle of bit
b := ina[noparse][[/noparse]sin] << 7 | b >> 1 ' sample bit
waitcnt(t + bitTime) ' allow for stop bit

return (b ^ inverted) & $FF ' adjust for mode and strip off high bits
Sign In or Register to comment.