-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of Wire library. #3
Comments
Hi. As it works and I am not personally using either Wire or Arduino anyway (I rather use my own low level libs on STM32 with STDPeriphLib) I don't think I will have much time for optimization. |
koepel you have identified a couple of problems here well done. I'm going to make the changes and do a pull request. |
Whilst looking at the code:
I see the address in held in a 2 byte integer uint16_t Should the code not be
|
Could you talk about the "i2c address" or "register address" ? It would be easier if the library uses uint8_t for the "register address". Beside the problems with waiting after a |
Cool, Thanks @rharrison. I'll verify that it still works on a devkit and update. |
I have read your notes, but if you want to make the code better, there are some issues with the usage of the Wire library.
There is no need to wait after a Wire.requestFrom().
A Wire.requestFrom() should not be followed by a Wire.endTransmission().
Explanation: Common-mistakes, number 1 and 2.
See also my explanation of the functions.
When reading 32 bits, you do a Wire.request() for only 2 bytes.
Reading 16 bits could be like this:
Reading 32 bits could be like this:
The extra variable "data" is not needed. If there are four bytes available, the Wire.read() returns a signed integer with a value of 0 to 255. It is never -1 when only those four (available) bytes are read.
The text was updated successfully, but these errors were encountered: