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
I2C issues
Re: I2C issues
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.
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.
Re: I2C issues
Thanks - when the board resets I get a load of gibberish ending with: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.
Code: Select all
삌l��lrl�l��|��rrnb��l���b�b쌜�����bllbl��ln�l`��ln�prl�l��|��rrnb����#5 ets_task(40100368, 3, 3fff62f0, 4)
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.
If I click "constants" it just reloads that page - no values appear...??
Re: I2C issues
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
};
Re: I2C issues
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.
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.