allanbian1017 / i2c-ch341-usb

A Linux kernel driver for ch341 emulating the I2C bus
62 stars 57 forks source link

i2cdetect device probe reports "phantom" I2C devices #1

Closed dewhisna closed 6 years ago

dewhisna commented 7 years ago

Overall, this driver seems to work very well. The only issue I've found so far is that running i2cdetect to probe for I2C devices reports devices present at every address regardless of how many I2C devices are really connected. For example:

$ i2cdetect -r 18
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-18 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 
70: 70 71 72 73 74 75 76 77                         

In this particular case, I had a single I2C device at address 0x76, but it also reports that there's devices on all addresses even when no I2C devices are even connected.

I don't know if this is an issue in the driver or in the CH341 interface chip. I suppose it could be either. I haven't dug into it, but I'm suspecting this could be a simple pull-up vs. pull-down or default high vs low issue and may not be easily solved in the driver. But that's just my guess.

Otherwise, it seems to be working correctly, at least on the BME280 sensor I'm using it for.

panciunio commented 7 years ago

I had the same issue with ALL-IN-ONE module based on CH341A (my exercise: https://systemembedded.eu/viewtopic.php?f=19&t=26). It's working perfectly if you know I2C address which you should use. It's not so hart do find address for any device... I like this driver, good work Tse Lun Bien!.

dewhisna commented 7 years ago

It's interesting to know that the CH341A does it too (mine was the CH341T chip on the YS-CH341T I2C/UART adapter). I'm suspecting it's a peculiarity with all the CH341x chips in how they report data, meaning there may not be a way to "fix it" (or should I say "work around it") in the driver.

And yes, one should know the address of the device they are using. But the scan feature is often convenient when troubleshooting connectivity and pull-up resistor issues, when your device isn't responding at all in your application or is giving bad/unexpected data, especially with multiple devices on the bus. Often the first question is whether or not it's responding to the 'read byte' commands normally.

Otherwise the driver is working perfectly for me. And I agree -- good work Tse Lun Bien!.