Hardware Reference
In-Depth Information
Wire.endTransmission() specii es the end of the message, and sends it. This
function takes an optional parameter, the bus release parameter. If TRUE, a stop
message is sent, and the I 2 C bus is freed. If FALSE, a restart message is sent; the
I 2 C bus is not released, and the master can continue issuing orders. By default,
the bus is always freed.
Wire.endTransmission(); // send the message
Wire.endTransmission(stop); // send the message and close the connection
Wire.endTransmission() returns a status byte. Table 8-2 shows a list of
return values.
Table 8-2: Transmit Error Codes
RETURN CODE
RESULT
0
Success
1
Data too long to fi t in the transmit buff er
2
Receives a NACK on transmit of address
3
Receives a NACK on transmit of data
4
Unknown error
Requesting Information
When requesting information, the master performs a read operation, specify-
ing the destination and the number of bytes the slave should send. The entire
message is created using a single function: Wire.requestFrom(). This function
takes two parameters and an optional third. First, the destination has to be
specii ed—which slave is to receive this message and send data? Second, how
much data is the master requesting? This is specii ed as the number of bytes.
Finally, an optional parameter specii es if the bus should be released.
Wire.requestFrom(address, quantity);
Wire.requestFrom(address, quantity, stop);
Wire.requestFrom() creates a message and immediately sends it on the I 2 C
bus. Now that the request has been sent, the master can wait for a message
using Wire.read().
data = Wire.read(); // store the information in a variable
Wire.read() returns a single byte from the input buffer. For multibyte mes-
sages, this function must be called for each byte. Requesting a certain amount
 
Search WWH ::




Custom Search