TWI as Slave Write Issue
i'm not sure main intention of using write during twi request in onreuqest function is, if several writes, data of last write send master.
example:
if in source code of wire/twi library find write calls twi_transmit(data, size).
a close view @ function shows problem:
-> function overwrites every call transmit buffer (standard length 32bytes).
maybe better change function append data buffer submitted write.
i think there shouldn't errors, because transmitindex , transmitlen reseted before event call.
i change function following , seems work fine:
did missed something?
what think?
example:
code: [select]
char buf[4];
...
void requestevent()
{
wire.write(0xfe); // skipped
wire.write(0x32); // skipped
wire.write(buf, sizeof(buf)); // send
}
if in source code of wire/twi library find write calls twi_transmit(data, size).
a close view @ function shows problem:
code: [select]
uint8_t twi_transmit(const uint8_t* data, uint8_t length)
{
uint8_t i;
// ensure data fit buffer
if(twi_buffer_length < length){
return 1;
}
// ensure slave transmitter
if(twi_stx != twi_state){
return 2;
}
// set length , copy data tx buffer
twi_txbufferlength = length;
for(i = 0; < length; ++i){
twi_txbuffer[i] = data[i];
}
return 0;
}
-> function overwrites every call transmit buffer (standard length 32bytes).
maybe better change function append data buffer submitted write.
i think there shouldn't errors, because transmitindex , transmitlen reseted before event call.
i change function following , seems work fine:
code: [select]
uint8_t twi_transmit(const uint8_t* data, uint8_t length)
{
uint8_t i, t;
// ensure data fit buffer
if(twi_buffer_length < twi_txbufferlength+length){
return 1;
}
// ensure slave transmitter
if(twi_stx != twi_state){
return 2;
}
// set length , copy data tx buffer
t = twi_txbufferlength;
twi_txbufferlength += length;
for(i = 0; < length; ++i){
twi_txbuffer[t+i] = data[i];
}
return 0;
}
did missed something?
what think?
in onrequest handler, 1 wire.write may used.
i don't know if written somewhere, fact.
you have build array data in onrequest handler.
it great if changes okay.
the wire.write can used anywhere in situation. don't know if can changed while maintaining compatibility.
i have problem master-receiver myself, http://forum.arduino.cc/index.php?topic=172296.0
i don't know if written somewhere, fact.
you have build array data in onrequest handler.
it great if changes okay.
the wire.write can used anywhere in situation. don't know if can changed while maintaining compatibility.
i have problem master-receiver myself, http://forum.arduino.cc/index.php?topic=172296.0
Arduino Forum > Development > Suggestions for the Arduino Project > TWI as Slave Write Issue
arduino
Comments
Post a Comment