Go Down

Topic: RS485 issue using SoftwareSerial() (Read 866 times) previous topic - next topic

fiddler

Hi

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

Code: [Select]

//#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

PaulS

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.

fiddler

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

PaulS

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

AcmeUK


fiddler

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

Go Up