亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 16911 | 回復(fù): 4
打印 上一主題 下一主題

請(qǐng)教關(guān)于i2c Remote I/O error [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-02-03 09:49 |只看該作者 |倒序?yàn)g覽
我用2.6.24內(nèi)核自帶的i2c-dev.c通過ioctl來操作適配器進(jìn)而讀寫24c02,
可程序運(yùn)行錯(cuò)誤:
ioctl error 1:Remote I/O error
ioctl error 2:Remote I/O error
懇請(qǐng)各位高手指教,謝謝!

代碼列出如下,i2c-msg以改成內(nèi)核定義形式。



        #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>
        #define I2C_RETRIES 0x0701
        #define I2C_TIMEOUT 0x0702
        #define I2C_RDWR 0x0707
        /*********定義struct i2c_rdwr_ioctl_data和struct i2c_msg,要和內(nèi)核一致*******/
struct i2c_msg
        {
                unsigned short addr;
                unsigned short flags;
        #define I2C_M_TEN 0x0010
        #define I2C_M_RD 0x0001
                unsigned short len;
                unsigned char *buf;
        };
struct i2c_rdwr_ioctl_data
        {
                struct i2c_msg *msgs;
                int nmsgs;
        /* nmsgs這個(gè)數(shù)量決定了有多少開始信號(hào),對(duì)于“單開始時(shí)序”,取1*/
        };
/***********主程序***********/
        int main()
        {
                int fd,ret;
                struct i2c_rdwr_ioctl_data e2prom_data;
                fd=open("/dev/i2c-0",O_RDWR);
        /*
        */dev/i2c-0是在注冊(cè)i2c-dev.c后產(chǎn)生的,代表一個(gè)可操作的適配器。如果不使用i2c-dev.c
        *的方式,就沒有,也不需要這個(gè)節(jié)點(diǎn)。
        */
                if(fd<0)
                {
                        perror("open error";
                }
                e2prom_data.nmsgs=2;
        /*
        *因?yàn)椴僮鲿r(shí)序中,最多是用到2個(gè)開始信號(hào)(字節(jié)讀操作中),所以此將
        *e2prom_data.nmsgs配置為2
        */
                e2prom_data.msgs=(struct i2c_msg*)malloc(e2prom_data.nmsgs*sizeof(struct i2c_msg));
                if(!e2prom_data.msgs)
                {
                        perror("malloc error";
                        exit(1);
                }
                ioctl(fd,I2C_TIMEOUT,1);/*超時(shí)時(shí)間*/
                ioctl(fd,I2C_RETRIES,2);/*重復(fù)次數(shù)*/
                /***write data to e2prom**/

                e2prom_data.nmsgs=1;
                (e2prom_data.msgs[0]).len=2; //1個(gè) e2prom 寫入目標(biāo)的地址和1個(gè)數(shù)據(jù)
                (e2prom_data.msgs[0]).addr=0x50;//e2prom 設(shè)備地址
                (e2prom_data.msgs[0]).flags=0; //write
                (e2prom_data.msgs[0]).buf=(unsigned char*)malloc(2);
                (e2prom_data.msgs[0]).buf[0]=0x10;// e2prom 寫入目標(biāo)的地址
                (e2prom_data.msgs[0]).buf[1]=0x58;//the data to write
        ret=ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
                if(ret<0)
                {
                        perror("ioctl error1";
                }
                sleep(1);
        /******read data from e2prom*******/
                e2prom_data.nmsgs=2;
                (e2prom_data.msgs[0]).len=1; //e2prom 目標(biāo)數(shù)據(jù)的地址
                (e2prom_data.msgs[0]).addr=0x50; // e2prom 設(shè)備地址
                (e2prom_data.msgs[0]).flags=0;//write
                (e2prom_data.msgs[0]).buf[0]=0x10;//e2prom數(shù)據(jù)地址
                (e2prom_data.msgs[1]).len=1;//讀出的數(shù)據(jù)
                (e2prom_data.msgs[1]).addr=0x50;// e2prom 設(shè)備地址
                (e2prom_data.msgs[1]).flags=I2C_M_RD;//read
                (e2prom_data.msgs[1]).buf=(unsigned char*)malloc(1);//存放返回值的地址。
                (e2prom_data.msgs[1]).buf[0]=0;//初始化讀緩沖
        ret=ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
                if(ret<0)
                {
                        perror("ioctl error2";
                }
                printf("buff[0]=%x\n",(e2prom_data.msgs[1]).buf[0]);
        /***打印讀出的值,沒錯(cuò)的話,就應(yīng)該是前面寫的0x58了***/
                close(fd);
                return 0;
        }

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2010-02-05 09:37 |只看該作者
問題解決,因?yàn)樾〉艿?e2prom_data.msgs[0]).addr=0x50設(shè)置錯(cuò)誤,應(yīng)該是0xa0>>1,多謝各位大俠~

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2011-03-21 09:57 |只看該作者
想問一下你確定嗎,0x50與0xa0>>1有什么區(qū)別嗎

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2012-06-11 11:42 |只看該作者
我也遇到這個(gè)錯(cuò)誤了,不知道是什么原因呢。 0x50確實(shí)和0xa0>>1沒啥區(qū)別啊

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2014-05-19 14:09 |只看該作者
確實(shí)應(yīng)該是 >> 1;
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP