0

I am a beginner in Embedded Linux. I am working on Hitex LPC4350 Eval Board. I have written a code to blink LEDs in my Board using I2C.

I could find the device driver present:

/dev # ls 

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

When i try to load my module - I get the message:

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

I have the i2c nod:

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

Am I missing something ? I tried various options given but of no use.

Please help me.

Edit:

The I2C pins are connected to a I2C Expander PCA9673 and the I2C Address is 0x48

Here is my code :

#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;
}
shan2u
  • 9
  • 4
  • Yeah, you missed to show the sources (either via source hosting, or services like pastebin.com). And also you didn't share what hidden under *I tried various options…*. – 0andriy Jan 14 '16 at 19:55
  • @Andy Shevchenko : I have edited my post and added my code. – shan2u Jan 14 '16 at 22:00
  • Before doing your custom program did you run i2c-tools, i.e. i2cdump ? Try those first and check if the device is there. – 0andriy Jan 15 '16 at 13:36
  • Sorry for the late reply... I am running busybox in my board and i could not run i2cdump or i2cdetect – shan2u Jan 20 '16 at 23:21
  • busybox has implementation of i2c-tools. – 0andriy Jan 21 '16 at 12:56
  • I dont find any option in menuconfig of Busybox. What should i do to get he i2c-tools implementation for Busybox ? – shan2u Jan 22 '16 at 13:37
  • There should be *miscutils/i2c_tools.c* file present. If you have no such file you perhaps are using too old BusyBox. – 0andriy Jan 23 '16 at 12:11
  • Yes you are right. I checked and found that i am running Busybox 1.17.0 version which doesnt have the i2c_tools in it. Now I have to update Busybox to the latest version. I will do it and give you a feedback. – shan2u Jan 26 '16 at 16:44

0 Answers0