Sunday 19 February 2012

RS232

Over the last couple of days I have been reading up on RS232. My idea is to add RS232 support to my kiln controller so it can 'talk to'a PC. It seems fairly easy to implement a simple version in which it uses only the basic Rx Tx lines to transfer data.

As always I like to try and understand the thing I'm working on so I'm not going to use any built-in UART on the PIC, and instead do all the work in code.

I'm going to use 9600 baud rate and this will be fixed in my hardware. According to the specs this means that data has to be sent at 104 uS per bit. So one of the key tasks I needed to do was to setup my timing. Luckily my Ebay digital scope came in very handy to do the measurements. What I did was I created some PIC code to output a single byte to one of the PIC output pins and repeat forever. This allowed me to measure with my scope to see how far off my timings were. The format for the data is 10 bits, starting with a start bit followed by 8 data bits then finally a stop bit.


A little sketch of what I wanted to achieve.





Controller running and hooked up to my digital scope.



The picture below shows the output levels. Using the scope markers it showed me the timing was slightly longer for each bit than I really wanted. After sending 10 bits the 10th bit was approx 36 uS off  (988 uS instead of 1024 uS) but if the receiving device started sampling at the fixed period of 104 uS after the initial 52 uS offset, the data, I'm guessing would actually pass without error; But when I come to add the final code to send data  I'll need to make sure the timing is a little more closer to the specs but for this experiment everything went very well!




No comments:

Post a Comment