How can I tell if or when the wire.read() (or is it wire.endtransmission()) statement has completed and all the data has been sent?
I think, not sure, still debugging, I'm asking for data before the transmit has completed.
How can I tell if or when the wire.read() (or is it wire.endtransmission()) statement has completed and all the data has been sent?
I think, not sure, still debugging, I'm asking for data before the transmit has completed.
In Arduino Platform, we use the following statements to send data byte 0x23 (for example) from Master UNO-1 to a Slave UNO-2 with I2C address 0x37 (for example).
Wire.beginTransmission(0x37);
Wire.write(0x23);
Wire.endTransmission();
Let us try to understand the meaning of 'transmit complete' of your post's title keeping in mind that the following events (as I understand) occur in response to the above-mentioned three high-level codes:
1. The Master brings START condition on the I2C Bus.
2. The Master asserts address (0x37) of the Slave on the Bus and waits for the ACK to be generated on the Bus.
3. After seeing ACK signal, the Master puts the data byte (0x23) on the I2C Bus and waits for the ACK signal to be generated on the Bus.
4. The Master detects the ACK signal and immediately brings STOP condition on the I2C Bus in order to make the Bus free so that other competing (if any) Master can acquire the Bus and use it.
5. The data transmission is complete.
That sums it up. Is the wire library blocking or is the data transmission asynchronous? I assume asynchronous, but ask to verify.
When is that transmit of the data complete? After the endTransmission() instruction completes?
adwsystems:
When is that transmit of the data complete? After the endTransmission() instruction completes?
In fact, the high level line Wire.beginTransmission(0x37); is not executed immediately to make a roll-call of the Slave by asserting the slave address on the I2C Bus. As I have understood (reading Arduino Reference Documents), the data byes 37 and 23 are queued in a buffer. The line Wire.endTransmission() begins in 'the execution chain' that I have laid down in Post#1.
Things could be explained by putting Assembly/Register level codes; but, (I think) this is not the appropriate time.
GolamMostafa:
In fact, the high level line Wire.beginTransmission(0x37); is not executed immediately to make a roll-call of the Slave by asserting the slave address on the I2C Bus. As I have understood (reading Arduino Reference Documents), the data byes 37 and 23 are queued in a buffer. The line Wire.endTransmission() begins in 'the execution chain' that I have laid down in Post#1.
Therein lies the question, is there a way to tell when 'the execution chain' has completed and all the data has been sent?
Yes!
At the end of successful bus transactions for the queued data bytes, the mechanism produces a 0x00 valued so called Status Word.. Other values for the status word indicate error conditions. For example:
Wire.beginTransmission(0x37);
Wire.write(0x23);
byte busStatus = Wire.endTransmission();
if (busStatus != 0x00)
{
//error and stay here or take corrective action
while(1);
}
I'm going to look, but in case you have the answer at hand. Is there a busy status? That way I could wait on busy for good or error.
I do not really know if there is any concept of busy flag in the I2C Protocol. What I have known is that the mechanism produces different kinds of values for different kinds of bus transactions. For example:
Status Word 0x08 is generated when the slave accepts its address.
Status word 0x28 is generated when the slave accepts the data byte.
The Arduino produces Status Word 0x00 when the above two status words are generated.
Therein lies the question, is there a way to tell when 'the execution chain' has completed and all the data has been sent?
That way I could wait on busy for good or error.
This is starting to sound like an XY problem.
What problem are you seeing that would require you to "wait".
cattledog:
This is starting to sound like an XY problem.What problem are you seeing that would require you to "wait".
adwsystems:
How can I tell if or when the wire.read() (or is it wire.endtransmission()) statement has completed and all the data has been sent?I think, not sure...still debugging, I'm asking for data before the transmit has completed.
More like a possible problem of the cart before the horse
hi,
Is it possible to communicate back and forth between uno and nano via i2c.
so sending a byte from the master and amediatly receive data back from the slave?
I tried multiple ways in coding. the best way I had it send me 0 on both arduino's.
maybe if both arduino's are masters??
If someone have some example for master-slave or master-master??
thanks.
alex_lan:
hi,
Is it possible to communicate back and forth between uno and nano via i2c.
so sending a byte from the master and amediatly receive data back from the slave?
I tried multiple ways in coding. the best way I had it send me 0 on both arduino's.
maybe if both arduino's are masters??If someone have some example for master-slave or master-master??
thanks.
(A) What does this have to do with transmit complete?
(B) It's rude to hijack or jump on another thread with a new discussion
(C) Did you read up on the wire library in the reference section of this website? Hint: Wire Library Reference Hint, hint: look at the examples.
alex_lan:
If someone have some example for master-slave or master-master??
adwsystems:
(B) It's rude to hijack or jump on another thread with a new discussion
Please, place a post under NEW TOPIC; surely, we will receive a pleasant Step-by-Step Tutorial.
adwsystems:
How can I tell if or when the wire.read() (or is it wire.endtransmission()) statement has completed and all the data has been sent?
endTransmission() is a blocking function that returns success or a failure code.
Details here Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino.