Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By dayzman
#18437
eriksl wrote:Clock stretching is someting a slave does. Is your implementation creating a slave or a master? A master would sound much more logical. A master does not do clock stretching by definition, because the master supplies the clock. The only requirement for the clock is that it runs at < 100 KHz at any single time. Besides that, it can be as monotonic or non-monotonic as you like, comparable to SPI. Clock is a bit confusing in this context, it's not a wall clock, it's more like a "data is valid NOW" strobe (+ out-of-band conditions like start and stop, but that's a different story altogether).

That means that the timing is really not quite critical, on a master. On a slave it's much more critical, especially if the master doesn't honour clock stretching by the client.

Having said that, I doubt it won't be harmful if you disable interrupts every now and time, as long as you treat the piece of code that runs with interrupts disable just like and interrupt service handler itself; do only what's really necessary and move all other code out of the critical section.


I'm trying to create a slave - a BMP180. So I'm not sure if clock stretching is needed here.
User avatar
By martinayotte
#18439 @dayzman, if you try to hook a BMP180, the BMP180 is the slave in this scenario and the ESP is the master. So, no issue there about clock stretching.
It is a bit different if you hook up 2 ESPs together, one will be the master and the other one the slave.
User avatar
By Baoshi
#18558
dayzman wrote:
Baoshi wrote:Zarya's implementation uses os_delay_us to fulfill the clock rate. It is ok. I2C is relatively a slow bus. Disable interrupts is not a good idea.
I have a similar implementation using RTOS SDK. https://github.com/baoshi/ESP-I2C-OLED


Indeed. How would you critically compare your implementation with his? Yours seems to use clock stretching and his disables interrupts during init.


I think you refer to the while loop waiting for slave to release SCL. Yes it is dangerous if slave never respond. I should have put a timeout here. But if slave doesn't release bus, this usually means hardware failure, and I2C bus will not be usable at all. So I rather let system watchdog to reset.