BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / embedded-system / #7070同步于 2009/12/22
Embedded_System机器人发帖

大家谁用POWERPC做过IIC驱动的研究的啊

swhlnu
2009/12/22镜像同步0 回复
我最近在做这个,想用linux本身提供的I2C-DEV来做,但是老是失败,我想控制EEPROM ATC24C02,但是在实际的运行中老是出现错误,谁能告诉我错误在哪里啊? 这是我的代码。 #include <stdio.h> #include <linux/types.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ioctl.h> #define I2C_RETRIES 0x0701 #define I2C_TIMEOUT 0x0702 #define I2C_SLAVE 0x0703 int main() { unsigned int fd; unsigned short mem_addr; unsigned short size; unsigned short idx; #define BUFF_SIZE 32 char buf[10]; buf[0] =0x00; buf[1] =0x01; char cswap; int reta,ret0,ret1,ret2,ret3,ret4; union { unsigned short addr; char bytes[2]; } tmp; mem_addr=0x58; fd = open("/dev/i2c-dev", O_RDWR); printf("fd is %d\n",fd); if (!fd) { printf("Error on opening the device file\n"); return 0; } reta= ioctl(fd, 0704, 0); ret0=ioctl(fd, I2C_SLAVE, (0x50>>1)); ret1=ioctl(fd, I2C_TIMEOUT, 1); ret2=ioctl(fd, I2C_RETRIES, 1); ret3=write(fd, &buf[0], 1); ret4=write(fd, &buf[1], 1); printf("hello 1\n\n"); printf("get is reta,ret0,ret1,ret2,ret3,ret4is %d %d,%d,%d,%d,%d\n\n",reta,ret0,ret1,ret2,ret3,ret4); close(fd); return 0; } 返回值ioctl的全部正确为0,而读写就错误,为-1。大家谁能告诉我一下啊?谢谢了!
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。