Communicating with VFD over Modbus

Hello, I am looking to communicate with an Allen Bradley Powerflex 4 VFD, using my Arduino Uno and Modbus communication. I am currently using the SimpleModbusMaster library from Juan B. I have tried changing my code several times and I made sure the VFD's parameters were set to communicate over the com ports. Does anyone have experience with this sort of project? Any help would be greatly appreciated. I will post my code below and here is the link to the VFD manual:

#include <SimpleModbusMaster.h>
#include <TimerOne.h>
//#include <SoftwareSerial.h>

//////////////////// Port information ///////////////////

#define baud 9600        
#define timeout 1000      
#define polling 600      
#define retry_count 10    
#define TxEnablePin 2    
#define TOTAL_NO_OF_REGISTERS 1 
//////////////////// Assembly of the Modbus packets ///////////////
int LED = 13;
enum
{
  PACKET1,
  PACKET2,
  PACKET3,
  TOTAL_NO_OF_PACKETS // Leave this last entry. It tells the library how many packets are to be sent out.
};
Packet packets[TOTAL_NO_OF_PACKETS]; //Leave this line in here.

enum {
  Master_CommandWord,
  Master_SetSpeed,
  Regs_Size
};
// Masters register array
unsigned int regs[Regs_Size];
/////////////////////////VFD READS//////////////////////////////
Packet* statusWordVSD = &packets[PACKET1];
/////////////////////////VFD WRITES/////////////////////////////
Packet* commandWordVSD = &packets[PACKET2];
Packet* userSetSpeedVSD = &packets[PACKET3];

void setup()
{
  //modbus_construct(statusWordVSD, 2, READ_HOLDING_REGISTERS, 8448, 1, 0);
  modbus_construct(commandWordVSD, 2, PRESET_SINGLE_REGISTER, 8192, 1, 0);
  modbus_construct(userSetSpeedVSD, 2, PRESET_SINGLE_REGISTER, 8193, 1, 1);
  
  modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
  pinMode(LED, OUTPUT);
 }
 
void loop()
{ 
  modbus_update();
  regs[Master_CommandWord] = 1;
  regs[Master_SetSpeed] = 200;

  //if (packets[TOTAL_NO_OF_PACKETS].failed_requests >= 4) {
  //digitalWrite(LED,HIGH);
  //}
}

I've interfaced to a lot of AB drives over the years, but not with an Arduino. My real job is DCS configuration.

I do have a couple of questions. Are you trying to talk to the drive over RS232 or RS485? I did not notice a slave address in the code.

What hardware are you using to convert the TTL signal into true RS232/485?

If you are using RS232, I would recommend going to RS485 to minimize the noise created by the drive itself.

Hello, I actually managed to get it to work. I can explain more about my code if you would like. I did find a way to add a terminating resistor that I did not have before and I connected pin 16 to the PE ground, so I believe this what finally let the communication work. I am communicating over RS485 and I am using the DFRobot RS485 shield. Thank you for your reply!

Hello Parker,

I am also trying to communicate with Powerflex 4m using an RS485 converter.
I keep getting communication error F081 on the Allen-Bradley controller and am not able to communicate correctly.

Would you be able to provide you final working code so I can take a look and try to understand where I went wrong?

I truly appreciate it.