Shop OBEX P1 Docs P2 Docs Learn Events
Arduino / Propeller Modbus riddle — Parallax Forums

Arduino / Propeller Modbus riddle

I am trying to read an Elite Power Systems CPU using a Mega 2560 and a DFRobot RS232 shield. Here is my code. The Elite CPU has a Propeller chip in it and it is coded in Spin.
// modbus toggle pin: D2

#include <SimpleModbusMaster.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

double bmsHighestCellVoltage = 0;                                                  // from BMS register 30007
double bmsLowestCellVoltage = 0;                                                   // from BMS register 30009
double officialCellCount = 5;                                                        // from BMS register 30001
double packAmps = 0;

LiquidCrystal_I2C lcd1(0X20, 20, 4);                                              // set the LCD address to 0X20 for a 20 chars and 4 line display for lcd 1

#define baud        19200
#define timeout     1500
#define polling     200                                                           // the scan rate
#define retry_count 20
#define TxEnablePin 2                                                             // used to toggle the receive/transmit pin on the driver     

enum
{
  PACKET1,
  TOTAL_NO_OF_PACKETS                                                              // leave this entry as last
};
Packet packets[TOTAL_NO_OF_PACKETS];                                               // Create an array of Packet arrays to be configured
packetPointer packet1 = &packets[PACKET1];                                         // Create a packetPointer to access each packet array
unsigned int readRegsc[20];

void setup () {

  lcd1.init ();                                                                     // lcd setUp LCD1 display - lcd on @ start up
  lcd1.backlight ();
  lcd1.display ();

  modbus_construct(packet1, 1, READ_INPUT_REGISTERS, 30001, 18, readRegsc);        // read 18 BMS registers starting at register 30001 ending at 30019
  modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);      // Initialize communication settings:
  packets[PACKET1].connection = 1;                                                  // turns packet1 read connection on or off
}

void loop() {
  modbus_update();
  bmsHighestCellVoltage = readRegsc[6];                                             // from BMS register 30007
  bmsLowestCellVoltage = readRegsc[8];                                              // from BMS register 30009
  packAmps = readRegsc[11];
  double  packSOC  = readRegsc[12];                                                   // from BMS register 30013
  double  minCellTemp = readRegsc[17];                                                // from BMS register 30017

  lcd1.setCursor (0, 0);
  lcd1.print (packets[PACKET1].connection);
  lcd1.setCursor (0, 1);
  lcd1.print ( bmsHighestCellVoltage);
  lcd1.setCursor (9, 1);
  lcd1.print (bmsLowestCellVoltage);
  lcd1.setCursor (0, 2);
  lcd1.print (packSOC);
  lcd1.setCursor (9, 2);
  lcd1.print (packAmps);
  lcd1.setCursor (0, 3);
  lcd1.print (minCellTemp);
}

When the code runs it times out and the connection turns off. The CPU does not respond in any fashion. I have used the hardware to communicate with a Midnite Solar charge controller so I know the Mega and RS232 shield work and are wired correctly. I have used the CAS Modbus scanner to communicate with the CPU so I know it is alive and works. The CAS Scanner gives the connection details so I know that the baud rate and 8N1 are correct. Here is a link to the Elite Modbus Specifications. The CPU is the Slave.

http://elitepowersolutions.com/docs/EMS MODBUS Specification.pdf

There is something about the CPU and the Spin Modbus that I do not understand. I an quite sure my code should work so I wonder if there is something about the Propeller that I need to do differently.

Thanks for any help.

Will

Comments

  • kwinnkwinn Posts: 8,697
    Are the Mega and DFR both using the same signal protocol (ie RS232 <> RS232 or RS485 <> RS485). RS232 <> RS485 will not work.
  • Hello,

    Thank you for the reply. Yes- the Mega and DFR are both on RS 232. I have used the equipment, with different code, to do serial with my Midnite Classic solar charge controller and it works well. The Elite CPU is also set for RS 232. It seems strange to me that the CAS modbus scanner sytem will communicate with the propeller chip in the CPU but the Modbus code I am running will not, however the code works with other hardware. This is what makes me think it may be a propeller issue of some kind.

    Will
  • I am not that experienced a coder. The Elite Modbus protocol states the CPU slave will only reply to a command of $04 ( function Read Input Registers) . This to me is one byte binary 00000100. The modbus master object I am using in C sends a command of 4. This to me is also binary 00000100 so I think the CPU should respond but it does not.

    Thanks

    Will
  • Been there, done that w/ similar devices. A logic analyzer/scope is your best friend. One of the Salae LAs will pay for itself in no time. Without the ability to see what's on that wire, you're shooting in the dark.

    -Mike
  • kwinnkwinn Posts: 8,697
    You could also try a scope if you have one at hand. At least you can see if the TX line from the propeller is the correct polarity when idling, and sending bits occasionally.
  • Hello,

    Thanks for the replys. I will learn about logic analyzers. I don't have a scope. I have been reading a topic on the Arduino forum and it has aposting that says both the dricer ics if the slave ( Propeller) and master ( Arduino) must be at the same voltage. The Propeller chip runs at 3.3V and the Mega at 5V. I would assume the driver ics run the same voltage of the chip?? If this is the case then maybe my problem is the voltage difference between the two micro controllers.

    Thanks for all help.

    Will
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2016-10-03 01:41
    Don't make it complicated, just build a simple modbus packet "manually" with checksum and send it, then capture anything that comes back. If there is no response then it may be something as simple as baud rate.
  • I managed to get the Modbus to work between the Propeller chip and the Arduino. I did not understand the offset for the register addresses well enough and was requesting invalid registers. The CPU was repying but just sending me an error code.

    Thanks for all the help.

    Will
Sign In or Register to comment.