I2C issues

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

I2C issues

Post by warren » Tue Aug 02, 2016 5:36 pm

Hi,

I am experimenting with some I2C sensors, and have been playing with the clock frequency to see how it affects reliability.

Three specific questions:

1) The Micropython default clock speed (if you create an I2C object but do not give a 'freq=' parameter) - is it 400kHz?

2) I notice that if I reduce the clock to a ridiculous 100Hz, the ESP automatically resets. Why does the board crash when the frequency gets too low...?

3) Is there a safe LOWEST clock speed that can be used with the ESP?

And more generally has anyone experience of using I2C sensors on cables longer than 2 metres - reliable?

Thanks

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: I2C issues

Post by deshipu » Tue Aug 02, 2016 5:52 pm

The implementation of I2C is available for inspection at https://github.com/micropython/micropyt ... hine_i2c.c

1) In this line https://github.com/micropython/micropyt ... i2c.c#L248 you can see the default is 400000

2) I'm guessing that this is due to the watchdog timer kicking in, but to confirm you would need to check the reset code that is printed right after the board resets.

3) I think it *should* work with pretty much any speed you set, and the reset from 2) is a bug.

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: I2C issues

Post by warren » Tue Aug 02, 2016 6:20 pm

deshipu wrote: 2) I'm guessing that this is due to the watchdog timer kicking in, but to confirm you would need to check the reset code that is printed right after the board resets.
Thanks - when the board resets I get a load of gibberish ending with:

Code: Select all

삌l��lrl�l��|��rrnb��l���b�b쌜�����bllbl��ln�l`��ln�prl�l��|��rrnb����#5 ets_task(40100368, 3, 3fff62f0, 4)
If I manually invoke "print (machine.reset_cause())" I get the number 3

The "machine" docs for the ESP 8266 say:

Code: Select all

machine.reset_cause()
    Get the reset cause. See constants for the possible return values.
(Here: http://docs.micropython.org/en/latest/e ... -constants )

If I click "constants" it just reloads that page - no values appear...??

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: I2C issues

Post by deshipu » Tue Aug 02, 2016 8:12 pm

Yup, that's the watchdog:

Code: Select all

enum rst_reason {
	REASON_DEFAULT_RST		= 0,
	REASON_WDT_RST			= 1,
	REASON_EXCEPTION_RST	= 2,
	REASON_SOFT_WDT_RST   	= 3,
	REASON_SOFT_RESTART 	= 4,
	REASON_DEEP_SLEEP_AWAKE	= 5,
	REASON_EXT_SYS_RST      = 6
};

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: I2C issues

Post by warren » Tue Aug 02, 2016 9:47 pm

Thanks for that.

it does not crash at 200Hz. I would never want to go that slowly anyway - it takes ~ 5 seconds to get a reading from the sensor.

At least now I know a lower limit should I have to reduce clock frequency to cope with longer cable runs.

Post Reply