-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
i2c_software: Implementation of software i2c #6141
Conversation
a74c6d1
to
fdc1c24
Compare
Any other test results? e.g an Octopus board. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. As high-level feedback, the functionality seems useful. I have some comments on the implementation - see below.
Can you provide additional information on how this will be used? Is there a device that needs this support and requires high speed I2C access?
-Kevin
src/i2c_software.c
Outdated
gpio_out_write(is->sda, b & 0x80); | ||
b <<= 1; | ||
i2c_delay(is->ticks); | ||
gpio_out_write(is->scl, 1); | ||
i2c_delay(is->ticks); | ||
gpio_out_write(is->scl, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To communicate over an I2C bus, the transmitter should transition between GND and high-Z states. This code is transitioning between GND and HIGH states. If the transmitter transitions to a HIGH state while the receiver is in a GND state it would result in a "short" on the wires that would consume power, generate heat, and possibly destabilize the board voltage.
I have written code to communicate with I2C devices using just GND/HIGH transitions (eg, klippy/extras/mcp4018.py
). This change, though, may confuse users into thinking Klipper supports I2C on any device. I'm not sure that is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Theoretically this is a problem.
It would be perfect if there were a universal API to set GPIO as Open-Drain output, but some MCU (such as RP2040) do not seem to have the Open-Drain feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the code transmit bits by switching between gpio_in_reset(is->sda_in, 1)
and gpio_out_reset(is->sda_out, 0)
?
I suspect the transfer rate would be slower, but it would hopefully not cause electrical problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the transfer rate would be slower. Mainly affecting MCU with lower main frequencies such as STM32G0B1 64MHz.
The measured results are as follows
1 | gpio_out_write |
gpio_in/out_reset |
---|---|---|
STM32G0B1 | 70KHz | 30-40KHz |
RP2040 | 84KHz | 70KHz |
For MCUs with high main frequencies like STM32H7
, The impact is minimal.
8f1e835
to
55b5e92
Compare
It can work normally in Octopus F4/H7 versions |
Thanks. I guess my main question is - which users are expected to utilize this and what hardware is it expected that they will use it with? Is this just general functionality that some users may find useful or is there a specific hardware setup that requires this functionality? In general I prefer to only add code when we have a general idea of who will be using it and what they use it for. (That way, I can get a better feel for the maintenance costs of the extra code relative to the functionality obtained by that new code.) Cheers, |
Signed-off-by: Alan.Ma from BigTreeTech tech@biqu3d.com
This requirement is raised by some of our customers who want to connect |
Okay, thanks. In general, it looks fine to me. I'll look to commit early next week. -Kevin |
Thanks. -Kevin |
This looks to break smaller STM32 builds like the 042 with an error of
Seems to push it over the flash size Thanks |
seems changing line 10 of Kconfig from |
This seems to allow compilation of FW for STM32F042. I have one in a Voron 0 display board. But the commit 645a1b seems to break i2c communication nonetheless. I have made several attempts, including a complete reinstall of klipper, but they all failed and I had to rollback to previous commit, which works without a problem, both in compiling FW and communication with the display board.
|
then my commit/solution may be just a sticking plaster for other problems caused by this commit |
See #6244 for code to optionally disable software i2c (and other features) on chips with small flash sizes. -Kevin |
This also seems to break some rp2040 boards, at least a couple of SB2040 mellow owners have tmc uart issues on this commit, that i have seen on the discord Thanks |
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
Follow up #6130
Software I2C tested on
STM32H7
with bothBME280
andsh1106
, The actual test results are normal.The following are some results captured by the logic analyzer.
100KHz i2c read
100KHz i2c write
400KHz i2c read400KHz i2c writeNote
The maximum rate in the .c source file is limited to 1MHz, and the actual rate captured by the logic analyzer is between 800KHz-1MHzSpeed fixed to 100KHzi2c_delay
function, the occupancy rate of the mcu is still 100%, so it is not recommended to use software i2c on MCU like Mega2560