Arduino I²C 库(Wire)的 Linux 等效项?
我正在尝试将 Arduino 程序移植到 Linux。我陷入困境,因为我似乎找不到 I²C 函数的等效项Arduino 在“Wire.h”中。
连线头:连线库
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)
I am trying to port an Arduino program to Linux. I'm stuck because I can't seem to find equivalents to the I²C functions that the Arduino has in "Wire.h".
Wire header: Wire Library
Linux i2C-dev.h: Using I²C from userspace in Linux
Specifically, I can't see how I can do a
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 does not appear to have the equivalent of requesting a specific number of bytes from a I²C device. I imagine that "i2c_smbus_read_byte" is the equivalent of receive, and that it would ascend the available bytes if called in succession.
I²C options in Linux:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能正在寻找 i2c_smbus_read_block_data ,它接受文件描述符、要发出的命令以及要从设备读取的字节块。
使用它的代码可能如下所示:
这是函数描述的链接:http://ww2.cs.fsu.edu/~rosentha/linux/2.6.26.5/docs/DocBook/kernel-api/re1222.html
I think you're probably looking for
i2c_smbus_read_block_data
which takes in a file descriptor, the command to be issued, and a block of bytes to be read from the device.The code for using it would probably look something like this:
Here's a link for the function description: http://ww2.cs.fsu.edu/~rosentha/linux/2.6.26.5/docs/DocBook/kernel-api/re1222.html