1

我正在编写一个 C 程序,目的是通过 Dante Brooklyn II 的 I2C 接口配置外围设备(CS5368 ADC),这是一个基于运行 uClinux 2.4 的 Microblaze 软核处理器的板。

我已经按照 Dante OEM 文档的指导实施了配置,但是在运行我的程序时,我EPERM在尝试使用i2c_smbus_write_byte_data.

这是包含罪魁祸首调用的代码部分i2c_smbus_write_byte_data

    // Set ADC I2S to "Slave mode all speeds".
    printf("Set the CS5368 I2S mode to slave\n");
    unsigned char adc_dif = 0x01;  // I2S mode
    unsigned char adc_mode = 0x03; // Slave mode all speeds
    unsigned char data = 0x90 | (adc_dif << 2) | adc_mode;
    result = i2c_smbus_write_byte_data(i2c_fd, CS5368_GCTL_MDE, data);
    if (result < 0) {
        perror("Failed to write to the 'Global Mode Control' register");
        return -1;
    }

这是小程序完整源代码的上下文中的代码。该程序首先通过 GPIO 引脚重置 CS5368,然后通过 I2C 进行配置。

EPERM无论我是否连接了 CS5368,都会返回。我已经能够使用 Arduino Uno 的 I2C 接口成功配置 CS5368,因此问题似乎与 CS5368 无关。

telnet要运行程序,我通过as登录到开发板root,所以我怀疑该错误与用户权限有关。

OEM 文档状态:

Brooklyn II 模块可以作为以 100Khz 运行并使用 7 位寻址模式的 I2C 控制器运行。它支持多主机操作。可以从 Brooklyn II 模块上运行的用户应用程序访问 I2C 设备。该接口支持 SMBus(系统管理总线)协议,它是 I2C 协议的子集。

它继续列出支持的i2c_smbus_*功能,包括i2c_smbus_write_byte_data,因此该问题似乎与缺乏对 SMBus 或 I2C 的支持无关。

我遇到了一个相关问题EPERM,即用户在尝试使用 I2C API 时收到错误代码write,但解决方案似乎是使用i2c_smbus_*我已经在做的 API。

任何有关可能导致返回此错误代码或如何进一步调试问题的建议将不胜感激!


编辑:如果有帮助,这里是完整的输出,从将 exe 移动到/tmp通过 ftp 后通过 telnet 登录到板开始:

$ telnet 169.254.72.245                                                
Trying 169.254.72.245...                                                                                  
Connected to 169.254.72.245.                        
Escape character is '^]'.                            
login: root                                                                                               
Password:                                                                                                 
                                                                                                          
                                                     
BusyBox v1.23.2 (2018-05-31 11:33:18 AEST) hush - the humble shell                                        
                                                                                                          
/ # cd /tmp                                          
/var/tmp # ./cs5368-i2c-config                       
Open GPIO device                                                                                          
Set GPIO tristate outputs                            
Set GPIO pins low                                    
Sleep for 10 secs                                    
Set GPIO pins high
Close GPIO file descriptor                           
Searching for I2C device                                                                                  
  Opening /dev/i2c-0                                                                                      
  Setting I2C_SLAVE 4c...                                                                                 
  I2C Interface found: /dev/i2c-0                                                                         
Set the CS5368 as the slave                                                                               
Set the CS5368 I2S mode to slave                                                                          
Failed to write to the 'Global Mode Control' register: Operation not permitted                            
4

0 回答 0