0

私は組み込み Linux の初心者です。私は Hitex LPC4350 評価ボードに取り組んでいます。I2C を使用してボードの LED を点滅させるコードを作成しました。

デバイスドライバーが存在することがわかりました:

/dev # ls 

console  kmem     null     pts      sample   ttyS0    ttyS2    zero
i2c-0    mem      ptmx     random   tty      ttyS1    urandom

モジュールをロードしようとすると、次のメッセージが表示されます。

/mnt/blinkled/app # ./blinkled
/dev/i2c-0 : No such device or address

私はi2cのうなずきを持っています:

nod /dev/i2c-0 0777 0 0 c 89 0

何か不足していますか?与えられたさまざまなオプションを試しましたが、役に立ちませんでした。

私を助けてください。

編集:

I2C ピンは I2C Expander PCA9673 に接続され、I2C アドレスは 0x48 です。

これが私のコードです:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <sys/types.h>

// I2C Linux device handle
int g_i2cFile;

// open the Linux device
void pca9673_i2c_open(void)
{
    g_i2cFile = open("/dev/i2c-0", O_RDWR);
    if (g_i2cFile < 0) {
        perror("/dev/i2c-0 ");
        exit(1);
    }
}

// close the Linux device
void pca9673_i2c_close(void)
{
    close(g_i2cFile);
}

// set the I2C slave address for all subsequent I2C device transfers
void pca9673_i2c_setaddress(int address)
{
    if (ioctl(g_i2cFile, I2C_SLAVE, address) < 0) {
        perror("/dev/i2c-0 Set Address");
        exit(1);
    }
}

void pca9673_i2c_outputdata(u_int8_t* data, int numbytes)
{
    if (write(g_i2cFile, data, numbytes) != numbytes) {
        perror("/dev/i2c-0 output data");
    }
}

void pca9673_i2c_inputdata(u_int8_t* data, int numbytes)
{
    if (read(g_i2cFile, data, numbytes) != numbytes) {
        perror("/dev/i2c-0 input data");
    }
}

int main(int argc, char **argv)
{
    u_int8_t buffer[2];

    // open Linux I2C device
    pca9673_i2c_open();

    // set address of the PCA9673
    pca9673_i2c_setaddress(0x48);

    // set 16 pin IO directions
    buffer[0] = 0x00;   // p0 to p7 output
    buffer[1] = 0xFF;   // p10 to p17 output
    pca9673_i2c_outputdata(buffer, 2);

    // glow LED
    buffer[0] = 0x05;   // p0 to p7 output
    pca9673_i2c_outputdata(buffer, 1);

    while (1) {
    }

    // close Linux I2C device
    pca9673_i2c_close();

    return 0;
}
4

0 に答える 0