{"id":4765,"date":"2019-08-31T21:00:34","date_gmt":"2019-08-31T20:00:34","guid":{"rendered":"https:\/\/www.purplemeanie.co.uk\/?p=4765"},"modified":"2025-01-31T13:09:20","modified_gmt":"2025-01-31T13:09:20","slug":"ecu-diagnostics-part-2-ecu-obd-and-can","status":"publish","type":"post","link":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-2-ecu-obd-and-can\/","title":{"rendered":"ECU Diagnostics \u2013 part 2 : ECU, OBD and CAN"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">ECU<\/h3>\n\n\n\n<p>Caterhams, like all modern cars, have an Engine Control Unit (ECU) &#8211; a black box full of electronics, controlled by a microprocessor that manages how the engine runs. &nbsp;And because it has a microprocessor it means it runs some software to control everything. It also connects to a bunch of sensors, like temperature, pressure, engine speed, air-flow, lambda etc which it then uses to set the engine\u2019s inputs, things like ignition advance\/retard, air\/fuel mixture and other stuff.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"400\" data-attachment-id=\"4786\" data-permalink=\"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-2-ecu-obd-and-can\/9a4\/\" data-orig-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4.jpg\" data-orig-size=\"400,400\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"9A4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4.jpg\" src=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4.jpg\" alt=\"\" class=\"wp-image-4786\" srcset=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4.jpg 400w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4-150x150.jpg 150w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/9A4-100x100.jpg 100w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/figure>\n\n\n\n<p>The ECU on a factory, or self-build car, is manufactured by&nbsp;<a href=\"http:\/\/www.mbesystems.com\/\">MBE Systems<\/a> and seems to be supplied to Caterham through&nbsp;<a href=\"https:\/\/www.sbdmotorsport.co.uk\/\">SBDMotorsport<\/a>&nbsp;in the UK. The model used by Caterham is the <a href=\"https:\/\/www.sbdmotorsport.co.uk\/index.php\/products\/index\/2629\">9A4<\/a> that runs Caterham specific software and mapping. It is also \u201clocked\u201d \u2013 meaning that there is no user accessible way of modifying the software or the map. We\u2019ll talk about maps and software in a later post.<\/p>\n\n\n\n<p>What these MBE ECU\u2019s do allow though, is access to the internal sensor information used by the ECU to run the engine. There are many, many parameters used by the software to make an engine run properly and we hoped to be able to see all this information in \u201creal time\u201d \u2013 meaning we can see the data change in front of our eyes, hopefully being updated many times per second.<\/p>\n\n\n\n<p>It&#8217;s also important to understand that there is both primary data (taken directly from physical sensors) and derived data (secondary, extrapolated or calculated data derived from the primary data). We&#8217;ll hopefully be able to see both.<\/p>\n\n\n\n<p>The standard location for the ECU is underneath the battery in the engine bay:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1460\" data-attachment-id=\"4814\" data-permalink=\"https:\/\/purplemeanie.co.uk\/a24b14ee-8d8a-4500-a994-84a1e0e168a5\/\" data-orig-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A24B14EE-8D8A-4500-A994-84A1E0E168A5.jpeg\" data-orig-size=\"2363,1685\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;1.8&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone XS&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567281360&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.25&quot;,&quot;iso&quot;:&quot;320&quot;,&quot;shutter_speed&quot;:&quot;0.03030303030303&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"A24B14EE-8D8A-4500-A994-84A1E0E168A5\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A24B14EE-8D8A-4500-A994-84A1E0E168A5-2048x1460.jpeg\" src=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A24B14EE-8D8A-4500-A994-84A1E0E168A5-2048x1460.jpeg\" alt=\"\" class=\"wp-image-4814\" srcset=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A24B14EE-8D8A-4500-A994-84A1E0E168A5-2048x1460.jpeg 2048w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A24B14EE-8D8A-4500-A994-84A1E0E168A5-600x428.jpeg 600w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A24B14EE-8D8A-4500-A994-84A1E0E168A5-768x548.jpeg 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><figcaption>MBE 9A4 ECU located under the battery and behind the grey plug connecting it to the wiring loom<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">OBD<\/h3>\n\n\n\n<p>In order for us to be able to interrogate the ECU and extract all this data, we need some way of connecting a computer into the ECU.&nbsp;Handily, legislation has been in place for a number of years (2001 for petrol and 2004 for diesel) that requires car manufacturers to fit a car with a diagnostic connector. This is known as the OBD port and looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1499\" data-attachment-id=\"4815\" data-permalink=\"https:\/\/purplemeanie.co.uk\/a6c70596-3520-4ac2-9499-94f473d9e9a1\/\" data-orig-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A6C70596-3520-4AC2-9499-94F473D9E9A1.jpeg\" data-orig-size=\"2332,1707\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;1.8&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone XS&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567281445&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.25&quot;,&quot;iso&quot;:&quot;32&quot;,&quot;shutter_speed&quot;:&quot;0.022222222222222&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"A6C70596-3520-4AC2-9499-94F473D9E9A1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A6C70596-3520-4AC2-9499-94F473D9E9A1-2048x1499.jpeg\" src=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A6C70596-3520-4AC2-9499-94F473D9E9A1-2048x1499.jpeg\" alt=\"\" class=\"wp-image-4815\" srcset=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A6C70596-3520-4AC2-9499-94F473D9E9A1-2048x1499.jpeg 2048w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A6C70596-3520-4AC2-9499-94F473D9E9A1-600x439.jpeg 600w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/A6C70596-3520-4AC2-9499-94F473D9E9A1-768x562.jpeg 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><figcaption>OBD connector located above the ignition switch on the steering column<\/figcaption><\/figure>\n\n\n\n<p>On modern Caterhams the OBD connector is placed by the ignition switch under the dashboard. With some older cars (some R400&#8217;s for instance) it can be found behind the RHS knee trim panel, next to where the battery isolation switch is located. Going even further back, things become a little less simple and a serial lead is required to be connected to the ECU directly. We won&#8217;t be covering serial connections in this series of articles.<\/p>\n\n\n\n<p>It&#8217;s through this connector that we&#8217;ll be getting access to the ECU and hopefully seeing what&#8217;s going on. The OBD port on a Caterham is located above the steering column underneath the dash. On my 2017 car it is loosely mounted, dangling on a short length of electrical cables that run to the connector. So you need to be careful when handling it so you don&#8217;t pull any of the cables out of the connector.<\/p>\n\n\n\n<p>There are a bunch of standards that define the physical and electrical OBD connector used on cars. The data that\u2019s sent through this connector (I&#8217;ll also call it a port) is mostly open to the car manufacturer as to what gets sent and what standard transmission protocols are supported. It\u2019s also very common that the data sent on these ports is proprietary to the particular ECU manufacturer, each one having their own protocols.<\/p>\n\n\n\n<p>For those reading this that aren\u2019t quite so into <a href=\"https:\/\/en.wikipedia.org\/wiki\/Communication_protocol\">communications protocols<\/a> \u2013 a protocol is like a language. Computers and tech stuff communicate between each other using protocols. These protocols define what gets sent between two computers and how to interpret it. For instance, there are now over 8000 protocols that define how devices communicate over the internet, and more are being added every day. Check out the&nbsp;<a href=\"https:\/\/www.ietf.org\/standards\/rfcs\/\">IETF RFC pages<\/a>&nbsp;to learn more about those protocols and standards.<\/p>\n\n\n\n<p>To make things more complicated, manufacturers of different equipment may interpret the protocol definitions (known as \u201cstandards\u201d) differently and so end up with dialects of these languages. So the protocols differ from one manufacturer to another just like different dialects of French or English.<\/p>\n\n\n\n<p>Fortunately, there is one protocol that does seem to be reasonably well followed by most car manufacturers and that gives us something to start with. That protocol is often known as <a href=\"https:\/\/en.wikipedia.org\/wiki\/On-board_diagnostics\">OBD-II<\/a> (OBD 2). We&#8217;ll go into more detail about the protocols supported by the MBU 9A4 in a future post.<\/p>\n\n\n\n<p>As we started this investigation, learning about a Caterham\u2019s ECU diagnostic port, we knew only a few things:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>SBD Motorsport supplies a piece of Windows software (Easimap) that can get all the available data points from the car<\/li><li>OBD-II Scanners can access some data from the car (though not as much as Easimap)<\/li><li>People have tried to access the diagnostic data on a Caterham before and not been able to find much<\/li><\/ul>\n\n\n\n<p>So, we started with a general assumption that because the Easimap software could interrogate the car for lots of data, then hopefully we could too. Though one thing on our minds as we started out on this journey, was whether the data exchange (protocol) used between the car and the Easimap software was encrypted &#8211; that would cause a whole further level of investigation and might lead to all this effort being fruitless.<\/p>\n\n\n\n<p>Early on in our investigations we wondered if Caterham and MBE were doing something special (in an electrical sense) on the OBD port that was proprietary. However, a quick check under the dash and we can see that Caterhams have only 4 wires connected to the OBD port. There is 0v, 12v, CAN-L and CAN-H. CAN-L and CAN-H make up a twisted pair, see CAN bus below for more on those signals. So, we could see that none of the reserved connections on the OBD port were being used for anything special.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2842\" height=\"2852\" data-attachment-id=\"4778\" data-permalink=\"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-2-ecu-obd-and-can\/vqxvcwvjt6wupjftoobsxw\/\" data-orig-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891.jpg\" data-orig-size=\"2842,2852\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;1.8&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone XS&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1565817604&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.25&quot;,&quot;iso&quot;:&quot;25&quot;,&quot;shutter_speed&quot;:&quot;0.014705882352941&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;6&quot;}\" data-image-title=\"vQxvCWVJT6WUPjftoOBsxw\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891-2041x2048.jpg\" src=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891.jpg\" alt=\"\" class=\"wp-image-4778\" srcset=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891.jpg 2842w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891-150x150.jpg 150w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891-598x600.jpg 598w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891-768x771.jpg 768w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891-2041x2048.jpg 2041w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/vQxvCWVJT6WUPjftoOBsxw-e1567110066891-100x100.jpg 100w\" sizes=\"auto, (max-width: 2842px) 100vw, 2842px\" \/><\/a><figcaption>OBD Connector. 2 x 0v (black), 12v (purple), CAN-L and CAN-H<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">CAN Bus<\/h3>\n\n\n\n<p>There&#8217;s another twist to the OBD port. It&#8217;s one thing to know what it physically looks like, what its electrical connections are and how to connect to it, but its another to be able to understand the data that&#8217;s flowing through the connector.<\/p>\n\n\n\n<p>The first layer of that puzzle is to know that two of the twelve electrical connections on an OBD port support a standard called <a href=\"https:\/\/en.wikipedia.org\/wiki\/CAN_bus\">CAN bus<\/a>. CAN stands for Controller Area Network and is used in industrial and automotive systems. It&#8217;s called a network because you can have many CAN bus devices connected in a network. In computing terms a &#8220;bus&#8221; is something that transfers data from one device in the network to another, we often say that a &#8220;bus is shared&#8221; between the devices. Modern cars can have more than 50 devices in their CAN bus network; controlling everything from the engine, gearbox, infotainment systems, door locks, windows, lights, brakes and everything in between. <strong>My 420R 2017 Caterham has only one CAN bus device, the ECU.<\/strong> It seems that other cars (such as Sigma engined cars also have the rev-counter connected to the CAN bus &#8211; but not on my Duratec car).<\/p>\n\n\n\n<p>Most modern cars also have multiple CAN busses: private ones, not directly connected to the under-dash OBD port, for the safety critical components and public ones that are connected to the OBD port and more readily accessible to people like us. These private and public CAN busses are often connected together via a CAN bus bridge. <strong>There&#8217;s no evidence so far that there is any more than one CAN bus on a Caterham<\/strong>, and therefore no bridges.<\/p>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/CAN_bus\">CAN bus<\/a> defines both an electrical connection (wiring, what each wire does, voltages, termination impedances etc) but also a transmission protocol&#8230; i.e. what sequences of voltage changes mean (how fast are the changes (bitrate), is it digital or analogue, is it serial or parallel communication, etc.).<\/p>\n\n\n\n<p>So the CAN bus standard defines all this with the following key points for Caterham tinkerers:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>There are two electrical signals making up a single serial data channel. The two signals are differentially coded, meaning you take the two electrical cables as a pair and use the voltage difference between the two to give you a single signal. The two signals are called CAN-L and CAN-H (CAN Low and CAN High). And Soto measure the data in the bus you measure the voltage difference between CAN-L and CAN-H.<\/li><li>When there&#8217;s no data being transferred on the bus the two data lines, CAN-L and CAN-H sit at about 2.5V. It&#8217;s one of the main ways you can find a CAN bus on a car&#8230; looks for pairs of wires that have a voltage of about 2.5V on them, there isn\u2019t much other wiring at that voltage on a car.<\/li><li>The two CAN-L and CAN-H signals combine to create a single serial data stream &#8211; meaning digital bits are transferred one at a time in succession.<\/li><li>CANBus can run up to 1Mbps (mega-bits-per-second). <strong>On a Caterham the speed is set to 500,000 bps.<\/strong><\/li><li>There are three main types of CAN bus signalling. Standard addressing (using 11 bit identifiers (IDs)), Extended addressing (using 29bit IDs) and <a href=\"https:\/\/en.wikipedia.org\/wiki\/CAN_FD\">CAN-FD<\/a> (or Flexible Data &#8211; sending larger amount of data in one go). <strong>Caterham&#8217;s use Extended addressing and not FD.<\/strong><\/li><li>A stream of bits being sent on the bus forms a frame.<\/li><li>Each frame contains information about: <ul><li>when the frame starts<\/li><li>what type of frame it is (standard, extended, error, etc)<\/li><li>how much data is in the frame (up to 8 bytes)<\/li><li>error checking<\/li><li>acknowledgement bits and<\/li><li>end bits <\/li><\/ul><\/li><li>Data on the CAN bus can be either:<ul><li>Broadcast: a device on the bus continuously sends data at pre-determined intervals. The 9A4 ECU does broadcast some information on the bus (I&#8217;ve called this protocol &#8220;MBE-Broadcast&#8221;) and I&#8217;ll talk about this in a future post<\/li><li>Request\/Response: This is how the OBD-II protocol works and how Easimap communicates with the car. A device that want&#8217;s data (Easimap on a computer or a sniffer\/scanner) &#8220;requests&#8221; data from the ECU and the ECU &#8220;responds&#8221; with the data. We&#8217;ll talk about the &#8220;OBD-II&#8221; and &#8220;MBE-ISOTP&#8221; protocol in later post.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>For those interested, the format of a CAN bus packet is shown in the diagram below. Later on we&#8217;ll see that all we&#8217;re really interested in is the ID, Extended ID and the Data Field. The rest of the protocol is either handled by the CAN bus chipset or by the low level software (in my case that&#8217;s the Linux SocketCAN kernel driver).<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone\"><a href=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2620\" height=\"732\" data-attachment-id=\"4787\" data-permalink=\"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-2-ecu-obd-and-can\/canbus-extended-frame-diagram-microchip\/\" data-orig-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip.png\" data-orig-size=\"2620,732\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"CANbus Extended Frame Diagram Microchip\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip-2048x572.png\" src=\"https:\/\/www.purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip.png\" alt=\"\" class=\"wp-image-4787\" srcset=\"https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip.png 2620w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip-600x168.png 600w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip-768x215.png 768w, https:\/\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/08\/CANbus-Extended-Frame-Diagram-Microchip-2048x572.png 2048w\" sizes=\"auto, (max-width: 2620px) 100vw, 2620px\" \/><\/a><figcaption>Extended 29bit CAN bus packet format. From the Microchip MPC2515 datasheet.&nbsp;<\/figcaption><\/figure>\n\n\n\n<p>If that diagram isn&#8217;t making sense then perhaps this paragraph is for you: Each of the oblong boxes running across the centre of the diagram represents a single bit transmitted on the CAN bus. Therefore, time runs from left to right, so the leftmost oblong (bit) on the diagram is sent on the CANbus first, followed by the second, etc etc until the last bit represented by the rightmost oblong on the diagram is sent last. All those bits together are a CANbus frame and can contain up to 8 bytes of data on the MBE 9A4 CAN bus.<\/p>\n\n\n\n<p>If you want more info on what all the stuff means in the diagram then I&#8217;d recommend heading over to the CANbus&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/CAN_bus\">wikipedia link<\/a>, I can&#8217;t add much more to what they say there.<\/p>\n\n\n\n<p>There&#8217;ll be a post later in this series about me connecting my Logic Analyzer to the CAN bus and hopefully the screenshots there will explain a little more about how data is sent on CAN bus.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Arbitration Fields, CAN bus IDs and Addresses<\/h3>\n\n\n\n<p>Having said that, I hope I can clear up one thing that caused me confusion at first. The diagram above and the wikipedia page shows a field called the &#8220;Arbitration Field&#8221;.<\/p>\n\n\n\n<p>At the physical level (i.e. the 0&#8217;s and 1&#8217;s on the electrical wires) the arbitration field controls who gets access to the bus. It does this because if two devices start to transmit on the bus at the same time then the one with the lowest numeric around bitration field code &#8220;wins&#8221; and continues to transmit, while the second device with the higher arbitration code backs off and tries again later. However, at a higher level, such as SocketCAN (see below), these arbitration fields are also like addresses, in computer terms, and different devices will listen for different arbitration fields which are known as ID&#8217;s (identifiers).<\/p>\n\n\n\n<p>And for even higher software levels such as ISOTP (see a future post) they are also known as transmit and receive addresses.&nbsp;<\/p>\n\n\n\n<p>That&#8217;s all a little confusing, but all you really need to know is that Arbitration Fields, CAN bus ID&#8217;s and the ISOTP Receive and Transmit Addresses are all the same thing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CAN bus Software<\/h3>\n\n\n\n<p>We&#8217;ll be talking some more about the CAN bus software in a future post but for the moment it&#8217;s worth pointing out that there seem to be a few ways of accessing CAN bus data for writing your own code on a computer.<\/p>\n\n\n\n<p>I&#8217;m mainly interested in using Python as a programming language to do my tinkering and in my opinion the only way to do that is with a Unix derived system. And that means either Linux (RedHat, Ubuntu and their derivatives) or MacOS (BSD based).<\/p>\n\n\n\n<p>&#8230; and for those operating systems and for Python there are a couple of ways of poking at the CAN bus.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>SocketCAN: this is the way I went. For me it gives closer access to the bus and allows me to use packet capture software like Wireshark. The CAN bus drivers are included in modern kernels and there is good support for other kernel mode protocols like ISOTP that we&#8217;ll need later. The CAN bus kernel module creates an interface that makes the CAN bus look like a network socket and so turns CAN bus frames into packets like an IP packet. These packets are then available to software applications like Wireshark so they can be captured and viewed. Python has a good wrapper for SocketCAN which is simply called <a href=\"https:\/\/python-can.readthedocs.io\/en\/master\/\">python-can<\/a>.<\/li><li>ELM327: Another way to get CAN bus frames into a computer is to use a ELM327, or similar, device. They can connect to phones and computers using Bluetooth or Wifi and have python support through the <a href=\"https:\/\/python-obd.readthedocs.io\/en\/latest\/\">python-OBD<\/a> project. They&#8217;re good because they mean your computer can be remote from the car. But I&#8217;m not a big fan of Wireless for critical connections and I&#8217;m hoping that my future OBD dashboard will be critical. They also have to work in &#8220;user space&#8221; (i.e. not in the kernel) and so can suffer from Linux&#8217;s susceptibility to not being as &#8220;real time&#8221; as some other OSes.<\/li><\/ol>\n\n\n\n<p>Yet another route for accessing CAN bus is through even smaller computing devices. I&#8217;ve spent a lot of time playing with the <a href=\"https:\/\/www.arduino.cc\">Arduino<\/a> and <a href=\"https:\/\/www.adafruit.com\/feather\">Adafruit Feather<\/a> devices over the years and I&#8217;m thinking that at some point I might switch from the Linux environment to Arduino for this project. These Arduino derivatives have their own programming environment and software drivers for things like CAN bus and they are also more &#8220;real time&#8221; than OSes like Linux and especially Windows. There are CANbus &#8220;shields&#8221; for Arduino and even Feather CANbus boards for the Adafruit feather line. But for the moment, Linux is a great way to figure out what&#8217;s going on with the car and to get rapid development done.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example CAN packets<\/h3>\n\n\n\n<p>We&#8217;ll get into discussing the protocols used on a CAN bus in much more detail in furture posts, but for the moment here&#8217;s what three CAN bus frames look like to and from the car. The first two packets in the diagram below are to the car from Easimap and the third is the car&#8217;s response back to Easimap. The frames below are how Wireshark (a packet sniffer software tool) displays the frames once captured from the CAN bus, it takes the serial stream of bits and decodes them into what each bit means, displaying them in a more &#8220;human readable&#8221; form&#8230;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Frame 626:\nController Area Network\n...0 1100 1011 1110 0001 0001 0000 0001 = Identifier: 0x0cbe1101\n1... .... .... .... .... .... .... .... = Extended Flag: True\n.0.. .... .... .... .... .... .... .... = Rem. Tx Req. Flag: False\n..0. .... .... .... .... .... .... .... = Error Flag: False\nData: 10 0a 01 00 00 00 00 12\n\nFrame 627:\nController Area Network\n...0 1100 1011 1110 0001 0001 0000 0001 = Identifier: 0x0cbe1101\n1... .... .... .... .... .... .... .... = Extended Flag: True\n.0.. .... .... .... .... .... .... .... = Rem. Tx Req. Flag: False\n..0. .... .... .... .... .... .... .... = Error Flag: False\nData: 21 66 67 a8 a9 00 00 12\n\nFrame 628:\nController Area Network\n...0 1100 1011 1110 0000 0001 0001 0001 = Identifier: 0x0cbe0111\n1... .... .... .... .... .... .... .... = Extended Flag: True\n.0.. .... .... .... .... .... .... .... = Rem. Tx Req. Flag: False\n..0. .... .... .... .... .... .... .... = Error Flag: False\nData: 05 81 aa aa 16 00 12 66<\/pre>\n\n\n\n<p>CANbus packets will be printed differently depending on which software you use to look at them. In this particular example from Wireshark:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> <span style=\"font-size: inherit;\"><strong><em>0x0cbe1101<\/em><\/strong> and <strong><em>0x0cbe0111<\/em><\/strong> are CAN bus identifiers (ID&#8217;s) or Arbitration fields written in <\/span><a style=\"font-size: inherit;\" href=\"https:\/\/en.wikipedia.org\/wiki\/Hexadecimal\">hexadecimal<\/a><span style=\"font-size: inherit;\">&nbsp;(the 0x means hexadecimal). From the discussion above about arbitration, the device sending the ID of <strong><em>0x0cbe0111<\/em><\/strong> would take priority over the device sending <strong><em>0x0cbe1101<\/em><\/strong><\/span> , because <strong><em>0xcbe0111<\/em><\/strong> is less than <strong><em>0x0cbe1101<\/em><\/strong>. <\/li><li>The first two frames with an ID of <strong><em>0x0cbe1101<\/em><\/strong> are sent from Easimap and the last frame with an ID of <strong><em>0x0cbe0111<\/em><\/strong> is the response from the car&#8217;s ECU back to Easimap<\/li><li>There are various flags shown, extended flag (meaning 29bit IDs), Remote Transmission Request Flag and the error flag.<\/li><li><p>The hexadecimal numbers on the Data line are the data, ie the stuff we\u2019re really going to be interested in like engine speed and fuel mixture.&nbsp;<\/p><\/li><\/ul>\n\n\n\n<p>Well that&#8217;s about it for the basics of ECU&#8217;s, OBD and CAN bus. We&#8217;ll build on all of this in future posts.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>ECU Caterhams, like all modern cars, have an Engine Control Unit (ECU) &#8211; a black box full of electronics, controlled by a microprocessor that manages how the engine runs. &nbsp;And because it has a microprocessor it means it runs some software to control everything. It also connects to a bunch of sensors, like temperature, pressure, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[51,20],"tags":[34],"class_list":["post-4765","post","type-post","status-publish","format-standard","hentry","category-caterham-blog","category-ecu-diagnostics","tag-ecu-diagnostics"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8yl38-1eR","jetpack-related-posts":[{"id":5112,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/20\/ecu-diagnostics-part-13-three-diagnostic-protocols-in-the-mbe-9a4-ecu\/","url_meta":{"origin":4765,"position":0},"title":"ECU Diagnostics &#8211; part 13 : Three Diagnostic Protocols in the MBE 9A4 ECU","author":"John Martin","date":"September 20, 2019","format":false,"excerpt":"This one's just a short post to introduce the next three posts. In our investigations of the MBE 9A4 ECU we've found three different diagnostics protocols supported on the OBD port. The following three posts will summarise what we've learnt about each protocol and will be updated with new information\u2026","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4726,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/08\/31\/ecu-diagnostics-part-1-introduction\/","url_meta":{"origin":4765,"position":1},"title":"ECU Diagnostics &#8211; part 1 : Introduction","author":"John Martin","date":"August 31, 2019","format":false,"excerpt":"So here we go for a marathon series of posts. I'll update this page with links to the completed posts as they come along... IntroductionECUs, OBD and CANTest SetupWireshark Patching and OBD-II ResultsThe Correlator Dead-EndReading MaterialECU Maps and MappingEasimap uses ISOTP (sort of)The Easimap Protocol TheoryDecoding EC2 FilesLogic Analyzer on\u2026","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5192,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/20\/ecu-diagnostics-part-14-software-framework-mbe-py\/","url_meta":{"origin":4765,"position":2},"title":"ECU Diagnostics &#8211; part 14 : Software Framework mbe.py","author":"John Martin","date":"September 20, 2019","format":false,"excerpt":"This is hopefully a reasonably short post about the software framework I've developed to help read sensor data from the MBE 9A4 ECU. The software is written in Python 3 and is available here: Caterham-OBD. However, I'm going to talk about using one file only which is mbe.py.\u00a0 The idea\u2026","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5086,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/16\/ecu-diagnostics-part-12-osi-7-layers-for-caterham-diagnostics\/","url_meta":{"origin":4765,"position":3},"title":"ECU Diagnostics &#8211; part 12 : OSI 7 Layers for Caterham Diagnostics","author":"John Martin","date":"September 16, 2019","format":false,"excerpt":"Communications protocols are often called protocol stacks... they're layers, or stacks, of different protocols... one layered on top of the other from lowest level (hardware\/physical) to highest level (software application). This is where the OSI 7 Layer model comes in... it standardises how we think about the layers and allows\u2026","rel":"","context":"In &quot;ECU Diagnostics&quot;","block_context":{"text":"ECU Diagnostics","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/ecu-diagnostics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/ECU-OSI-Layers.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":4954,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/07\/ecu-diagnostics-part-6-reading-material\/","url_meta":{"origin":4765,"position":4},"title":"ECU Diagnostics &#8211; part 6 : Reading Material","author":"John Martin","date":"September 7, 2019","format":false,"excerpt":"Another quick one, really quick this time... Mark (CTRMint) had been doing his research and had told us about a book he was buying, and I just couldn't resist... The Car Hacker's Handbook The book isn't the cheapest of purchases, at least not in the UK. But for me it\u2026","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/purplemeanie.co.uk\/wp-content\/uploads\/2019\/09\/51itpsaLlfL._SX376_BO1204203200_.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5038,"url":"https:\/\/purplemeanie.co.uk\/index.php\/2019\/09\/15\/ecu-diagnostics-part-10-decoding-ec2-files\/","url_meta":{"origin":4765,"position":5},"title":"ECU Diagnostics &#8211; part 10 : Decoding EC2 Files","author":"John Martin","date":"September 15, 2019","format":false,"excerpt":"Now we need to start proving some of our theories about how Easimap is actually talking to the ECU. And it seemed to me that if I was going to prove anything then I'd need to pass a lot of data through any theory I came up with, and that\u2026","rel":"","context":"In &quot;Caterham Blog&quot;","block_context":{"text":"Caterham Blog","link":"https:\/\/purplemeanie.co.uk\/index.php\/category\/caterham-blog\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/4765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=4765"}],"version-history":[{"count":3,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/4765\/revisions"}],"predecessor-version":[{"id":7972,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/4765\/revisions\/7972"}],"wp:attachment":[{"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=4765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=4765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/purplemeanie.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=4765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}