INPUT state of Open Drain OUTPUT

captain_morgan
Posts: 42
Joined: Wed Dec 09, 2015 6:39 pm

INPUT state of Open Drain OUTPUT

Postby captain_morgan » Mon Dec 28, 2015 8:35 pm

This is pushing the limits on my MCU/GPIO knowledge so sorry if I'm missing something obvious.

I'm trying to port an i2c bit-banging library but I cannot seem to get it to read the pin state. My understanding is that
configuring the GPIO as an Open Drain OUTPUT with the Pull Up resistor enabled should allow me to read it's INPUT
state as if it were an INPUT. Trying to read with GPIO_INPUT_GET always read 0, gpio_config_get() doesn't reflect changes
in the pin state.

Any suggestions of what I'm missing?

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: INPUT state of Open Drain OUTPUT

Postby martinayotte » Mon Dec 28, 2015 8:48 pm

Did you tried with an external pullup if it is working ?
Also, are you switching pin mode from Open Drain Output to Input, because during Output mode, probably Input can't be read.

captain_morgan
Posts: 42
Joined: Wed Dec 09, 2015 6:39 pm

Re: INPUT state of Open Drain OUTPUT

Postby captain_morgan » Mon Dec 28, 2015 8:51 pm

I'm not switching to INPUT as none of the examples I've seen for the ESP8266 do that. They simply read it as if it were an INPUT. I'll try the external pullup next

captain_morgan
Posts: 42
Joined: Wed Dec 09, 2015 6:39 pm

Re: INPUT state of Open Drain OUTPUT

Postby captain_morgan » Mon Dec 28, 2015 9:54 pm

External pullup doesn't seem to help either.

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: INPUT state of Open Drain OUTPUT

Postby martinayotte » Mon Dec 28, 2015 10:27 pm

But then, it should not be configured as output.
If you look at Arduino for ESP8266, they init the pins to inputs, and while bit-banging, when the level is LOW they change the mode on the fly and when HIGH it is becoming an input again.

Code: Select all

#define SDA_LOW()   (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
#define SDA_HIGH()  (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)

captain_morgan
Posts: 42
Joined: Wed Dec 09, 2015 6:39 pm

Re: INPUT state of Open Drain OUTPUT

Postby captain_morgan » Tue Dec 29, 2015 12:53 am

Yup, with a closer look the original driver did switch to INPUT but I've messed up something... time to try again.

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: INPUT state of Open Drain OUTPUT

Postby martinayotte » Tue Dec 29, 2015 6:07 am

Yes, in other words, the ONLY time the pin is acting as an output is when the SDA/SCL needs to be bring to LOW, in any other states, the pins should be back to Input mode, leaving the pullups doing their job, also allowing the Slaves to do such things like "clock stretching".

(Unfortunately, I can't test any of those things on ESP32 since I didn't received module yet from Beta program ... :( )

User avatar
ESP_Me-no-dev
Posts: 77
Joined: Mon Jan 04, 2016 6:30 pm

Re: INPUT state of Open Drain OUTPUT

Postby ESP_Me-no-dev » Thu Jan 07, 2016 11:48 am

my software I2C (the one inside ESP8266 Arduino) is working just fine on the ESP31B. Only thing needed to change was those 4 definitions on top to the new register locations.

pinWork is simple:
Set the pins as: PullUP ON, Mode GPIO, output LOW
then to switch the pin level you only need to Enable/Disable this pin as Output.
When switched to output it will output low because that is how we have it set and when switched to INPUT it will output HIGH because of the pull-up.
On the receive side the pin is input and pulled up so the sending end can freely alter the pin level and allow us to read it.

Who is online

Users browsing this forum: No registered users and 57 guests