RUI3 (RAK Unified Interface 3) - RAK4631

Functions

void begin (void)
 
void end (void)
 
void setClock (uint32_t freq)
 
void beginTransmission (uint8_t address)
 
uint32_t endTransmission (uint8_t sendStop=true)
 
uint8_t requestFrom (uint8_t address, uint8_t quantity, uint8_t sendStop)
 
virtual size_t write (const uint8_t *data, size_t size)
 
virtual int available (void)
 
virtual int read (void)
 

Detailed Description

Function Documentation

◆ begin()

void begin ( void  )
Description
Initiate the Wire library and join the I2C bus as a master
Syntax
Wire.begin();
Returns
void
Example
void setup() {
  Wire.begin();
}

void loop() {
}

◆ end()

void end ( void  )
Description
End the I2C bus
Syntax
Wire.end();
Returns
void
Example
void setup() {
  Wire.begin();
}

void loop() {
  Wire.end();
}

◆ setClock()

void setClock ( uint32_t  freq)
Description
This function modifies the clock frequency for I2C communication. I2C slave devices have no minimum working clock frequency, however 100KHz is usually the baseline
Syntax
Wire.setClock(freq);
Parameters
freqthe value (in Hertz) of desired communication clock. Accepted values are 100000 (standard mode) and 400000 (fast mode)
Returns
void
Example
  void setup() {
    Wire.begin();
Wire.setClock(400000);
  }

  void loop() {
  }

◆ beginTransmission()

void beginTransmission ( uint8_t  address)
Description
Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the write() function and transmit them by calling endTransmission()
Syntax
Wire.beginTransmission(address);
Parameters
addressthe 7-bit address of the device to transmit to
Returns
void
Example
void setup() {
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0b1110000);
  Wire.write(0x35);
  Wire.endTransmission();
}

◆ endTransmission()

uint32_t endTransmission ( uint8_t  sendStop = true)
Description
Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write()
Syntax
Wire.endTransmission();
Wire.endTransmission(sendStop);
Parameters
sendStop(optional)true will send a stop message, releasing the bus after transmission.
false will send a restart, keeping the connection active(default = false)
Return values
0success
1fail
Example
void setup() {
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0b1110000);
  Wire.write(0x35);
  Wire.endTransmission();
}

◆ requestFrom()

uint8_t requestFrom ( uint8_t  address,
uint8_t  quantity,
uint8_t  sendStop 
)
Description
Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available() and read() functions
Syntax
Wire.requestFrom(address, quantity);
Wire.requestFrom(address, quantity, sensStop);
Parameters
addressthe 7-bit address of the device to request bytes from
quantitythe number of bytes to request
sendStoptrue will send a stop message after the request, releasing the bus.
false will continually send a restart after the request, keeping the connection active(default = false)
Returns
the number of bytes returned from the slave device(Type: byte)
Example
void setup() {
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0b1110000);
  Wire.write(0x35);
  Wire.endTransmission();

  Wire.requestFrom(0b1110000, 6);

  while(Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }
  delay(5000);

}

◆ write()

virtual size_t write ( const uint8_t *  data,
size_t  size 
)
virtual
Description
Writes data to a slave device
Note
in-between calls to beginTransmission() and endTransmission()
Syntax
Wire.write(value);
Wire.write(data, size);
Parameters
valuea value to send as a single byte
dataan array of data to send as bytes
sizethe number of bytes to transmit
Returns
write() will return the number of bytes written, though reading that number is optional(Type: byte)
Example
  void setup() {
    Wire.begin();
  }

  void loop() {
    Wire.beginTransmission(0b1110000);
    Wire.write(0x35);
    Wire.endTransmission();

    Wire.requestFrom(0b1110000, 6);

    while(Wire.available()) {
      char c = Wire.read();   
      Serial.print(c);
}
    delay(5000);

  }

Reimplemented from Print.

◆ available()

virtual int available ( void  )
virtual
Description
Returns the number of bytes available for retrieval with read()
Syntax
Wire.availavle()
Returns
The number of bytes available for reading
Example
void setup() {
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0b1110000);
  Wire.write(0x35);
  Wire.endTransmission();

  Wire.requestFrom(0b1110000, 6);

  while(Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }
  delay(5000);

}

Implements Stream.

◆ read()

virtual int read ( void  )
virtual
Description
Reads a byte that was transmitted from a slave device to a master
Syntax
Wire.read()
Note
read() inherits from the Stream utility class
Returns
The next byte received
Example
void setup() {
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0b1110000);
  Wire.write(0x35);
  Wire.endTransmission();

  Wire.requestFrom(0b1110000, 6);

  while(Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }
  delay(5000);

}

Implements Stream.