PDA

View Full Version : Writing my own serial reciever



kt88seamp
12-27-2009, 03:48 AM
I am attempting to write my own Dull Duplex Serial. I know one exists in the object exchange but I just want to see if I can do it. Meanwhile what I wrote is not working. I think its the baudrate part. Right now the code only expects one byte so I put in nothing to compensate for the stop bit. It communicates at 9600 baud. If only spin had a debugger I would be able to see exactly what is going on!





ina[15]~ 'Make pin an input
wait := clkfreq / 9600 'Set bit timing

repeat while ina[15] <> 1 'Wait for start bit.
waitcnt(wait + cnt) 'Wait for first bit.
repeat 8 'Read in each bit
buffer <<= ina[15]
waitcnt(wait + cnt) 'Next bit

Mike Green
12-27-2009, 03:58 AM
There are several debuggers you can use with Spin including ViewPort.

You don't make a pin an input by doing "ina[15]~". I/O pins are inputs by default, but you can change an output pin to an input pin by clearing the corresponding bit in DIRA to zero.

You're waiting for the leading edge of the start bit and using that as a reference for the first data bit. What you need to do is wait for 1 1/2 bit times from the leading edge of the start bit. This'll put you in the middle of the first data bit. After that, you wait one bit time for each additional data bit.

The data bits come in LSB first. You're not shifting them in properly. Look at the description of "<<=" and "<<" in the Propeller Manual.

Best is to use working code as an example. Start with understanding something like Simple_Serial from the Object Exchange.