mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 01:39:30 +02:00
update DUAL_CAN to CAN_ADDON and update CAN_FD to CANFD_ADDON
This commit is contained in:
parent
4fef40b2a3
commit
7fe5dcb0b8
9 changed files with 54 additions and 54 deletions
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
|
@ -23,6 +23,6 @@
|
|||
- Inverter communication protocol: ``
|
||||
- Hardware used for Battery-Emulator: `HW_LILYGO, HW_STARK, Custom`
|
||||
- CONTACTOR_CONTROL: `yes/no`
|
||||
- DUAL_CAN: `yes/no`
|
||||
- CAN_ADDON: `yes/no`
|
||||
- WEBSERVER: `yes/no`
|
||||
- MQTT: `yes/no`
|
||||
|
|
|
@ -65,16 +65,16 @@ CAN_device_t CAN_cfg; // CAN Config
|
|||
const int rx_queue_size = 10; // Receive Queue size
|
||||
volatile bool send_ok = 0;
|
||||
|
||||
#ifdef DUAL_CAN
|
||||
#ifdef CAN_ADDON
|
||||
#include "src/lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
static const uint32_t QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL; //MHZ configured in USER_SETTINGS.h
|
||||
ACAN2515 can(MCP2515_CS, SPI, MCP2515_INT);
|
||||
static ACAN2515_Buffer16 gBuffer;
|
||||
#endif //DUAL_CAN
|
||||
#ifdef CAN_FD
|
||||
#endif //CAN_ADDON
|
||||
#ifdef CANFD_ADDON
|
||||
#include "src/lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
||||
ACAN2517FD canfd(MCP2517_CS, SPI, MCP2517_INT);
|
||||
#endif //CAN_FD
|
||||
#endif //CANFD_ADDON
|
||||
|
||||
// ModbusRTU parameters
|
||||
#ifdef MODBUS_INVERTER_SELECTED
|
||||
|
@ -276,10 +276,10 @@ void core_loop(void* task_time_us) {
|
|||
|
||||
// Input, Runs as fast as possible
|
||||
receive_can_native(); // Receive CAN messages from native CAN port
|
||||
#ifdef CAN_FD
|
||||
#ifdef CANFD_ADDON
|
||||
receive_canfd(); // Receive CAN-FD messages.
|
||||
#endif
|
||||
#ifdef DUAL_CAN
|
||||
#ifdef CAN_ADDON
|
||||
receive_can_addonMCP2515(); // Receive CAN messages on add-on MCP2515 chip
|
||||
#endif
|
||||
#ifdef RS485_INVERTER_SELECTED
|
||||
|
@ -456,7 +456,7 @@ void init_CAN() {
|
|||
// Init CAN Module
|
||||
ESP32Can.CANInit();
|
||||
|
||||
#ifdef DUAL_CAN
|
||||
#ifdef CAN_ADDON
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("Dual CAN Bus (ESP32+MCP2515) selected");
|
||||
#endif
|
||||
|
@ -478,12 +478,12 @@ void init_CAN() {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CAN_FD
|
||||
#ifdef CANFD_ADDON
|
||||
#ifdef DEBUG_VIA_USB
|
||||
Serial.println("CAN FD add-on (ESP32+MCP2517) selected");
|
||||
#endif
|
||||
SPI.begin(MCP2517_SCK, MCP2517_SDO, MCP2517_SDI);
|
||||
ACAN2517FDSettings settings(CAN_FD_CRYSTAL_FREQUENCY_MHZ, 500 * 1000,
|
||||
ACAN2517FDSettings settings(CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ, 500 * 1000,
|
||||
DataBitRateFactor::x4); // Arbitration bit rate: 500 kbit/s, data bit rate: 2 Mbit/s
|
||||
#ifdef USE_CANFD_INTERFACE_AS_CLASSIC_CAN
|
||||
settings.mRequestedMode = ACAN2517FDSettings::Normal20B; // ListenOnly / Normal20B / NormalFD
|
||||
|
@ -683,7 +683,7 @@ void print_can_frame(CAN_frame frame, frameDirection msgDir) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CAN_FD
|
||||
#ifdef CANFD_ADDON
|
||||
// Functions
|
||||
void receive_canfd() { // This section checks if we have a complete CAN-FD message incoming
|
||||
CANFDMessage frame;
|
||||
|
@ -697,7 +697,7 @@ void receive_canfd() { // This section checks if we have a complete CAN-FD mess
|
|||
rx_frame.DLC = frame.len;
|
||||
memcpy(rx_frame.data.u8, frame.data, MIN(rx_frame.DLC, 64));
|
||||
//message incoming, pass it on to the handler
|
||||
receive_can(&rx_frame, CAN_ADDON_FD_MCP2518);
|
||||
receive_can(&rx_frame, CANFD_ADDON_MCP2518);
|
||||
receive_can(&rx_frame, CANFD_NATIVE);
|
||||
}
|
||||
}
|
||||
|
@ -738,7 +738,7 @@ void send_can() {
|
|||
#endif // CHARGER_SELECTED
|
||||
}
|
||||
|
||||
#ifdef DUAL_CAN
|
||||
#ifdef CAN_ADDON
|
||||
void receive_can_addonMCP2515() { // This section checks if we have a complete CAN message incoming on add-on CAN port
|
||||
CAN_frame rx_frame; // Struct with our CAN format
|
||||
CANMessage MCP2515Frame; // Struct with ACAN2515 library format, needed to use the MCP2515 library
|
||||
|
@ -757,7 +757,7 @@ void receive_can_addonMCP2515() { // This section checks if we have a complete
|
|||
receive_can(&rx_frame, CAN_ADDON_MCP2515);
|
||||
}
|
||||
}
|
||||
#endif // DUAL_CAN
|
||||
#endif // CAN_ADDON
|
||||
|
||||
#ifdef DOUBLE_BATTERY
|
||||
void check_interconnect_available() {
|
||||
|
@ -1198,7 +1198,7 @@ void transmit_can(CAN_frame* tx_frame, int interface) {
|
|||
ESP32Can.CANWriteFrame(&frame);
|
||||
break;
|
||||
case CAN_ADDON_MCP2515: {
|
||||
#ifdef DUAL_CAN
|
||||
#ifdef CAN_ADDON
|
||||
//Struct with ACAN2515 library format, needed to use the MCP2515 library for CAN2
|
||||
CANMessage MCP2515Frame;
|
||||
MCP2515Frame.id = tx_frame->ID;
|
||||
|
@ -1211,11 +1211,11 @@ void transmit_can(CAN_frame* tx_frame, int interface) {
|
|||
can.tryToSend(MCP2515Frame);
|
||||
#else // Interface not compiled, and settings try to use it
|
||||
set_event(EVENT_INTERFACE_MISSING, interface);
|
||||
#endif //DUAL_CAN
|
||||
#endif //CAN_ADDON
|
||||
} break;
|
||||
case CANFD_NATIVE:
|
||||
case CAN_ADDON_FD_MCP2518: {
|
||||
#ifdef CAN_FD
|
||||
case CANFD_ADDON_MCP2518: {
|
||||
#ifdef CANFD_ADDON
|
||||
CANFDMessage MCP2518Frame;
|
||||
if (tx_frame->FD) {
|
||||
MCP2518Frame.type = CANFDMessage::CANFD_WITH_BIT_RATE_SWITCH;
|
||||
|
@ -1234,7 +1234,7 @@ void transmit_can(CAN_frame* tx_frame, int interface) {
|
|||
}
|
||||
#else // Interface not compiled, and settings try to use it
|
||||
set_event(EVENT_INTERFACE_MISSING, interface);
|
||||
#endif //CAN_FD
|
||||
#endif //CANFD_ADDON
|
||||
} break;
|
||||
default:
|
||||
// Invalid interface sent with function call. TODO: Raise event that coders messed up
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
CAN_NATIVE = Native CAN port on the LilyGo & Stark hardware
|
||||
CANFD_NATIVE = Native CANFD port on the Stark CMR hardware
|
||||
CAN_ADDON_MCP2515 = Add-on CAN MCP2515 connected to GPIO pins
|
||||
CAN_ADDON_FD_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins
|
||||
CANFD_ADDON_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins
|
||||
*/
|
||||
|
||||
volatile CAN_Configuration can_config = {
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
//#define TESLA_MODEL_SX_BATTERY
|
||||
//#define VOLVO_SPA_BATTERY
|
||||
//#define TEST_FAKE_BATTERY
|
||||
//#define DOUBLE_BATTERY //Enable this line if you use two identical batteries at the same time (requires DUAL_CAN setup)
|
||||
//#define DOUBLE_BATTERY //Enable this line if you use two identical batteries at the same time (requires CAN_ADDON setup)
|
||||
|
||||
/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */
|
||||
//#define AFORE_CAN //Enable this line to emulate an "Afore battery" over CAN bus
|
||||
|
@ -65,17 +65,17 @@
|
|||
//#define NC_CONTACTORS //Enable this line to control normally closed contactors. CONTACTOR_CONTROL must be enabled for this option. Extremely rare setting!
|
||||
|
||||
/* Other options */
|
||||
//#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production)
|
||||
//#define DEBUG_CAN_DATA //Enable this line to print incoming/outgoing CAN & CAN-FD messages to USB serial (WARNING, raises CPU load, do not use for production)
|
||||
//#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting
|
||||
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 chip (Needed for some inverters / double battery)
|
||||
#define CRYSTAL_FREQUENCY_MHZ 8 //DUAL_CAN option, what is your MCP2515 add-on boards crystal frequency?
|
||||
//#define CAN_FD //Enable this line to activate an isolated secondary CAN-FD bus using add-on MCP2518FD chip / Native CANFD on Stark board
|
||||
#ifdef CAN_FD // CAN_FD additional options if enabled
|
||||
#define CAN_FD_CRYSTAL_FREQUENCY_MHZ \
|
||||
ACAN2517FDSettings:: \
|
||||
OSC_40MHz //CAN_FD option, what is your MCP2518 add-on boards crystal frequency? (Default OSC_40MHz)
|
||||
#endif
|
||||
//#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs (WARNING, raises CPU load, do not use for production)
|
||||
//#define DEBUG_CAN_DATA //Enable this line to print incoming/outgoing CAN & CAN-FD messages to USB serial (WARNING, raises CPU load, do not use for production)
|
||||
//#define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting
|
||||
//#define CAN_ADDON //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 chip (Needed for some inverters / double battery)
|
||||
#define CRYSTAL_FREQUENCY_MHZ 8 //CAN_ADDON option, what is your MCP2515 add-on boards crystal frequency?
|
||||
//#define CANFD_ADDON //Enable this line to activate an isolated secondary CAN-FD bus using add-on MCP2518FD chip / Native CANFD on Stark board
|
||||
#ifdef CANFD_ADDON // CANFD_ADDON additional options if enabled
|
||||
#define CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ \
|
||||
ACAN2517FDSettings:: \
|
||||
OSC_40MHz //CANFD_ADDON option, what is your MCP2518 add-on boards crystal frequency? (Default OSC_40MHz)
|
||||
#endif // CANFD_ADDON
|
||||
//#define USE_CANFD_INTERFACE_AS_CLASSIC_CAN // Enable this line if you intend to use the CANFD as normal CAN
|
||||
//#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)
|
||||
|
@ -138,7 +138,7 @@
|
|||
|
||||
/* Do not change any code below this line unless you are sure what you are doing */
|
||||
/* Only change battery specific settings in "USER_SETTINGS.h" */
|
||||
typedef enum { CAN_NATIVE = 0, CANFD_NATIVE = 1, CAN_ADDON_MCP2515 = 2, CAN_ADDON_FD_MCP2518 = 3 } CAN_Interface;
|
||||
typedef enum { CAN_NATIVE = 0, CANFD_NATIVE = 1, CAN_ADDON_MCP2515 = 2, CANFD_ADDON_MCP2518 = 3 } CAN_Interface;
|
||||
typedef struct {
|
||||
CAN_Interface battery;
|
||||
CAN_Interface inverter;
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
|
||||
// CAN2 defines below
|
||||
|
||||
// DUAL_CAN defines
|
||||
// CAN_ADDON defines
|
||||
#define MCP2515_SCK 12 // SCK input of MCP2515
|
||||
#define MCP2515_MOSI 5 // SDI input of MCP2515
|
||||
#define MCP2515_MISO 34 // SDO output of MCP2515 | Pin 34 is input only, without pullup/down resistors
|
||||
#define MCP2515_CS 18 // CS input of MCP2515
|
||||
#define MCP2515_INT 35 // INT output of MCP2515 | | Pin 35 is input only, without pullup/down resistors
|
||||
|
||||
// CAN_FD defines
|
||||
// CANFD_ADDON defines
|
||||
#define MCP2517_SCK 17 // SCK input of MCP2517
|
||||
#define MCP2517_SDI 23 // SDI input of MCP2517
|
||||
#define MCP2517_SDO 39 // SDO output of MCP2517
|
||||
|
@ -80,17 +80,17 @@
|
|||
#endif
|
||||
|
||||
#ifdef CHADEMO_BATTERY
|
||||
#ifdef DUAL_CAN
|
||||
#error CHADEMO and DUAL_CAN cannot coexist due to overlapping GPIO pin usage
|
||||
#ifdef CAN_ADDON
|
||||
#error CHADEMO and CAN_ADDON cannot coexist due to overlapping GPIO pin usage
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef EQUIPMENT_STOP_BUTTON
|
||||
#ifdef DUAL_CAN
|
||||
#error EQUIPMENT_STOP_BUTTON and DUAL_CAN cannot coexist due to overlapping GPIO pin usage
|
||||
#ifdef CAN_ADDON
|
||||
#error EQUIPMENT_STOP_BUTTON and CAN_ADDON cannot coexist due to overlapping GPIO pin usage
|
||||
#endif
|
||||
#ifdef CAN_FD
|
||||
#error EQUIPMENT_STOP_BUTTON and CAN_FD cannot coexist due to overlapping GPIO pin usage
|
||||
#ifdef CANFD_ADDON
|
||||
#error EQUIPMENT_STOP_BUTTON and CANFD_ADDON cannot coexist due to overlapping GPIO pin usage
|
||||
#endif
|
||||
#ifdef CHADEMO_BATTERY
|
||||
#error EQUIPMENT_STOP_BUTTON and CHADEMO_BATTERY cannot coexist due to overlapping GPIO pin usage
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
|
||||
// CAN2 defines below
|
||||
|
||||
// DUAL_CAN defines
|
||||
// CAN_ADDON defines
|
||||
#define MCP2515_SCK 12 // SCK input of MCP2515
|
||||
#define MCP2515_MOSI 5 // SDI input of MCP2515
|
||||
#define MCP2515_MISO 34 // SDO output of MCP2515 | Pin 34 is input only, without pullup/down resistors
|
||||
#define MCP2515_CS 18 // CS input of MCP2515
|
||||
#define MCP2515_INT 35 // INT output of MCP2515 | | Pin 35 is input only, without pullup/down resistors
|
||||
|
||||
// CAN_FD defines
|
||||
// CANFD_ADDON defines
|
||||
#define MCP2517_SCK 12 // SCK input of MCP2517
|
||||
#define MCP2517_SDI 5 // SDI input of MCP2517
|
||||
#define MCP2517_SDO 34 // SDO output of MCP2517
|
||||
|
@ -76,17 +76,17 @@
|
|||
#endif
|
||||
|
||||
#ifdef CHADEMO_BATTERY
|
||||
#ifdef DUAL_CAN
|
||||
#error CHADEMO and DUAL_CAN cannot coexist due to overlapping GPIO pin usage
|
||||
#ifdef CAN_ADDON
|
||||
#error CHADEMO and CAN_ADDON cannot coexist due to overlapping GPIO pin usage
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef EQUIPMENT_STOP_BUTTON
|
||||
#ifdef DUAL_CAN
|
||||
#error EQUIPMENT_STOP_BUTTON and DUAL_CAN cannot coexist due to overlapping GPIO pin usage
|
||||
#ifdef CAN_ADDON
|
||||
#error EQUIPMENT_STOP_BUTTON and CAN_ADDON cannot coexist due to overlapping GPIO pin usage
|
||||
#endif
|
||||
#ifdef CAN_FD
|
||||
#error EQUIPMENT_STOP_BUTTON and CAN_FD cannot coexist due to overlapping GPIO pin usage
|
||||
#ifdef CANFD_ADDON
|
||||
#error EQUIPMENT_STOP_BUTTON and CANFD_ADDON cannot coexist due to overlapping GPIO pin usage
|
||||
#endif
|
||||
#ifdef CHADEMO_BATTERY
|
||||
#error EQUIPMENT_STOP_BUTTON and CHADEMO_BATTERY cannot coexist due to overlapping GPIO pin usage
|
||||
|
|
|
@ -38,7 +38,7 @@ GPIOs on extra header
|
|||
#define CAN_RX_PIN GPIO_NUM_26
|
||||
// #define CAN_SE_PIN 23 // (No function, GPIO 23 used instead as MCP_SCK)
|
||||
|
||||
// CAN_FD defines
|
||||
// CANFD_ADDON defines
|
||||
#define MCP2517_SCK 17 // SCK input of MCP2517
|
||||
#define MCP2517_SDI 5 // SDI input of MCP2517
|
||||
#define MCP2517_SDO 34 // SDO output of MCP2517
|
||||
|
|
|
@ -271,7 +271,7 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
#endif
|
||||
case CAN_ADDON_MCP2515:
|
||||
return "Add-on CAN via GPIO MCP2515";
|
||||
case CAN_ADDON_FD_MCP2518:
|
||||
case CANFD_ADDON_MCP2518:
|
||||
#ifdef USE_CANFD_INTERFACE_AS_CLASSIC_CAN
|
||||
return "Add-on CAN-FD via GPIO MCP2518 (Classic CAN)";
|
||||
#else
|
||||
|
|
|
@ -22,15 +22,15 @@
|
|||
#error You must select a HW to run on!
|
||||
#endif
|
||||
|
||||
#if defined(DUAL_CAN) && defined(CAN_FD)
|
||||
#if defined(CAN_ADDON) && defined(CANFD_ADDON)
|
||||
// Check that user did not try to use dual can and fd-can on same hardware pins
|
||||
#error CAN-FD AND DUAL-CAN CANNOT BE USED SIMULTANEOUSLY
|
||||
#endif
|
||||
|
||||
#ifdef USE_CANFD_INTERFACE_AS_CLASSIC_CAN
|
||||
#if !defined(CAN_FD)
|
||||
#if !defined(CANFD_ADDON)
|
||||
// Check that user did not try to use classic CAN over FD, without FD component
|
||||
#error PLEASE ENABLE CAN_FD TO USE CLASSIC CAN OVER CANFD INTERFACE
|
||||
#error PLEASE ENABLE CANFD_ADDON TO USE CLASSIC CAN OVER CANFD INTERFACE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue