【问题标题】:Linux equivalents for Arduino I²C libraries (Wire)?Arduino I²C 库 (Wire) 的 Linux 等价物?
【发布时间】:2011-02-17 13:03:31
【问题描述】:

我正在尝试将 Arduino 程序移植到 Linux。我被困住了,因为我似乎找不到 Arduino 在“Wire.h”中的 I²C 函数的等价物。

线头:Wire Library

Linux i2C-dev.h:Using I²C from userspace in Linux

具体来说,我看不出我该怎么做

Wire.request(address, num_of_bytes); //Request 4 bytes
int a = Wire.receive(); //Receive the four bytes
int b = Wire.receive();
int c = Wire.receive();
int d = Wire.receive();

Linux 似乎没有从 I²C 设备请求特定字节数的等效项。我想“i2c_smbus_read_byte”相当于接收,如果连续调用它会提升可用字节。

Linux 中的 I²C 选项:

i2c_smbus_write_quick( int file, __u8 value)
i2c_smbus_read_byte(int file)
i2c_smbus_write_byte(int file, __u8 value)
i2c_smbus_read_byte_data(int file, __u8 command)
i2c_smbus_write_byte_data(int file, __u8 command, __u8 value)
i2c_smbus_read_word_data(int file, __u8 command)
i2c_smbus_write_word_data(int file, __u8 command, __u16 value)
i2c_smbus_process_call(int file, __u8 command, __u16 value)
i2c_smbus_read_block_data(int file, __u8 command, __u8 *values)
i2c_smbus_write_block_data(int file, __u8 command, __u8 length, __u8 *values)
i2c_smbus_read_i2c_block_data(int file, __u8 command, __u8 *values)
i2c_smbus_write_i2c_block_data(int file, __u8 command, __u8 length, __u8 *values)
i2c_smbus_block_process_call(int file, __u8 command, __u8 length, __u8 *values)

【问题讨论】:

    标签: linux port arduino i2c


    【解决方案1】:

    我认为您可能正在寻找i2c_smbus_read_block_data,它接收文件描述符、要发出的命令以及要从设备读取的字节块。

    使用它的代码可能如下所示:

    int retval;
    uint8_t *block;
    
    block = malloc(32); //i2c_smbus_read_block_data() can return up to 32 bytes
    retval = i2c_smbus_read_block_data(fd, req, block);
    
    // check retval.  retval returns bytes read on success, or <0 on error
    

    这里是函数描述的链接:http://ww2.cs.fsu.edu/~rosentha/linux/2.6.26.5/docs/DocBook/kernel-api/re1222.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多