-
-
Notifications
You must be signed in to change notification settings - Fork 129
Suggest adding I2C_writeAnything to Wire library #62
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
Comments
A note must be added that only ONE write operation can be used inside of the uint8_t twi_transmit(const uint8_t* data, uint8_t length){
// stuff
twi_txBufferLength = length;
// stuff
} Which is call from ..\library\Wire.cpp // must be called in:
// slave tx event callback
// or after beginTransmission(address)
size_t TwoWire::write(const uint8_t *data, size_t quantity)
{
if(transmitting){
// in master transmitter mode
for(size_t i = 0; i < quantity; ++i){
write(data[i]);
}
}else{
// in slave send mode
// reply to master
twi_transmit(data, quantity);
}
return quantity;
} The boolean Chuck. |
Quite right, which is why I changed |
I like your coding, I was just recommending that the Single write restriction should be prominently marked, or the underlying code fixed. It is a sore point for me. enum STAGE { twi_reStart,twi_start};
void onRequestEvent(STAGE stage){// just use a single byte Wire.write() to support unlimited lengths
switch(stage){
twi_start : ; // slave read bare, no register address set, Start from begining
twi_reStart : ; // slave read, continue from prior register address
}
} this coding will support Wire.begin(addr);
Wire.write(z);//register address
Wire.endTransmission(false); // set register address (z)
Wire.requestFrom(addr,x,false); // read from (z) for (x) bytes
Wire.requestFrom(addr,xmore,false); // read from (z+x) for (xmore) bytes
Wire.requestFrom(addr,xevenmore,true); // read from (z+x+xmore) for (xevenmore) bytes, and end transaction
//and now that a stop has been issued on the I2C buss
Wire.requestFrom(addr,x,false); // start reading from address (0), controlled by twi_start Case of onRequestevent()
Wire.requestFrom(addr,xmore,true); // read from (0+x) for (xmore) bytes. To me this added complexity makes it easier for a novice to effectively uses I2C slave mode to transfer more than one value. Chuck. |
Quite possibly however that goes outside the scope of this particular change request. :) |
I just discovered this. But this just further supports adding @nickgammon's template since it allows one to do:
to very easily send 6 |
It's also worth pointing out that there are 153 "code result" matches on GitHub of use of |
Some of them use the older version which does multiple writes. Oh well. :( My code for I2C_Anything is now on GitHub: |
I have the following small template library on my page about I2C ( http://www.gammon.com.au/i2c ):
It has been suggested to me that I request that you include this in the standard Wire library (Wire.h). This lets you more easily send things like floats or structs via I2C. For example:
Being a template function it won't add any bloat unless you actually use it.
Related request: https://github.com/arduino/Arduino/issues/3692
The text was updated successfully, but these errors were encountered: