Banana Pi BPI-M4: How to get I2C and SPI running (tutorial)

Hello, I took me some hours to figure out how to get I2C and SPI running on the BPI-M4 (RTD1395), so I document it here:

The below should work for all Banana PI Linux images (Raspbian, Ubuntu etc.), however I tested it with Raspbian and Kernel 4.9.119 (2020-05-18-raspbian-stretch-bpi-m4-sd-emmc.img)

  1. I2C should work out of the box - finding I2C devices with i2cdetect may not work as expected, however communication works - example (read WHOAMI ID from MPU6050 connected to CON1-P03/I2C1_SDA and CON1-P05/I2C1_SCL): Screenshot%20from%202021-12-11%2010-40-05

  2. For SPI, I needed to activate it in the Linux device tree.

Approach A): Patching device-tree using fdtput command without building kernel. Make sure boot partition mounted before doing this:

fdtput -t s /media/pi/BPI-BOOT/bananapi/bpi-m4/linux/rtd-1395-bananapi-m4-2GB.dtb /[email protected] status okay
fdtput -t s /media/pi/BPI-BOOT/bananapi/bpi-m4/linux/rtd-1395-bananapi-m4-1GB.dtb /[email protected] status okay

Approach B): Rebuilding kernel package

2.1 Download kernel package to your Linux PC:

2.2 Activate SPI in device tree (linux-rtk/arch/arm64/boot/dts/realtek/rtd139x/rtd-1395-bananapi-m4-1GB.dts and rtd-1395-bananapi-m4-2GB.dts): Screenshot%20from%202021-12-11%2011-43-00

2.3 Optional: change kernel options ./build 4

2.4 Compile kernel: ./build 1

2.5 Transfer kernel to SD card (with ready Raspbian on it): ./build 7

  1. Test SPI with a ‘loopback cable’ (connect together CON1-P19/GSPI-MOSI and CON1-P21/GSPI-MISO)


gcc -o spidev_test spidev_test.c

RX should return TX data: Screenshot%20from%202021-12-11%2010-38-24


Feel free to ask if you have questions, comments etc. :slight_smile:

1 Like

very good job, thank you share this