Em 20/02/2014 12:49, Mike snyder escreveu: > Hi Isacc, > > Thanks for the info - looks like the switching time is pretty short so it > should work - I will work on trying this out.. (to your point it definite= ly > looks like it would simplify the code significantly...) > > To answer your questions > > Do you use interrupts on the RX pin? > > No interrupts in use today on RX pin but I agree it would make sense to > move to an interrupt based scheme for the RX routine... Perhaps you know already the method of doing bit-banged UART with interrupts but I will explain here for the benefit of others that may not know it: Reception: 1) Set an interrupt on the falling edge of RXD pin; 2) In the RXD interrupt handler: a) Set a timer to overflow in exactly half a bit time and enable its interrupt; b) Disable the RXD pin interrupt; c) Set a global bit counter to zero; d) Return; 3) In the timer interrupt handler: a) Sample the pin and save its value; b) Reprogram the timer to overflow in exactly one bit time; c) If the bit counter is zero: i) Check whether the received bit is a valid start bit (logic level zero) - If not, it was a glitch, disable the timer and its interrupt and re-enable the RXD pin interrupt; - if yes, increment the bit counter ii) Return; d) If the bit counter is between one and eight: i) Shift the bit to a static variable; ii) Increment the bit counter; ii) Return; e) If the bit counter is nine: =20 i) Check whether the bit is a valid stop bit (logic level one) - If not, re-enable RXD pin interrupt; - If yes, save the byte; ii) Zero the bit counter; iii) Disable the timer interrupt; iv) Re-enable the RXD pin interrupt; v) Return. Transmission is much simpler, just set-up a timer to overflow in exactly a bit time and shift the bits out on each timer interrupt. =20 > What is the baud-rate? > > Its an odd baud rate 20600 bps At this rate,, using interrupts a PIC32 running at 40MHz should spend 5 to 10% of CPU time in the UART routines. Perhaps less if you write them in assembly. I think it is perfectly doable and you still have almost 90% of CPU time for the rest of the application. > What is the processor? > > PIC32 That's great, because the PIC32 port of my SimpleRTOS is the most stable, you could start using it right away. Best regards, Isaac --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .