Hello, I'm using arduino for prototyping to another microcontroller, and my question revolves around how Wire is functioning with the I2C protocol.
I read this tutorial to get a basic understanding of the I2C command sequence:
Here it states that if for example I would read a package, I should do the following:
Send Start bit
Send 7 bit address
send read flag
Recieve acknowledge bit
Recieve data byte
Send acknowledge bit
Recieve data byte
Send acknowledge bit
... until im done, then
send NACK instead of ACK bit, followed by a Stop bit.
The image that illustrates this:
Now, I have some arduino code (which works fine by the way), that goes like this:
Setup portion
// in the setup
Wire.beginTransmission(address);
Wire.write(moderegadr);
Wire.write(instruct);
Wire.endTransmission();
delay(10);
Wire.beginTransmission(address);
Wire.write(regb);
Wire.write(regbdata);
Wire.endTransmission();
delay(10);
Loop portion
// in the loop
Wire.beginTransmission(address);
Wire.write(dataregadr1);
Wire.endTransmission();
Wire.beginTransmission(address);
Wire.requestFrom(address,6);
delay(10);
if(6<= Wire.available()) // if two bytes were received
{
for(i=0;i<6;i++)
{
readingdata[i]=Wire.read();
}
}
My question is: How do i translate this to "raw" I2C command sequence? My particular interest is in the last code snippet:
Is it correctly understood that the last part works like this?
Wire.beginTransmission(address) =
- Send Start bit
- Send Device address
- Send write flag
Wire.write(dataregadr1) = - Send register byte
Wire.endTransmission() = - Send stop bit
Wire.beginTransmission(address) =
- Send Start bit
- Send Device address
- Send read flag
Wire.requestFrom(address,6) =
this part i dont understand, does it merely listen and acknowledge 6 packets, and put them in a buffer?
At any rate, I need the entire rundown of the last code snippet, in step-by-step I2C command sequence form. If anyone can help me with this, you would be doing me a great favor!
Best regards
Jesper