Arduino / Propeller Modbus riddle
willeert
Posts: 14
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.
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
// 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
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
Thanks
Will
-Mike
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
Thanks for all the help.
Will