diff --git a/Software/src/communication/can/comm_can.cpp b/Software/src/communication/can/comm_can.cpp
index 5ed4be1b..1f82a655 100644
--- a/Software/src/communication/can/comm_can.cpp
+++ b/Software/src/communication/can/comm_can.cpp
@@ -41,7 +41,8 @@ void register_can_receiver(CanReceiver* receiver, CAN_Interface interface, CAN_S
ACAN_ESP32_Settings* settingsespcan;
-static const uint32_t QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL; //MHZ configured in USER_SETTINGS.h
+uint8_t user_selected_can_addon_crystal_frequency_mhz = 0;
+static uint32_t QUARTZ_FREQUENCY;
SPIClass SPI2515;
ACAN2515* can2515;
@@ -59,6 +60,12 @@ bool native_can_initialized = false;
bool init_CAN() {
+ if(user_selected_can_addon_crystal_frequency_mhz > 0){
+ QUARTZ_FREQUENCY = user_selected_can_addon_crystal_frequency_mhz * 1000000UL;
+ } else {
+ QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
+ }
+
auto nativeIt = can_receivers.find(CAN_NATIVE);
if (nativeIt != can_receivers.end()) {
auto se_pin = esp32hal->CAN_SE_PIN();
diff --git a/Software/src/communication/can/comm_can.h b/Software/src/communication/can/comm_can.h
index 6e8e6a4b..2b7ece97 100644
--- a/Software/src/communication/can/comm_can.h
+++ b/Software/src/communication/can/comm_can.h
@@ -4,6 +4,7 @@
#include "../../devboard/utils/types.h"
extern bool use_canfd_as_can;
+extern uint8_t user_selected_can_addon_crystal_frequency_mhz;
void dump_can_frame(CAN_frame& frame, frameDirection msgDir);
void transmit_can_frame_to_interface(const CAN_frame* tx_frame, int interface);
diff --git a/Software/src/communication/nvm/comm_nvm.cpp b/Software/src/communication/nvm/comm_nvm.cpp
index 91adc099..36904535 100644
--- a/Software/src/communication/nvm/comm_nvm.cpp
+++ b/Software/src/communication/nvm/comm_nvm.cpp
@@ -103,6 +103,7 @@ void init_stored_settings() {
user_selected_inverter_ah_capacity = settings.getUInt("INVAHCAPACITY", 0);
user_selected_inverter_battery_type = settings.getUInt("INVBTYPE", 0);
user_selected_inverter_ignore_contactors = settings.getBool("INVICNT", false);
+ user_selected_can_addon_crystal_frequency_mhz = settings.getUInt("CANFREQ", 8);
auto readIf = [](const char* settingName) {
auto batt1If = (comm_interface)settings.getUInt(settingName, (int)comm_interface::CanNative);
diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp
index 7ca338ce..8b1bf9ee 100644
--- a/Software/src/devboard/webserver/settings_html.cpp
+++ b/Software/src/devboard/webserver/settings_html.cpp
@@ -500,6 +500,10 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
return settings.getBool("INVICNT") ? "checked" : "";
}
+ if (var == "CANFREQ") {
+ return String(settings.getUInt("CANFREQ", 8));
+ }
+
return String();
}
@@ -823,6 +827,9 @@ const char* getCANInterfaceName(CAN_Interface interface) {
+
+
+
diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp
index 71df6879..eb3870cb 100644
--- a/Software/src/devboard/webserver/webserver.cpp
+++ b/Software/src/devboard/webserver/webserver.cpp
@@ -515,6 +515,9 @@ void init_webserver() {
} else if (p->name() == "INVBTYPE") {
auto type = atoi(p->value().c_str());
settings.saveUInt("INVBTYPE", (int)type);
+ } else if (p->name() == "CANFREQ"){
+ auto type = atoi(p->value().c_str());
+ settings.saveUInt("CANFREQ", type);
}
for (auto& boolSetting : boolSettings) {