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 に答える