# longan-labs/serial_can_bus architecture

> Architecture diagram of the GitHub repository longan-labs/serial_can_bus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/longan-labs/serial_can_bus
- Repository: https://github.com/longan-labs/serial_can_bus

## Overview

This repository is an Arduino serial-to-CAN firmware paired with a CAN Bus Shield driver. Its principal workflow accepts serial input, handles either AT-style configuration or binary CAN frames, and in data mode transmits frames or returns received frames over serial. Configuration includes serial/CAN rates and CAN masks and filters, persisted in EEPROM. The driver configures the MCP2515 and performs CAN message I/O over SPI. The README contains no capability details, and the main sketch and driver internals were not fully sampled, so uncertain orchestration links are omitted or marked unverified.

Main entry points: [`Serial_CAN_Firmware/cmdMode.cpp`](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/cmdMode.cpp) (Serial command handling), [`libraries/CAN_BUS_Shield/mcp_can.h`](https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can.h) (CAN driver API), [`Serial_CAN_Firmware/Serial_CAN_Firmware.ino`](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/Serial_CAN_Firmware.ino) (Firmware entry), [`Serial_CAN_Firmware/EEPROM_SET.cpp`](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/EEPROM_SET.cpp) (EEPROM config helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Serial-CAN firmware"]
  node_sketch["Firmware entry"]
  node_serial["Serial command handling<br/>[cmdMode.cpp]"]
  node_declarations["Firmware declarations<br/>[func.h]"]
end

subgraph group_config["Configuration storage"]
  node_eepromconfig["EEPROM config helpers<br/>[EEPROM_SET.cpp]"]
  node_constants["Firmware constants<br/>[firmware_dfs.h]"]
end

subgraph group_driver["CAN shield driver"]
  node_api["CAN driver API<br/>[mcp_can.h]"]
  node_driver["MCP2515 CAN driver<br/>[mcp_can.cpp]"]
  node_definitions["MCP2515 definitions<br/>[mcp_can_dfs.h]"]
end

node_host(("Serial host"))
node_canbus(("CAN bus"))
node_eeprom[("Arduino EEPROM")]
node_mcp2515["MCP2515 hardware"]

node_host -->|"sends commands"| node_serial
node_serial -->|"returns replies"| node_host
node_serial -->|"configures and sends"| node_api
node_serial -->|"checks and reads"| node_api
node_serial -->|"reads and writes"| node_eeprom
node_eepromconfig -->|"reads and writes"| node_eeprom
node_sketch -.->|"dispatches"| node_serial
node_sketch -.->|"initializes"| node_eepromconfig
node_api -->|"declares operations"| node_driver
node_driver -.->|"controls over SPI"| node_mcp2515
node_canbus -.->|"carries CAN frames"| node_mcp2515

click node_sketch "https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/Serial_CAN_Firmware.ino"
click node_serial "https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/cmdMode.cpp"
click node_eepromconfig "https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/EEPROM_SET.cpp"
click node_constants "https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/firmware_dfs.h"
click node_declarations "https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/func.h"
click node_api "https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can.h"
click node_driver "https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can.cpp"
click node_definitions "https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can_dfs.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sketch,node_serial,node_declarations toneBlue
class node_eepromconfig,node_constants,node_eeprom toneAmber
class node_api,node_driver,node_definitions toneMint
class node_host,node_canbus,node_mcp2515 toneIndigo
```

## Components

### Serial-CAN firmware

- [Firmware entry](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/Serial_CAN_Firmware.ino): `Serial_CAN_Firmware/Serial_CAN_Firmware.ino`
- [Serial command handling](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/cmdMode.cpp): `Serial_CAN_Firmware/cmdMode.cpp`
- [Firmware declarations](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/func.h): `Serial_CAN_Firmware/func.h`

### Configuration storage

- [EEPROM config helpers](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/EEPROM_SET.cpp): `Serial_CAN_Firmware/EEPROM_SET.cpp`
- [Firmware constants](https://github.com/longan-labs/serial_can_bus/blob/master/Serial_CAN_Firmware/firmware_dfs.h): `Serial_CAN_Firmware/firmware_dfs.h`

### CAN shield driver

- [CAN driver API](https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can.h): `libraries/CAN_BUS_Shield/mcp_can.h`
- [MCP2515 CAN driver](https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can.cpp): `libraries/CAN_BUS_Shield/mcp_can.cpp`
- [MCP2515 definitions](https://github.com/longan-labs/serial_can_bus/blob/master/libraries/CAN_BUS_Shield/mcp_can_dfs.h): `libraries/CAN_BUS_Shield/mcp_can_dfs.h`

### Other components

- **Serial host**
- **CAN bus**
- **Arduino EEPROM**
- **MCP2515 hardware**

## Connections

- Serial host → Serial command handling: sends commands (evidence: `Serial_CAN_Firmware/cmdMode.cpp`)
- Serial command handling → Serial host: returns replies (evidence: `Serial_CAN_Firmware/cmdMode.cpp`)
- Serial command handling → CAN driver API: configures and sends (evidence: `Serial_CAN_Firmware/cmdMode.cpp`)
- Serial command handling → CAN driver API: checks and reads (evidence: `Serial_CAN_Firmware/cmdMode.cpp`)
- Serial command handling → Arduino EEPROM: reads and writes (evidence: `Serial_CAN_Firmware/cmdMode.cpp`)
- EEPROM config helpers → Arduino EEPROM: reads and writes (evidence: `Serial_CAN_Firmware/EEPROM_SET.cpp`)
- Firmware entry → Serial command handling: dispatches
- Firmware entry → EEPROM config helpers: initializes
- CAN driver API → MCP2515 CAN driver: declares operations (evidence: `libraries/CAN_BUS_Shield/mcp_can.h`)
- MCP2515 CAN driver → MCP2515 hardware: controls over SPI
- CAN bus → MCP2515 hardware: carries CAN frames
