Content originally posted in LPCWare by shamvhgowda on Mon Feb 17 00:12:20 MST 2014
Hello Friends,
I am using Ububtu 12.04 version and doing uclinux on LPC 1788 Board.
Since I'm new to LPCware and also new to LPC1788 uclinux. I am writing Device drivers for LPC1788 uclinux . So i'm strucked in i2c communication protocol. So can anyone help me to solve this issue.
Here is my user space code
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <linux/kernel.h>
#include <linux/fs.h>
int main ( void )
{
int file;
int adapter_nr = 0; /* probably dynamically determined */
char filename[20];
char i = 0;
int res;
char buf[8],Buffer1[8];
buf[0] = 00; // Seconds
buf[1] = 00; // Minutes
buf[2] = 00; // Hours
buf[3] = 00; // Day of week
buf[4] = 15; // Date
buf[5] = 02; // Month
buf[6] = 14; // Year
buf[7] = 0x00; // Control = 00h
for(i=0; i<7; i++)
{
buf = RX8035_toBCD(buf);
}
//-- Set control bits
buf[2] &= 0x3F; //-- Hours bit 7(12/24) = 0(12-hour mode)
buf[5] &= 0x1F;
snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);//Make sure to give mknod /dev/i2c-2 c 89 0 in target(minicom)
file = open(filename, O_RDWR);
if (file < 0)
{
printf("/* ERROR IN FILE OPEN\r\n");
return 0;
}
else
printf("File open Success\r\n");
int addr = 0x64; /* The I2C slave address(rtc) address */
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
printf("/* ERROR IN ioctl \r\n");
/* ERROR HANDLING; you can check errno to see what went wrong */
return 0;
}
/* Using I2C Write, equivalent of
i2c_smbus_write_word_data(file, register, 0x6543) */
if (write(file, buf, 8) != 8)
{
printf("/* ERROR IN write\r\n");
/* ERROR HANDLING: i2c transaction failed */
}
else
printf(" WRITE Succes %d\n",buf[0]);
int addr1 = 0x65; /* The I2C address */
if (ioctl(file, I2C_SLAVE_FORCE, addr1) < 0)
{
printf("/* ERROR IN ioctl \r\n");
/* ERROR HANDLING; you can check errno to see what went wrong */
return 0;
}
/* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */
if (read(file, Buffer1, 8) != 8)
{
printf("/* ERROR IN Read\r\n");
/* ERROR HANDLING: i2c transaction failed */
}
else
{
printf("Succes %d\n",Buffer1[0]);
/* buf[0] contains the read byte */
}
}
In target(minicom) i got error like this
~ # chmod +x i2capp
~ # ./i2capp
File open Success
/* ERROR IN writ------------[ cut here ]------------
WARNING: at kernel/irq/manage.c:274 0xa00865e7()
Unbalanced enable for IRQ 10
Modules linked in:
Backtrace: no frame pointer
---[ end trace 84d59ffaa05f0b6c ]---
e
/* ERROR IN Read
~ #
Any reply will be appreciated and i need reply soon because i am strucked from past 3 days. and tell me if i'm doing any thing wrong.
Thanq
Sham