Skip to content

Open Drain outputs don't work (also breaks bitbangio.I2C) #3845

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

Closed
jepler opened this issue Dec 18, 2020 · 4 comments · Fixed by #5866
Closed

Open Drain outputs don't work (also breaks bitbangio.I2C) #3845

jepler opened this issue Dec 18, 2020 · 4 comments · Fixed by #5866
Labels
bug espressif applies to multiple Espressif chips
Milestone

Comments

@jepler
Copy link

jepler commented Dec 18, 2020

On the Kaluga, I have two sensors attached to the I2C bus at IO10/11. They are detected if I scan with busio.I2C but not with bitbangio.I2C. When I scope bitbangio, there is literally no activity on the pins 10/11; there is the expected activity with busio.I2C.

>>> import board,bitbangio
>>> bus = bitbangio.I2C(board.IO10, board.IO11); bus.try_lock(); bus.scan(); bus.deinit()
True
[]
>>> import busio, board
>>> bus = busio.I2C(board.IO10, board.IO11); bus.try_lock(); bus.scan(); bus.deinit()
True
[11, 112]

I'm testing a local build. Possibly important, this is a DEBUG=1 build.

@jepler jepler added bug espressif applies to multiple Espressif chips labels Dec 18, 2020
@tannewt tannewt added this to the Long term milestone Dec 22, 2020
@tannewt
Copy link
Member

tannewt commented Dec 22, 2020

Maybe we aren't correctly supporting open drain outputs in the digitalio code.

@jepler
Copy link
Author

jepler commented Dec 23, 2020

I tested with adafruit_bitbangio and that works on Kaluga. However, on further inspection, adafruit_bitbangio.I2C doesn't seem to use drive_mode=digitalio.DriveMode.OPEN_DRAIN which is a surprise! I thought that would answer the open drain question but I guess it doesn't.

@jepler jepler changed the title bitbangio.I2C does not work Open Drain outputs don't work (also breaks bitbangio.I2C) Dec 23, 2020
@jepler
Copy link
Author

jepler commented Dec 23, 2020

I wired up a couple of LEDs and can confirm that open drain doesn't work, or at least not as I expect it.

In push/pull mode, one LED lights brightly depending whether the pin's value is True or False.

In open drain mode, neither LED lights no matter whether the value is True or False. However, the upper LED should light when value is False.

image

I did verify that in input mode, pull up/down/none all work; the pulls can be seen as a dimly lighting LED.

@dhalbert
Copy link
Collaborator

Simple fix for this, which I am doing as part of #5816:

@@ -108,11 +108,9 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
     digitalio_digitalinout_obj_t *self,
     digitalio_drive_mode_t drive_mode) {
     gpio_num_t number = self->pin->number;
-    gpio_mode_t mode;
+    gpio_mode_t mode = GPIO_MODE_DEF_OUTPUT;
     if (drive_mode == DRIVE_MODE_OPEN_DRAIN) {
-        mode = GPIO_MODE_DEF_OD;
-    } else {
-        mode = GPIO_MODE_DEF_OUTPUT;
+        mode |= GPIO_MODE_DEF_OD;
     }
     esp_err_t result = gpio_set_direction(number, mode);
     if (result != ESP_OK) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants