Go Down

Topic: Difficulty talking to VFD over modbus.  (Read 31 times) previous topic - next topic

jmusther

Sep 04, 2015, 06:10 am Last Edit: Sep 04, 2015, 06:12 am by jmusther
I have a variable frequency drive (VFD) for driving a three phase motor (on a pump).  It has an RS485 modbus RTU interface (page 162) and decent documentation (download PDF here: https://www.dropbox.com/s/j1zbez2j69bc2fx/KOC100%20Series%20User%20Manual--20150119%28V1.1%29.pdf?dl=0).  

I'm aware of the various modbus libraries that are available, but right now I'm just tying to verify that I can get things to work.  I've got an arduino hooked to a TTL/RS485 module (like this: http://yourduino.com/sunshop2/index.php?l=product_detail&p=323), which in turn is connected to the VFD.  

I've gone through the controls and set up the VFD:
To take communication from over modbus - page 37, b0-02 set to 2
To run at 1200 baud - page 52, bA-01 set to 2
To use 8N1 serial - page 52, bA-02 set to 3
To have address 1 - page 52, bA-03 set to 1

I've written a little bit of code to try to send the forward start command (general interface described from page 162, start command at top of page 167).  

Code: [Select]
#include <SoftwareSerial.h>
// Define the pins on which RS485 is connected
#define RO  3
#define DI  5
#define DE  4   // RE is connected here too

byte buffer[8];

SoftwareSerial RS485(RO, DI);   // RX, TX

void setup() {
  pinMode(DE, OUTPUT);           // set pin to input
  Serial.begin(9600);
  RS485.begin(1200);
  
  digitalWrite(DE, LOW);

  delay(200);   // Let serial come up and give stable DE high

  // Create message
  buffer[0] = 0x01;   // Address
  buffer[1] = 0x06;   // Command - write
  buffer[2] = 0x20;   // Function code H
  buffer[3] = 0x00;   // Function code L
  buffer[4] = 0x00;   // Function number H
  buffer[5] = 0x01;   // Function number L
  buffer[6] = 0xCA;   // CRC H
  buffer[7] = 0x43;   // CRC L
}

void loop() {
  Serial.println("Waiting...");
  delay(50);
  Serial.println("Sending now...");
  
  digitalWrite(DE, HIGH);   // Pull up DE
  delay(50);
  int bytesSent = RS485.write(buffer, 8);   // Write the message

  delay(50);               // Delay to allow message to finish
  digitalWrite(DE, LOW);    // Drop DE

  Serial.print("Sent ");
  Serial.print(bytesSent);
  Serial.println(" bytes");

  // Now let's do nothing, forever...
  while (true) {
  }
}


As you can see I'm bringing up the DE pin (which is shorted to the RE pin) on my RS485 module in order to start sending data.  Using the scope I can see that when the DE/RE pins are LOW I get about -2.5V, when I bring those pins up, i get 0V.  When I run the code above, I can see the bytes transmitted between -2.5 and 2.5V.  This all looks good, and I'm using a nice slow baud rate because I'm aware of issues with softwareserial at higher rates.  

Note that I've pulled the bytes for the message from the manual, and I've calculated the CRC here:
http://www.lammertbies.nl/comm/info/crc-calculation.html

So I expect the VFD to start, but it isn't.  Any thoughts?

jmusther

I managed to get the hardware side of this working by reading LOTS more about RS485 and balancing the lines.  I then had more a problem making sense of the VFDs response, so in case anyone is interested, the post about that is here: http://forum.arduino.cc/index.php?topic=345885.0

Go Up