Hey everyone! I could use some help getting communication between a Controller (Danfoss EKE 1C) and Arduino Mega. Thanks for your feedback!
Purpose: Query/write to controller in a hex-array format using Modbus RS485.
Desired: When the hex message is sent to the controller (slave), the message reply is an echo of the original message to acknowledge (or some exception).
Actual: Every row of buffer reads 0xFF. available() function returns 0 and read() function returns -1.
Troubleshooting:
I measured voltages and resistances throughout the circuit. Also verified pins are wired per diagram below.
I attempted to use write() and read() directly using parity and crc calculations that I found online, with the exact same outcome.
I believe the issue may lie in the start/stop/parity bits and the doubled/inverted format in gammon's library, but:
- I would expect some response from the controller.
- I'm not sure how to build the message (adding start/stop/parity/crc).
Components:
Max485 dev board (Amazon)
Expansion valve controller (Danfoss EKE 1C)
Arduino Mega 2560
My code is a modified version of this Gammon example using the RS485_protocol library.
Arduino Code:
#include "RS485_protocol.h"
#include <SoftwareSerial.h>
const byte ENABLE_PIN = 28;
// const byte LED_PIN = 13;
SoftwareSerial exp_v (15, 14); // receive pin, transmit pin
// callback routines
void fWrite (const byte what)
{
exp_v.write (what);
}
int fAvailable ()
{
return exp_v.available ();
}
int fRead ()
{
return exp_v.read ();
}
void setup()
{
exp_v.begin (19200);
pinMode (ENABLE_PIN, OUTPUT); // driver output enable
Serial.begin (19200);
Serial.println("Expansion Valve Comms");
} // end of setup
byte old_level = 0;
void loop()
{
// Wait for user input to start
while(Serial.available() == 0){
// do nothing
}
Serial.println("Querying EV");
// assemble message per guide step 1: Main switch= off
byte msg [] = {
0xF0, // Unit address: 240
0x06, // Function code (03: read, 06: write)
0x0B, /* Hi Byte address (PNU) Main switch (PNU: 3001, actual
request is for 3000), 00 should be used for 2 digit hex */
0xB8, // Lo Byte address (PNU)
0x00, // Desired Value set to off (=0)
0x00 // Desired Value set to off
};
// send to slave
Serial.println("Sending Query");
digitalWrite (ENABLE_PIN, HIGH); // enable sending
sendMsg (fWrite, msg, sizeof msg);
// delayMicroseconds(520);
digitalWrite (ENABLE_PIN, LOW); // disable sending
// receive response
byte buf [11];
byte received = recvMsg (fAvailable, fRead, buf, sizeof buf);
// print response to Serial monitor
if(received == 0){
Serial.println("No comms");
}
else {
Serial.println("Message:");
for(byte i=0; i < sizeof buf; i++){
Serial.print(buf[i]);
Serial.print(" ");
}
Serial.println(" ---End of Message---");
}
// clear serial cache
while(Serial.available() > 0){
Serial.read();
}
} // end of loop
The breadboard wiring is pretty messy, but here's a diagram:
The valve controller provides the following guidance for RS485 communication.