本文转载自:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <stdio.h>#include <linux/types.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <sys/types.h>#include <sys/ioctl.h>#include <errno.h>#include <linux/i2c.h>#include <linux/i2c-dev.h>int main(){ int fd,ret; struct i2c_rdwr_ioctl_data codec_data; fd=open("/dev/i2c-3",O_RDWR); if(fd<0) perror("open error"); codec_data.nmsgs=2; codec_data.msgs=(struct i2c_msg*)malloc(codec_data.nmsgs*sizeof(struct i2c_msg)); if(!codec_data.msgs) { perror("malloc error"); exit(1); } ioctl(fd,I2C_TIMEOUT,1);/*超时时间*/ ioctl(fd,I2C_RETRIES,2);/*重复次数*/ sleep(1); codec_data.nmsgs=1; (codec_data.msgs[0]).len=2; (codec_data.msgs[0]).addr=(0x36 >> 1);//我的音频硬件地址; (codec_data.msgs[0]).flags=0; //write (codec_data.msgs[0]).buf=(unsigned char*)malloc(2); (codec_data.msgs[0]).buf[0]=0x04; (codec_data.msgs[0]).buf[1]=0x55;//the data to write ret=ioctl(fd,I2C_RDWR,(unsigned long)&codec_data); if(ret<0) perror("ioctl error1"); sleep(1); /******read data from e2prom*******/ printf("read start\n"); codec_data.nmsgs=2; (codec_data.msgs[0]).len=1; //e2prom 目标数据的地址 (codec_data.msgs[0]).addr=(0x36 >> 1);//yinpin; (codec_data.msgs[0]).flags=0;//write (codec_data.msgs[0]).buf[0]=0x04; (codec_data.msgs[1]).len=1;//读出的数据 (codec_data.msgs[0]).addr=(0x36 >> 1); (codec_data.msgs[1]).flags=I2C_M_RD;//read (codec_data.msgs[1]).buf=(unsigned char*)malloc(1);//存放返回值的地址。 (codec_data.msgs[1]).buf[0]=0;//初始化读缓冲 ret=ioctl(fd,I2C_RDWR,(unsigned long)&codec_data); if(ret<0) perror("ioctl error2"); close(fd); return 0;} |
音频的硬件地址是没有错误的。在开发板上运行的结果是这样的
ioctl error2: Remote I/O error
只提示了读的时候错误了。请问,这个错误是怎么造成的,我一直困惑了好久!