techElder
Well-known member
Wow! This can drive you nuts! RS485 has stubs that "listen" to the message traffic on the pair. I'm building one of the "slaves/stubs" that sit there and wait for their own address with instruction to do something.
I didn't quite realize that EVERY message that passes on the pair has to be decoded to see if it is for this particular slave. EVERY message. If there is 250 stubs, EVERY one of them is doing the same thing ... scanning EVERY message.
Then to watch for hser interrupts and flags and work through the scratchpad memory to see if there is a message with the right address. WHEW!
Can't lose any characters in the stream, so have to keep up with the pointers.
I'm going to go crazy before I get this right.
I didn't quite realize that EVERY message that passes on the pair has to be decoded to see if it is for this particular slave. EVERY message. If there is 250 stubs, EVERY one of them is doing the same thing ... scanning EVERY message.
Then to watch for hser interrupts and flags and work through the scratchpad memory to see if there is a message with the right address. WHEW!
Can't lose any characters in the stream, so have to keep up with the pointers.
I'm going to go crazy before I get this right.
Code:
[color=Blue]do
if [/color][color=Purple]@ptr [/color][color=DarkCyan]= [/color][color=Black]QUALIFIER [/color][color=Blue]then
[/color][color=Black]messageHead [/color][color=DarkCyan]= [/color][color=Purple]ptr
[/color][color=Blue]inc [/color][color=Purple]ptr
[/color][color=Black]messageAddress [/color][color=DarkCyan]= [/color][color=Purple]@ptr
[/color][color=Blue]if [/color][color=Black]messageAddress [/color][color=DarkCyan]<> [/color][color=Black]ZERO [/color][color=DarkCyan]AND [/color][color=Black]messageAddress [/color][color=DarkCyan]<> [/color][color=Black]stubAddress [/color][color=Blue]then
[/color][color=Purple]ptr [/color][color=DarkCyan]= [/color][color=Black]lastByte [/color][color=DarkCyan]+ [/color][color=Navy]1
[/color][color=Blue]exit
endif
inc [/color][color=Purple]ptr
[/color][color=Black]messageFunction [/color][color=DarkCyan]= [/color][color=Purple]@ptr
[/color][color=Blue]inc [/color][color=Purple]ptr
[/color][color=Blue]if [/color][color=Purple]@ptr [/color][color=DarkCyan]= [/color][color=Blue]LF then
[/color][color=Black]messageTail [/color][color=DarkCyan]= [/color][color=Purple]ptr
[/color][color=Blue]inc [/color][color=Purple]ptr
[/color][color=Blue]exit
endif
else
inc [/color][color=Purple]ptr
[/color][color=Blue]endif
loop until [/color][color=Purple]ptr [/color][color=DarkCyan]> [/color][color=Black]lastByte[/color]