PDA

View Full Version : Half Duplex Serial I/O


tom@origtech.com
08-20-2008, 03:30 PM
I am trying to develop a Snappy script file to support half duplex on one of the UARTs. (Where I will either transmit or receive but not both simultaneously. The unit will control a spare I/O pin to indicate if it is transmitting or receiving) I've looked at the multidrop scripts and have a basic understanding of how to transfer serial data from a master node to a slave node, but I have a few questions.

1. How do I make characters received over the air cause HOOK_STDIN event? As I receive characters I want to exam them and send them to the output UART. In this application I only want to use the switchboard function in one direction.

2. How do I examine the transmit buffer of a UART? I need to know when the transmit buffer is empty (not the transmit holding register but the output buffer) so I can know when the last bit of the last byte has been sent by the UART. Is it possible to get a hook function when the transmit buffer is empty?

3. Currently there is a hook function for 100mS timer interrupt. How can I get a hook function on a 1mS timer interrupt?

Thanks,
Tom

kbanks
08-21-2008, 09:36 AM
1. How do I make characters received over the air cause HOOK_STDIN event? As I receive characters I want to exam them and send them to the output UART. In this application I only want to use the switchboard function in one direction.

Because you want to examine the characters, as well as forward them, you need to pass the characters to the node using an RPC call. Define a function in your SNAPpy script that takes a string, looks at it, and then decides what to do with it.

For the function to be able to send the data on to the UART, you will need to connect STDOUT to the UART, and use the print statement.

This is how we have done this sort of the thing in the past. It may also be possible to use uniConnect()s in the correct combination to do what you want, but I have never tried it.

2. How do I examine the transmit buffer of a UART? I need to know when the transmit buffer is empty (not the transmit holding register but the output buffer) so I can know when the last bit of the last byte has been sent by the UART. Is it possible to get a hook function when the transmit buffer is empty?

There is no HOOK function for this. You will have to peek() at the register directly.

Depending on which register you want, you need to check the SCI1S1 (address 0x001C) or SCI2S1 (address 0x0024) register.

The bit in the register you are interested in is the 0x40 bit, which is a 0 when data is still being shifted out, and a 1 when transmission is really complete.

(Bit 0x80 is the holding register flag, and = 1 when the holding register is empty. You are correct, this bit alone does not mean the last character has made it all the way out, and you want to check the 0x40 bit instead).

These are described near page 179 of the MC9S08GB60A Data Sheet, available elsewhere on this forum.

For examples of using peek() to directly read processor registers like this, take a look at pinWakeup.py (comes with Portal) and PWM.py (elsewhere on this forum).

3. Currently there is a hook function for 100mS timer interrupt. How can I get a hook function on a 1mS timer interrupt?


HOOK_100MS is the only timer hook available. I do not know if a SNAPpy script could keep up with events happening 1000 times per second (maybe if you were doing very little processing per event).

I have heard of people using the PWM capability (GPIO0) to drive another input pin (using the monitorPin() capability). This lets them "cheat" and get faster timebases. If you do this, you will be handling the HOOK_GPIN event, not the HOOK_100MS event.

Note that the monitorPin() sampling rate is controlled by the setRate() function, which takes values of 0=off, 1=100 ms sampling, 2 = 10 ms sampling, and 3 = 1 ms sampling.

Again, whether or not such an approach would work for you depends on how much processing you are trying to do per "tick".