Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ Electronics
➜ Microprocessors
➜ RS485 library - issue handling and interrupts
RS485 library - issue handling and interrupts
|
Postings by administrators only.
Refresh page
Posted by
| Rasihasi
(2 posts) Bio
|
Date
| Mon 03 Dec 2012 07:02 PM (UTC) |
Message
| Hi Nick,
first, thanks for your great RS485 library, I use these lib in my current arduino project to remote control ham radio related gear just like a antenna tuner and a antenna switch. Your lib works fine!
I've two questions please:
1. interrupt
it's possible to use an interrupt to signaling the main process (means the main loop), when bytes are in the rx buffer? Then the main process can make a brake, receive the complete message and returns to his other jobs . You know what I mean?? There is a coding example?
2. issue handling:
what is the best way to inform the main process about an communication problem, so the process can send the message again? At the moment I calculate my own checksum over the transmitted bytes and the slave calculate the checksum again over the received bytes. When both checksums are equal, all is fine, otherwise the master is sending the message again.
There is a more simple way and a code snippet if possible?
Thanks in advance and excuse my english,
Steffen
(Rasihasi)
| Top |
|
Posted by
| Nick Gammon
Australia (23,094 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 03 Dec 2012 07:23 PM (UTC) |
Message
| 1. If you use serial processing to get the incoming data it is already handled by interrupts. You have time to check in your main loop until the Rx buffer fills up (usually 32 bytes).
One way of doing this would be to check in the main loop if enough data has arrived to fill an expected packet, eg.
if (Serial.available () > 10)
{
byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf));
// if received is non-zero process message here
}
2. You don't need to calculate a checksum because the library does a CRC check. If it fails it returns zero from recvMesg.
So in the above example:
byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf));
if (received == 0)
{
// request message again
}
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Rasihasi
(2 posts) Bio
|
Date
| Reply #2 on Mon 03 Dec 2012 07:47 PM (UTC) |
Message
| Hi Nick,
wow, a really quick response, thanks a lot :-)
to 1: yes, that's what I'm looking for
to 2: okay, I understand. The master send his message only once and the slave must request the message when the transmission is corrupted, otherwise the slave sends only a short "ACK"nowledge. Good, then I can rebuild my error handling logic now.
Thanks again!
Kind regards,
Rasihasi
| Top |
|
Posted by
| Nick Gammon
Australia (23,094 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 03 Dec 2012 11:14 PM (UTC) |
Message
| I have made a non-blocking version of the class as described here:
http://www.gammon.com.au/forum/?id=11428
This lets you call a function in loop(), and when the packet has arrived you can process it. This might be more suitable if you need to do other things while you are waiting for incoming data. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
16,279 views.
Postings by administrators only.
Refresh page
top