-
• #2
The default bitrate is actually 50000 (at least on proper Espruino boards)... Which one are you using?
You can check
i2c._options.bitrate
- however if the use didn't initialise I2C or didn't specify a bitrate then it won't be there, so you'd have to do something like:var br = (i2c._options && i2c._options.bitrate) || 50000; if (br < 10000 || br > 100000) { ....
This could be built into Espruino itself as a function - but then you'd have to wait for the next version before your code would work.
-
• #3
The default bitrate is actually 50000 (at least on proper Espruino boards)... Which one are you using?
Good to know. I thought the default bitrate were higher. I'm using a classic and different pico boards. So it is unnecessary in my case to check the bitrate if nobody increase it explicitly. Ok, thanks.
i2c._options.bitrate
looks more like an internal API. I would prefer a documented getBitrate() method but that's only my viewpoint. -
• #4
There is an issue open for this (not specifically on I2C): https://github.com/espruino/Espruino/issues/119
I've just linked this forum post. I'll have a think about a nice way of doing it - the thing really is finding a way of doing it that uses up very little memory. Some of the boards without much flash have a lot of trouble getting Espruino in at the moment (literally ~300 bytes free or so) - normally I'd just not include non-vital functions on those boards - but with something like this, modules that used the function would just refuse to work of the function didn't exist.
Currently I'm developing an Espruino module for an I2C sensor which is not able to run with the default bitrate of 400 kHz.
I want to ensure that nobody fall into the same trap to forget the bitrate parameter in I2C.setup(). I know: "Read the datasheet carefully ...". But better would be an automatic check with a human readable hint about the wrong usage.
Is it possible to get the bitrate of an I2C instance to check the correct usage in the connect()-methods or directly in the constructor function of i2c-sensors, e.g.