RS-485 automatic T/R switch.

Go To Last Post
34 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello:

I had designed a little board to interface USART to RS-485, that has two types of connection: one row of the DIP MAX232, or the ISP header for ATmega64-128-1281-2561 family.

But after few hours of desing, I had decided to improve the circuit, by adding automatic capabilities to the T/R signal, instead of using SCK from the ISP header.

After one hour googling for circuits that automatically switch T/R signal, I didn't find anything insteresting. Only one circuit that uses a simple transistor and few resistors, but that doesn't satisfy me, since I'm not shure that it switches off the trasnceiver too early after the last bit had been sent.

So I must admit that I'm a lazy guy, since I'm asking for suggestions about that.

My first bet would be to add a capacitor between T/R pins and ground or VCC to add some delay.

Has someone experience with this kind of circuits?

Thanks in advance,

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Has someone experience with this kind of circuits?
Got some sample chips from Maxim the other day :-)

Look at the MAX13414E, MAX13415E

All built in including a 5V regulator in a 8 pin package. I have given up on trying to use the RTS from the pc to change direction....but haven't had the time to play with the new chip yet. :(

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've seen circuits using a 555timer as a monostable! Just have to tweek the time to suit the baud rate.

Js - best to use a FTDI chip for PC->485 as it has built in hardware that takes care of the bus direction. 485 becomes a no-brainer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

B&B Electronics RS232-RS485 converters (at least some of them) have automatic switching. I don't remember the circuit (we may have reverse-engineered it when repairing) but you might check the Web site.

Why >>not<< use SCK? I'd think it would be faster that way, less time between transmit-to-receive, than timing out.

Quote:

MAX232

Are you sure that you did not mean MAX485?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your help, gentlement:

I had checked Maxim, as John suggested, and I found http://datasheets.maxim-ic.com/e... as a suitable IC. Drop in replacement for LTC485 and similar (I have 5V, so I don't need regulator). So probably this is the one that I would use. Available at Farnell also.

NE555 is a good idea that I didn't had. Thanks, Kartman. BTW, I also support your idea of FTDI to RS485 up to the point that I had done this board, and it is up and running on my desk right now. A pity that I have lost the sch and pcb, otherwise I could post them here.

Back to the original issue, just for your information, so this will explain few details.

I'm a collaborator of an spanish robotics associations. Since I'm one of the few AVR freaks here, I had done a little PCB, totally THT, to evaluate and test all the M16 - 32 - 324 - 644 -1284 family in DIP package, under the nick Beamspot.

This is a link to the PCB: http://wiki.webdearde.com/index....

I'm also working in a RS-485 interface for this project. I had observed that MAX-232 IC's have all the interesting signal on one side of the DIP package (pins 8 to 16), so my first idea was to design a little PCB that fits into the socket or footprint of a MAX232, or at least that could be plugged verticaly on it.

But I'm also working at home with some ATmega64 and ATmega128 boards. As users of this family should know, ISP signals are routed to a serial port on the uC. That makes ISP header a nice target to plug comms boards for debug et alter. I'm not the only one that has some little boards that connect ISP to 232. So I had decided to use the RS-485 interface the capability to be used also for this connector.

As I had commented also, the T/R signal should be SCK, the only SPI signal present on the ISP header for this boards, but sine one of my boards has SPI flash memories, I can't use it, hence my need for an Autodirection system. This also will add all opportunities and possibilities to that board, so it will be more 'general purpose'.

I add the schematic that I had drawn, and I will post all the resources needed to build it in that web. Probably I will desing two versions: THT and SMD, and share publicly all of them.

The 'main problem' will be that all this documentation is available in spanish only (but I'm shure Il Signore will understand it perfectly if he is interested), thus I will see what I do, and if I also post some english version here.

Thanks again.

Attachment(s): 

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So probably this is the one that I would use.
Good find, it is probably cheaper that the ones I suggested.

Beamspot seems a nasty person :) I was looking for the friendly Guillem there to no avail. So the Spanish speaking world is also worried about Microchip.

Anyway a few more posts and then you will be "Usuario Experto" not like here that you have to sweat for your stars :lol:

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some suggestions: There's the LT1785 which has voltage tolerance to +/-60v on the bus terminals that will obviate the need for the transil/transzorb diodes. I found the transil diodes are fine until you hit them with enough voltage to make them go up in smoke - either them or the pcb. Mind you, in my application I had 24VDC in the same cable as the 485 bus so it was common for people to wire it wrong and get smoke. My way around that was to put polyswitches in series to save the transil diodes in the event of 24v being applied to the 485 bus. With the adventof the LT1785, I can do away with the diodes and the polyswitches.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman, thanks for the info. I had downloaded LT1785 datasheet, and it seems that I will recommend to use it if no Autodirection is needed. For certain applications that I have in mind, I probably will go for it.

John, Spain is PICland. Some of them are really fanatics of PIC and worry anything AVR related :evil: . Others, 'au contraire', are open minded, like those nice people at this web :D. So that is the reason why I prefer some degree of privacy, anonimate.

And yes, it is easy and fast to be an 'expert user' ('Usuario experto'), mostly because activity in that forum (as in many others) is nothing comparable to the activity present here. Top posters there are in the range of 1500, so Il Signore Samperi will became something like SF or God there (like the actual triumvirate in this forums?? ;) ) with 6850 posts.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guillem,

If this is an application when your AVR transmits and has to switch back to recieve
mode use the TXC interrupt to commence the change from TX to RX.

Quote:
The Transmit Complete (TXC) flag bit is set one when the entire frame in the Transmit
Shift Register has been shifted out and there are no new data currently present in the
transmit buffer. The TXC flag bit is automatically cleared when a transmit complete interrupt
is executed, or it can be cleared by writing a one to its bit location. The TXC flag is
useful in half-duplex communication interfaces (like the RS-485 standard), where a
transmitting application must enter receive mode and free the communication bus
immediately after completing the transmission.

Ron.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
I've seen circuits using a 555timer as a monostable! Just have to tweek the time to suit the baud rate.

Js - best to use a FTDI chip for PC->485 as it has built in hardware that takes care of the bus direction. 485 becomes a no-brainer.

At the bottom of the following document on RS-485 is an exanple circuit for what you are referring to:

http://www.embeddedsys.com/subpages/resources/images/documents/microsys_art_RS485.pdf

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I also support your idea of FTDI to RS485 up to the point that I had done this board, and it is up and running on my desk right now. A pity that I have lost the sch and pcb, otherwise I could post them here.

We use the schematic(s) right out of the FTDI datasheet for "no micro" USB-RS485 (and (USB-RS232) converters.

Now, if not far away from the PC then you don't need the RS485 at all, do you? It then becomes USB-FTDI-USART.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have never used autoswitching RS485 devices as most of my stuff needs to run only from a few metres to a few hundred metres.

I did look at autoswitching years ago when I was looking at RS485 repeaters to extend the range considerably for a project which never happened. Autoswitching meant just plugging in an box without having to run an extra, buffered connection to change direction. The circuits I looked at all had monostables to change direction and of course the mandatory 2ms delay on the part of the slaves before responding.

Autoswitching should make it very easy for RS232-RS485 converters so that one does not have to worry about Windows taking tens of ms before doing anything with the command to change RTS therefore making communications with external microcontoller based boxes a breeze. I guess it is the same with USB-RS485 with the FTDI chips but if one has real RS232 ports (some prehistoric people still have them :? ) and existing boards then an autoswitching RS485 chip will do nicely.

Now I JUST HAVE TO try these chips. :-)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
of course the mandatory 2ms delay on the part of the slaves before responding.

Sounds like Modbus. ;) But I'm LOL at this one because I always run my AVR USART comms with TXC instead of UDRE, as most of my stuff is RS485 and it just makes it simpler. Occasionally I get lambasted from the UDRE people with their claim of enhanced throughput. At most it is a fraction of a bit time. In practice, I can't even see it on the 'scope except for a bit of jitter on a repetitive test pattern.

Anyway, I also sometimes find that I have to slow down my lightly-loaded slaves a bit when responding to a poll as the master may not have had a chance to turn off TE and have it "take". This is typically a few us, though.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Sounds like Modbus.
I guess the manufacturer of the boxes would need to make them work for worst case scenario.

Unless the monostables' timing were adjustable to suit the baud rate, then the changeover would have to occur for the slowest bit rate. At 600baud it's almost 2ms per bit. So if the slave responded before then it would have been likely that the driver would be still in the TX mode.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tend to use ModBus since I have some tools that ease my live when debugging. And IIRC, JS also uses ModBus from time to time.

I use the UDRE/TxC approach, since someone recommended it. In some cases, I had to download up to 3MBytes of data at 9600 BPS, so I tried to use the (in theory) faster UDRE/TXC approach. After all, it is only just another ISR more, few lines of code. But Lee's aproach probably is more compact and simple, and there wouldn't be a big difference, since most of the time is wasted in EOF's, turn around, master processing time, etc.

The reason why I will use RS-485 is basicly because I have more than one node attached to the same line (three in fact right now, up to 16 in future projects) and up to 30-50 m away. Plus, another simple and stupid reason, is that I have my USB-485 module (right out of FTDI datasheets, as Lee said), but no RS-232 for my PC. Of course, that is only a question of money and time to buy an USB-232 adapter.

I never used Autodirecton also, but I think it would be great since it will make things simplier for this application, as I had explained before (SCK pin used by some SPI peripheral).

@bwall: nice link, thanks for posting it.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
JS also uses ModBus from time to time.
..not quite modbus..just a home cooked protocol for my own stuff just to confuse people. :lol:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

Based on Guillem Planisi's RS-485 circuit (shown above), I would like to ask two questions:

1. At the RS-485 line circuit there are 2x27K Pull-up and Pull-down resistors at A and B respectively. If there are more than one terminals then the Pull-up (or Pull-down) 27K is parallelised with another 27K Pull-up(27K//27K).

I believe that those Pull-up resistors must be exist only to the Master's PCB? Is that true?

2. Between A and B lines, Terminal Resistors 120Ohm must be connected. This is only for the 1st and the end devices on the comunication line. The 1st terminal will be always the master, so I have put the parallel 120Ohm in the design. My problem is that I really don't know which will be the end device. Each terminal device (slave) has a user interface with LCD and buttons. I don't want to place there a pin header for the user to sellect the terminal 120Ohm. Is there any way to give the abillity to make this sellection by software (to control a circuit that connects the resistors between A and B lines?

What would you do in that case?

Thank you all.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The bus bias resistors I put on each device. If you use devices like the MAX485 that give an idle output on an open bus, bus biasing is not such a crucial requirement. Yes, once you start putting a number of deovces on the bus, then the bus bias resistors parallel and have have lower resistance - thats why we start we a high resistance in the first place - the bias resistors are usually 560ohm if you only have them in one place.

Termination may or not be required. for most of my work I don't require termination as the baud rate is 19200 and the distances are around 1km. However, I have a jumper to selectively enable termination if required. I have read and green leds on the tx and rx of the 485 driver, not using termination means the green light stays on if the bus is reversed. This can be a handy diagnostic feature.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman,

- MAX485 can support up to 32 devices. So 27000Ohm / 32 devices = 843.75Ohm. Ok thanks for that.
- The idea of the LED is just fantastic. I'll involve it to my design. Never thought of this.
- I need termination because my Baud Rate is 115200 and the cable length comes up to 1Km (3800 ft aprox.). Do you have any idea about my last question?

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I recall correctly, one B&B converter applies TX *data* to the rs-485 transceiver *direction* controls, while the tx data input was tied in a fixed state. Weird, but it actually worked, and no timer devices were used.

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tpappano wrote:
If I recall correctly, one B&B converter applies TX *data* to the rs-485 transceiver *direction* controls, while the tx data input was tied in a fixed state. Weird, but it actually worked, and no timer devices were used.

:D I'll be damed it worked!

I ran the Data out through a 74hct04 to pins 2,3

**Incorrect Tied pin 4 to 5V and wala it worked.
**Correction pin 4 was GND not 5v and viola it worked!

I only have the master and one slave and am running 38400 baud with a 75176 chip.

Thanks

Last Edited: Sat. Jul 31, 2010 - 06:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kpyro wrote:
I ran the Data out through a 74hct04 to pins 2,3 Tied pin 4 to 5V and wala it worked.
I am pleased that your technical problem was solved ... but sad that you "murdered" that lovely French word. :oops:

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe he's a Kiwi... "And Koala, it worked!"

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Maybe he's a Kiwi... "And Koala, it worked!"
Very clever Bob.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Should we tell him he has the wrong country?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No ... let him enjoy his moment in the spotlight :lol:

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
Yes it works but be careful.
The reason it works, is that there are probably Pull Up & Pull Down resistors on the comms lines. These put the comms lines in a specific state i.e. logic 0. When you join the line driver in the method you describe, it only enables the output drivers when transmitting a logic 1. So you get full drive when transmitting a logic 1 and NO drive when it should be driving the lines at a logic 0 state.
So what this means, is that the lines are susceptible to noise at this time due to the drivers not being turned on.

Kind Regards,

Neil Wrightson.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice catch Neil.

When are you next in Melbourne? We should try to arrange another wild drinking event for the Melbourne chapter of 'Freaks.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Ross,

Good to here from you.
I was there this morning and Monday morning. Admittedly it was only a stop over to and from Adelaide :-) Actually, I've spent the last few weeks in Adelaide.

I will probably be down there in a month or so. I will let you know as soon as it's in writing.

Neil.

Kind Regards,

Neil Wrightson.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, give us a bit of notice and I will attempt to gather the troops.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guillem,
I have done many '485 designs with AVR's and using the TXC flag mentioned above is spot on. Once he flag indicates TX completion then toggle the control line for RX, or vice versa. Simple.

Oh by the way,
How is the little one and when are you all comming to NY so I can take the three of you out on the town in NYC?!!!!!!!

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi:

This thread had been interesting to read. Since all '485 designs' I've made have the pull up/down resistors this interesting solution may be good to apply. A pity that at my job right now there are no uC and neither 485. Some ARM in a 'near future' (by the end of the year). So I will work on this in my spare - hobby time. Something that I've lost lately.

@Jim: Not too much time left for Internet. The little one requires all our atention :D You know, this is a demanding task, but also a joy. She is growing fast, now with 8 months she tries to catch the little dog, but she barely handle to 'walk on four legs' (sorry, I don't know the proper english term :S)

BTW, How is your little one (his name is David, am I right)?

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Guillem

Danny is hauling butt up the main staircase!! I clocked him at under 10 seconds per 8 steps. Not bad for a 16month old!

Quote:
but she barely handle to 'walk on four legs' (sorry, I don't know the proper english term :S)

In the USA we call it 'crawling'(wink)

You still have not answered my question on when our broods are getting together for a weekend in NYC!!!!!

With regard to the '485 question, I will look at it more in depth and post sone ideas(both intelligent and idiotic)

Regards
jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Jim:

Wow, 10 seconds per 8 steps is damn fast for a 16 month old! But staircases are not exactly a safe part of the house. Right now we realize the amount of possibly dangerous things we have at home, and right now we begin to foresee some work to improve safety at home. For sure you know the amount of attention and sport that a young person like Danny requires ;)

Huh, I doubt that we will abroad in the next years. We think that it would be better if we begin to travel when she would be conscious of the trips. And certainly, NYC is in the first places of our wishlist, but now it seems that it should wait some years :(

Ah, and I'm sorry for my bad memory.

Regarding '485, I will re-start it again as I had finished some of my 'home work' (I'm sorry, but I prefer not to say anything about a personal project I'm working right now).

Guillem.
"Common sense is the least common of the senses" Anonymous.