Hi my name is Amadeusz, and I am currently completing my university placement year as a Software Engineer here at Zircon. In addition to computer technology, I am also a fan of fast cars and motorsports. For this article I would like to tell the story of how this hobby sparked my interest in software engineering for embedded systems.
How Did It All Start?
After doing well in my A level exams, I wasn’t sure on where I wanted to go or what I would be good at. I had so many potential ideas I decided to take some time to mull things over, so to keep myself busy I relocated and found myself a fulltime job. After a few years of employment I decided to treat myself to a nice car, a BMW from a local auction, which is where our story begins.
It took less than a couple of hours for my ‘treat’ car to start throwing errors at me. A quick inspection highlighted that the source of my woes was the left side headlight that had stopped working. Naively hoping for burnt bulbs I got hold of some replacements, but it was no help at all. Not one of the local garages could provide me with a solution, instead directing me to a BMW authorised garage. Taking this advice I booked my car in for an inspection, however the resulting quote I was given exceeded a third of the value of the car itself.
My nature wouldn’t simply let me accept such a high price. Having asked for some clarification of the problem, I found myself presented with two options:
- Give up and pay for the repairs
- Try finding a solution for the problem itself
“If someone else can do it, surely I can do it too. Nothing is impossible” was the thought that pushed me to take my car back from the garage and begin my research. Unsurprisingly the garage wasn’t too keen on sharing their knowledge on the procedure, and I quickly found that no one within the UK had managed to solve this problem. Unable to find any DIY instructions online I turned to international forums, where I was advised to acquire a number of books. I was able to glean the information I needed but only after they were translated from German.
For me the most challenging step of the repair process was understanding the functionality and architecture of the CANBUS, a vehicle bus standard that allows microcontrollers and devices to communicate with each other in applications without a host computer. I ended up spending a lot of time figuring out how I could interact with the CANBUS in my car using my laptop and a simple OBD interface.
We can imagine CAN as a multi-master serial bus on the car, used for connecting electronic control units/nodes, such as the engine/transmission ECU or the Light Control Unit (LCU). There have to be two or more nodes on the CAN network, there is no need for a hosting machine. The complexity of the node can range from a simple I/O device up to an embedded computer with a CAN interface and sophisticated software. The node may also be a gateway allowing a standard computer to communicate over USB or Ethernet port to devices on a CAN network. In the automotive industry this node is referred to as the ON Board Diagnostic (OBD) port, and it allowed me to connect to the CANBUS of my car.
The First Line Of Code
With knowledge of the CANBUS finally under my belt the next step was to get my hands on an OBD2 K+DCAN cable, which supports read/write data transfer of specific diagnostic messages using CANBUS protocol. While waiting for the cable to arrive I began my preparation, reading about its capabilities and what modes it can support.
It was during this prep time that I stumbled across something called ‘UART’, a programing library used to read and write to the data frame of the CAN messages directed to different nodes. Initially I had no idea what all of the introduced variables were for. I found myself getting lost in the ‘nested loops’ and confused by ‘arrays’, but I refused to give up. I immersed myself in YouTube tutorials and C programming by Tony Royce until finally it began to make sense.
To avoid injuring my car further I felt it wise to practice writing a few simple programs in C using a TRICORE compiler as a means to develop my programming skills.
Fixing The Problem