<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aswin Kumar M on Medium]]></title>
        <description><![CDATA[Stories by Aswin Kumar M on Medium]]></description>
        <link>https://medium.com/@aswinkmm?source=rss-20e0fb5c091f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Aswin Kumar M on Medium</title>
            <link>https://medium.com/@aswinkmm?source=rss-20e0fb5c091f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:50:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aswinkmm/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CAN Bus for Beginners: A Fresher's Guide]]></title>
            <link>https://medium.com/@aswinkmm/can-bus-for-beginners-a-freshers-guide-3c56d8160e0d?source=rss-20e0fb5c091f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c56d8160e0d</guid>
            <category><![CDATA[automotive-software]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[can-bus]]></category>
            <dc:creator><![CDATA[Aswin Kumar M]]></dc:creator>
            <pubDate>Tue, 24 Nov 2026 18:55:11 GMT</pubDate>
            <atom:updated>2026-11-24T18:55:11.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IwxBzyVKYNoNaTwLXVOAOw.png" /></figure><p>Part 1 of the CAN series: h<em>ow the little two-wire network inside every car actually works, with hands-on experiments you can run tonight.</em></p><p><em>This post builds on several great CAN explainers and projects by other authors. They are credited with links in the References section at the end.</em></p><h3>Why CAN, and why you should care</h3><p>A modern car has somewhere between 30 and 100+ small computers called <strong>ECUs</strong> (Electronic Control Units). One controls the engine, one the brakes, one the airbags, one the radar that watches the road ahead. They all need to talk to each other, constantly, reliably, and in real time.</p><p>In the early 1980s, cars connected these units with point-to-point wires. Every new feature meant more copper, more weight, more connectors to fail. Bosch fixed this by designing the <strong>Controller Area Network (CAN)</strong>, released in 1986 and later standardised as <strong>ISO 11898</strong>. The idea was simple: put every ECU on one shared pair of wires and let them broadcast short messages.</p><p>Forty years later, CAN is still everywhere: cars, trucks, tractors, e-bikes, elevators, medical devices, industrial robots and even satellites. If you are starting a career in automotive or embedded systems, CAN is one of the first things you will touch, so understanding it well pays off on day one.</p><p>By the end of this post you will know:</p><ul><li>How the physical bus works and why it is so robust to noise</li><li>What a CAN frame looks like, bit by bit</li><li>How dozens of nodes share one wire without a master (arbitration)</li><li>How CAN detects and handles errors on its own</li><li>How ECUs in a real car use CAN, with a radar example</li><li>Which chips, modules and tools you will meet at work</li><li>How to run two experiments: a virtual CAN bus on Linux, and a real one with Arduino</li></ul><h3>The big picture: one bus, many nodes</h3><p>CAN is a <strong>multi-master broadcast bus</strong>. Every node is connected to the same two wires, every node hears every message, and any node may start talking when the bus is idle. There is no central master and no node addresses.</p><pre>ECU 1            ECU 2            ECU 3            ECU 4<br> (Engine)         (Brakes)         (Radar)       (Instrument)<br>    |                |                |                |<br>====+================+================+================+==== CAN_H<br>[120R]                                                [120R]<br>====+================+================+================+==== CAN_L</pre><p>A few key ideas make this work.</p><p><strong>1. Messages carry an ID, not an address.</strong> A frame does not say &quot;send this to the brake ECU&quot;. It says &quot;this is message 0x0C9, vehicle speed&quot;. Every node receives it, and each one decides whether it cares (this filtering is usually done in hardware).</p><p><strong>2. Two wires, differential signalling.</strong> The bus uses a twisted pair called <strong>CAN_H</strong> and <strong>CAN_L</strong>. Receivers look at the <em>difference</em> between them, not the absolute voltage. Noise from the ignition or motors hits both wires equally, so the difference barely changes. This is why CAN survives in such an electrically noisy place.</p><p><strong>3. Dominant and recessive bits.</strong> The bus has two states:</p><pre>State              Logic   CAN_H     CAN_L     Difference<br>-----------------  -----   -------   -------   ----------<br>Recessive (idle)     1     ~2.5 V    ~2.5 V    ~0 V<br>Dominant             0     ~3.5 V    ~1.5 V    ~2 V</pre><p>A dominant 0 always overwrites a recessive 1. If one node sends 0 and another sends 1 at the same moment, the bus shows 0. Think of it as a wired-AND. This one rule is the secret behind arbitration and error signalling, which we will see shortly.</p><pre>Recessive   Dominant   Recessive<br>            (1)         (0)        (1)<br>3.5 V              ___________<br>CAN_H  ___________|           |___________<br>2.5 V  ___________             ___________<br>CAN_L             |___________|<br>1.5 V</pre><p><strong>4. Termination.</strong> A classic high-speed CAN bus is a straight line (a &quot;linear bus&quot;) with a <strong>120 ohm resistor at each end</strong>. They prevent signal reflections. Two 120 ohm resistors in parallel give 60 ohms, so a quick multimeter check between CAN_H and CAN_L on a powered-off bus should read about 60 ohms. Reading 120 means one is missing; reading 40 means you have three.</p><p><strong>5. Speed versus length.</strong> Classic CAN runs up to 1 Mbit/s. The faster you go, the shorter the bus can be, because every node must see each bit within a fraction of a bit time.</p><pre>Bit rate      Typical max length   Where you see it<br>-----------   ------------------   ------------------------------<br>1 Mbit/s      ~40 m                Industrial, some powertrain<br>500 kbit/s    ~100 m               Most passenger car buses<br>250 kbit/s    ~250 m               Trucks and tractors (J1939)<br>125 kbit/s    ~500 m               Body and comfort, low speed</pre><h3>Anatomy of a CAN frame</h3><p>Everything on a CAN bus travels in <strong>frames</strong>. A classic CAN data frame carries an ID and <strong>0 to 8 bytes</strong> of data. That sounds tiny, but 8 bytes is plenty for things like &quot;wheel speed = 52.3 km/h&quot; or &quot;brake pedal pressed&quot;.</p><h3>Standard data frame (11-bit ID, CAN 2.0A)</h3><pre>+-----+-------------+-----+-----+----+-----+-----------+-------+-----+-----+-----+-----+<br>| SOF | Identifier  | RTR | IDE | r0 | DLC |   Data    |  CRC  | CRC | ACK | ACK | EOF |<br>|     |   11 bits   |     |     |    |  4  | 0-64 bits |  15   | del |slot | del |  7  |<br>+-----+-------------+-----+-----+----+-----+-----------+-------+-----+-----+-----+-----+<br>  1        11          1     1    1     4     0..64       15     1     1     1     7<br>|&lt;---- Arbitration ----&gt;|&lt;-- Control --&gt;|&lt;-- Data --&gt;|&lt;--- CRC ---&gt;|&lt;-- ACK --&gt;|</pre><ul><li><strong>SOF (Start of Frame), 1 bit:</strong> a single dominant bit that wakes everyone up and syncs their clocks.</li><li><strong>Identifier, 11 bits:</strong> the message ID. Lower value means higher priority.</li><li><strong>RTR, 1 bit:</strong> 0 = data frame, 1 = remote request.</li><li><strong>IDE, 1 bit:</strong> 0 = standard 11-bit ID, 1 = extended 29-bit ID.</li><li><strong>r0, 1 bit:</strong> reserved.</li><li><strong>DLC (Data Length Code), 4 bits:</strong> how many data bytes follow (0 to 8).</li><li><strong>Data, 0 to 64 bits:</strong> the payload.</li><li><strong>CRC, 15 + 1 bits:</strong> checksum plus a recessive delimiter.</li><li><strong>ACK, 1 + 1 bits:</strong> receivers drive this slot dominant to say &quot;I got it&quot;.</li><li><strong>EOF (End of Frame), 7 bits:</strong> seven recessive bits closing the frame.</li></ul><p>After EOF comes a short 3-bit <strong>interframe space</strong> before the next frame can start.</p><h3>Extended frame (29-bit ID, CAN 2.0B)</h3><p>Some networks need more IDs than 2048. The extended format splits the ID into an 11-bit base and an 18-bit extension, giving over 536 million possible IDs. Trucks and buses using <strong>SAE J1939</strong> rely on extended IDs.</p><pre>| SOF | Base ID (11) | SRR | IDE=1 | Ext ID (18) | RTR | r1 | r0 | DLC | Data | CRC | ACK | EOF |</pre><p>Because IDE is dominant (0) in a standard frame and recessive (1) in an extended frame, a standard frame always wins against an extended frame with the same base ID.</p><h3>The four frame types</h3><ul><li><strong>Data frame:</strong> carries data. 99% of what you will see.</li><li><strong>Remote frame:</strong> asks another node to send a data frame with that ID. Rarely used in modern cars.</li><li><strong>Error frame:</strong> sent by any node that detects an error, to destroy the faulty frame.</li><li><strong>Overload frame:</strong> asks for extra delay between frames. Almost never seen today.</li></ul><h3>The ACK trick</h3><p>The transmitter sends the ACK slot as recessive (1). Any node that received the frame correctly overwrites it with a dominant (0). So the sender knows that <strong>at least one</strong> node got the message. It does not know which one. If nobody acknowledges, the sender treats it as an error and retries. This is why a CAN node alone on a bench, with nobody else connected, keeps retransmitting forever and reports ACK errors. Remember this; it is the most common beginner surprise.</p><h3>Arbitration: how nodes share one wire without fighting</h3><p>What happens if two ECUs start sending at exactly the same moment? On Ethernet&#39;s old shared bus, both frames would collide and be lost. CAN does something smarter: <strong>bitwise, non-destructive arbitration</strong>. The highest-priority message wins and goes through untouched, and the losers simply wait.</p><p>Here is the rule:</p><ol><li>Every node that wants to send starts with SOF at the same time.</li><li>Each node sends its ID one bit at a time, most significant bit first, and <strong>listens to the bus while sending</strong>.</li><li>If a node sends a recessive 1 but reads back a dominant 0, someone else has a lower ID. That node stops transmitting immediately and becomes a receiver.</li><li>The node with the lowest ID never sees a mismatch, so it finishes its frame as if nothing happened.</li></ol><h3>Worked example</h3><p>Three nodes start at the same time with these IDs:</p><ul><li>Node A: <strong>0x120</strong> (say, a door status message)</li><li>Node B: <strong>0x0F5</strong> (say, steering angle)</li><li>Node C: <strong>0x0F2</strong> (say, brake pressure)</li></ul><pre>Bit position:   10  9  8  7  6  5  4  3  2  1  0<br>-------------------------------------------------<br>Node A 0x120:    0  0  1  -  -  -  -  -  -  -  -   loses at bit 8<br>Node B 0x0F5:    0  0  0  1  1  1  1  0  1  -  -   loses at bit 2<br>Node C 0x0F2:    0  0  0  1  1  1  1  0  0  1  0   WINS<br>-------------------------------------------------<br>Bus level:       0  0  0  1  1  1  1  0  0  1  0</pre><ul><li>At bit 8, A sends 1 while B and C send 0. The bus shows 0. A notices the mismatch and backs off.</li><li>At bit 2, B sends 1 while C sends 0. B backs off.</li><li>C finishes its frame. Nobody lost any data, and no time was wasted.</li><li>A and B automatically retry as soon as the bus is idle again. B (0x0F5) will now beat A (0x120).</li></ul><h3>What this means in practice</h3><ul><li><strong>Lower ID = higher priority.</strong> System designers give safety-critical messages (brakes, airbags, steering) low IDs and comfort messages (seat heaters, radio) high IDs.</li><li><strong>Each ID must have exactly one sender.</strong> If two nodes send the same ID with different data, arbitration cannot separate them and you get bit errors.</li><li><strong>CAN is deterministic for the top messages.</strong> The highest-priority message waits at most one frame time. Lower-priority messages can be delayed when the bus is busy, which is why engineers keep bus load under roughly 50 to 70%.</li></ul><h3>Bit timing and bit stuffing</h3><p>CAN has <strong>no separate clock wire</strong>. Each node runs on its own oscillator and has to stay in step with the others just by watching the edges on the bus. Two mechanisms make that possible: careful bit timing and bit stuffing.</p><h3>Splitting a bit into time quanta</h3><p>A CAN controller divides each bit into small slices called <strong>time quanta (tq)</strong>. The bit is made of four segments:</p><pre>|&lt;------------------------- 1 bit time -------------------------&gt;|<br>+--------+-------------+--------------------------+--------------+<br>|  Sync  |    Prop     |        Phase Seg 1       | Phase Seg 2  |<br>|  1 tq  |   1-8 tq    |          1-8 tq          |   1-8 tq     |<br>+--------+-------------+--------------------------+--------------+<br>                                                  ^<br>                                            Sample point</pre><ul><li><strong>Sync segment:</strong> always 1 tq. An edge is expected here.</li><li><strong>Propagation segment:</strong> covers the signal delay along the wire and through the transceivers.</li><li><strong>Phase segment 1:</strong> can be lengthened to resync with a late edge.</li><li><strong>Phase segment 2:</strong> can be shortened to resync with an early edge.</li><li><strong>SJW (Sync Jump Width):</strong> the maximum number of tq a resync may adjust by.</li></ul><p>The bus level is read at the <strong>sample point</strong>, between Phase Seg 1 and Phase Seg 2. For automotive buses, a sample point around <strong>87.5%</strong> of the bit is a common recommendation.</p><h3>A worked example: 500 kbit/s from a 16 MHz clock</h3><ul><li>Bit time at 500 kbit/s = 1 / 500,000 = <strong>2 microseconds</strong></li><li>Choose a prescaler of 2, so 1 tq = 2 / 16 MHz = <strong>125 ns</strong></li><li>Bits per tq: 2 us / 125 ns = <strong>16 tq per bit</strong></li><li>Split: Sync 1 + Prop and Phase Seg 1 together 13 + Phase Seg 2 = 2</li><li>Sample point = (1 + 13) / 16 = <strong>87.5%</strong></li></ul><p>Every node on the bus must use the same bit rate, and ideally similar sample points. A mismatched bit rate is the number one reason a new node &quot;sees nothing&quot; or floods the bus with error frames. You rarely compute this by hand; tools like the bit-timing calculators in your MCU vendor&#39;s configurator, or the kernel&#39;s automatic calculation on Linux, do it for you.</p><h3>Bit stuffing</h3><p>Resynchronisation needs edges. A long run of identical bits has no edges, so the receivers&#39; clocks could drift apart. CAN fixes this with <strong>bit stuffing</strong>:</p><blockquote><em>After 5 consecutive bits of the same value, the transmitter inserts one bit of the opposite value. Receivers remove it automatically.</em></blockquote><pre>Original bits:  0 0 0 0 0 0 0 1 1 1 1 1 1 0<br>On the wire:    0 0 0 0 0 [1] 0 0 1 1 1 1 1 [0] 1 0<br>                          ^stuff               ^stuff</pre><p>Stuffing applies from SOF through the CRC field. The fixed-format fields at the end (CRC delimiter, ACK, EOF) are not stuffed. That is why seven recessive bits in a row (EOF) can never appear inside a normal frame, and why six identical bits in a row means something special: an error flag.</p><p>A quick rule of thumb: an 8-byte standard frame is around 111 bits including the interframe space, and up to about 135 bits with worst-case stuffing. At 500 kbit/s that is roughly 0.22 to 0.27 ms per frame, so one bus can carry a few thousand frames per second.</p><h3>Error handling: CAN polices itself</h3><p>CAN&#39;s error handling is one of the main reasons it is trusted for brakes and airbags. Every node checks every frame, and any node that spots a problem can destroy that frame for everyone. The sender then retransmits it automatically, with no software involved.</p><h3>The five error checks</h3><ul><li><strong>Bit error</strong> (detected by the transmitter): it sent a bit but read back a different level, outside arbitration and the ACK slot.</li><li><strong>Stuff error</strong> (receivers): six identical bits in a row where stuffing should have happened.</li><li><strong>CRC error</strong> (receivers): the 15-bit checksum does not match the received bits.</li><li><strong>Form error</strong> (receivers): a fixed-format bit (CRC delimiter, ACK delimiter, EOF) has the wrong value.</li><li><strong>ACK error</strong> (transmitter): nobody drove the ACK slot dominant.</li></ul><h3>Error frames</h3><p>When a node detects an error, it immediately sends an <strong>error flag</strong>: six dominant bits in a row. That deliberately breaks the stuffing rule, so every other node sees a stuff error too and also discards the frame. This guarantees that either <strong>every node accepts a frame, or none do</strong>. After the flag comes an 8-bit recessive error delimiter, and then the original sender tries again.</p><h3>Fault confinement: TEC, REC and the three node states</h3><p>What if one node is broken and keeps raising false errors? It could jam the whole car. To prevent that, every node keeps two counters:</p><ul><li><strong>TEC</strong> (Transmit Error Counter): goes up by 8 for each transmit error, down by 1 for each successful transmission</li><li><strong>REC</strong> (Receive Error Counter): goes up (usually by 1) for each receive error, down by 1 for each good frame</li></ul><p>The counters move the node between three states:</p><pre>TEC or REC &gt; 127             TEC &gt; 255<br>+--------------+ -----------&gt; +---------------+ ----------&gt; +----------+<br>| Error Active |              | Error Passive |             | Bus Off  |<br>|  (normal)    | &lt;----------- |  (restricted) |             | (silent) |<br>+--------------+ both &lt;= 127  +---------------+             +----------+<br>       ^                                                         |<br>       |        128 x 11 recessive bits seen (+ software reset)  |<br>       +---------------------------------------------------------+</pre><ul><li><strong>Error Active:</strong> normal. Signals errors with a dominant (active) error flag.</li><li><strong>Error Passive:</strong> still works, but signals errors with recessive bits so it can no longer disturb others, and waits a little longer before transmitting again.</li><li><strong>Bus Off:</strong> fully disconnected from the bus. It must see 128 runs of 11 recessive bits before it may rejoin, and most software also requires an explicit restart.</li></ul><p>Because the transmitter&#39;s counter rises 8 times faster than it falls, a node with a faulty transmitter quickly pushes itself off the bus, while healthy nodes carry on. In a real ECU, a bus-off event usually sets a <strong>diagnostic trouble code (DTC)</strong> and triggers a recovery strategy written into the software requirements.</p><h3>CAN in a real car: how ECUs use it</h3><p>Now that the mechanics are clear, let&#39;s zoom out to the vehicle.</p><h3>Several buses, joined by a gateway</h3><p>A car rarely has just one CAN bus. ECUs are grouped by <strong>domain</strong>, each on its own bus, so a chatty infotainment unit cannot slow down the brakes. A <strong>central gateway</strong> ECU routes selected messages between buses and acts as a firewall.</p><pre>+--------------------+<br>                     |  Central Gateway   |------ OBD-II port (diagnostics)<br>                     +--------------------+<br>          |               |              |               |<br>   Powertrain CAN    Chassis CAN     ADAS CAN (FD)    Body CAN<br>    500 kbit/s       500 kbit/s       2-5 Mbit/s      125-500 kbit/s<br>     |      |         |      |         |      |         |      |<br>  Engine  Gearbox    ABS/ESC  EPS    Radar  Camera    Doors  Lights<br>                   (brakes) (steering)              Climate Seats</pre><h3>Signals, messages and the DBC file</h3><p>On the wire you only see IDs and raw bytes. The meaning lives in a <strong>communication matrix</strong>, usually stored as a <strong>DBC file</strong> (a text format created by Vector that almost every tool can read). A DBC file says which ECU sends each message, how often, and how to decode every <strong>signal</strong> inside it.</p><p>A small, made-up example:</p><pre>BO_ 201 VehicleDynamics: 8 ESC<br> SG_ VehicleSpeed : 0|16@1+ (0.01,0) [0|655.35] &quot;km/h&quot; RADAR,EPS<br> SG_ YawRate      : 16|16@1- (0.01,0) [-327.68|327.67] &quot;deg/s&quot; RADAR<br> SG_ AliveCounter : 48|4@1+  (1,0) [0|15] &quot;&quot; RADAR<br> SG_ Checksum     : 56|8@1+  (1,0) [0|255] &quot;&quot; RADAR</pre><p>Read the first signal as: <em>VehicleSpeed starts at bit 0, is 16 bits long, little-endian (@1), unsigned (+). Physical value = raw x 0.01 + 0, in km/h. Sent by ESC, received by RADAR and EPS.</em> So raw bytes B8 0B (little-endian 0x0BB8 = 3000) mean 30.00 km/h.</p><p>The golden formula you will use daily:</p><pre>physical_value = raw_value x factor + offset</pre><h3>Example: a front radar ECU on CAN</h3><p>Take an adaptive cruise control (ACC) front radar, the kind of ECU many firmware engineers work on.</p><p><strong>What the radar receives:</strong></p><ul><li><strong>Vehicle speed and yaw rate</strong> (every 10 to 20 ms): to predict the car&#39;s own path and separate moving from stationary targets.</li><li><strong>Steering angle, gear and brake status</strong> (every 10 to 20 ms): to know where the driver is heading.</li><li><strong>ACC on/off and set speed from the cluster</strong> (every 50 to 100 ms): the driver&#39;s intent.</li></ul><p><strong>What the radar sends:</strong></p><ul><li><strong>Lead vehicle distance and relative speed</strong> (every 20 to 50 ms): so the engine and brake ECUs can keep a safe gap.</li><li><strong>Detected object list</strong> (every 50 to 60 ms): for fusion with the front camera.</li><li><strong>Radar status, blockage and faults</strong> (every 100 ms or on change): so the cluster can warn the driver.</li></ul><p>Safety-related messages like these also carry an <strong>alive counter</strong> (it increments every frame, so a frozen sender is noticed) and a <strong>CRC or checksum</strong> over the payload. This end-to-end (E2E) protection, defined in AUTOSAR, catches problems that CAN&#39;s own CRC cannot, like a software bug sending stale data.</p><p>Because radar object lists are large, newer radars often sit on a <strong>CAN FD</strong> bus or Automotive Ethernet, while still using classic CAN for vehicle-level signals.</p><h3>Inside the ECU: the software stack</h3><p>Your application code almost never touches CAN registers directly. In an AUTOSAR-based ECU the path from the wire to your function looks like this:</p><pre>+------------------------------------------------------+<br>| Application (SWCs): ACC logic, tracking, ...         |<br>+------------------------------------------------------+<br>| RTE (Runtime Environment)                            |<br>+---------------------------+--------------------------+<br>| COM (packs/unpacks        | DCM (diagnostics, UDS)   |<br>|      signals)             | CanTp (ISO-TP)           |<br>+---------------------------+--------------------------+<br>| PduR (routes PDUs between modules)                   |<br>+------------------------------------------------------+<br>| CanIf (CAN interface)  |  CanSM / CanNm (state, NM)  |<br>+------------------------------------------------------+<br>| CAN Driver (MCU specific)                            |<br>+------------------------------------------------------+<br>| CAN controller (in MCU) -&gt; Transceiver -&gt; CAN bus    |<br>+------------------------------------------------------+</pre><p>Non-AUTOSAR projects follow the same idea with a simpler driver, a message table and a signal packing layer, often generated from the DBC.</p><h3>Diagnostics over CAN</h3><p>When a technician plugs a scan tool into the OBD-II port, it speaks <strong>UDS (ISO 14229)</strong> on top of <strong>ISO-TP (ISO 15765-2)</strong>, a transport layer that splits long messages across many 8-byte frames. On many cars, the tester sends a functional request on ID <strong>0x7DF</strong> and ECUs answer on IDs like <strong>0x7E8</strong>. This is how DTCs are read, software is flashed, and radars are calibrated at the end of the production line.</p><h3>Hardware: controllers, transceivers and modules</h3><p>Every CAN node needs two pieces of hardware, and beginners often mix them up.</p><pre>+---------+   SPI or    +----------------+  TX/RX   +-------------+  CAN_H<br>|   MCU   |&lt;-----------&gt;| CAN controller |&lt;--------&gt;| Transceiver |========<br>| (your   |  internal   | (protocol:     |  logic   | (physical:  |  CAN_L<br>|  code)  |    bus      |  frames, CRC,  |  levels  | differential|========<br>+---------+             |  arbitration)  |          |  voltages)  |<br>                        +----------------+          +-------------+</pre><ul><li>The <strong>CAN controller</strong> speaks the protocol. It builds frames, adds stuffing and CRC, runs arbitration, filters IDs, and counts errors. It works with ordinary logic levels (TX and RX pins).</li><li>The <strong>transceiver</strong> converts those TX/RX logic levels into the CAN_H/CAN_L differential voltages and back. It also protects the chip from shorts and voltage spikes on the bus.</li></ul><p>You always need a transceiver. Connecting an MCU&#39;s CAN TX/RX pins straight to another board&#39;s pins will not work as a real bus.</p><h3>Popular parts you will meet</h3><ul><li><strong>Microchip MCP2515</strong> (standalone controller, SPI): CAN 2.0B up to 1 Mbit/s, 3 transmit buffers, 2 receive buffers, 6 filters and 2 masks. The classic choice for adding CAN to an Arduino or Raspberry Pi.</li><li><strong>Microchip MCP2518FD</strong> (standalone controller, SPI): the CAN FD successor to the MCP2515.</li><li><strong>NXP TJA1050</strong> (transceiver, 5 V): very common on cheap MCP2515 modules. An older part, but fine for learning.</li><li><strong>NXP TJA1051 / TJA1042</strong> (transceivers): newer automotive parts. The TJA1042 adds a standby mode for low power.</li><li><strong>TI SN65HVD230</strong> (transceiver, 3.3 V): a good match for 3.3 V boards like the ESP32 and STM32.</li><li><strong>Microchip MCP2551 / MCP2562</strong> (transceivers): widely used in hobby and industrial boards.</li><li><strong>TI TCAN1042 / TCAN1462</strong> (transceivers): automotive grade and CAN FD capable.</li></ul><h3>Built-in CAN controllers in microcontrollers</h3><p>Automotive and many industrial MCUs already contain one or more CAN controllers, so they only need an external transceiver.</p><ul><li><strong>NXP S32K:</strong> FlexCAN (classic and FD)</li><li><strong>Infineon AURIX TC3xx:</strong> MCMCAN (based on Bosch M_CAN, FD capable)</li><li><strong>Renesas RH850:</strong> RS-CANFD</li><li><strong>TI TMS570 / Hercules:</strong> DCAN</li><li><strong>STM32:</strong> bxCAN on older parts (F1, F4), FDCAN on newer ones (G4, H7)</li><li><strong>Espressif ESP32:</strong> TWAI (Two-Wire Automotive Interface), compatible with classic CAN</li></ul><h3>The cheap MCP2515 module</h3><p>The blue board you can buy for a few dollars has an MCP2515, a TJA1050, a crystal (usually <strong>8 MHz</strong>, sometimes 16 MHz), a screw terminal for CAN_H/CAN_L, and a jumper that connects a 120 ohm terminator. Two things to check before you use one:</p><ol><li><strong>Read the crystal.</strong> Your code must be told the right oscillator frequency, or the bit rate will be wrong and nothing will talk.</li><li><strong>Check the termination jumper.</strong> Only the two modules at the ends of the bus should have it fitted.</li></ol><h3>Tools of the trade</h3><p>You cannot see CAN traffic with your eyes, so tools are your best friends. Here is what you will meet, from free to professional.</p><h3>Free and open source</h3><ul><li><strong>SocketCAN:</strong> CAN support built into the Linux kernel. CAN interfaces appear as network devices like can0. It is the foundation for everything else on Linux.</li><li><strong>can-utils:</strong> command-line tools for SocketCAN, such as candump, cansend, cangen, cansniffer, canplayer and isotpsend. Great for quick sniffing, sending and replaying logs.</li><li><strong>python-can:</strong> a Python library that talks to SocketCAN, PCAN, Kvaser, Vector and more. Use it to write test scripts and simple simulators.</li><li><strong>cantools:</strong> a Python library that reads DBC files and encodes or decodes signals, turning raw bytes into &quot;VehicleSpeed = 30 km/h&quot;.</li><li><strong>Wireshark:</strong> the famous packet analyzer, which can capture from SocketCAN interfaces. Good for filtering and inspecting frames in a GUI.</li><li><strong>SavvyCAN:</strong> a cross-platform GUI for capturing, graphing and reverse engineering CAN. Good for visualising signals and exploring unknown buses.</li></ul><h3>Hardware interfaces (USB to CAN)</h3><p>To connect your laptop to a real bus you need an adapter.</p><ul><li><strong>PEAK PCAN-USB:</strong> very common in labs. Comes with the free PCAN-View tool and works with SocketCAN and python-can.</li><li><strong>Kvaser Leaf / U100:</strong> popular and robust, with good drivers on Windows and Linux.</li><li><strong>Vector VN1610 / VN1630:</strong> the industry standard, used with CANoe and CANalyzer.</li><li><strong>CANable / candleLight boards:</strong> low-cost open-hardware USB adapters that work natively with SocketCAN.</li></ul><h3>Professional suites</h3><ul><li><strong>Vector CANoe and CANalyzer</strong>: the de facto standard in automotive. CANalyzer is for analysis; CANoe adds full network simulation, test automation and scripting in CAPL. If you join an OEM or a Tier 1 supplier, you will almost certainly use them.</li><li><strong>PEAK PCAN-Explorer</strong>, <strong>Kvaser CanKing</strong>, <strong>Intrepid Vehicle Spy</strong> and <strong>ETAS BUSMASTER</strong> (open source) are other common choices.</li></ul><h3>A five-minute can-utils cheat sheet</h3><pre>candump can0                      # print every frame<br>candump -tz can0                  # with timestamps from start<br>candump can0,0C9:7FF              # only ID 0x0C9<br>cansend can0 123#DEADBEEF         # send ID 0x123 with 4 data bytes<br>cansend can0 12345678#11.22       # extended 29-bit ID<br>cangen can0 -g 10 -I 100 -L 8     # generate random traffic every 10 ms<br>cansniffer -c can0                # live view, highlights changing bytes<br>candump -l can0                   # log to a file<br>canplayer -I candump-xxxx.log     # replay a log</pre><h3>Experiment 1: a virtual CAN bus on Linux (no hardware)</h3><p>Linux can create a <strong>virtual CAN interface (vcan)</strong> that behaves like a real bus inside your computer. It is perfect for learning the tools and writing scripts before you touch hardware. You need any Linux machine, a Linux VM, or WSL2 with a kernel that includes the vcan module. (A Raspberry Pi works great too.)</p><h3>Step 1: create the bus</h3><pre>sudo apt install can-utils<br>sudo modprobe vcan<br>sudo ip link add dev vcan0 type vcan<br>sudo ip link set up vcan0<br>ip -details link show vcan0</pre><h3>Step 2: send and receive with can-utils</h3><p>Open two terminals.</p><pre># Terminal 1: listen<br>candump vcan0<br><br># Terminal 2: send a frame with ID 0x123 and 4 bytes<br>cansend vcan0 123#DEADBEEF</pre><p>Terminal 1 should print:</p><pre>vcan0  123   [4]  DE AD BE EF</pre><p>Now try cangen vcan0 in terminal 2 to generate random traffic, and cansniffer -c vcan0 to watch which bytes change. Congratulations, you are sniffing a CAN bus.</p><h3>Step 3: simulate an ECU with python-can and a DBC file</h3><p>Install the Python libraries:</p><pre>pip install python-can cantools</pre><p>Save this as demo.dbc. It describes one message, like the vehicle dynamics frame a radar would receive from the ESC:</p><pre>VERSION &quot;&quot;<br><br>NS_ :<br><br>BS_:<br><br>BU_: ESC RADAR<br><br>BO_ 201 VehicleDynamics: 8 ESC<br> SG_ VehicleSpeed : 0|16@1+ (0.01,0) [0|655.35] &quot;km/h&quot; RADAR<br> SG_ YawRate : 16|16@1- (0.01,0) [-327.68|327.67] &quot;deg/s&quot; RADAR<br> SG_ AliveCounter : 48|4@1+ (1,0) [0|15] &quot;&quot; RADAR</pre><p><strong>sender.py</strong>, a fake ESC that sends speed and yaw rate every 20 ms:</p><pre>import time, math<br>import can, cantools<br><br>db = cantools.database.load_file(&quot;demo.dbc&quot;)<br>msg_def = db.get_message_by_name(&quot;VehicleDynamics&quot;)<br><br>with can.Bus(interface=&quot;socketcan&quot;, channel=&quot;vcan0&quot;) as bus:<br>    counter = 0<br>    t0 = time.time()<br>    while True:<br>        t = time.time() - t0<br>        data = msg_def.encode({<br>            &quot;VehicleSpeed&quot;: 50 + 20 * math.sin(t / 5),  # km/h, slowly varying<br>            &quot;YawRate&quot;: 2.0 * math.sin(t),                # deg/s<br>            &quot;AliveCounter&quot;: counter,<br>        })<br>        bus.send(can.Message(arbitration_id=msg_def.frame_id,<br>                             data=data, is_extended_id=False))<br>        counter = (counter + 1) % 16<br>        time.sleep(0.02)                                  # 20 ms cycle</pre><p><strong>receiver.py</strong>, a fake radar that decodes the signals and checks the alive counter:</p><pre>import can, cantools<br><br>db = cantools.database.load_file(&quot;demo.dbc&quot;)<br><br>with can.Bus(interface=&quot;socketcan&quot;, channel=&quot;vcan0&quot;,<br>             can_filters=[{&quot;can_id&quot;: 0x0C9, &quot;can_mask&quot;: 0x7FF}]) as bus:<br>    last = None<br>    for msg in bus:                     # blocks and yields each frame<br>        sig = db.decode_message(msg.arbitration_id, msg.data)<br>        cnt = sig[&quot;AliveCounter&quot;]<br>        if last is not None and cnt != (last + 1) % 16:<br>            print(&quot;WARNING: lost or repeated frame!&quot;)<br>        last = cnt<br>        print(f&quot;speed={sig[&#39;VehicleSpeed&#39;]:6.2f} km/h  &quot;<br>              f&quot;yaw={sig[&#39;YawRate&#39;]:5.2f} deg/s  counter={cnt}&quot;)</pre><p>Run python3 receiver.py in one terminal and python3 sender.py in another. You should see something like:</p><pre>speed= 50.00 km/h  yaw= 0.00 deg/s  counter=0<br>speed= 50.08 km/h  yaw= 0.04 deg/s  counter=1<br>speed= 50.16 km/h  yaw= 0.08 deg/s  counter=2</pre><p>And in a third terminal, candump vcan0 shows the raw bytes behind those values:</p><pre>vcan0  0C9   [8]  88 13 00 00 00 00 00 00<br>  vcan0  0C9   [8]  90 13 04 00 00 00 01 00</pre><p>88 13 is little-endian 0x1388 = 5000, and 5000 x 0.01 = 50.00 km/h. That is exactly the DBC formula from earlier.</p><p><strong>Things to try next:</strong></p><ul><li>Stop the sender with Ctrl+C and add a timeout to the receiver that prints &quot;ESC message missing&quot; after 100 ms. This is exactly how real ECUs detect a lost sender.</li><li>Record traffic with candump -l vcan0 and replay it with canplayer.</li><li>Open Wireshark, capture on vcan0, and inspect the frames in a GUI.</li></ul><h3>Experiment 2: a real CAN bus with two Arduinos</h3><p>Time for real wires. We will build a tiny two-node network: one Arduino reads a potentiometer (pretend it is the accelerator pedal) and broadcasts its position; the other receives it and drives an LED (pretend it is the engine ECU).</p><h3>What you need</h3><ul><li>2 x Arduino Uno or Nano</li><li>2 x MCP2515 CAN modules (the blue boards with a TJA1050)</li><li>1 x 10 kilohm potentiometer, 1 x LED with a 220 ohm resistor</li><li>A short twisted pair of wires for CAN_H and CAN_L, and jumper wires</li><li>The <strong>arduino-mcp2515</strong> library by autowp (install it from the Arduino Library Manager or GitHub)</li></ul><h3>Wiring</h3><p>Wire each Arduino to its MCP2515 module the same way:</p><pre>MCP2515 pin    Arduino Uno pin<br>-----------    ---------------<br>VCC            5V<br>GND            GND<br>CS             D10<br>SO (MISO)      D12<br>SI (MOSI)      D11<br>SCK            D13<br>INT            D2</pre><p>Then connect the two modules together:</p><pre>Arduino A + MCP2515            Arduino B + MCP2515<br>  [J1 jumper ON = 120R]          [J1 jumper ON = 120R]<br>        CAN_H  o------------------------o  CAN_H<br>        CAN_L  o------------------------o  CAN_L<br>        (twist these two wires together)<br><br>  Pot middle pin -&gt; A0 on A        LED (+ 220R) -&gt; D7 on B</pre><p>With only two nodes, both are &quot;ends of the bus&quot;, so <strong>fit the termination jumper on both modules</strong>. Also connect the GND of the two Arduinos together, or power both from the same USB hub.</p><h3>Sender sketch (Node A: &quot;pedal ECU&quot;)</h3><pre>#include &lt;SPI.h&gt;<br>#include &lt;mcp2515.h&gt;<br><br>MCP2515 mcp2515(10);          // CS pin<br>struct can_frame frame;<br>uint8_t counter = 0;<br><br>void setup() {<br>  Serial.begin(115200);<br>  mcp2515.reset();<br>  // Use MCP_16MHZ if your module has a 16 MHz crystal<br>  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);<br>  mcp2515.setNormalMode();<br>  Serial.println(&quot;Pedal ECU ready&quot;);<br>}<br><br>void loop() {<br>  int raw = analogRead(A0);                 // 0..1023<br>  uint8_t pedal = map(raw, 0, 1023, 0, 100); // 0..100 %<br><br>  frame.can_id  = 0x100;                    // message ID<br>  frame.can_dlc = 2;                        // 2 data bytes<br>  frame.data[0] = pedal;<br>  frame.data[1] = counter++;                // alive counter<br><br>  if (mcp2515.sendMessage(&amp;frame) == MCP2515::ERROR_OK) {<br>    Serial.print(&quot;Sent pedal = &quot;);<br>    Serial.println(pedal);<br>  } else {<br>    Serial.println(&quot;Send failed (check wiring and termination)&quot;);<br>  }<br>  delay(100);                               // 100 ms cycle<br>}</pre><h3>Receiver sketch (Node B: &quot;engine ECU&quot;)</h3><pre>#include &lt;SPI.h&gt;<br>#include &lt;mcp2515.h&gt;<br><br>MCP2515 mcp2515(10);<br>struct can_frame frame;<br>const int LED_PIN = 7;<br>unsigned long lastRx = 0;<br><br>void setup() {<br>  Serial.begin(115200);<br>  pinMode(LED_PIN, OUTPUT);<br>  mcp2515.reset();<br>  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);<br>  mcp2515.setNormalMode();<br>  Serial.println(&quot;Engine ECU ready&quot;);<br>}<br><br>void loop() {<br>  if (mcp2515.readMessage(&amp;frame) == MCP2515::ERROR_OK) {<br>    if (frame.can_id == 0x100 &amp;&amp; frame.can_dlc &gt;= 2) {<br>      uint8_t pedal = frame.data[0];<br>      lastRx = millis();<br>      digitalWrite(LED_PIN, pedal &gt; 50 ? HIGH : LOW);<br>      Serial.print(&quot;Pedal: &quot;);<br>      Serial.print(pedal);<br>      Serial.print(&quot; %  counter: &quot;);<br>      Serial.println(frame.data[1]);<br>    }<br>  }<br><br>  // Timeout monitoring, just like a real ECU<br>  if (lastRx != 0 &amp;&amp; millis() - lastRx &gt; 500) {<br>    digitalWrite(LED_PIN, LOW);             // safe state<br>    Serial.println(&quot;Pedal message lost! Going to safe state.&quot;);<br>    lastRx = 0;<br>  }<br>}</pre><p>Upload both, open the Serial Monitor on Node B at 115200 baud, and turn the potentiometer. The LED switches on above 50%. Now unplug CAN_H: Node B reports a lost message and goes to a safe state, and Node A starts reporting send failures because nobody acknowledges its frames. You have just seen timeout monitoring and the ACK mechanism in real hardware.</p><h3>Taking it further</h3><ul><li><strong>Sniff the bus from your PC.</strong> Add a USB-CAN adapter (PCAN-USB, CANable) as a third node and run candump can0 after sudo ip link set can0 up type can bitrate 500000. Remember to remove one of the terminators if the adapter adds its own.</li><li><strong>Use a Raspberry Pi instead of a USB adapter.</strong> Connect an MCP2515 module to the Pi&#39;s SPI pins and add dtoverlay=mcp2515-can0,oscillator=8000000,interrupt=25 to the boot config. It shows up as a normal SocketCAN can0, so every tool from Experiment 1 works on real hardware.</li><li><strong>Try an ESP32.</strong> Its built-in TWAI controller only needs an SN65HVD230 transceiver, no MCP2515.</li><li><strong>Add a third node</strong> with a lower ID and watch arbitration decide who goes first.</li></ul><h3>Beyond classic CAN</h3><p>Classic CAN&#39;s 8 bytes at 1 Mbit/s is not enough for radars, cameras and fast software updates, so the family has grown.</p><ul><li><strong>Classic CAN (2.0A/B):</strong> up to 8 bytes per frame, up to 1 Mbit/s. Carries most existing vehicle signals.</li><li><strong>CAN FD (Flexible Data-rate):</strong> up to 64 bytes per frame, with 2 to 5 Mbit/s in the data phase (arbitration stays slow). Used for ADAS, radar and faster flashing, and now standard on new platforms.</li><li><strong>CAN XL:</strong> up to 2048 bytes per frame, at 10 Mbit/s and beyond. A bridge between CAN and Automotive Ethernet.</li></ul><p>CAN FD keeps the same arbitration as classic CAN, then switches to a faster bit rate for the data (the <strong>BRS</strong> bit), and uses a stronger CRC. If you understand classic CAN, you already understand 90% of CAN FD.</p><p>You will also hear about <strong>higher-layer protocols</strong> that run on top of CAN: <strong>SAE J1939</strong> (trucks and agriculture), <strong>CANopen</strong> (industrial automation), <strong>ISO-TP, UDS and OBD-II</strong> (diagnostics). They define what the IDs and bytes mean, while CAN just delivers them.</p><h3>Common beginner mistakes</h3><ol><li><strong>Wrong or missing termination.</strong> Measure about 60 ohms between CAN_H and CAN_L with power off.</li><li><strong>Bit rate mismatch.</strong> Every node must use the same bit rate, and the code must know the real crystal frequency.</li><li><strong>Testing with only one node.</strong> With no one to acknowledge, the sender retransmits forever and racks up errors. Use two nodes, or put the controller in loopback mode.</li><li><strong>Swapped CAN_H and CAN_L.</strong> Nothing works, and nothing tells you why.</li><li><strong>No common ground.</strong> CAN is differential, but transceivers still need a shared reference.</li><li><strong>Byte order confusion.</strong> DBC signals can be Intel (little-endian) or Motorola (big-endian). Always check before decoding by hand.</li><li><strong>Two nodes sending the same ID.</strong> Every ID needs exactly one owner.</li></ol><h3>Glossary</h3><ul><li><strong>ECU:</strong> Electronic Control Unit, a small computer in the vehicle</li><li><strong>Node:</strong> any device connected to the CAN bus</li><li><strong>Frame:</strong> one CAN message on the wire</li><li><strong>Identifier (ID):</strong> an 11- or 29-bit number that names a message and sets its priority</li><li><strong>DLC:</strong> Data Length Code, the number of data bytes</li><li><strong>Dominant / recessive:</strong> logic 0 (wins on the bus) / logic 1 (the idle level)</li><li><strong>Arbitration:</strong> the bit-by-bit process that decides who sends when two nodes start together</li><li><strong>Bit stuffing:</strong> inserting an opposite bit after five identical bits</li><li><strong>TEC / REC:</strong> transmit and receive error counters</li><li><strong>Bus off:</strong> the state where a faulty node disconnects itself</li><li><strong>DBC:</strong> a file format describing messages and signals</li><li><strong>Signal:</strong> a value packed into a frame, such as vehicle speed</li><li><strong>SocketCAN:</strong> the Linux kernel&#39;s CAN networking support</li><li><strong>UDS:</strong> Unified Diagnostic Services (ISO 14229)</li></ul><h3>Wrapping up</h3><p>CAN has survived for four decades because its core ideas are simple and strong: two twisted wires, messages named by priority, dominant bits that win, and a protocol that checks itself. Every brake press, steering correction and radar warning in a modern car rides on those ideas.</p><p>The best way to make it stick is to get your hands dirty. Spin up vcan0 tonight, send your first frame with cansend, and decode it with a DBC. Then wire up two Arduinos and watch a pedal turn on an LED across a real bus. Once you have done that, a CANoe trace at work will feel familiar instead of scary.</p><p>This is Part 1 of a series on CAN. In Part 2 we will look at CAN FD: how it squeezes 64 bytes into a frame, why it switches speed in the middle of a frame, and how to try it on vcan. Follow so you don&#39;t miss it, and drop your questions in the comments.</p><h3>References and credits</h3><p>This guide stands on the shoulders of some excellent explainers. If you want a second angle on any topic above, these are the best places to go next, and full credit to their authors.</p><p><strong>Beginner explainers</strong></p><ul><li><a href="https://www.csselectronics.com/pages/can-bus-simple-intro-tutorial">CAN Bus Explained: A Simple Intro</a> by Martin Falch, CSS Electronics. A clear visual tour of frames, higher-layer protocols, logging and DBC decoding.</li><li><a href="https://www.circuitbread.com/tutorials/understanding-can-a-beginners-guide-to-the-controller-area-network-protocol">Understanding CAN: A Beginner&#39;s Guide to the Controller Area Network Protocol</a> by Jesal Shah, CircuitBread. Physical layer, data frame, arbitration and bit stuffing.</li><li><a href="https://resources.altium.com/p/can-bus-part-1-informal-introduction">CAN-Bus: Introduction and History</a> by David Bortolami, Altium. Part 1 of a three-part series, strong on history and ISO 11898-2 vs -3.</li><li><a href="https://kvaser.com/about-can/the-can-protocol/">The CAN Bus Protocol</a> by Kvaser. A short protocol overview from one of the major CAN tool vendors.</li><li><a href="https://www.ti.com/document-viewer/lit/html/SLOA101">Introduction to the Controller Area Network (CAN), SLOA101</a>, Texas Instruments application note. A classic engineering reference on frames, arbitration, errors and transceivers.</li></ul><p><strong>Hands-on projects</strong></p><ul><li><a href="https://dev.to/onlybytes/getting-started-with-can-bus-a-practical-guide-with-arduino-2h6a">Getting started with CAN bus: a practical guide with Arduino</a> by Olivier, DEV Community. A three-node Arduino and MCP2515 build with a sensor, LCD and servo.</li><li><a href="https://medium.com/@esebranek/creating-a-diy-can-533f8b5656b9">Creating a DIY CAN</a> by Evan Sebranek, on Medium. A six-node breadboard network with Arduino Nano/Uno and MCP2515 modules.</li></ul><p><strong>Libraries and documentation used in the experiments</strong></p><ul><li><a href="https://github.com/autowp/arduino-mcp2515">arduino-mcp2515</a> library by autowp (MIT licensed), used in Experiment 2.</li><li><a href="https://docs.kernel.org/6.16/networking/can.html">SocketCAN: Controller Area Network</a>, Linux kernel documentation, by the kernel development community.</li><li>python-can and cantools, the open-source Python libraries used in Experiment 1, and the linux-can can-utils project.</li></ul><p><strong>Standards</strong></p><ul><li>ISO 11898-1 (data link layer) and ISO 11898-2 (high-speed physical layer)</li><li>Bosch CAN Specification 2.0</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c56d8160e0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>