From cba77f9eb52e8fd5816a418c79ff95d516e6e47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Wed, 21 Aug 2024 22:18:27 +0300 Subject: [PATCH 1/3] Add SMA Enable pin to Stark HAL --- Software/src/devboard/hal/hw_stark.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Software/src/devboard/hal/hw_stark.h b/Software/src/devboard/hal/hw_stark.h index 39af1f8e..7bc45a54 100644 --- a/Software/src/devboard/hal/hw_stark.h +++ b/Software/src/devboard/hal/hw_stark.h @@ -51,6 +51,9 @@ GPIOs on extra header #define PRECHARGE_PIN 25 #define BMS_POWER 23 +// SMA CAN contactor pins +#define INVERTER_CONTACTOR_ENABLE_PIN 19 + // LED #define LED_PIN 4 #define LED_MAX_BRIGHTNESS 40 From 4db1ad23a7f78e01615581903a1781085837c2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Wed, 21 Aug 2024 22:23:38 +0300 Subject: [PATCH 2/3] Add BYD_SMA to github workflow --- .github/workflows/compile-all-combinations.yml | 1 + .github/workflows/compile-all-inverters.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/compile-all-combinations.yml b/.github/workflows/compile-all-combinations.yml index f4521504..799023fe 100644 --- a/.github/workflows/compile-all-combinations.yml +++ b/.github/workflows/compile-all-combinations.yml @@ -53,6 +53,7 @@ jobs: # These are the emulated inverter communication protocols for which the code will be compiled. inverter: - BYD_CAN + - BYD_SMA - BYD_MODBUS - LUNA2000_MODBUS - PYLON_CAN diff --git a/.github/workflows/compile-all-inverters.yml b/.github/workflows/compile-all-inverters.yml index 78f52408..d12c7c7e 100644 --- a/.github/workflows/compile-all-inverters.yml +++ b/.github/workflows/compile-all-inverters.yml @@ -43,6 +43,7 @@ jobs: # These are the emulated inverter communication protocols for which the code will be compiled. inverter: - BYD_CAN + - BYD_SMA - BYD_MODBUS - LUNA2000_MODBUS - PYLON_CAN From 9ada5b9f5e30f8330443423e9e2abd1fb9713ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Wed, 21 Aug 2024 22:31:48 +0300 Subject: [PATCH 3/3] Fix SMA CAN H code like HVS --- Software/src/inverter/BYD-SMA.cpp | 6 ++-- Software/src/inverter/SMA-CAN.cpp | 46 ++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Software/src/inverter/BYD-SMA.cpp b/Software/src/inverter/BYD-SMA.cpp index 8100fbb8..229ec696 100644 --- a/Software/src/inverter/BYD-SMA.cpp +++ b/Software/src/inverter/BYD-SMA.cpp @@ -46,7 +46,7 @@ CAN_frame SMA_558 = {.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x558, - .data = {0x03, 0x13, 0x00, 0x03, 0x00, 0x66, 0x04, 0x07}}; + .data = {0x03, 0x13, 0x00, 0x03, 0x00, 0x66, 0x04, 0x07}}; //4x BYD modules, Vendor ID 7 BYD CAN_frame SMA_598 = {.FD = false, .ext_ID = false, .DLC = 8, @@ -66,12 +66,12 @@ CAN_frame SMA_618_2 = {.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x618, - .data = {0x01, 0x2D, 0x42, 0x6F, 0x78, 0x20, 0x48, 0x31}}; + .data = {0x01, 0x2D, 0x42, 0x6F, 0x78, 0x20, 0x48, 0x31}}; //- B o x H 1 CAN_frame SMA_618_3 = {.FD = false, .ext_ID = false, .DLC = 8, .ID = 0x618, - .data = {0x02, 0x30, 0x2E, 0x32, 0x00, 0x00, 0x00, 0x00}}; + .data = {0x02, 0x30, 0x2E, 0x32, 0x00, 0x00, 0x00, 0x00}}; // 0 . 2 static int16_t discharge_current = 0; static int16_t charge_current = 0; diff --git a/Software/src/inverter/SMA-CAN.cpp b/Software/src/inverter/SMA-CAN.cpp index d9008e02..b9cff6b3 100644 --- a/Software/src/inverter/SMA-CAN.cpp +++ b/Software/src/inverter/SMA-CAN.cpp @@ -6,7 +6,7 @@ /* TODO: Map error bits in 0x158 */ /* Do not change code below unless you are sure what you are doing */ -static unsigned long previousMillis100ms = 0; // will store last time a 100ms CAN Message was send +static unsigned long previousMillis60s = 0; //Actual content messages CAN_frame SMA_558 = {.FD = false, @@ -151,6 +151,12 @@ void update_values_can_inverter() { //This function maps all the values fetched } //Error bits + if (!datalayer.system.status.inverter_allows_contactor_closing) { + SMA_158.data.u8[2] = 0x6A; + } else { + SMA_158.data.u8[2] = 0xAA; + } + /* //SMA_158.data.u8[0] = //bit12 Fault high temperature, bit34Battery cellundervoltage, bit56 Battery cell overvoltage, bit78 batterysystemdefect //TODO: add all error bits. Sending message with all 0xAA until that. @@ -208,15 +214,35 @@ void receive_can_inverter(CAN_frame rx_frame) { //Frame0-1 Voltage //Frame2-3 Current break; + case 0x3E0: //Message originating from SMA inverter - ? + break; case 0x420: //Message originating from SMA inverter - Timestamp //Frame0-3 Timestamp - break; - case 0x3E0: //Message originating from SMA inverter - ? + transmit_can(&SMA_158, can_config.inverter); + transmit_can(&SMA_358, can_config.inverter); + transmit_can(&SMA_3D8, can_config.inverter); + transmit_can(&SMA_458, can_config.inverter); + transmit_can(&SMA_518, can_config.inverter); + transmit_can(&SMA_4D8, can_config.inverter); break; case 0x5E0: //Message originating from SMA inverter - String break; case 0x560: //Message originating from SMA inverter - Init break; + case 0x5E7: //Pairing request + transmit_can(&SMA_558, can_config.inverter); + transmit_can(&SMA_598, can_config.inverter); + transmit_can(&SMA_5D8, can_config.inverter); + transmit_can(&SMA_618_1, can_config.inverter); + transmit_can(&SMA_618_2, can_config.inverter); + transmit_can(&SMA_618_3, can_config.inverter); + transmit_can(&SMA_158, can_config.inverter); + transmit_can(&SMA_358, can_config.inverter); + transmit_can(&SMA_3D8, can_config.inverter); + transmit_can(&SMA_458, can_config.inverter); + transmit_can(&SMA_518, can_config.inverter); + transmit_can(&SMA_4D8, can_config.inverter); + break; default: break; } @@ -225,22 +251,16 @@ void receive_can_inverter(CAN_frame rx_frame) { void send_can_inverter() { unsigned long currentMillis = millis(); - // Send CAN Message every 100ms - if (currentMillis - previousMillis100ms >= INTERVAL_100_MS) { - previousMillis100ms = currentMillis; + // Send CAN Message every 60s + if (currentMillis - previousMillis60s >= INTERVAL_60_S) { + previousMillis60s = currentMillis; - transmit_can(&SMA_558, can_config.inverter); - transmit_can(&SMA_598, can_config.inverter); - transmit_can(&SMA_5D8, can_config.inverter); - transmit_can(&SMA_618_1, can_config.inverter); // TODO, should these 3x - transmit_can(&SMA_618_2, can_config.inverter); // be sent as batch? - transmit_can(&SMA_618_3, can_config.inverter); // or alternate on each send? + transmit_can(&SMA_158, can_config.inverter); transmit_can(&SMA_358, can_config.inverter); transmit_can(&SMA_3D8, can_config.inverter); transmit_can(&SMA_458, can_config.inverter); transmit_can(&SMA_518, can_config.inverter); transmit_can(&SMA_4D8, can_config.inverter); - transmit_can(&SMA_158, can_config.inverter); } } #endif