circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

Issue 156 July 2003
Build a Coyote Protocol Converter


RS-232 TO RS-485

I’m on a roll. So, let’s move on to converting the RS-232 and RS-485 serial streams.
You can make this as complicated as you want, however, I refuse to breed complexity. Again, using constructs from here and there, I pieced together some code that turns the Coyote into a serial pipe. RS-232 in yields RS-485 out, and vice versa. All of the code in Listing 3 uses the services of the standard Rabbit 3000 RS-232 library. The RS-232 function calls allow me to sit and wait for incoming data from either serial port, and redirect the incoming serial data to an opposite outgoing serial port. Simple yet effective. “Splash three.”

 CLOCKED COYOTE

I returned to the Z-World web site to see if I could squeeze out some additional scoop on RabbitNet, but was unsuccessful. So, I decided to concentrate on the Coyote’s clocked CMOS communications port. But, it seems as though what I call “clocked” is more like the SPI-based RS-422 RabbitNet port than the clocked CMOS port on the Coyote. As it turns out, the clocked CMOS port is simply another asynchronous communications port without RS-232 conversion circuitry.

To test that theory, I put together a serially controlled 4 × 20 LCD module based on an AVR Atmega16 (see Figure 3). The idea was to connect the clocked CMOS serial port to the AVR board and send a message to the LCD from a telnet session aimed at the Coyote.

(Click here to enlarge)

Figure 3—You can get the Coyote schematic from the Z-World web site. I used this string of parts to make a thingamajig to bark with the Coyote.

The coding was a piece of cake. I simply added RS-232 library defines for port C to the existing serialexa.c program. On the AVR side, I stuffed the Atmega16 with an interrupt-driven asynchronous communications application that manipulates the LCD. I tested the AVR board using a Sipex SP233ACP RS-232 converter IC attached directly to a Tera Term Pro terminal emulation session on the Tera Term-equipped PC. I used the ImageCraft AVR C compiler to architect the Atmega16 firmware, and implemented an Atmel AVR ISP programmer pod to push the finished code onto the AVR.

After debugging the AVR code with Tera Term Pro, I removed the Sipex SP233ACP IC and connected the AVR/LCD module’s USART directly to the Coyote’s clocked CMOS pins. I did this in a three-wire, null-modem fashion (i.e., Coyote TX to AVR RX, and AVR TX to Coyote RX, plus a common ground). You may download the AVR code from the Circuit Cellar ftp site. The companion AVR hardware is depicted in Photo 3.

(Click here to enlarge)

Photo 3—The Atmega16 may be overkill for this application, but I figure I’ll be adding more gadgets to this board, and having all of the AVR functionality plus a pack of I/O pins will make life easier later on. The RS-232 port is just below the SP233ACP, which is removed when the clocked CMOS port is connected to the three-pin connector to the left of the serial port.

 

Even with the three-wire RS-232 converterless communications success, I still wondered about the CLKC line. Further study indicated that the clocked CMOS port could be used in SPI mode. The Coyote’s clocked CMOS port is supported in SPI mode by a Dynamic C SPI library. So, the clocked CMOS port can be used to interface to external specialty ICs that communicate using SPI. And, oh, yeah, “Splash four.”

“BEEP, BEEP”

Well, the Coyote has arrived and like that fast bird we all know and love, I’ve got to go. The Coyote I’ve examined has a belly full of Rabbit, which gives it the power to measure, control, and communicate using a variety of protocols on just as many physical interfaces. On second thought, the Coyote would make a perfect sprinkler controller or hot-water heater monitor/controller, but I’ll leave the final applications to you. My job is done, and once again I’ve proven that even products based on floppy-eared varmints and named for wild dogs don’t have to be complicated to be embedded.