diff --git a/Software/Software.ino b/Software/Software.ino index 33a81c3c..ba3a41da 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -276,7 +276,7 @@ void core_loop(void*) { transmit_can(currentMillis); // Send CAN messages to all components #ifdef RS485_BATTERY_SELECTED - transmit_rs485(); + transmit_rs485(currentMillis); #endif // RS485_BATTERY_SELECTED #ifdef FUNCTION_TIME_MEASUREMENT END_TIME_MEASUREMENT_MAX(cantx, datalayer.system.status.time_cantx_us); diff --git a/Software/src/battery/BATTERIES.h b/Software/src/battery/BATTERIES.h index 80afe51f..1f1e0d8b 100644 --- a/Software/src/battery/BATTERIES.h +++ b/Software/src/battery/BATTERIES.h @@ -151,7 +151,7 @@ void setup_battery(void); void update_values_battery(); #ifdef RS485_BATTERY_SELECTED -void transmit_rs485(); +void transmit_rs485(unsigned long currentMillis); void receive_RS485(); #else void handle_incoming_can_frame_battery(CAN_frame rx_frame); diff --git a/Software/src/battery/DALY-BMS.cpp b/Software/src/battery/DALY-BMS.cpp index 59e135c9..6e96db01 100644 --- a/Software/src/battery/DALY-BMS.cpp +++ b/Software/src/battery/DALY-BMS.cpp @@ -154,24 +154,21 @@ void decode_packet(uint8_t command, uint8_t data[8]) { } } -void transmit_rs485() { +void transmit_rs485(unsigned long currentMillis) { static uint8_t nextCommand = 0x90; - if (millis() - lastPacket > 60) { + if (currentMillis - lastPacket > 60) { + lastPacket = currentMillis; uint8_t tx_buff[13] = {0}; tx_buff[0] = 0xA5; tx_buff[1] = 0x40; tx_buff[2] = nextCommand; tx_buff[3] = 8; tx_buff[12] = calculate_checksum(tx_buff); - #ifdef DEBUG_VIA_USB dump_buff("transmitting: ", tx_buff, 13); #endif - Serial2.write(tx_buff, 13); - lastPacket = millis(); - nextCommand++; if (nextCommand > 0x98) nextCommand = 0x90;