Jump to content
I2Cdevlib Forums
Sign in to follow this  
bechtold

Arduino Wire endTransmission readBytes not working

Recommended Posts

Hi,

in readBytes() in I2Cdev.cpp the register to read from is written and then before reading the actual value a new transmission is started.

This is not working for the MPR121.

 

Currently it does this:

Wire.beginTransmission(devAddr);
Wire.write(regAddr);
Wire.endTransmission();
Wire.beginTransmission(devAddr);
Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH));

Here is explained that the endTransmission is needed to actually send the regAddr.

But this is not working for the MPR121 because I guess it forgets the register you want to read from when the transmission is closed.

So on the request it always answers with the content of register 0x00.

So obviously all the mpr functions to read from special registers don't work. For example the testConnection() is not working.

 

It must be like this:

Wire.beginTransmission(devAddr);
Wire.write(regAddr);
Wire.endTransmission(false);
Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH));

Then the regAddr is sent but the connection is not closed. This way everything works fine.

 

It took me quite a while to figure this out. And it also made me create my own library, but I hate competing libraries :-)

So I would like to contribute this to the devlib, but I'm not experienced how to do this. Should I sent a pullrequest on github? And how could I make sure not to break the behavior with other i2c devices. I don't think it would break, but how can I be sure of this?

Since I will heavily use the mpr I will be happy to contribute some more mpr related stuff like functions and examples, I guess this could be done with pullrequests as well.

 

edit: The same problem seems to exist with the FastWire implementation.

 

Cheers

bechtold

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×