[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Electronics
. -> [Folder]  Microprocessors
. . -> [Subject]  RS485 library - issue handling and interrupts
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

RS485 library - issue handling and interrupts

Postings by administrators only.

[Refresh] Refresh page


Posted by Rasihasi   (2 posts)  [Biography] 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)
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] 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
[Go to top] top

Posted by Rasihasi   (2 posts)  [Biography] 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

[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] 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
[Go to top] 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.


4,114 views.

Postings by administrators only.

[Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]