I2C-Library for various sensors

Embed: (wiki syntax)

« Back to documentation index

TWI_Master Class Reference

TWI_Master Class Reference

TWI_Master is used for interacting with different libraries of I2C sensors, which I wrote. More...

#include <twi_master.h>

Public Member Functions

 TWI_Master (PinName sda, PinName scl, uint32_t frequency=400000)
 Construct a new TWI_Master object.
void i2c_write (uint8_t i2c_address, uint8_t slave_address, const uint8_t data)
 Writes data into specified address (changes every bit)
void i2c_writeBits (uint8_t i2c_address, uint8_t slave_address, const uint8_t data, uint8_t mask)
 Writes bits by masking the necessary bits.
uint8_t i2c_readBits (uint8_t i2c_address, uint8_t slave_address, uint8_t mask)
 Reads one register from the specified address and masks it with the given mask.
void i2c_readSeries (uint8_t i2c_address, uint8_t slave_address, uint8_t *data, uint8_t length)
 Reads multiple registers.
uint8_t i2c_read (uint8_t i2c_address, uint8_t slave_address)
 Reads one register from the specified register-address.

Detailed Description

TWI_Master is used for interacting with different libraries of I2C sensors, which I wrote.

This library has been inspired by the Adafruit Sensor-Library and the I2Cdevlib by jrowberg.

It is not an I2C driver, since the existing I2C functions are used and new things, such as masking and individual bit changes, are built in around them.

Definition at line 21 of file twi_master.h.


Constructor & Destructor Documentation

TWI_Master ( PinName  sda,
PinName  scl,
uint32_t  frequency = 400000 
)

Construct a new TWI_Master object.

The given parameters should be all the necessary things to start interacting with the other libraries.

Parameters:
sdaSDA-Pin
sclSCL-Pin
frequencyI2C-frequency (default: 400kHz)

Definition at line 19 of file twi_master.cpp.


Member Function Documentation

uint8_t i2c_read ( uint8_t  i2c_address,
uint8_t  slave_address 
)

Reads one register from the specified register-address.

Parameters:
slave_addressthe desired register-address for reading
Returns:
uint8_t returns read data

Definition at line 85 of file twi_master.cpp.

uint8_t i2c_readBits ( uint8_t  i2c_address,
uint8_t  slave_address,
uint8_t  mask 
)

Reads one register from the specified address and masks it with the given mask.

Parameters:
slave_addressthe desired register-address for reading
maskthe mask for the desired bits
Returns:
uint8_t returns the masked data

Definition at line 102 of file twi_master.cpp.

void i2c_readSeries ( uint8_t  i2c_address,
uint8_t  slave_address,
uint8_t *  data,
uint8_t  length 
)

Reads multiple registers.

Parameters:
slave_addressthe start register-address
dataarray, which the functions saves the data to
lengththe length of the read-sequence

Definition at line 68 of file twi_master.cpp.

void i2c_write ( uint8_t  i2c_address,
uint8_t  slave_address,
const uint8_t  data 
)

Writes data into specified address (changes every bit)

Parameters:
slave_addressregister-address which will be written to
data8-bit value that overwrites the register-value

Definition at line 31 of file twi_master.cpp.

void i2c_writeBits ( uint8_t  i2c_address,
uint8_t  slave_address,
const uint8_t  data,
uint8_t  mask 
)

Writes bits by masking the necessary bits.

The data variables will be normally masked with the mask (data & mask), the register will be masked by the inverted mask (register_value & ~mask). What will be written to the register will be new_register_data = (data | register_value) .

Parameters:
slave_addressregister-address that will be edited
data8-bit value that edit the editable bits (which are determined by the mask)
maskBits that want to be changed, all the other bits will be saved.

Definition at line 46 of file twi_master.cpp.