-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i2cdetect "phantom devices" #7
Comments
Yeah, I'm using that one (that version doesn't handle GPIO), but this detects phantom devices... |
You'll have to excuse me for being unfamiliar with "correct operation" of Git etc. I've got a tentative patch in my fork at https://github.com/MarkMLl/i2c-ch341-usb but the situation appears to be that (a) if I leave that patch disabled I can drive e.g. an mfrc522, (b) if I either enable that patch or use the pre-GPIO variant from https://github.com/allanbian1017/i2c-ch341-usb then phantom device detection swallows bytes being transferred. So the basic problem is either that my use of the I2C API is broken, or that allanbian1017's hack doesn't work. |
Sorry, I think I don't understand your problem... if I use https://github.com/allanbian1017/i2c-ch341-usb, the i2cdetec -y 4 gives correct result: But with this driver: (And I inspected a little more, the advised read() function also gives 255 if no device) |
Sure, i2cdetect works properly... but have you actually tried using the I2C API to talk to a real device? My experience- which I thought I was making clear- is that the patch which fixes i2cdetect breaks the API on e.g. an mfrc522. |
Sorry, I don't understand your problem.... I can think you are using Pi - and Pi I2C API, sorry I'm using PC + Linux, I tried eeproms, sensores and more. I used i2c_smbus_functions and ioctl in C/C++ and I can talk to devices well with that driver, also this driver reads eeprom properly only some error handling is not the same I think. |
Ahh, As I inspected this code, I think I can see what is your problem with allanbian's version. That version does a fake transfer before each real transfer to detect the if there is a device, so e.g. continuous reading you can lost packets/data and so on... maybe reading blocks can solve that. |
Ahh, interesting: I'll investigate :-) Dealing with other minor points that you've raised, I'm using Linux on a PC and my only reference to an RPi was because I'd tweaked my fork to get the naming to act the same. I've been using the SPI variant of the module heavily, and have tested the GPIO stuff fairly thoroughly. PITA that one has to juggle installed/blacklisted modules when switching to an Arduino (clone) that has a CH341, there's probably a way to sort that that involves a patch to the mainstream kernel (which DKMS might or not be able to apply). |
I've been comparing the I2C implementation using the onboard facilities of a Raspberry Pi with the implementations by Gunar (i.e. this project) and Allan. I don't want to cloud the issue by using my own code, since I make no claim to be a competent kernel developer. All three module/driver variants appear correct with single-byte I2C reads, where the specific sequence is that a register number is written to the slave and a single byte of data read back. This appears to be irrespective of whether a pair of standard kernel calls is used (i.e. register number followed by data as a two-byte write) or the I2C write-read ioctl is used (i.e. to write a register number and immediately read a single byte of data). The RPi and Gunar variants appear correct with multi-byte reads, where a register number is written to the slave and a sequence of bytes read back. These are being handled by single-byte write and read operations since the data I'm using comes back in chunks of 64 bytes but somewhere there's a 63-byte transfer limitation in the write-read ioctl. ... The Allan variant only transfers half the data, the trailing zeroes below being the pre-initialised buffer: My own fork behaves like either the Gunar or the Allan variants, depending on whether I incorporate the phantom-device fix. I'm not sure that there's an application-level way round this, since it's basically down to how the I2C bus and the supporting kernel module/driver handles a certain type of chip. The bottom line is that there's a problem in Allan's code upstream, which only becomes apparent with certain types of slave. |
Ty, as I said, Allan's drops data because of device detection fake messages, but I changed my code when 16 bit addressed eeprom (e.g Atmel 24c256) read to read 16byte blocks and worked well... `
` but falls when reading bytes with e.g. i2c_smbus_read(), And if but works with i2c_smbus_read_byte/word_data( file, address, command=8bit address), when you always specify mem/red address. |
Some question, maybe ch341a datasheet can answer
|
I2C_SLAVE is definitely implemented, I'd expect I2C_SLAVE_FORCE to be a kernel issue so that's probably implemented. The others I'll have to research and it might take me some time. In any event: provided that Gunar's code is used without Allan's patch then the standard I2C API works, and we've got Allan's driver (or my fork) to fall back on if i2cdetect is needed during development. |
If found something about i2cstatus |
i2cdetect -y <bus_number> shows phantom devices at all addresses.
The upstream version of the driver at https://github.com/allanbian1017/i2c-ch341-usb has a patch which attempts to do a status check before every operation, but I find that this is incompatible with e.g. an MFRC522 (RFID reader) slave.
I can't see an easy fix for this. I've been investigating whether it would be possible to decide whether to do a status check based on whether an access was a simple read or write or a combined write/read, but this won't work since there is a limit on the write/read transfer size hence for larger transfers it is necessary to fall back to single-byte operations.
The only remaining possibility that I can see is to recognise that i2cdetect uses SMB operations and to apply a status check only to those. That would at least leave i2cdetect plus basic I2C operations working. However I've not so far been able to work out how to distinguish these cases.
The text was updated successfully, but these errors were encountered: