포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 20MB 입니다.

특정 i2c bus line(여기서는 /dev/i2c-0 - 즉, 첫번째 버스라인)에 붙어 있는 i2c를 scan하는 
소스입니다.

참고하시기 바랍니다.
=====================================
#include <stdlib.h>

#include <string.h>

#include <assert.h>
#include <sys/user.h>
#include <fcntl.h>
#include <sys/mman.h>

#include <sys/ioctl.h>
#include <errno.h>
#define I2C_RDWR    0x0707

struct i2c_msg {
        unsigned short addr;
        unsigned short flags;
        unsigned short len;
        unsigned char * buf;
};


struct i2c_rdwr_ioctl_data {
        struct i2c_msg *msgs;
        unsigned int nmsgs;
};


int fd;

int i2c_scan()
{
        int rc, adr, found=0;
        struct i2c_msg msg;
        struct i2c_rdwr_ioctl_data msgset;

        /* scan the whole I²C bus range */
        for (adr = 1; adr < 128; adr++) {
                msg.addr  = adr;
                msg.flags = 0;
                msg.buf   = 0;
                msg.len   = 0;

                msgset.msgs  = &msg;
                msgset.nmsgs = 1;

                rc = ioctl(fd , I2C_RDWR , &msgset );
                if ( rc == 1 ) {
                        found++;
                        printf("Find Device I2C Addr = %x \n", adr);
                }
        }
}



int main (int argc, char *argv[])
{
        int j;
        int n, i;
        int iret = 0;
        int chip;
        unsigned char value = 0x00;
        fd = open("/dev/i2c-0", O_RDWR);

        if (fd < 0) {
                printf("Open Error...!\n");
                exit(0);
        }

        i2c_scan();
        close(fd);

}

"사람은 자기가 보고 싶은 현실만 볼 뿐이다." - Gaius Julius Caesar
엮인글 :
http://www.aesop.or.kr/index.php?mid=Board_Documents_Linux_Applications&document_srl=79433&act=trackback&key=129
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
93 Yocto zynq howto - 예전자료 고도리 2019-08-24 283
92 Yocto project 소개자료 [2] 고도리 2019-08-24 883
91 apache-1.3.33 arm porting by tssuk [3] 고도리 2013-05-21 3336
» i2c scan하는 코드입니다. 고도리 2012-07-27 5307
89 dropbear ssh daemon 포팅하기 [1] 고도리 2012-06-30 5846
88 ffmpeg을 이용한 camera 영상 저장 file [1] 고도리 2012-05-01 5892
87 Linux Clustering - Building and Maintaining Linux Clusters file 김재훈 2009-01-31 5998
86 Linux Operating System Networking HowTo file 김재훈 2009-01-31 6001
85 patch file 만들기 고현철 2009-01-30 6005
84 Linux Operating System 100 Tips & Tricks file 김재훈 2009-01-31 6014
83 The GNU Assembler - How to Using AS file 김재훈 2009-04-03 6017
82 RedHat Complete Linux Command Reference file 김재훈 2009-01-31 6029
81 유용한 ARM 어셈블리 분기 명령어 시리즈 #1 김재훈 2009-01-31 6029
80 펌웨어 프로그래밍 팁 - 2진수 처리기 김재훈 2009-01-31 6037
79 ARM ADS Errors and Warning 코드 설명 file 김재훈 2009-02-12 6040
78 The GNU Linker - How to Using ld file 김재훈 2009-04-03 6044
77 일본어 mount option 고현철 2009-01-30 6046
76 SDL에서 touchscreen enable 시키는 방법 고현철 2009-03-04 6046
75 유용한 ARM 어셈블리 매크로 김재훈 2009-01-31 6056
74 한글 mount/samba option 고현철 2009-01-30 6059

사용자 로그인