The checksum method above is just a basic one, there are many formulas, this was good enough for me.
The code above is a basic structured approach. I try to keep all my "stuff" in the same order, makes it easier for me to find stuff (to copy&paste into new programs). Nothing is forcing you to organize your code, but there are some exceptions (DT_INT must be the first of DT includes). There is also paging issues, but that's advanced stuff. Generally; config fuses at top, then defines, registers, ports, variables, code and then data (it can be anywhere, it's just easier when it's at the bottom of the scroll range - especially when you have LOTS of data statements).
Comments are your friend and take no space.
I don't know how complex your PIC network will be, but the code above gives you a basic design. The Address can be for a single PIC, or a Call-All-PICs address (999 or whatever you want). The Command gives you flexibility in telling the slave what code to execute. The Buffers can be whatever you want (within PBP/PIC limits), mine will be at least 55 bytes. Same with the address and command; they can be whatever format you want.
There are many ways to handle the actual message size. Some send one byte at a time, some send the longest record and let the slave figure out what it needs. Another way is to send a command first, the slave determines which size wil be sent, signals the master to send the data and then waits for it. You transfer less bytes but you do more data transfers; if my buffer lengths vary little, I send it all, if there's a HUGE difference in size, it's worth telling the slave what to wait for.
There's no limit to how complex you can handle communications. I suggest you stick with whatever makes you happy.
(have to get back to my PC, wife doesn't like having parts in the kitchen)
Robert
Bookmarks