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;
}