CAN bus and Modbus: how cars and factories communicate
In short: The CAN bus connects control units in cars over two wires, Modbus connects sensors and controllers in plants; both are robust and simple, but mostly without encryption and authentication.
In more detail: Not every network is Ethernet. In vehicles, machines and buildings devices communicate over fieldbuses. They are designed for reliability, real time and few wires.
In Depth
CAN bus (Controller Area Network)
- Developed by Bosch (1980s), standard in cars (engine, ABS, airbag, window lifters), industry, medical technology, agricultural machinery, OBD-II diagnostics.
- Two wires (CAN_H/CAN_L, differential, twisted, 120 Ω termination resistors at both ends), speed 125 kbit/s – 1 Mbit/s (CAN FD up to ~8 Mbit/s).
- Broadcast: every message has an ID (not a destination address); everyone listens and filters by ID. Lower ID = higher priority (lossless arbitration when sending simultaneously).
- Frame: ID, up to 8 data bytes (CAN FD: 64), CRC, ACK. Error handling (retransmission, devices can switch themselves off).
- For tinkerers: MCP2515/ESP32 TWAI, SocketCAN under Linux (
candump can0,cansend), OBD-II adapters (ELM327) read fault codes/measured values (own vehicle).
Modbus
- 1979 (Modicon) for PLCs; open, very widespread in sensors, meters, inverters (PV), heat pumps, industry.
- Master/slave (client/server): the master asks, the slave answers.
- Variants: Modbus RTU (serial RS-485, binary, up to ~1200 m), Modbus ASCII, Modbus TCP (Ethernet, port 502).
- Data model: coils (output bits), discrete inputs, input registers, holding registers (16-bit values). Commands (function codes):
0x03read holding registers,0x06write etc. - Example: read a solar inverter via Modbus TCP (power in a register, mind scaling) and display it in Home Assistant/Grafana.
- Tools:
mbpoll,pymodbus, QModMaster, Node-RED.
Security (important)
CAN and Modbus were built for closed, trusted environments: no authentication, no encryption; whoever has access to the bus can read and send (vehicle hacks via infotainment/OBD, Modbus TCP open on the internet = foreign control). Protection: separate networks (firewall/segmentation, IT/OT separation), no Modbus port to the internet, VPN, gateways with filters, OBD port protection, updates, access control, monitoring; modern standards (OPC UA, TLS, secure onboard communication in cars). Manipulating other people’s vehicles/plants is punishable and dangerous.
Classification and learning
- Comparison: Ethernet/TCP-IP (office), PROFINET/EtherCAT (real-time Ethernet), PROFIBUS, KNX (buildings), LIN (simple car devices), MQTT (IoT, see), I²C/SPI/UART (on the board), Zigbee/Matter (smart home).
- Layers: CAN up to OSI layers 1–2; Modbus layer 7 (application).
- Training: IT specialists/electronics technicians/mechatronics technicians meet buses in Industry 4.0 and vehicle technology.
- Practice: ESP32 + transceiver, simulators (software Modbus slave), Wireshark captures, Home Assistant with Modbus integration.
See also: I²C, SPI and UART, Raspberry Pi, OSI model