当前位置: 技术问答>linux和unix
在S3C2410上写基于linux 的IIC程序具体怎么写啊?
来源: 互联网 发布时间:2016-04-28
本文导语: 目标机是s3c2410,目标机的内核不是是我移植的,我怎样才能知道目标机linux下还需不需要写IIC驱动呢?怎么才能查看目标机上是否已有现成的字符设备从而可以让我直接在上面写IIC程序呢? 还有,我写了个IIC...
目标机是s3c2410,目标机的内核不是是我移植的,我怎样才能知道目标机linux下还需不需要写IIC驱动呢?怎么才能查看目标机上是否已有现成的字符设备从而可以让我直接在上面写IIC程序呢?
还有,我写了个IIC的程序如下:
#include
#include
#include
#include
#include
#define CHIP_ADDR 0X50
#define PAGE_SIZE 8
#define I2C_DEV "/dev/i2c/0"
static int read_eeprom(int fd,char buff[],int addr,int count)
{
int res;
if(write(fd,&addr,1)!=1)
return -1;
res=read(fd,&buff,count);
printf("read % d byte at 0x % xn", res,addr);
return res;
}
static int write_eeprom(int fd,char buff[],int addr,int count)
{
int res;
int i;
static char sendbuffer[PAGE_SIZE+1];
memcpy(sendbuffer+1,buff,count);
sendbuffer[0]=addr;
res=write(fd,&addr,count+1);
printf("write % d byte at 0x % xn",res,addr);
}
int main(void){
int fd,n,res;
unsigned char buf[PAGE_SIZE];
fd= open(I2C_DEV,0_RDWR);
if(fd
还有,我写了个IIC的程序如下:
#include
#include
#include
#include
#include
#define CHIP_ADDR 0X50
#define PAGE_SIZE 8
#define I2C_DEV "/dev/i2c/0"
static int read_eeprom(int fd,char buff[],int addr,int count)
{
int res;
if(write(fd,&addr,1)!=1)
return -1;
res=read(fd,&buff,count);
printf("read % d byte at 0x % xn", res,addr);
return res;
}
static int write_eeprom(int fd,char buff[],int addr,int count)
{
int res;
int i;
static char sendbuffer[PAGE_SIZE+1];
memcpy(sendbuffer+1,buff,count);
sendbuffer[0]=addr;
res=write(fd,&addr,count+1);
printf("write % d byte at 0x % xn",res,addr);
}
int main(void){
int fd,n,res;
unsigned char buf[PAGE_SIZE];
fd= open(I2C_DEV,0_RDWR);
if(fd