Skip to content

Commit b9df4ea

Browse files
committed
WIP use both
1 parent 7391526 commit b9df4ea

File tree

5 files changed

+292
-117
lines changed

5 files changed

+292
-117
lines changed

inc/sp140/bms.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
#pragma once
22

33
#include <Arduino.h>
4-
#include <SPI.h>
5-
#include <BMS_CAN.h>
6-
4+
#include "driver/twai.h"
75
#include "sp140/structs.h"
86

9-
// BMS-related constants
10-
#define MCP_CS 5 // MCP2515 CS pin
11-
#define MCP_BAUDRATE 250000
7+
// BMS CAN message IDs (from ANT BMS protocol)
8+
#define BMS_BASIC_INFO_1 0x18FF28F4 // SOC, voltage, current, status flags
9+
#define BMS_BASIC_INFO_2 0x18FE28F4 // Cell voltages, temperatures
10+
#define BMS_CYCLE_INFO 0x18A328F4 // Battery cycle information
11+
#define BMS_BATTERY_ID_BASE 0x18A028F4 // Battery ID parsing (base address)
12+
#define BMS_TEMPERATURE 0x18B428F4 // Battery temperature parsing
13+
#define BMS_CELL_VOLTAGE_BASE 0x18C828F4 // Per-cell voltage frames (base address)
14+
15+
// BMS constants
16+
#define BMS_TIMEOUT_MS 1000 // Timeout for BMS connection
17+
#define BMS_MAX_TEMPERATURES 8 // Maximum number of temperature sensors
18+
#define BMS_MAX_CELLS 24 // Maximum number of battery cells
1219

1320
// External declarations
1421
extern STR_BMS_TELEMETRY_140 bmsTelemetryData;
15-
extern BMS_CAN* bms_can;
22+
extern bool bmsTwaiInitialized;
1623

1724
// BMS functions
25+
void initBMS();
1826
void updateBMSData();
27+
void parseBMSPacket(const twai_message_t* message);
28+
bool isBMSConnected();
1929
void printBMSData();

inc/sp140/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern UnifiedBatteryData unifiedBatteryData; // Instance to hold battery data
2121
extern STR_BMS_TELEMETRY_140 bmsTelemetryData;
2222

2323
// Hardware/Connection Status Flags
24-
extern bool bmsCanInitialized;
24+
extern bool bmsTwaiInitialized; // BMS now uses TWAI instead of SPI
2525
extern bool escTwaiInitialized;
2626

2727
#endif // INC_SP140_GLOBALS_H_

platformio.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ lib_deps =
4949
adafruit/Adafruit BMP3XX Library@2.1.6
5050
adafruit/Adafruit ST7735 and ST7789 Library@1.11.0
5151
adafruit/Adafruit NeoPixel@1.14.0
52-
adafruit/Adafruit CAN@0.2.1
53-
adafruit/Adafruit MCP2515@0.2.1
5452
https://github.com/rlogiacco/CircularBuffer@1.4.0
5553
https://github.com/openppg/SINE-ESC-CAN
56-
https://github.com/openppg/ANT-BMS-CAN#97170331e1faedb5435657806ad6f9579de9552f
5754
lvgl/lvgl@^8.3.11
5855
lib_ignore =
5956
Adafruit SleepyDog Library

0 commit comments

Comments
 (0)