diff --git a/Software/Software.ino b/Software/Software.ino index eeb9d5a5..bf011743 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -124,6 +124,7 @@ void setup() { init_contactors(); init_modbus(); + init_serialDataLink(); inform_user_on_inverter(); @@ -241,6 +242,11 @@ void init_modbus() { handle_static_data_modbus_byd(); #endif #if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS) + #if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER) + // Check that Dual LilyGo via RS485 option isn't enabled, this collides with Modbus! + #error MODBUS CANNOT BE USED IN DOUBLE LILYGO SETUPS! CHECK USER SETTINGS! + #endif + // Init Serial2 connected to the RTU Modbus RTUutils::prepareHardwareSerial(Serial2); Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN); @@ -627,18 +633,18 @@ void update_values() { } void runSerialDataLink() { - static unsigned long sdlTimer = 0; + static unsigned long updateTime = 0; unsigned long currentMillis = millis(); #ifdef SERIAL_LINK_RECEIVER - if (currentMillis - sdlTimer >= 1) { //--- try 2 second - sdlTimer = currentMillis; + if ((currentMillis - updateTime) > 1) { //Every 2ms + updateTime = currentMillis; manageSerialLinkReceiver(); } #endif #ifdef SERIAL_LINK_TRANSMITTER - if (currentMillis - sdlTimer >= 1) { //--- try 2 second - sdlTimer = currentMillis; + if ((currentMillis - updateTime) > 1) { //Every 2ms + updateTime = currentMillis; manageSerialLinkTransmitter(); } #endif diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h index 417c2bb9..a5c521a3 100644 --- a/Software/USER_SETTINGS.h +++ b/Software/USER_SETTINGS.h @@ -44,6 +44,6 @@ //#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters) //#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter) //#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery) -#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver +//#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver #endif diff --git a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp index aee4dd1f..e4ddf207 100644 --- a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp +++ b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.cpp @@ -19,8 +19,6 @@ const uint8_t sendingNumVariables = 0; #define SerialReceiver Serial2 #endif -#define REPORT_SDL_DATA 1 - // txid,rxid, num_send,num_recv SerialDataLink dataLinkReceive(SerialReceiver, 0, 0x01, sendingNumVariables, INVERTER_RECV_NUM_VARIABLES); // ... @@ -55,8 +53,8 @@ void __getData() { void updateData() { // --- update with fresh data dataLinkReceive.updateData(0, inverterAllowsContactorClosing); - //dataLinkReceive.updateData(1,var2); - //dataLinkReceive.updateData(2,var3); + //dataLinkReceive.updateData(1,var2); // For future expansion, + //dataLinkReceive.updateData(2,var3); // if inverter needs to send data to battery } /* @@ -156,7 +154,7 @@ void manageSerialLinkReceiver() { // --- printUsefullData(); //Serial.print("SOC = "); //Serial.println(SOC); -#ifdef REPORT_SDL_DATA +#ifdef DEBUG_VIA_USB update_values_serial_link(); #endif } diff --git a/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp b/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp index 838b94df..ccf07c8f 100644 --- a/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp +++ b/Software/src/inverter/SERIAL-LINK-TRANSMITTER-INVERTER.cpp @@ -17,8 +17,6 @@ const uint8_t receivingNumVariables = BATTERY_RECV_NUM_VARIABLES; const uint8_t receivingNumVariables = 0; #endif -//#define REPORT_SDL_DATA 1 - // txid,rxid,num_tx,num_rx SerialDataLink dataLinkTransmit(Serial2, 0x01, 0, BATTERY_SEND_NUM_VARIABLES, receivingNumVariables); @@ -26,8 +24,8 @@ void printSendingValues(); void _getData() { inverterAllowsContactorClosing = dataLinkTransmit.getReceivedData(0); - //var2 = dataLinkTransmit.getReceivedData(1); - //var3 = dataLinkTransmit.getReceivedData(2); + //var2 = dataLinkTransmit.getReceivedData(1); // For future expansion, + //var3 = dataLinkTransmit.getReceivedData(2); // if inverter needs to send data to battery } void manageSerialLinkTransmitter() { @@ -92,7 +90,7 @@ void manageSerialLinkTransmitter() { Serial.print(currentTime); Serial.println(" - Transmit Good"); // printUsefullData(); -#ifdef REPORT_SDL_DATA +#ifdef DEBUG_VIA_USB void printSendingValues(); #endif }