Hi, Mark my problem is that I'm traying to communicate a Arduino UNO and a 2560 using the RS485, the Uno is the Master and I'm using the Software Serial library to the comunication the reason is because i'm using the serial port to control a display, I can send data from the Slave to the master and the reception of the message is Ok but when I send the data to the slave the message isn't detected. there is the code that I try to use to test the communication, it isn't the final code.
I get this code from internet,I only modified a few code lines and alter the master and slave roles.
Master
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 15 //Serial Receive pin
#define SSerialTX 14 //Serial Transmit pin
#define SSerialTxControl 34 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("YourDuino.com SoftwareSerial remote loop example");
Serial.println("Use Serial Monitor, type in upper window, ENTER");
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
if (Serial.available())
{
digitalWrite(Pin13LED, HIGH); // Show activity
byteReceived = Serial.read();
Serial.println("Valor leido");
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteReceived); // Send byte to Remote Arduino
//RS485Serial.write('k'); // Send byte to Remote Arduino
Serial.println("Valor enviado");
digitalWrite(Pin13LED, LOW); // Show activity
delay(100);
digitalWrite(SSerialTxControl, RS485Receive);
//delay(1000);
if(RS485Serial.available()>0){
byteReceived = RS485Serial.read();
Serial.println("Respuesta Recivida");
Serial.println(byteReceived);
delay(100);
}
}
}
Slave
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 5 //Serial Receive pin
#define SSerialTX 4 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("SerialRemote"); // Can be ignored
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//Copy input data to output
if (RS485Serial.available())
{
Serial.println("Respuesta Recivida");
byteSend = RS485Serial.read();
Serial.println(byteSend);
delay(100);
digitalWrite(Pin13LED, HIGH); // Show activity
delay(100);
digitalWrite(Pin13LED, LOW);
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteReceived);
digitalWrite(SSerialTxControl, RS485Receive);
Serial.println("Respuesta enviada");
}// End If RS485SerialAvailable
}//--(end main loop )---