포럼 회원으로 등록하신분만 다운로드가 가능합니다. 최대 업로드 가능한 용량은 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=7eb
List of Articles
번호 제목 글쓴이 날짜sort 조회 수
13 grep을 이용한 검색 script ==> gref 고현철 2009-01-30 6118
12 uBuntu 8.10 에서의 리눅스 개발 환경 설정 [6] 김재훈 2009-01-29 12628
11 wxDevcpp를 이용한 windows용 tutorial입니다. file 고도리 2008-07-18 7426
10 windows/linux에서 작업했던 tutorial입니다. file 고도리 2008-07-18 6631
9 wxWidget hello unix example file 고도리 2008-07-18 6504
8 devcpp howto입니다.(devcpp/wxWidget/SDL) file 고도리 2008-07-18 6924
7 wxWidget sample program 올리기 - windows/linux file 고도리 2008-07-18 6945
6 wxWidget mysql direct access file 고도리 2008-07-18 6101
5 wxWidget odbc file 고도리 2008-07-18 6571
4 강좌(공식문서포함) 문서의 양식 포맷입니다. file [4] 고도리 2008-07-11 8781
3 ARM 어셈블러 설명서 한글판. file [7] 유형목 2007-12-15 7701
2 ARM 7 강좌를 다른 분이 편집한 자료 같네요. file [2] 황순일 2007-12-13 6236
1 ARM7 강좌를 PDF로 변환했습니다. start.S 분석자료 추가.. file [8] 유형목 2007-12-12 7736

사용자 로그인