PLC communication (RS485) with AVR

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

Hello everybody...

i have been in this forum since 2001 and i see so much progress since then... anyway..

my project i am looking for is to make communication modules with AVR for a PLC with RS485.

in other words i would like to control the inputs and outputs of the AVR with the PLC via RS485...

Does anyone has any example test circuits, code in C for a beginer start e.g. communication between 2 AVR....

i would like to use MAX485

thanx for the help

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

Quote:
i have been in this forum since 2001 ....
So, why do you post in the Academy section ? Each forum has a sticky in the top that describes the purpose. Please do read it.

I will move this thread to the General AVR-forum.

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tessa and Tina, You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

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

Quote:
i would like to control the inputs and outputs of the AVR with the PLC via RS485...
Do yuo know the protocol used by the PLC you intend to talk to?

Go to National Semi ad download Application Note 979, I think they may have others too.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Modbus seems to be popular for PLC interface to external devices. What PLC? I use AutomationDirect PLC equipment and most of thier models support serial I/O but through a protocol sometimes unique to the PLC brand. I have never conquered using modbus but looks like it kind of universal. There is also a PLC web site for various PLC brands, internet search for Mr.PLC.

I'll believe corporations
are people when Texas executes one.

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

Also go to modbus.org and read the protocol specs. I suggest using RTU for it's simplicity and efficiency. Avrs can process modbus traffic as a background task with 2 ports tied behind their backs.

Tom Pappano
Tulsa, Oklahoma

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

js wrote:
National Semi ad download Application Note 979, .

http://www.national.com/an/AN/AN...

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

I have shied away from using modbus because the CRC calculation seems a little intimidating, at least for me. Some years ago I had an OMRON that had a simpler method, something like XOR each of the bytes. Of course, not every single byte of the message was included in the CRC.
I wonder if any avr freaks have examples of how to do a modbus interface.

I'll believe corporations
are people when Texas executes one.

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

dk6avr wrote:
Hello everybody...

I have been in this forum since 2001 and i see so much progress since then... anyway..p


If my maths serves me correctly, I have deduced your average post rate is 1 post every 8 years.

If your PLC has CAN, and atmel makes chips with on board CAN (which handles all the protocol stuff like CRC arbitration etc.)... then you are A for away. If however your PLC doesnt have CAN, then please unread this post.

Just a noob in this crazy world trying to get some electrons to obey me.

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

fever2tel wrote:
dk6avr wrote:
Hello everybody...
If my maths serves me correctly, I have deduced your average post rate is 1 post every 8 years.

i had another login name... DK-6- but i lost the password.. because i lost my email account.. anyway

Quote:
If your PLC has CAN, and atmel makes chips with on board CAN (which handles all the protocol stuff like CRC arbitration etc.)... then you are A for away. If however your PLC doesnt have CAN, then please unread this post.

i need example code modbus in C+ (i use imagecraft compiler)

my PLC is LG GLOFA GM series...

PLC (master) -modbus----> AVR i/o (slave) ------> AVR i/o (slave) -----....

and another question.. if the cable for RS485 is not twisted will be a problem? i will cover 20m distance...

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

Tom Pappano
Tulsa, Oklahoma

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

Quote:
I have shied away from using modbus because the CRC calculation seems a little intimidating, at least for me.
I have the 16 bit CRC calculations routine that I have used for a few years in assembler (avr, pic??, hc11 and hc05).

I haven't used Modbus but my own simple protocol, however I have used the same CRC routine AFAIK....not that I pretend to understand it.. :) I just use it.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

The crc routine I use is six short lines of C code. If I remember correctly, there is a crc16 routine that comes with avr-gcc, but a constant needed to be changed to do the proper Modbus thing.

Tom Pappano
Tulsa, Oklahoma

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

the modbus slave stack to buy is 300e...

the freemodbus stack is free.. from the same company..

what is the difference??? :?

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

dk6avr wrote:
the modbus slave stack to buy is 300e...

the freemodbus stack is free.. from the same company..

what is the difference??? :?

anyone?

anyway my project is to control AVR (slave) digital inputs and digital outputs with a PLC (master) via modbus.

do you know if freemodbus.org for my AVR is suitable for this?

thanx!

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

Quote:
anyone?

Probably just "factory support". You get to call someone and ask them questions.

Quote:
do you know if freemodbus.org for my AVR is suitable for this?

It should work fine. I actually just wrote my own Modbus layers because it was much easier and faster than trying to figure out how to use the freemodbus package, which also seemed to use up a lot of memory. I'm sure you can trim it once you get it running, but for me time is usually at a premium.

Tom Pappano
Tulsa, Oklahoma

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

Just for a reference point:

Our Modbus RTU slave for an AVR, plus a Modbus RTU master on a PC, took about a person-month. Definitely 100+ hours.

When operational, we had a fully-layered Modbus slave that legally interacts with any master we throw it at. It recognizes all transaction types and gives a reasonable response to all (even though all transaction types are not applicable/not supported).

With the three layers it is reasonably fast but not a screamer given the callback functions in both the USART and timer ISRs.

A Mega8 (or Mega88) is way-cool for this, as it can have buffer(s) to handle a full Modbus 256+ message frame without contortions.

This implementation takes about half the flash of a Mega88, or about 4KB.

From this working implementation, I made my own "Lite" version that takes half the flash of a Mega48, or about 2KB.

It compresses the layers as much as practical, gives rudimentary responses to unsupported transactions, and only fully supports the few needed transaction types. It uses a single buffer (of 256+ if interoperability needed).

Now, when I use my Lite version and >>my<< master and I know the max frame size I can cut that buffer way down.

The summary is that it depends on what you are going to do with it. With your own master and your own slave you can take some shortcuts.

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

I guess my Modbus slave is "Lite-Lite" My devices only need commands 03 and 06, and this is handled in 1042 bytes. The Modbus messages run at 19.2kb in the background while processing 9600 samples/sec of analog signal to do true RMS readings on 8 channels. Cpu clocks at 6 Mhz and there is still plenty of time left over. I like these Avr things 8-)

Tom Pappano
Tulsa, Oklahoma

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

thanx guys... now i am looking forward to make my test boards... cu soon again ;-)