未检测到i2c-0设备驱动程序

时间:2016-01-14 11:23:57

标签: linux-device-driver uclinux

我是嵌入式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扩展器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;
}

0 个答案:

没有答案
相关问题