Close

Episode Two: Hardware

A project log for Switching music with CAN bus

Summary of my struggles with automotive CAN bus sniffing and Bluetooth LE powered microcontrollers (nRF51)

Wiktor BurdeckiWiktor Burdecki 02/04/2021 at 12:440 Comments

Since Raspberry Pi is capable of doing all the things like Bluetooth LE and CANBUS, i consider it too easy in execution and too overkill hardware-wise. This project is intended to be a simple, minimalistic device so highly embedded microcontroller with most needed functions and peripherals on-board is needed. 

First promising candidate was ESP32 from Espressif, since it has embedded BLE and SJA1000 CAN controller. Problem is, due to hardware limitations involving clock distribution inside the chip, CAN controller can't run slower than 50kbaud. Second problem for me, is that ESP32 is intended to be used more like a module than a chip. This means easier development, but less flexibility when designing a final product.

Since I haven't found any more BLE+CANbus microcontrollers, my attention was drawn more towards BLE enabled ARM microcontrollers. After some research I established that the best way to get started was Nordic Semi NRF5 family. Chips are already for some time on the market, there are a lot of resources available, and Nordic distributes them with free and very extensive SDK (software development kit) and documentation. Price is maybe not the lowest but still attractive, especially for older NRF51xxx family. To simplify my development stage I bought a simple breakout board with NRF51822.

I already set up my firmware development toolchain with GCC (GNU C Cross-Compiler for ARM). Starting this way was a very steep learning curve, but payed off in a lot of gained knowledge, especially about the low-level working of microcontrollers (reset/interrupt vectors, linker scripts, startup). My final setup was Ecplise for C/C++ with Eclipse Embedded CDT plugin. My flash/debug probe was at first a J-Link device, but later I managed to get cheap ST-Link V2 working with help of OpenOCD software. To set up Eclipse IDE, this tutorial is a bit outdated but still helpful. After having a working toolchain I created a first warm-up project to get started with development for this microcontroller. After a lot of included headers from SDK, and learning from examples provided in it, I managed to get my first non-BLE application running - simple UART command line interface running on top of FreeRTOS

Since NRF51 doesn't come with embedded CAN controller i need an external solution to communicate with vehicle. This time choice was simple - the most popular MCP2515 which I also used earlier with RPi to sniff SWCAN bus on my car. It's a pretty simple and robust chip, also comes with hardware CAN frame filtering, which in my case reduces CAN data processing by MCU to nearly zero since receiving data frame means a change of steering wheel button state - all other data from CANbus is discarded earlier by MCP2515 hardware filter.

After familiarizing with BLE inner workings, and Nordic's SoftDevice software, I already got a working BLE keyboard example running with modified report descriptor to be used as Consumer/Multimedia HID (Human Interface Device). Software wise only thing left is writing C library to support MCP2515 on NRF51 platform, which I'm in the middle of.

I'll keep you posted ;)

Discussions