Writing my own serial reciever
kt88seamp
Posts: 112
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[noparse][[/noparse]15]~ 'Make pin an input wait := clkfreq / 9600 'Set bit timing repeat while ina[noparse][[/noparse]15] <> 1 'Wait for start bit. waitcnt(wait + cnt) 'Wait for first bit. repeat 8 'Read in each bit buffer <<= ina[noparse][[/noparse]15] waitcnt(wait + cnt) 'Next bit
Comments
You don't make a pin an input by doing "ina[noparse][[/noparse]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.