Rise error when I2C is not prepared
Benik3 opened this issue · 6 comments
Hello.
I spend a lot of time now finding why I don't get any data from my sensor (BMP180) and then I found that I forgot to call init function with I2c.begin(). :D
Anyway it took me so long because all write and read functions returned 0 like OK.
Wouldnt be better to make, that if I2C is not initialized, the functions will end automatically with error?
P.S. nice to see that this library is still maintained. It's in my opinion much better then Wire library for Atmega, where I had some weird lock-ups and also work with this is much easier and clear in the code.
Hmm now I see that there is no room for new error :/
Any idea?
"maintained" is a bit of a stretch... I haven't looked in to this in a loong while but will of course merge any sane looking requests when I get around to eyeballing them.
Anyway, it would require a breaking change to switch the return values to int16_t and use negative numbers for errors like this.
Backwards compatible option would be to find a value in the reserved range that is not actually used by any of the supported MCU:s and use that for this purpose.
edit: and with some ifdefs we can even work around the problem that in the future (or even now) there might come a MCU that uses said code (but probably not another).
I also thought about switching error to int16, but it's not 100% ideal for backward compatibility.
Anyway when I look on error codes of TWS, I think that we can use safely code 0xFF.
The 5 bits of TWSR are similar to our first 7 codes so it's not possible to rise all these errors at once :)
Also the max error of TWS is 0xF8, not 0xFF (because first 3 bits are omitted).
Is this library compatible with the ATmega2560 chip?
Is this library compatible with the ATmega2560 chip?
off-topic for this issue, but maybe for the first TWI peripheral, the I2C::pullup method at least does not have a case for 2560. Just try it if it works it works, if not then you can add the support and make a PR, shouldn't be too hard.
Sorry about the off-topic post. I'm a bit of a noob in GitHub!
I'm not using the pull-up feature as I have external pull-ups on the bus so probably this won't affect me.