Linux

i2c-tools

i2c-tools는 코드를 작성하지 않고도 I2C 주변 장치를 쉽게 디버깅할 수 있게 해주는 I2C 프로그램이다.

 

i2cdetect

특정 I2C 버스에 어떤 주변 장치가 연결되어 있는지 확인할 수 있습니다.

i2cdetect -l // i2c 연결된 모든 라인 확인

특정 I2C 버스에서 감지된 주변 장치 목록을 가져옵니다

i2cdetect -r -y <i2cbus number> 2ex) i2cdetect -r -y 2 // i2c 라인 2번에 연결된 모든 장치 주소 확인

 

 

 

i2cset ( 1byte & 2byte Adress )

원하는 장치에 직접 쓰려면 i2cset를 사용한다.

i2cset -f -y <i2cbus number> <peripheral address> <value> 2ex) i2cset -f -y 2 0x10 0x01 0x50 
// i2c 라인 2번에 연결된 0x10 주소를 가진 장치의 0x01 (1byte) 레지스터에 0x50 값을 설정
i2cset -f -y <i2cbus number> <peripheral address> <MSB address> <LSB address> <MSB value> <LSB value> i 2ex) i2cset -f -y 2 0x10 0x02 0x50 0x10 i 
// i2c 라인 2번에 연결된 0x10 주소를 가진 장치의 0x0250 (2byte) 레지스터에 0x10 값을 설정

i2ctransfer ( 1byte Adress )

i2ctransfer -f -y <i2cbus number> w<number of bytes>@<peripheral address> <byte value 1> <byte value 2> ... <byte value n> 2ex) i2ctransfer -f -y 2 w2@0x48 0x00 0x52
// i2c 라인 2번에 연결된 0x48 주소를 가진 장치의 0x00 (1byte) 레지스터에 0x52 값을 설정

 

i2cget ( 1byte Adress )

하나의 장치에 데이터를 직접 읽으려면 i2cget를 사용한다.

i2cget -f -y <i2cbus number> <peripheral address> 2ex) i2cget -f -y 2 0x10 0x0f 
// i2c 라인 2번에 연결된 0x10 주소를 가진 장치의 0x0f (1byte) 레지스터의 값을 1byte 로 반환
i2cget -f -y <i2cbus number> <peripheral address> <address> w 2ex) i2cget -f -y 2 0x10 0x0f w 
// i2c 라인 2번에 연결된 0x10 주소를 가진 장치의 0x0f (1byte) 레지스터의 값을 2byte 로 반환

i2ctransfer ( 1byte & 2byte Adress )

i2ctransfer -f -y <i2cbus number> w<number of bytes to write>@<peripheral address> <byte value 1> <byte value 2> ... <byte value n> r<number of bytes to read> 2
i2ctransfer -f -y 2 w2@0x10 0x00 0x52 r1 
// i2c 라인 2번에 연결된 0x10 주소를 가진 장치의 0x0052 (2byte) 레지스터의 값을 1byte 로 반환

 

 

i2ctransfet의 경우 i2cset, i2cget 이후에 나온 기능으로 두 기능보다 쓰기 간단하여 편리하다는 장점이 있다.

 

참고 :

https://wiki.st.com/stm32mpu/wiki/I2C_i2c-tools

 

I2C i2c-tools - stm32mpu

1 Article purpose[edit] This article aims to give some first information useful to start with the Linux® tool : I2C tools. 2 Introduction[edit] i2c-tools is a complete user-space package that comes on top of I2C subsystem. It offers: tools: a set of I2C

wiki.st.com

 

'Linux' 카테고리의 다른 글

ubuntu 네트워크 장치 이름 변경  (0) 2023.07.16
PCIe ASPM Error  (0) 2023.07.02
SSD 자동 인식  (0) 2023.01.28
리눅스 커널 소스의 구조  (0) 2022.12.03
Memory mapping  (0) 2022.11.27