Pages: [1]   Go Down
Author Topic: RS485 issue using SoftwareSerial()  (Read 730 times)
0 Members and 1 Guest are viewing this topic.
NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I have downloaded Nick Gammon code, but are having some compiling issues.
I got it down to 2 errors

Code:
//#include "WConstants.h"
#include <RS485_non_blocking.h>
//#include "RS485_protocol.h"
#include <SoftwareSerial.h>

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

SoftwareSerial rs485(2, 3);  // receive pin, transmit pin

// 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);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
  pinMode (LED_PIN, OUTPUT);  // built-in LED
}  // end of setup
 
byte old_level = 0;

void loop()
{

  // read potentiometer
  byte level = analogRead (0) / 4;
 
  // no change? forget it
  if (level == old_level)
    return;
     
  // assemble message
  byte msg [] = {
     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;

}  // end of loop

Errors are:
sketch_jan14a.cpp: In function ‘void loop()’:
sketch_jan14a.cpp:62:35: error: ‘sendMsg’ was not declared in this scope
sketch_jan14a.cpp:67:62: error: ‘recvMsg’ was not declared in this scope

But what do I replace the sendMsg with.
I have looked through the SoftwareSerial.cpp and .h files but nothing springs to mind

Thanks for any suggestions

Kim
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
sketch_jan14a.cpp:62:35: error: ‘sendMsg’ was not declared in this scope
sketch_jan14a.cpp:67:62: error: ‘recvMsg’ was not declared in this scope
Well, they aren't, are they?

A link to where you got the code would be good. That way, we can see whether you got ALL the code. Doesn't look like you did. Or, you were expected to write those functions.
Logged

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Straight from Nick Gammon site
http://www.gammon.com.au/forum/?id=11428
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess we'll have to wait for Nick to respond.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess we'll have to wait for Nick to respond.

In the meantime have a look at post #8 in this thread http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=11603
Logged

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorted.

For some reason I commented out 
//#include <RS485_protocol.h>
and included
#include <RS485_non_blocking.h>

when both should be included.
Sometimes you just can't see the forest for the trees

Cheers
Logged

Pages: [1]   Go Up
Jump to: