SPI issues with Banana Pi M2 Zero - wrong sensor readings and SPI display not working


FurretUber
 Share

1 1

Recommended Posts

Hello, initially, I would like to thank the Armbian project for making many of these SBCs that aren't so common usable with such a good distribution. I'm using a Banana Pi M2 Zero, and the manufacturer provided Android image didn't boot at all and I got concerned I had a brick. However, Armbian has multiple images for this board available and, right now, this board is running Armbian 21.08.6 Focal using the kernel Linux 5.10.60-sunxi. The performance difference compared to a Raspberry Pi Zero is dramatic. And it even has a Mali 400!

 

Step by step, I'm getting more features on the board working, either by reading Armbian documentation or user contributions. From what wasn't working on a clean install, I got the camera working. However, now I got in a situation I wasn't able to find a solution:

 

I'm facing issues with the SPI interface. Initially, I thought the problem was with the display I had (4" ILI9486L), but it seems to happen with all SPI devices. I tested with two SPI devices:

After trying many, many different settings with the display, I got it to the point where it will blink, reduce the brightness a bit, appear as /dev/fb0 and dmesg has some messages related to the ili9486 with no errors, but it does not display a image. I confirmed the display works with a Raspberry Pi Zero using https://github.com/juj/fbcp-ili9341 and it worked as well as a Raspberry Pi Zero can allow it to. The display is powered independently from any of the Pi(es) with 3,3V from a 4,8 A charger with a 5-3,3V step-down, only the data is connected to the Pi(es).

 

dmesg:

[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 129920
[    5.072053] spidev spi1.0: probing from DT
[    7.673894] systemd[1]: Listening on initctl Compatibility Named Pipe.
[   11.457837] [drm] Initialized ili9486 1.0.0 20200118 for spi0.0 on minor 2
[   13.354429] ili9486 spi0.0: [drm] fb0: ili9486drmfb frame buffer device
[   13.422932] fb_ili9486: module is from the staging directory, the quality is unknown, you have been warned.

The wiring on the following images is not that robust, but it works when the device works. I expect to improve it once I get everything working.

 

Then, I decided to check if the problem was with the display + BPi-M2Z or it was the SPI interface. For this, a BMP280 sensor was used with the Adafruit Circuitpython library. This sensor worked correctly on the Raspberry Pi Zero's I2C and SPI interfaces and on the Banana Pi M2 Zero's I2C interface: around 28°C today. Connecting to the Banana Pi M2 Zero with /dev/spidev1.0 (the Circuitpython library has this preset for the H3), it will raise an exception that it couldn't find the correct chip ID:

RuntimeError: Failed to find BMP280! Chip ID 0xb0

The 0xb0 changes, it's not consistent, but it consistently won't be 0x58 (the expected value). Editing the Adafruit library to bypass this check, it's possible to "read" the sensor, but then, the temperature is 109°C, which is off compared to 28°C that was read with the other configurations. The sensor wiring can be seen here:

Y9Diqvk.png

Right red is VCC, black is GND, blue is SCL, purple is SDA, the other red (need more wires!) is CS and brown is SDO.

 

With both the display and the sensor, pin 38 (PA21) was used, as its primary function on the BPi-M2Z is PA21. As the sensor works with 3 of the 4 possible configurations, it's more likely there is something wrong with the Banana Pi M2 Zero SPI interface.

 

The /boot/armbianEnv.txt content is:

verbosity=7
bootlogo=false
console=both
disp_mode=1280x720p60
overlay_prefix=sun8i-h3
rootdev=UUID=e7e80086-a15f-4f2e-825d-9913c71ff19c
rootfstype=ext4
overlays=cpu-clock-1.3GHz-1.3v i2c0 spi-spidev 
extraargs=
param_spidev_spi_bus=1
param_spidev_spi_cs=0
param_spidev_max_freq=1000000
# user_overlays=ili9486
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

Unfortunately, sudo armbianmonitor -u doesn't work on my install, the script shows the text as if it would show a link but the script closes without ever displaying the link with the report.

 

The overlay I tried setting up for the display, may be messed up by my attempts already... ):

/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun8i-h3";

        fragment@0 {
                target = <&spi0>;
                __overlay__ {
                        status = "okay";
                };
        };

        fragment@1 {
                target = <&spi0>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;

                        ili9486: ili9486@0 {
                                compatible = "ilitek,ili9486";
                                reg = <0>;

                                spi-max-frequency = <10000000>;
                                rotate = <90>;
                                fps = <15>;
                                buswidth = <8>;
                                regwidth = <18>;
                                reset-gpios = <&pio 0 21 0>;    //40pin, phy.38 PA21
                                dc-gpios = <&pio 2 4 0>;        //40pin, phy.18 PC4
                                //debug = <0>;

                                init = <0x10000b0 0x00
                                        0x1000011
                                        0x20000ff
                                        0x100003a 0x66
                                        0x1000036 0x28
                                        0x10000c2 0x44
                                        0x10000c5 0x00 0x00 0x00 0x00
                                        0x10000e0 0x0f 0x1f 0x1c 0x0c 0x0f 0x08 0x48 0x98 0x37 0x0a 0x13 0x04 0x11 0x0d 0x00
                                        0x10000e1 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
                                        0x10000e2 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
                                        0x1000036 0x28
                                        0x1000011
                                        0x1000029>;
                        };
                };
        };
};

The python code for testing the SPI interface with the BMP280 sensor (requires adafruit-circuitpython-bmp280):

import board
import digitalio
import adafruit_bmp280
spi = board.SPI()
spi.try_lock()
spi.configure(baudrate=80000)
spi.unlock()
cs = digitalio.DigitalInOut(board.PA21)
sensor = adafruit_bmp280.Adafruit_BMP280_SPI(spi, cs)

Testing with that WiringPi from Sinovoip's Github, https://github.com/BPI-SINOVOIP/BPI-WiringPi2, it shows the pins as if they were set, but they don't work. Using Adafruit Blinka, the pins work, so I'm able to set PA21 output high to turn on a LED, for example.

 

I don't know what else I should try. And I'm sorry if the the answer is already available and/or if there was some relevant file/log content that was not added.

Edited by FurretUber
Left is not right, and PA21 correction
Link to post
Share on other sites

Armbian is a community driven open source project. Do you like to contribute your code?

After further investigation and testing with additional help from the Adafruit Discord server, what was discovered is that there is what seems to be a 1-bit shift somewhere when communicating with the BMP280 using SPI. That 0xb0 that seemed random is, actually, the 0x58 bit shifted. It is consistently bit shifted. The problem now is to discover where the value is getting bit shifted.

 

Using this SPIDEV test, I get the expected output when I connect MOSI to MISO. So the Banana Pi M2 Zero can, at least, communicate with itself using SPI. However, there is something going wrong when trying to communicate with the BMP280.

 

Here is a comparison of the SPI and the I2C raw values and the temperature output:

SPI:

raw temp:  27376.0625
56036.0
-11744.0
-1743.0
Temperature: 106.71640625

I2C:

raw temp:  543184.0
28018.0
26896.0
-1000.0

Temperature: 30.324

Is there further configuration that can be done on the Banana Pi M2 Zero SPI interface?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

1 1