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?
INPUT state of Open Drain OUTPUT
- martinayotte
- Posts: 141
- Joined: Fri Nov 13, 2015 4:27 pm
Re: INPUT state of Open Drain OUTPUT
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.
Also, are you switching pin mode from Open Drain Output to Input, because during Output mode, probably Input can't be read.
-
- Posts: 42
- Joined: Wed Dec 09, 2015 6:39 pm
Re: INPUT state of Open Drain OUTPUT
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
-
- Posts: 42
- Joined: Wed Dec 09, 2015 6:39 pm
Re: INPUT state of Open Drain OUTPUT
External pullup doesn't seem to help either.
- martinayotte
- Posts: 141
- Joined: Fri Nov 13, 2015 4:27 pm
Re: INPUT state of Open Drain OUTPUT
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.
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)
-
- Posts: 42
- Joined: Wed Dec 09, 2015 6:39 pm
Re: INPUT state of Open Drain OUTPUT
Yup, with a closer look the original driver did switch to INPUT but I've messed up something... time to try again.
- martinayotte
- Posts: 141
- Joined: Fri Nov 13, 2015 4:27 pm
Re: INPUT state of Open Drain OUTPUT
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 ... )
(Unfortunately, I can't test any of those things on ESP32 since I didn't received module yet from Beta program ... )
- ESP_Me-no-dev
- Posts: 80
- Joined: Mon Jan 04, 2016 6:30 pm
Re: INPUT state of Open Drain OUTPUT
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.
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: Google [Bot] and 59 guests