-
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
i2c read instructions fail for some devices #118
Comments
Taking a guess here, that this device behaves a little different compared to most other I2C devices, in the sense that it expects a read command byte, followed by a RESTART. Most devices can do a read after a STOP sequence, but it looks like the MPR121 does that a little different. |
Thanks for your thoughts. You are correct, all the other devices in my videos worked fine with a STOP between the write and the read. The other module I was trying was a very simple ambient light sensor. Again, worked fine on Arduino, but not on Agon. After many hours trying, I put it down to the same issue. |
If we can somehow confirm this to be the case, preferably by analyzing the behavior over the line, a potential solution could be to create another API call next to the (currently very simple) write/read calls, combined with a I2C state-machine change, where the call flags a RESTART start to be applied during it's invocation and the state-machine obeys this flag during the state-changes |
Given that every device I have used (so far) needs a write register before reading, to say what register you want to start reading from, it makes sense to have an api call which does the two things in one. eg: Parameters: A: Register to start reading from However, most devices have been ok with a write, then a separate read. Whether they would work ok with a joint command, I don't know. |
I have managed to communicate with many i2c devices, see my videos:
https://www.youtube.com/watch?v=WQATfp2rR_Y&list=PL-WZxPxo1iaBRPJj_mS7feUh_gO6pn-Qe
However, I have failed to get a few devices to communicate with Agon. One example is the MPR121 touch sensor.
I get no errors from the MOS commands, the device is seen on the i2c bus, but no data (or perhaps just 0) is returned when data is requested. MOS fills the required buffer with 0s instead of the expected data
Background
For most simple devices, you write a command, followed by a read request.
The command is normally just the device's register you want to write to or read from.
So, you might write the byte 12 first, then when you read, you can read 1 or more bytes starting from register 12.
The bytes read end up in the buffer pointed to by HL.
For all of the devices in my videos, this works perfectly.
However, a few devices have not sent back the required data.
Problem
I suspect that the problem is that some devices expect the initial write to be followed immediately by the read instruction, without a break.
If we send a MOS write, followed by a MOS read, the 'STOP' code is included in between the two. Therefore, the command is not complected by the device.
In MOS we have just two instructions, write, and read. We do not have a 'read from register x' which could combine the two.
See p. 25 of the touch capacitor notes.
NOTE: these troublesome devices all worked fine with an Arduino, so I know the hardware is ok.
MPR121-cap sensor.pdf
The text was updated successfully, but these errors were encountered: