![]() ![]() Wire.endTransmission() // "Hang up the line" so others can use it (can have multiple slaves & masters connected) Wire.requestFrom(address,1) // Tell slave we need to read 1byte from the current registerīyte slaveByte2 = Wire.read() // read that byte into 'slaveByte2' variable Wire.write(0x32) // The command byte, sets pointer to register with address of 0x32 Finally, we end the transmission.įor example : Wire.beginTransmission(address) // Get the slave's attention, tell it we're sending a command byte Then, we can request the number of bytes we want, and use read() to assign those incoming values to variables. If you want to read from a specific register, you must first move the pointer to that address with a write() command. Another Wire.write(v1) was sent, the slave device would've automatically incremented the pointer to the next address (r+1) and written 'v1' into that register. This tells the slave that you're done giving it instructions for now. Now that the pointer is 'pointing' at the specific register you wanted, this command will replace the byte stored in that register with the value 'v'. You can think of the pointer as a read/write head. This first byte written here 'r' moves the register pointer to the register with address 'r'. This begins transmission to slave device, where 'address' is the slave device's address. To understand that, you should first understand how the write command operates. Uint16_t touched = ((MSB << 8) | LSB) //16bits that make up the touch states And, it's used in that same example code, here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |