I've been looking into this RS485 protocol library.
I understand the master and slave code but the site mentions that the library contains an error checking protocol. When i look at the source code from the library there are no lines of code that suggest the use of an error check. Would you guys be so kind to enlighten me about the code? (I've included the code below.)
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WConstants.h"
#endif
typedef void (*WriteCallback) (const byte what); // send a byte to serial port
typedef int (*AvailableCallback) (); // return number of bytes available
typedef int (*ReadCallback) (); // read a byte from serial port
void sendMsg (WriteCallback fSend,
const byte * data, const byte length);
byte recvMsg (AvailableCallback fAvailable, ReadCallback fRead,
byte * data, const byte length,
unsigned long timeout = 500);
First, each nibble is turned into a byte, where the second four bits are the complement of the first. Thus only the following bytes are valid, and the others are rejected:
Now that I look into this thread, you piggy-backed onto an old (August 2013) thread about "RS485 Communication not working using Nick Gammon's RS485 library (Hardware)".
This (new question) is completely irrelevant to the topic of the library not working. Please in future just start a new thread, rather than tacking onto a 2-year old one. The fact that they both are something to do with RS485 is not sufficient justification.
The ones complement i understand, but there seems to be no code that does this? This part i do not understand.
This (new question) is completely irrelevant to the topic of the library not working. Please in future just start a new thread, rather than tacking onto a 2-year old one. The fact that they both are something to do with RS485 is not sufficient justification.
I'm sorry. I read the thread but not close enough it seems!
Generate the CRC or check the CRC? These lines do the check:
// if we have the ETX this must be the CRC
if (have_etx)
{
if (crc8 (data, input_pos) != current_byte)
return 0; // bad crc
return input_pos; // return received length
} // end if have ETX already
By using the ones complement, does it mean that a piece of data can't be something like 0xAF? For example i want to send an array that contains some values like: 0x45, 0x68, 0xFA, 0x65.
I’m so sorry! I never checked this file because the library is called with “RS485_protocol.h” and thought that this meant only the .h file was used.
So to make things clear (for me): The .cpp file is called with the funtions sendMsg and recvMsg through the .h file. These functions use the .cpp file to implement the start, stop, CRC, … For this I only need to insert the .h library in the sketch?
You include the .h file in the sketch, which triggers the IDE to include the .cpp ones as well. The .h file merely specifies which functions are available, the .cpp file implements them.