Hi. I am working with a rs485 project. Been writing a protocol to suite my needs. Nice progress done too.. Anyway.. My protocol sends a data, to be precise, non-ascii data (or partially ascii) over rs485. This data contains a dual header: 1 header with checksums and sender's id and receiver's id. If checksum doesn't match, receiving is ignored (as only one can talk at a time on rs485 and multiple devices cannot be answering that checksum didn't match and it just might be that it's the receiver's id that has malformed, even though it's double sent).. And then there's the message part that can also be checksumed. If checksum of message is not correct, receiver can inform that we didn't quite get that..
Answering is a 2 bytes, actually 4 is sent.. But 2 identical are needed the receipt to be complete. Very simple fixed bytes, 1 one value that allows an answer in form of message sending described before..
So this is the theory, and I've got it working. I have also tryied to get speeds up, so I am using 115200.. To simplify writing of my code, I've created similar system as serial messaging is, but a bit more complex.. And also a library for receipts..
So, when a command is received, it's parsed to parts: command and x arguments. Then this command is checked agains known commands and then void set for that command is executed.. Most of my commands, especially during this test phase, just have simple content: sendReceipt(ACK);
When I watch the process from my computer, I see what my master program is asking from devices.. And then it acts upon the answers, possibly asking more or starting the questioning from the beginning.. And now we come the strangest point..
Getting a receipt for some commands takes much longer time. I was first thinking that it's because they are in the command stack as last and strcmp is done for every other command until this point is reached; no..
It wasn't that. Then I added this before sendReceipt(ACK); :
Serial.print("Received command X - now sending receipt..\r\n"); and another similar to this debug line after sendreceipt.. As I wanted to see
if it's my receipt function that eats time.. It isn't. My master program received receipt lightning fast after I added these debug lines. I removed the later line, so the void starts with Serial.println.. And it's still fast. I remove it.. And a major slowdown..
Just wondering.. What is causing this? I would think that sending data to serial would slow down instead of speeding up..