Orange Pi 3: I2C works while 3rd party application doesn't


Recommended Posts

Hi,

 

I am facing an i2c problem on orange pi 3.

 

The i2c0 is enabled in armbian-config.

 

The i2cdetect output is correct, as I know my two slave boards connecting to gpio pin3 (SDA) and pin5(SCL) have the addresses 0x20 and 0x23. 

pi@orangepi3:~$ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- 23 -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@orangepi3:~$ 
 

However, when I use wiringOP library to access(read and write) slave i2c chip(mcp23008) registers, it always return -1.

 

int main(int argc, char** argv)
{
    int fd_s1 = wiringPiI2CSetup(SLAVE_1_DEVICE_ID); //0x20
    if (fd_s1 == -1)
    {
        std::cout << "Failed to init I2C Slave 1 communication." << std::endl;
        return -1;
    }

    int fd_s2 = wiringPiI2CSetup(SLAVE_2_DEVICE_ID); //0x23
    if (fd_s2 == -1)
    {
        std::cout << "Failed to init I2C Slave 2 communication." << std::endl;
        return -1;
    }

    std::cout << "I2C communication successfully setup." << std::endl;

    int reg_read;
    reg_read = wiringPiI2CReadReg8(fd_s1, REG_IODIR); //The register address is correct, as this code ran on raspberry Pi correctly
    std::cout << reg_read << std::endl;
}

 

Run output:

I2C communication successfully setup.

-1

 

The wiringOP library is from https://github.com/orangepi-xunlong/WiringOP

 

In the wiringPi library (in wiringOP), the code in wiringPiI2C.c shows that all APIs return -1, if the ioctl system call returns fault.

 

Not sure what I should investigate next step to solve this problem.

 

Thanks.

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?

No problem, thanks Igor, does the dmesg output look good?

 

pi@orangepi3:/boot$ dmesg |grep i2c
[    2.239314] i2c /dev entries driver
[    2.939717] sun50i-h6-pinctrl 300b000.pinctrl: pin-121 (5002000.i2c) status -517
[    2.939730] mv64xxx_i2c 5002000.i2c: Error applying setting, reverse things back
[    2.942492] axp20x-i2c 2-0036: AXP20x variant AXP806 found
[    2.955643] input: axp20x-pek as /devices/platform/soc/7081400.i2c/i2c-2/2-0036/axp221-pek/input/input0
[    2.962852] sun50i-h6-pinctrl 300b000.pinctrl: pin-121 (5002000.i2c) status -517
[    2.962864] mv64xxx_i2c 5002000.i2c: Error applying setting, reverse things back
[    2.981545] axp20x-i2c 2-0036: AXP20X driver loaded
pi@orangepi3:/boot$ 
 

Link to post
Share on other sites

Here is all the information I got from Armbian buster on Orangepi 3. Please give your advice if you have any. Thanks.

 

pi@orangepi3:~$ sudo i2cdetect -l
[sudo] password for pi: 
i2c-1    i2c           DesignWare HDMI                     I2C adapter
i2c-2    i2c           mv64xxx_i2c adapter                 I2C adapter
i2c-0    i2c           mv64xxx_i2c adapter                 I2C adapter
pi@orangepi3:~$ dmesg |grep i2c
[    2.239498] i2c /dev entries driver
[    2.944372] sun50i-h6-pinctrl 300b000.pinctrl: pin-121 (5002000.i2c) status -517
[    2.944384] mv64xxx_i2c 5002000.i2c: Error applying setting, reverse things back
[    2.945285] axp20x-i2c 2-0036: AXP20x variant AXP806 found
[    2.952116] input: axp20x-pek as /devices/platform/soc/7081400.i2c/i2c-2/2-0036/axp221-pek/input/input0
[    2.960280] sun50i-h6-pinctrl 300b000.pinctrl: pin-121 (5002000.i2c) status -517
[    2.960293] mv64xxx_i2c 5002000.i2c: Error applying setting, reverse things back
[    2.968835] axp20x-i2c 2-0036: AXP20X driver loaded
pi@orangepi3:~$ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- 23 -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@orangepi3:~$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@orangepi3:~$ sudo i2cdetect -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@orangepi3:~$ 
 

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...