I am trying to interface the GPS module with my ARM board. GPS sends RS232 signals from its single pin (say pin Z).
I want to use the watchdog timer for receiving and parsing the serial stream. Any idea of using watchdog in this context?
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.Sign up to join this community
You probably want to use an ordinary timer interrupt and sample at perhaps 8 times the baud rate though four times might possibly work (in hardware implementations 16x is common, but I've personally done it at 8x).
Most processors of modern clock speed should be able to fire an interrupt that fast, at least if your code in the ISR is efficient and you don't have much else interrupt-driven running.
You will probably want to run a state machine, advancing one state on each interrupt. Basically you look for the start bit transition and then read each data bit an appropriate number of oversampled cycles later. There are lots of implementations of this for FPGAs in verilog or VHDL floating around the net, translating back to assembly or C should not be difficult.
However, as you can likely reprogram your timers and interrupt modes quickly, there is another option for optimization: You could start out by having an edge sensitive interrupt on the input pin. When that fires, you then program a timer interrupt to generate delays of precisely a bit period (not oversampled), and simply read out the state on each interrupt. When the word is concluded, re-arm the edge interrupt.
But there is a catch with this optimized method: because you are only "paying attention" at the important times, you have to work harder to make sure that the initial transition is a start bit, and that you aren't catching some data word in mid-flight when your code starts up. Probably you want to do this by using your edge interrupt to make sure that the input has been in a quiescent state long enough (long enough since the last interrupt) - if it hasn't, discard what your get and wait for a clean character.
Some googling on "UART state machine" or the like would be informative. There's always the chance you will find reference code for your particular processor, particularly if it has no hardware UART or only one.
Another possibly applicable method is to use an external circuit to select one of the two input sources and feed the signal to the UART.
For this to be appropriate you need to know when you're expecting data so that you can switch to the appropriate device.
Another option is to add an external UART and receive data from that. It's kinda hard to be more specific without knowing more of the platform available.