Modbus Protocol Stack

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modbus Protocol Stack

8,790 Views
paulsky
Contributor II
Hi,
 
Does anybody know of a modbus (RTU)  protocol stack for the HCS08? - I want to run a modbus protocol over the serial interface.
 
 
 
 
Labels (1)
7 Replies

1,490 Views
paulsky
Contributor II
Thanks for the replies / advice. I've managed to get some information together on the protocol & it doesn't look that hard to impliment. I'll be running the unit as a slave and I'm using the HCS08GB60 processor. The only things that look like potential sticking points are:
 
  • There are some pretty strict timing requirements to detect and end/start of message ie. 3.5 or more times a character period, and the detection of a 'dead packet' i.e 1.5 times or more a character period. Although looking at the MCU datasheet it indicates a feature where there is an 'idle line' detection feature -an idle line meaning there is no traffic for 1 character period - I'm sure I could use this feature.
  • The MCU could be potentially very busy with incomming SCI generated interrupts, especially if there is a lot of traffic on the bus - but once again the MCU datasheet proves itself useful, there is a feature which allows me to 'filter' packets that aren't addressed to me. The modbus protocol defines the first byte as the address byte. This means that after detecting a start condition the MCU only needs to check the first byte & if the packet isn't for it it can mask off any further interrupts generated by incomming traffic until another start condition is detected.
  • The modbus RTU protocol defines the requirement for a CRC16 check on the packet. If the MCU is going to run this on every byte then it's going to be busy - however one of the documents I looked at showed a technique of using a look up table to compute the CRC16 which is going to save a lot of processor overhead.

Anybody else who wants to throw their two cents worth in is welcome.

 

paulsky

 

Modbus.zip

Message Edited by t.dowe on 2009-09-01 06:03 PM
0 Kudos

1,490 Views
rocco
Senior Contributor II
Hi Paulsky,

I use a serial bus very similar to the four-wire RS485 version of Modbus.

Some differences between my protocol and Modbus are:
Whereas Modbus typically uses 19.2 KBaud, I use 500 KBaud. (Modbus was not fast enough).
Whereas the Modbus can go idle, in my implementation the bus never goes idle.
Whereas Modbus uses CRC16, I use a longitudinal-check character for forward-error-correction.
In one of our systems, each node gets a new packet every 3 milliseconds. At the same time, each node needs to do some math and control a servo-motor, as well as other minor background tasks. So I can safely say that any of the 08s should be able to handle Modbus.

To implement it, I did the following:
I used the sleep/wake-up feature of the SCI to ignore packets destined for other nodes.
I used the idle-line interrupt feature to detect the end of each packet.
I only buffer the received characters in the ISR. I parsed the entire message separately.
No single ISR takes more than 5 microseconds to execute (I have a lot of ISRs).
Now, I only program in assembly language, so I can't say for sure what will happen in C. But I'm running at a speed 25 times faster than the Modbus default speed, and 4 times faster than 115 KBaud. I would hope that CodeWarrior would not affect performance THAT much.

If you would like some code examples, let me know (assembly language, of course).

1,490 Views
GsFilm
Contributor II

Hi Rocco !

I've also written a lot of code for MODBUS and added a couple of more efficient commands within the vast unused areas of the std MODBUS protocol for our own I/O system.  I really like to have contact with (the all to few) people like You who (like me) loves writing assembler to get optimal speed and efficiency.   Please check my vcard and send me a line if You feel like it.   I checked Your vcard but there was no email adresses in it.
Anyone else reading this are of course also welcome to contact me.

0 Kudos

1,490 Views
Rockyglen
Contributor I
Hi Rocco,  Is there any way I could have a look at your 08 control bus protocol code.
I need to set up a small control bus around the house and farm with quire a number of RTU's doing different things such as analogue and digital measurements, Motor and relay controll ect.
I do not need a full modbus and yours sound just right.
 
Yes assembly code is good , I have never made the step to CodeWarrior.
 
Thanks Rocky.
0 Kudos

1,490 Views
paulsky
Contributor II
rocco,
 
thanks for the insights. I don't have the freedom of creating a proprietry protocol. I have to interface with a Modbus system. As for the processor overhead concerns - OK it doesn't look like it's going to be odious for the MCU. I was concerned because the MCU is going to be busy with servicing several zigbee nodes. Anyway it looks like my thinking was along the right track as you have implimented code along the lines of my intentions i.e. idle line detect & address filtering. I guess all I need to do now is get on with it & see how well it works.
 
Thanks for your comments
 
 
paulsky.
 
 
0 Kudos

1,490 Views
celsoken
Contributor V
Dear Paulsky,

We have the same situation in our next project. We have to implement Master Modbus RTU in a HC08AP16. Let's keep in touch. If someone could help us that will be appreciated. We are considering the possibility of somehow joining our team in this case.

Cheers,

Celso
0 Kudos

1,490 Views
thisobj
Contributor III
Hello paulsky and celsoken,

I believe Micrium has a Modbus protocol stack.

www.micrium.com

Also, there is info on some free Modbus tools (stack, etc) at this link.

freemodbus.berlios.de


I provide this as information only, as I have no personal ties to either of the above sources.

Frank

(edit to correct spelling)


Message Edited by thisobj on 2007-08-17 07:41 AM
0 Kudos