MODBUS master and slave?
Is there any MODBUS implementation for the Propeller so far? I've used the search engine but haven't found much. MODBUS is used for industrial IO modules and VFDs, usually with rather low baud rates like 9.6kBd. But as the P2 has lots of power so I think it could even be used for transmitting servo commands with higher baud rates like 1MBd.
Unlike other standards like EtherCAT I think it's relatively easy to implement, at least if not all commands need to be supported. Simple register read and write commands are all you need for simple IO modules and even VFDs or servo drives with hundreds of parameters can be controlled that way.
BTW. I find the documentation of how MODBUS communication works in the technical manual of the Yaskawa GA500 drives much more comprehensible than the original MODBUS specification. It is relatively straigh-forward and explains the basics on only 6 pages whereas the official docs have 50 pages and are written in a quite "academical" style.
However, getting the CRC calculation, error and timeout handling right is somehow non-trivial, I think. So if there is existing code it would help me a lot.
Not Prop but it works:
Wouldn't let me paste in the link thingy
I see that Mikroe have a Click module for EtherCAT (although the chip is unobtainium, right now).
There is both master and slave versions for Prop1 - https://github.com/parallaxinc/propeller/tree/master/libraries/community/p1
https://github.com/parallaxinc/propeller/tree/master/libraries/community/p1/All/Modbus RTU Master
No need for a CRC table, there are hardware accelerated CRC instructions (CRCBIT and CRCNIB)
Thanks for the links.
Yes, it's would be a crime to use a table on the P2 instead of the built in CRCBIT/NIB instructions. But the table method might still be useful for the P1 part. I plan to use both. The servo controller (slave) has a P2 but my older design of the CNC controller has a P1 and would be the master.
My first try was successful. According to the manual $D140 is the correct result for this example.
I used this function in a P1 MODBUS app that I wrote a long time ago.
Mike Green's version is a tad faster -- which is helpful in pure Spin because the routine is a bit slow. I ran a test on an 11-byte packet. The first version takes 2.96ms, the second 2.77ms. Tested on P1 @ 80MHz.
I found a P2 MODBUS WIP -- this is my conversion of the CRC routine. It's identical to yours except that it expects a pointer to a buffer and a byte count.
On a P2 @ 200MHz it takes about 6us to calculate the CRC for the same 11-byte buffer.
Ok, I think I have to write my own code in assembler, at least for the servo where I have to update position and poll status about once per millisecond. But the above examples are extremely useful as starting point for my own experiments and can probably be used for low-speed applications (VFD speed control and sensor/actor IO) with very little modifications.
Thanks a lot!
I had a bit of time to kill before getting on a train, so I gave it a try. This is a conversion of my verbose CRC16 code -- the result matches with my Spin and Mike's Spin functions. Again, I tend to write very verbose code, so you may be able to trim this.
Edit: Moved and line after bits loop.
The conference starts later today, so I thought I'd review yesterday's code. A simple move of the AND instruction will speed up the pure Spin version:
We can wait until the end of the inner loop to clear the stray carry bits.