Wire.transfer()

Method transfer() replaces these 3 functions call beginTransmission(), write() и endTransmission(). This approach helps to reduce your code in some cases.

transfer(address, *buffer);
transfer(address, *buffer, count);
transfer(address, *buffer, sendStop);
transfer(address, *buffer, count, sendStop);
address: the 7-bit address of the device to transmit to slave.
buffer: pointer to data to be transmit
count: number of transmitting data in bytes. sendStop: true will send a stop message, releasing the bus after transmission. false will send a restart, keeping the connection active.
byte, which indicates the status of the transmission:
  • 0:success
  • 1:data too long to fit in transmit buffer
  • 2:received NACK on transmit of address
  • 3:received NACK on transmit of data
  • 4:other error
  • 5:timeout
  • There is example from beginTransmission() and its equivalent using transfer method.
    #include <Wire.h>
    
    void setup() {
      Wire.begin();
    }
    
    void loop() {
      Wire.beginTransmission(8);
      Wire.write("12345678");
      Wire.endTransmission();
      delay(500);
    }
    
    #include <Wire.h>
    
    void setup() {
      Wire.begin();
    }
    
    void loop() {
      Wire.transfer(8, "12345678");
      delay(500);
    }