Enable I2C and SPI

Hello, all. I’m struggling to enable i2c and SPI (actually I was able to see interface under /dev/spi* didn’t test it though). But I have problems with I2c, I can see three interfaces: i2c-0, i2c-1 and i2c-2 on 2 & 3 I can quickly run i2cdetect -y [1:2] but no matter what I do I cannot see my I2c LCD(verified that’s working and it’s address is 0x27) Any clues how to go around that? I see some weird stuff in DTB-s where for i2c0 pins are wrongly defined(PI6/PI7) where if you look the hardware designs it shows (PI7/PI8)

Edit: I’m using debian image

1 Like

Same to me. Which linux image do you use? Some info here 香橙派Orange Pi Zero2开发板26pin I2C测试_H('ω')M的博客-CSDN博客
or GitHub - orangepi-xunlong/wiringOP: wiringPi for Orange Pi

I have found a solution:
SPI and I2c are working (I2c on different pins TX5/RX5)
Some story before going to the solution. If you try to enable the I2c on pins PI7/PI8 (acording to the schematic) you will get:

[    2.645413] sun50i-h616-pinctrl 300b000.pinctrl: unsupported function i2c0 on pin PI7
[    2.645446] sun50i-h616-pinctrl 300b000.pinctrl: unsupported function i2c0 on pin PI8
[    2.645456] mv64xxx_i2c 5002000.i2c: there is not valid maps for state default

And if you look the decompiled “sun50i-h616-orangepi-zero2.dtb” you will see that for i2c0 the pins are a bit different (PI6/PI7) which is wrong.
To decompile .dtb use dtc you will get .dts file which you can edit with any editor after that compile it back to dtb

So the default pins (defined in the hardware) are not possible in I2c mode, so use the entry i2c2 with pins (PH2/PH3), just set the status from disabled to okay.

                i2c@5002800 {
                        compatible = "allwinner,sun50i-h616-i2c\0allwinner,sun6i-a31-i2c";
                        reg = <0x5002800 0x400>;
                        interrupts = <0x00 0x08 0x04>;
                        clocks = <0x02 0x4a>;
                        resets = <0x02 0x19>;
                        pinctrl-names = "default";
                        pinctrl-0 = <0x2d>;
                        status = "okay";
                        #address-cells = <0x01>;
                        #size-cells = <0x00>;
                        phandle = <0x6f>;
                };

Compile dtb and reboot, you should see more i2c interfaces under /dev/i2c*

For SPI - edit again dts and search for “spidev”, again set the status from disabled to okay for the child and the parent entry.

                spi@5011000 {
                        compatible = "allwinner,sun50i-h616-spi\0allwinner,sun8i-h3-spi";
                        reg = <0x5011000 0x1000>;
                        interrupts = <0x00 0x0d 0x04>;
                        clocks = <0x02 0x50 0x02 0x4e>;
                        clock-names = "ahb\0mod";
                        resets = <0x02 0x1d>;
                        pinctrl-names = "default";
                        pinctrl-0 = <0x31 0x32>;
                        dmas = <0x22 0x17 0x22 0x17>;
                        dma-names = "rx\0tx";
                        status = "okay";
                        #address-cells = <0x01>;
                        #size-cells = <0x00>;
                        phandle = <0x73>;

                        spidev@1 {
                                compatible = "rohm,dh2228fv";
                                status = "okay";
                                reg = <0x01>;
                                spi-max-frequency = <0xf4240>;
                        };
                };

Compile and reboot. You should have working SPI and I2c

2 Likes

I summarized changes in dts in my github project, H616-mangopi.

I would like to control also sensor led. If you have time could you help me with that?

2 Likes

I can’t get the i2s interface to work. When I run cat /sys/kernel/debug/pinctrl/300b000.pinctrl/pinmux-pins I don’t see the pins defined for i2s. Help with the solution, I’m already tired of fighting with this board. :smiling_face_with_tear:

root@debian:~# cat /sys/kernel/debug/pinctrl/300b000.pinctrl/pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner|gpio_owner (strict) hog?
pin 0 (PA0): device 5030000.ethernet function emac1 group PA0
pin 1 (PA1): device 5030000.ethernet function emac1 group PA1
pin 2 (PA2): device 5030000.ethernet function emac1 group PA2
pin 3 (PA3): device 5030000.ethernet function emac1 group PA3
pin 4 (PA4): device 5030000.ethernet function emac1 group PA4
pin 5 (PA5): device 5030000.ethernet function emac1 group PA5
pin 6 (PA6): device 5030000.ethernet function emac1 group PA6
pin 7 (PA7): device 5030000.ethernet function emac1 group PA7
pin 8 (PA8): device 5030000.ethernet function emac1 group PA8
pin 9 (PA9): device 5030000.ethernet function emac1 group PA9
pin 10 (PA10): UNCLAIMED
pin 11 (PA11): UNCLAIMED
pin 12 (PA12): UNCLAIMED
pin 64 (PC0): UNCLAIMED
pin 65 (PC1): UNCLAIMED
pin 66 (PC2): UNCLAIMED
pin 67 (PC3): UNCLAIMED
pin 68 (PC4): UNCLAIMED
pin 69 (PC5): UNCLAIMED
pin 70 (PC6): UNCLAIMED
pin 71 (PC7): UNCLAIMED
pin 72 (PC8): UNCLAIMED
pin 73 (PC9): UNCLAIMED
pin 74 (PC10): GPIO 300b000.pinctrl:74
pin 75 (PC11): UNCLAIMED
pin 76 (PC12): GPIO 300b000.pinctrl:76
pin 77 (PC13): UNCLAIMED
pin 78 (PC14): UNCLAIMED
pin 79 (PC15): UNCLAIMED
pin 80 (PC16): UNCLAIMED
pin 160 (PF0): device 4020000.mmc function mmc0 group PF0
pin 161 (PF1): device 4020000.mmc function mmc0 group PF1
pin 162 (PF2): device 4020000.mmc function mmc0 group PF2
pin 163 (PF3): device 4020000.mmc function mmc0 group PF3
pin 164 (PF4): device 4020000.mmc function mmc0 group PF4
pin 165 (PF5): device 4020000.mmc function mmc0 group PF5
pin 166 (PF6): UNCLAIMED
pin 192 (PG0): device 4021000.mmc function mmc1 group PG0
pin 193 (PG1): device 4021000.mmc function mmc1 group PG1
pin 194 (PG2): device 4021000.mmc function mmc1 group PG2
pin 195 (PG3): device 4021000.mmc function mmc1 group PG3
pin 196 (PG4): device 4021000.mmc function mmc1 group PG4
pin 197 (PG5): device 4021000.mmc function mmc1 group PG5
pin 198 (PG6): device 5000400.serial function uart1 group PG6
pin 199 (PG7): device 5000400.serial function uart1 group PG7
pin 200 (PG8): device 5000400.serial function uart1 group PG8
pin 201 (PG9): device 5000400.serial function uart1 group PG9
pin 202 (PG10): UNCLAIMED
pin 203 (PG11): UNCLAIMED
pin 204 (PG12): UNCLAIMED
pin 205 (PG13): UNCLAIMED
pin 206 (PG14): UNCLAIMED
pin 207 (PG15): GPIO 300b000.pinctrl:207
pin 208 (PG16): UNCLAIMED
pin 209 (PG17): UNCLAIMED
pin 210 (PG18): GPIO 300b000.pinctrl:210
pin 211 (PG19): UNCLAIMED
pin 224 (PH0): device 5000000.serial function uart0 group PH0
pin 225 (PH1): device 5000000.serial function uart0 group PH1
pin 226 (PH2): UNCLAIMED
pin 227 (PH3): UNCLAIMED
pin 228 (PH4): UNCLAIMED
pin 229 (PH5): GPIO 300b000.pinctrl:229
pin 230 (PH6): UNCLAIMED
pin 231 (PH7): UNCLAIMED
pin 232 (PH8): UNCLAIMED
pin 233 (PH9): UNCLAIMED
pin 234 (PH10): device 7040000.ir function ir_rx group PH10
pin 256 (PI0): UNCLAIMED
pin 257 (PI1): UNCLAIMED
pin 258 (PI2): UNCLAIMED
pin 259 (PI3): UNCLAIMED
pin 260 (PI4): UNCLAIMED
pin 261 (PI5): UNCLAIMED
pin 262 (PI6): UNCLAIMED
pin 263 (PI7): device 5002400.i2c function i2c1 group PI7
pin 264 (PI8): device 5002400.i2c function i2c1 group PI8
pin 265 (PI9): device 5002800.i2c function i2c2 group PI9
pin 266 (PI10): device 5002800.i2c function i2c2 group PI10
pin 267 (PI11): UNCLAIMED
pin 268 (PI12): UNCLAIMED
pin 269 (PI13): UNCLAIMED
pin 270 (PI14): UNCLAIMED
pin 271 (PI15): UNCLAIMED
pin 272 (PI16): UNCLAIMED

Did you manage (compile) dts file as it is my github pages? Please open issue ticket there.

Did you manage (compile) dts file as it is my github pages?

Yes.

Please open issue ticket there.

Opened a ticket :slightly_smiling_face:

Ok, I will continue there. I will check your command and send you other commands to check your status.

Regards MM

1 Like

Hello
i’m working on the mangopi M-quad (pink board with H616)
for SPI CS0 and CS1 were swapped
in the dtb sun50i-h616-orangepi-zero2.dtb PH9 is declared as CS0 when spidev0.1

(pin26 is enabled as cs0 instead of pin24)

how to change this ?

Sans-titre

I updated my github HDMI and Power LED dead after using this dtb file · Issue #5 · mamin27/H616-mangopi · GitHub. There is example of blinking status LED. Lets try to investigate how it was done. I added pin numbering file for mq-quad in OPi.GPIO library. So this way you could set each GPIO port and also make some test with SPI …