Chat freely about anything...

User avatar
By me21
#57150 The connect() function in esptool is as follows:
Code: Select all    """ Try connecting repeatedly until successful, or giving up """
    def connect(self):
        print 'Connecting...'

        for _ in xrange(4):
            # issue reset-to-bootloader:
            # RTS = either CH_PD or nRESET (both active low = chip in reset)
            # DTR = GPIO0 (active low = boot to flasher)
            self._port.setDTR(False)
            self._port.setRTS(True)
            time.sleep(0.05)
            self._port.setDTR(True)
            self._port.setRTS(False)
            time.sleep(0.05)
            self._port.setDTR(False)

            # worst-case latency timer should be 255ms (probably <20ms)
            self._port.timeout = 0.3
            for _ in xrange(4):
                try:
                    self._port.flushInput()
                    self._slip_reader = slip_reader(self._port)
                    self._port.flushOutput()
                    self.sync()
                    self._port.timeout = 5
                    return
                except:
                    time.sleep(0.05)
        raise FatalError('Failed to connect to ESP8266')


It obviously works, but I'm at a loss trying to understand why.
It sets RTS, waits a bit, then clears RTS line, thus putting ESP to reset. At least it should do so, based on the source of esptool and the fact that ESP is held in reset by low level on that line.
Can anyone please explain why does this code work?
User avatar
By picstart
#57152 I suspect this is to do with where the electrons are. RS232 is current driven so the electrons need to be on the move with respect to RTS and DTR. Often the movement of electrons is accomplished with a simple pull up or pull down resistor attached to an esp pin and doesn't necessarily need the esp pin to provide the electrons. In one state the esp pin provides electrons in another the pull up does it. Coders don't always think about where are the electrons but for electrical interfaces it is very useful.