2017-12-02 24 views
0

문제를 감지하는 방법? I2C 버스에서 하나의 장치를 찾으려고합니다. 버스를 찾았지만 어떤 장치도 찾지 못했습니다. 두 개의 메인 보드, 두 개의 다른 장치 (AM2321 및 변환기 I2C -> 3wire)를 가지고 있으며 서로 다른 조합으로 시도해 보았습니다. 나는 뭔가 잘못했으나 정확히 이해할 수 없다. 안드로이드 것들 DP 6I2C가 Android와 함께 Raspberry Pi 3에서 작동하지 않습니다.

val bus = manager.i2cBusList.first() // in my device one and only one bus now 
    Log.d("happy", "bus: $bus") 

    val devices = (0..127).filter { address -> 
     manager.openI2cDevice(bus, address).use { device -> 
      try { 
       device.write(ByteArray(1), 1) 
       true 
      } catch (e: IOException) { 
       false 
      } 
     } 
    } 

    if (devices.isEmpty()) { 
     Log.d("happy", "no devices") 
    } else { 
     devices.forEach { address -> 
      Log.d("happy", "device $address") 
     } 
    } 

답변

1

당신은 문제를 감지 PIO CLI Tool를 사용할 수 있습니다

pio i2c name address subcommand [arg] 

name is the name of a valid I2C bus. 

address is the address of an I2C device. 

subcommand can be one of the following: 
Subcommand Description 
read-raw size  Read size bytes from device. 
read-reg-byte reg  Read a byte from reg. 
read-reg-word reg  Read a word (2 bytes) from reg. 
read-reg-buffer reg size Read size bytes from reg. 
write-raw val [val ...] Write val to device. 
write-reg-byte reg val Write byte val to reg. 
write-reg-word reg val Write word val to reg. 
write-reg-buffer reg val [val ...] Write val to reg. 

$ pio i2c I2C1 0x10 write-reg-byte 0x20 0x40 
$ pio i2c I2C1 0x12 read-reg-byte 0x24 0x7F 

을 또한 thisthat 자습서를보십시오.

+0

감사합니다. 아주 좋은 자원이지만 여전히 나를 위해 일하지 않습니다. 'pio'는 내 코드와 동일한 오류를 반환합니다. 그리고 스캐너는 즉시 사용할 수 없습니다. 하드웨어에 문제가있는 것처럼 보이지만이를 감지하는 방법은 없습니다. 네이티브 리눅스를 설치하고 거기에서 시도해보십시오. – tse

+0

I2C를 확실히 사용했으며 정상적으로 작동했습니다. 다른 구성 요소를 사용해 볼 수 있습니까? 아마 I2C 핀이 고장 났을까요? – shalafi

+0

" ''pio '가 내 코드와 동일한 오류를 반환하면"- 코드에 문제가 없습니다. 문제가 유선 연결이거나 [shalafi] (https://stackoverflow.com/users/539171/shalafi)로 I2C 핀이 깨 졌음을 나타냅니다. –