1

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

线头:线库

Linux i2C-dev.h:在 Linux 中使用来自用户空间的 I²C

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

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)
4

1 回答 1

0

我认为您可能正在寻找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

于 2011-04-01T20:39:55.347 回答