Does anyone have some well doccumented code for receiving serial data
and sending serial data at the same time? I am working on a project
that needs to receive a 4800 baud data stream and send a different 4800
baud data streem at the same time. I will also have a project in the
future that will need to input a couple of serial channels and output a
couple channels at the same time. There is an app note on this in the
Microchip databooks, but I have had a hard time following it and
adapting it to my needs.

I will probably use a chip with a UART, but it would be nice to know how
to bit bang a solution also since there is only one UART available on
PICs.

At 07:12 AM 2/1/00 -0500, you wrote:
>Does anyone have some well doccumented code for receiving serial data
>and sending serial data at the same time? I am working on a project
>that needs to receive a 4800 baud data stream and send a different 4800
>baud data streem at the same time. I will also have a project in the
>future that will need to input a couple of serial channels and output a
>couple channels at the same time. There is an app note on this in the
>Microchip databooks, but I have had a hard time following it and
>adapting it to my needs.
>
>I will probably use a chip with a UART, but it would be nice to know how
>to bit bang a solution also since there is only one UART available on
>PICs.

Your best hope here is using the interrupt feature of the UART on received
bytes. Basically you write your int routine to buffer bytes in a circular
buffer as they come in. In the pauses when you are waiting for bytes to be
sent and in times when there is no outgoing you can loop and handle
incoming bytes.

You could do some type of state machine implementation and bit bang things,
but this gets much more complex. Basically I would use one of your
counters as a reference and have background processes that are guaranteed
to be called in your code at least every bit time. With interbit timing of
208uS at 4800 baud this could be potentially sticky depending on what you
are doing in the background. Its doable, but I'd avoid it. You can find
bit-banged uarts around on the web, I'm sure. Most compilers come with an
example, and I believe there is one on the Mchip website.

At 4800 bps on a 4MHz PIC you will have about 2ms to do stuff while you are
sending and receiving.

I'm not real sure of the utility of the sent byte interrupt, but if you're
clever there might be some good use for that... anyone?

Erik, I've done bit banging, dual uarts on a 16C74a (didn't even use the
internal uart) at 9600 baud send/receive/buffer, on both lines. The unit
was basically a Rs232-485 converter with about 150 characters of buffering.

My approach was to interupt every 36 useconds (20MHz crytal) and follow a
specific routine so that the timing was always exact. Since all of the
communications were done by bit-banging I used a 2 out of 3 majority wins
scheme. I am adding more features to this unit and will not bit-bang for
this application anymore. There simply wasn't enough time by the time
everything was finished.

> Your best hope here is using the interrupt feature of the UART on received
> bytes. Basically you write your int routine to buffer bytes in a circular
> buffer as they come in. In the pauses when you are waiting for
> bytes to be
> sent and in times when there is no outgoing you can loop and handle
> incoming bytes.
>
> You could do some type of state machine implementation and bit
> bang things,
> but this gets much more complex. Basically I would use one of your
> counters as a reference and have background processes that are guaranteed
> to be called in your code at least every bit time. With interbit
> timing of
> 208uS at 4800 baud this could be potentially sticky depending on what you
> are doing in the background. Its doable, but I'd avoid it. You can find
> bit-banged uarts around on the web, I'm sure. Most compilers come with an
> example, and I believe there is one on the Mchip website.
>
> At 4800 bps on a 4MHz PIC you will have about 2ms to do stuff
> while you are
> sending and receiving.
>
> I'm not real sure of the utility of the sent byte interrupt, but if you're
> clever there might be some good use for that... anyone?
>
> psuedo code for the use of a UART looks like this :
>
> receive_byte_interrupt
> {
> buffer_incoming_data(); /* size your buffer based on processing
> requirements */
> clear_interrupt();
> }
>
> main()
> {
> while(TRUE)
> {
> if (bytes_to_be_sent && last_byte_is_gone)
> give_uart_a_byte();
>
> if (there_are_incoming_bytes)
> handle_some_number_of_incoming_bytes();
> /*number of bytes */
>
> /* is based on your */
> /* real
> time budget of 2mS */
> }
> }
>
> Erik Reikes
> Software Engineer
> Xsilogy, Inc.
>
> .....ereikesKILLspam@spam@xsilogy.com
> ph : (858) 535-5113
> fax : (858) 535-5163
> cell : (858) 663-1206
>