RS485 compile errors

Posted by PyrotechMick on Wed 18 Apr 2012 03:56 AM — 10 posts, 35,740 views.

#0
Hi Nick (and others),

I copied the example code out of your RS485 thread into two new Arduino sketches. Also downloaded and copied the RS485_protocol folder into the Libraries directory. Upon compiling the sketch, I get the following errors:

GammonMaster.cpp: In function 'void fWrite(byte)':
GammonMaster:11: error: 'rs485' was not declared in this scope
GammonMaster.cpp: In function 'int fAvailable()':
GammonMaster:16: error: 'rs485' was not declared in this scope
GammonMaster.cpp: In function 'int fRead()':
GammonMaster:21: error: 'rs485' was not declared in this scope
GammonMaster.cpp: In function 'void setup()':
GammonMaster:26: error: 'rs485' was not declared in this scope

Any idea what's going wrong? I tried compiling this in IDE 1.0 and 0022. Forgive me if I've overlooked something simple. Thanks for your help.
Australia Forum Administrator #1
Did you install the library? And restart the IDE afterwards?
#2
Yes, the library is installed, and I restarted the IDE several times. To confirm, RS485_protocol does show up in the Library menu. Thanks.
Australia Forum Administrator #3
Perhaps I didn't upload the latest version which handles 1.0 version of the IDE. Try re-downloading, and changing NewSoftSerial to SoftwareSerial.
#4
Got it to compile! I have to confess, this might have been nothing more than an "ID10T" error... I had commented-out the line that defined the SoftwareSerial ports (since I'll be using hardware serial) but neglected to change the lines containing "rs485." to "Serial." Obviously I'm still learning. Forgive me for any confusion I've caused!
USA #5
I've got your libraries installed (both the normal and non-blocking versions), however my compile is choking on both the "sendMsg" and "recvMsg" areas.
I'm pretty sure I've missed something simple, but I can't figure it out.
Any advice? :)
Australia Forum Administrator #6
Post your code please?
USA #7
It's pretty much an exact copy of one of your examples.


#include "RS485_non_blocking.h"
#include <SoftwareSerial.h>

const byte ENABLE_PIN=4;
const byte LED_PIN=13;


SoftwareSerial rs485(2,3);


// callback routines
void fWrite( const byte what ){
  rs485.print(what);
}
int fAvailable(){
  return rs485.available();
}
int fRead(){
  return rs485.read();
}


void setup(){
  rs485.begin(28800); //28.8kbaud!
  pinMode( ENABLE_PIN, OUTPUT );
  pinMode( LED_PIN, OUTPUT );
}

byte old_level=0;

void loop(){
  // read potentiometer
  byte level=analogRead(0)/4;  // (scales 0-1023 down to 0-254)
  
  // no change in level, no transmit
  if ( level == old_level ){
    return;
  }
  
  byte msg[] = { // I think this is the protocol right here...
    1,    // Device 1
    2,    // Turn light on
    level // to what level
  };
  
  // send to slave
  digitalWrite( ENABLE_PIN, HIGH); // enable sending
  sendMsg ( fWrite, msg, sizeof msg );
  digitalWrite( ENABLE_PIN, LOW);  // disable sending
  
  // receive response
  byte buf[10];
  byte received = recvMsg( fAvailable, fRead, buf, sizeof buf);
  digitalWrite(LED_PIN, received==0); // turn on LED if error
  
  // only send once per successful change
  if ( received ){
    old_level = level;
  }
}


And this is the error I'm getting:

RS485_General__1.cpp: In function 'void loop()':
RS485_General__1:47: error: 'sendMsg' was not declared in this scope
RS485_General__1:52: error: 'recvMsg' was not declared in this scope
Amended on Thu 13 Dec 2012 09:23 PM by ChrisHem
USA #8
Figured it out.
I was including the "rs485_non_blocking", but did not include "rs485_protocol".
Including rs485_protocol fixed it!
Thank you for the quick response, though!
Australia Forum Administrator #9
Your code as posted seems to combine the non-blocking and blocking code. If you want blocking, just use the "RS485_protocol.h" file. Otherwise include the other file.