> Of Steve Rapinchuk > > A couple of years ago did a project for a client which included > implementing a Modbus slave (RTU) on a PIC18F252. At the time I Hi, I've done an RTU slave implementation on the PIC 16C series and 17C series in ASM - and also an 18F implementation in C. > remember it > was kind of strange that although Modbus is de facto standard, I couldn't > find any example code for a slave. (There was lots of code for a Modbus > master.) A few things I remember off the top of my head: I think most of the slave code ends up being developed for clients/employers - so it doesn't get out to the rest of the world (just my guess though). > - The freely available documentation isn't very thorough. There were no > examples of byte-for-byte messages including CRC. (This may have improved I thought the docs were Ok. The PM-MBUS-J-300 doc (or whatever it was) had examples of byte-for-byte messages I think. I had the CRC bytes swapped early on too :-) > - The documentation includes lots of controller (mostly PLC) > specific stuff > that doesn't apply for most implementations, so I didn't > implement some of > the messages. I didn't implement all messages either. Some of what makes sense for a "Big" PLC doesn't make sense for a PIC. > - Modbus messages don't include a start-of-message, length field, or > end-of-message. The end of a ModBus message is detected via a certain number of char times of *silence* on the line. So you don't know when the end of the message is coming - you just have to stash away the bytes in a buffer as you receive them and when the line is "silent" or "idle" for 2.5 char times (I think) then you consider the message complete and act on it. Some of this may be inacurate based on 6 years of memory fade :) > > Those are just a few of the things I remember at the moment, but I do > remember it was a pain. Anyone else out there who has implemented > a Modbus > slave have similar experiences? > Overall I wouldn't say my experience was a pain at all - it went pretty smooth for me. -- Mark -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist