NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Twisted pair

January 17, 2010
by exussum
exussum's Avatar

Hi,

Im wondering when programming the microcontroller, if I wanted to communicate with another device using RS422 would would the code work ?

By that I mean you have a TxD + and a TxD - same with the RxD.

I gather I would need 4 pins ? instead of the Standard 2 ?

January 18, 2010
by exussum
exussum's Avatar

Just to clarify a little.

Twisted pair signal cables have equal and opposite signals. So i guess if i send an 'A' across it it would equate to

01000001

and

10111110

But I don't know how to ensure they are simultaneous Thanks

January 18, 2010
by mongo
mongo's Avatar

RS422 is a serial communications setup that uses 4 wires. TXD, + and - & RXD + and -

Basically, it is a longer range version than RS232 that does not bother with all of the control lines. Handshaking is done through ascii control codes rather than CTS/RTS, etc. The + and - are mostly just that, though not necessarily polarity. They are more for getting them connected in the right places. TXD+ for one device connects to RXD+ at the other device, TXD- connects to RXD- follows suit.

RS422 normally operates on an industrial standard of a 20mA loop, which is highly immune to external noise, which is how it gets the boost in range.

A variation on the theme is RS485, which uses only two wires. A little trickier to use but has the same range characteristics.

RS422 can operate in full duplex mode. That means it can transmit and receive simultaneously. RS485 is either Half Duplex or Simplex mode. It can only transmit or receive separately and is usually in standby until a control code is detected to poll for data. It is used widely in 2 wire control systems and automation.

Many RS422 systems can switch to RS485 and vice-versa

Probably more than what you wanted there but I think it kind of covers the question...?

January 19, 2010
by exussum
exussum's Avatar

So what do I map stdin and stdout to ? Does the chip take care of that itself ? I understand what's actually happening with the wires what I don't get is how to read and write 422 with the nerdkit. Program wise

January 19, 2010
by BobaMosfet
BobaMosfet's Avatar

You have to write that part.

January 23, 2010
by exussum
exussum's Avatar

boba - But how - any example code ?

January 24, 2010
by BobaMosfet
BobaMosfet's Avatar

This is where the learning for you begins. Embedded development and microelectronics is in no way a trivial endeavor. This is where you find out if you have what it takes to do this.

You need to learn enough about protocols to determine which you want to use. You need to know enough about the chip, and a programming language in order to write good code for it. You need to be able to read the whitepaper on the protocol and translate that into your own algorithms.

Besides, you don't really want me to take all that away from you. If I did the work for you, you'd never feel the sense of reward and accomplishment from it that you have the opportunity to gain now.

I will however give you a hint. Instead of picking a protocol and trying to make that work on this chip, why don't you take a look at the datasheet and see what the chip already offers. At present, it's got three different means to communicate with other hardware, already built in.

Good luck, and let us know how you progress!

January 24, 2010
by exussum
exussum's Avatar

Im reading and writing to something that already exists, im not choosing it to be different ...

I already use the ones the chip has built in.

So the short version is i cant / need another chip to be able to communicate with something using RS422 ?

Thanks

January 26, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi exussum,

If your goal is simply to communicate with something that already speaks RS422, consider a chip like the Texas Instruments SN75176A (which is $0.88 from DigiKey)which will allow you to use the ATmega168's TX and RX ports for talking over a differential bus. However I am not 100% familiar with RS422 and whether the convention about start bits, etc. is similar enough to work.

If you instead want to explore differential communication without adding an external chip, you could for example drive two digital output pins directly in opposite to each other for transmitting, and then use the analog comparator as your digital receiver. Hope that helps!

Mike

January 26, 2010
by exussum
exussum's Avatar

Yeah, thanks Mike, Thats useful

January 26, 2010
by mongo
mongo's Avatar

Yup... This chip will do RS422 and RS485

Post a Reply

Please log in to post a reply.

Did you know that two resistors plus a transistor can be used to make a better voltage supply? Learn more...