Wrapper for accessing built-in I2C (TWI) communication interfaces.
More...
|
file | i2c.h |
| Wrapper for accessing built-in I2C (TWI) communication interfaces.
|
|
|
class | Avr::I2c |
| A C++ wrapper for accessing the built-in I2C (TWI) communication interfaces. More...
|
|
Wrapper for accessing built-in I2C (TWI) communication interfaces.
Avr::I2c is a class implementing a C++ wrapper for accessing the built-in I2C (TWI) communication interfaces.
◆ Avr::I2c
A C++ wrapper for accessing the built-in I2C (TWI) communication interfaces.
Usage:
i2c.write(10);
i2c.endTransmission(false);
uint8_t bytesRead = i2c.requestFrom(0xAB, 3);
for (int i = 0; i < bytesRead; i++) {
uint8_t byte i2c.read();
}
- Note
- Avr::I2c is currently limited to I2C (TWI) master functionality.
-
The implementation is based on i2cmaster (http://homepage.hispeed.ch/peterfleury/avr-software.html).
Public Member Functions |
void | beginTransmission (uint8_t address) |
| Starts transmission to I2C (TWI) slave device with given address . More...
|
|
void | write (uint8_t byte) |
| Queues data for transmission to a slave device. More...
|
|
void | endTransmission (bool stop=true) |
| Ends transmission to slave device. More...
|
|
uint8_t | requestFrom (uint8_t address, uint8_t quantity, bool stop=true) |
| Request bytes from an I2C (TWI) slave device. More...
|
|
uint8_t | read () |
| Reads a byte that was received from a slave device after requesting with requestFrom(). More...
|
|
Static Public Member Functions |
static I2c & | instance () |
| Returns the I2c::I2c instance. More...
|
|
◆ instance()
static I2c& Avr::I2c::instance |
( |
| ) |
|
|
inlinestatic |
Returns the I2c::I2c instance.
- Returns
- The I2c::I2c instance.
◆ beginTransmission()
void Avr::I2c::beginTransmission |
( |
uint8_t |
address | ) |
|
|
inline |
Starts transmission to I2C (TWI) slave device with given address
.
Bytes are queued for transmission with write() and sent when calling endTransmission().
- Parameters
-
address | The address of the slave device. |
◆ write()
void Avr::I2c::write |
( |
uint8_t |
byte | ) |
|
|
inline |
◆ endTransmission()
void Avr::I2c::endTransmission |
( |
bool |
stop = true | ) |
|
|
inline |
Ends transmission to slave device.
Has to be called after beginTransmission() and write().
- Parameters
-
stop | Send stop message after transmission. If set to true a stop message is sent to the slave device and the bus is released. If set to false no stop message is sent so that the master can continue the transmission (repeated start). |
◆ requestFrom()
uint8_t Avr::I2c::requestFrom |
( |
uint8_t |
address, |
|
|
uint8_t |
quantity, |
|
|
bool |
stop = true |
|
) |
| |
|
inline |
Request bytes from an I2C (TWI) slave device.
The bytes can be retrieved using read().
- Parameters
-
address | The address of the slave device. |
quantity | The number of bytes to request from the slave device. |
stop | Send stop message after transmission. If set to true a stop message is sent to the slave device and the bus is released. If set to false no stop message is sent so that the master can continue the transmission (repeated start). |
- Returns
- The number of bytes received from the slave device.
◆ read()
uint8_t Avr::I2c::read |
( |
| ) |
|
|
inline |
Reads a byte that was received from a slave device after requesting with requestFrom().
- Returns
- The next available byte.