Serial Port (DB9) control
Old_Lady
Posts: 20
Hi folks -
I have spent the last few weeks reading and downloading info from your forums.· Great stuff in terms of information exchange!· So I decided to jump in and design my board using the Parallax SX48DB.·
My question is this:· I'm using the SX48BD chip to control some industrial I/O functions.· I don't do anything with the information that I collect, instead I want the SX48BD to hand off the·data to a PC (AMPRO ReadyBoard 700) through a serial port, connected by a DB9 connector.· I have looked on your forum at the "Poor Man's Serial I/O", also called the "Half Duplex Serial I/O".·· Is this the correct way to communication serially with another board?·
Here is how I presently have the connections on my schematic:· (copied from 'Half Duplex Serial I/O')
······································· +5v
·········································|···· Q (pnp)
······································· /· E
RA0(TX)
4.7Kohm
B·········This transistor is here to source current, so that the SX doesn't have to?
······································ \
········································ |·C
·········································|············· TXOUT
·········································
DB9, pin2
········································ |
········································4.7Kohm
········································ |
········································ |············· RXIN
RA1(RX)
33Kohm
DB9, pin3
GND
DB9, pin5
I was also going to "loop back" DB9 pins 4 and 6, 1 and 6, and 7 and 8.· (DTR to DSR, DSR to DCD, and CTS to RTS)
Again, I appreciate any comments or thoughts here.· My board design experience has not included an embedded processor in MANY years, so I'm out of my comfort zone here.
Thanks,
···· Laura
I have spent the last few weeks reading and downloading info from your forums.· Great stuff in terms of information exchange!· So I decided to jump in and design my board using the Parallax SX48DB.·
My question is this:· I'm using the SX48BD chip to control some industrial I/O functions.· I don't do anything with the information that I collect, instead I want the SX48BD to hand off the·data to a PC (AMPRO ReadyBoard 700) through a serial port, connected by a DB9 connector.· I have looked on your forum at the "Poor Man's Serial I/O", also called the "Half Duplex Serial I/O".·· Is this the correct way to communication serially with another board?·
Here is how I presently have the connections on my schematic:· (copied from 'Half Duplex Serial I/O')
······································· +5v
·········································|···· Q (pnp)
······································· /· E
RA0(TX)
4.7Kohm
B·········This transistor is here to source current, so that the SX doesn't have to?
······································ \
········································ |·C
·········································|············· TXOUT
·········································
DB9, pin2
········································ |
········································4.7Kohm
········································ |
········································ |············· RXIN
RA1(RX)
33Kohm
DB9, pin3
GND
DB9, pin5
I was also going to "loop back" DB9 pins 4 and 6, 1 and 6, and 7 and 8.· (DTR to DSR, DSR to DCD, and CTS to RTS)
Again, I appreciate any comments or thoughts here.· My board design experience has not included an embedded processor in MANY years, so I'm out of my comfort zone here.
Thanks,
···· Laura
Comments
First of all let me welcome you to the forums. We don't have many females, so it's great to have one more.
The schematic looks right to me, just remember that the PC cannot be sending while it is receiving data. Also note that all data send FROM the PC will be looped back and be received by the PC automatically (local echo).
So if your SX48 waits for "HELLO" then sends "GOODBYE", if you make the PC send "HELLO" it will actually be receiving "HELLOGOODBYE" because of the local echo function of the circuit.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
www.iElectronicDesigns.com
·
I'm not following your local echo function, but I will look for more information on this. My board is a multi-purpose I/O controller board that is used in an industrial environment, so the SX48 will not need to do much data crunching, only handing off data to the PC board. I'm going to plunge into the SW world once I get this board out, so I'll probably post more questions at that point.
~ Laura
In other words, the PC will receive back everything it sends.
Even if the SX was not there, if the PC sent "HELLO" it would receive "HELLO" because the send and receive lines are connected together with the 4.7K resistor.
The circuit uses the -12V idle state of the PC send pin (pin 3) to create a -12V on the receive pin of PC (pin 2). When the transistor is turned on by the SX, the PC receive pin will be at +5V. So the PC receive pin vary from -12V to +5V.
When you start working with the PC software you will see what I mean. Just keep it in mind or you'll end up wondering why you're not receiving what you should.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
www.iElectronicDesigns.com
·
I am not sure if my experience can help, I have done this a bit, but I use the MAX232 IC. I keep a handful of these ICs in my bits trays. Our industrial environment is noisy and my cable runs are up to 20 metres. I should use RS485 but to be honest, I am just lazy. The MAX232 (or equivalent) are readily available (even here in the African bush) and I reckon that the more robust chip, compared to the transistor option,·pays for itself in reduced maintenance and head-scratching after the project is completed. (Remember that·we have very few competent technicians - they've all emmigrated to the US, Canada, the UK etc.)
My·most common application sniffs a PC to printer cable and extracts the part number of the piece being tested·as a label is printed. I was not allowed access to the PC because it drives test equipment and the equipment manufacturer claims proprietary rights – you do not want one of us African savages touching your German computer now, do you.·I might Voodoo it!!! The SX48 then monitors three outputs from a Hitachi PLC and a bunch of emergency stops. I am hoping to capture the motor speed from the·motor speed controller when we do the next upgrade and stick it in the SQL database as well.
We do not bother to echo but we do a simple CRC check and we also validate the SQL database records. We have had zero corruption caused by comms in a little over 650 000 records of 56 bytes each. I wish I could say the same for faults caused by PC software, incorrect PLC states, faulty German test equipment·and other factors.
Kind regards from Kwa Dukuza, South Africa – somewhere on the dark continent.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I have changed the design to incorporate a MAX232. Thank you for the suggestion.
Now my question is.... is there a preferred port to use for my Transmit and Receive line? I had them on the SX48DB port RA0 and RA1, but I'm wondering if I'm better off having them on the RB port, because they are "interrupt driven"... if the PC wants to send serial communication, would it work better for the SX48DB to have an interrupt? Otherwise, would the software be forced to poll those lines, looking for life on the RX line, which would indicate communication from the PC?
~ Laura
I've got a little SX48 module which has an on-board MAX232 (great chip) and I use the following pins:
Serial data (from the SX48 through MAX232) - RA.3 (TX)
Serial data (into the SX48 through MAX232) - RA.2 (RX)
http://forums.parallax.com/forums/default.aspx?f=7&m=194701
The choice for what pins to use is pretty flexible with the SX chips and that is one of the reasons I like them so much. If you use the built-in hardware timer or other specific features then the pin selection is a bit more important since the timers are set to work with a certain set of pins.
For the serial communications most of the routines I have seen don't rely on a transition of a pin to trigger an "Interrupt". Instead they just have an ISR setup to execute at a pre-determined interval which can constantly monitor whatever pins are going to be used for the serial routine. JonnyMac in particular has written some which are very solid and work well with SX/B. I've had great success using them (or variants) in my projects.
There are a couple of things to consider. First, make sure you use a resonator or some stable clock source for your SX chip. Don't rely on the internal clock of the SX when doing Serial communications. It isn't accurate enough and can't always rely on the serial communications when using it. (The internal clock is perfect for other projects where timing isn't as critical)
The other issue which got me and drove me nuts trying to figure out was with the SX48 chip. I was using the built-in timers to generate a PWM signal to drive a motor that moved the head of a robot. A feature of the timers is that they too can generate an Interrupt which then caused the Serial code to falsely look for serial data since it only was setup to expect Interrupts to occur at a specific internal. The extra Interrupts by the timers wreaked havoc with the serial data I was trying to send to control it. The fix was easy. I just had to add a couple commands at the beginning of my program to mask any interrupts generated by the timers and everything worked as expected. Since I was using the timers to do PWM I didn't care or want any Interrupts from them.
Robert
Our electrical engineering department here consists of two people.... my collegue has dabbled in the SX world, and was constantly raving about the wonderful support on these forums... I agreed to use the SX on this new design, and I'd have to agree with him... This is the most helpful resource that I've encountered in a long time. [noparse]:)[/noparse]
Post Edited (JonnyMac) : 12/5/2008 11:51:14 PM GMT