This class implements hardware I2C protocol used by NXShield on an Arduino.
More...
#include <BaseI2CDevice.h>
|
| BaseI2CDevice (uint8_t i2c_address) |
|
void | initProtocol () |
|
uint8_t * | readRegisters (uint8_t start_register, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0, bool clear_buffer=false) |
|
uint8_t | readByte (uint8_t location) |
|
int16_t | readInteger (uint8_t location) |
|
uint32_t | readLong (uint8_t location) |
|
char * | readString (uint8_t location, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0) |
|
bool | writeRegisters (uint8_t start_register, uint8_t bytes_to_write, uint8_t *buffer=0) |
|
bool | writeByte (uint8_t location, uint8_t data) |
|
bool | writeInteger (uint8_t location, uint16_t data) |
|
bool | writeLong (uint8_t location, uint32_t data) |
|
bool | checkAddress () |
|
bool | setAddress (uint8_t i2c_address) |
|
uint8_t | getAddress () |
|
uint8_t | getWriteErrorCode () |
|
char * | getFirmwareVersion () |
|
char * | getVendorID () |
|
char * | getDeviceID () |
|
char * | getFeatureSet () |
|
|
static uint8_t * | _buffer = 0 |
|
static bool | b_initialized = false |
|
This class implements hardware I2C protocol used by NXShield on an Arduino.
BaseI2CDevice::BaseI2CDevice |
( |
uint8_t |
i2c_address | ) |
|
constructor for the BaseI2C Device class; requires the i2c address of the device
bool BaseI2CDevice::checkAddress |
( |
| ) |
|
validate if a device is attached to the i2c bus with the specified i2c address
checkAddress() this function checks to see if there is any device at its specified address
uint8_t BaseI2CDevice::getAddress |
( |
| ) |
|
char * BaseI2CDevice::getDeviceID |
( |
| ) |
|
get the name of the device
char * BaseI2CDevice::getFeatureSet |
( |
| ) |
|
returns the features on the device, not supported by all devices
returns a string indicating the features on this device some devices may return null.
char * BaseI2CDevice::getFirmwareVersion |
( |
| ) |
|
return the firware version id of the device
char * BaseI2CDevice::getVendorID |
( |
| ) |
|
return the name of the vendor for the device
uint8_t BaseI2CDevice::getWriteErrorCode |
( |
| ) |
|
returns the error code for an error with the Wire.h library on the i2c bus
void BaseI2CDevice::initProtocol |
( |
| ) |
|
initialize hardware i2c using the Wire.h library
uint8_t BaseI2CDevice::readByte |
( |
uint8_t |
location | ) |
|
Read a byte from specified location
- Parameters
-
location | address to read at |
- Returns
- a byte value read from the location
int16_t BaseI2CDevice::readInteger |
( |
uint8_t |
location | ) |
|
Read an integer from specified location. Integer comprises of 2 bytes.
- Parameters
-
location | address to read at |
- Returns
- an integer value read from the location
uint32_t BaseI2CDevice::readLong |
( |
uint8_t |
location | ) |
|
Read a long from specified location. Long comprises of 4 bytes.
- Parameters
-
location | address to read at |
- Returns
- a long value read from the location
uint8_t * BaseI2CDevice::readRegisters |
( |
uint8_t |
start_register, |
|
|
uint8_t |
bytes_to_read, |
|
|
uint8_t * |
buffer = 0 , |
|
|
uint8_t |
buffer_length = 0 , |
|
|
bool |
clear_buffer = false |
|
) |
| |
read specified number of bytes from the start register.
- Parameters
-
start_register | location to start reading from |
bytes_to_read | Number of bytes to read (max 16 for LEGO compatible devices) |
buffer | (optional) buffer to read the data into |
buffer_length | (optional) length of the buffer if it was provided |
clear_buffer | (optional) to clear the buffer or not before using. |
- Returns
- pointer to data buffer that was read. If buffer was not provided, this is internal pointer.
char * BaseI2CDevice::readString |
( |
uint8_t |
location, |
|
|
uint8_t |
bytes_to_read, |
|
|
uint8_t * |
buffer = 0 , |
|
|
uint8_t |
buffer_length = 0 |
|
) |
| |
Read a string from specified location
- Parameters
-
location | address to read at |
bytes_to_read | number of bytes to read |
buffer | optional, a buffer to read the data into. |
buffer_length | optional, length of the buffer supplied. |
- Returns
- a char array read from the location
bool BaseI2CDevice::setAddress |
( |
uint8_t |
i2c_address | ) |
|
set the i2c address for this device
- Parameters
-
i2c_address | new device address. |
setAddress(address) this function set's the i2c address for this instance to given address Note that, generally i2c address of a physical device does not change. Use this function if there are multiple devices on your bus and you want to conserve processor memory from instantiating another class instance.
void BaseI2CDevice::setWriteErrorCode |
( |
uint8_t |
code | ) |
|
|
protected |
write the internal error code
bool BaseI2CDevice::writeByte |
( |
uint8_t |
location, |
|
|
uint8_t |
data |
|
) |
| |
write one byte to the specified register location
- Parameters
-
location | location to write to. |
data | the data to write. |
bool BaseI2CDevice::writeInteger |
( |
uint8_t |
location, |
|
|
uint16_t |
data |
|
) |
| |
write two bytes (int) to the specified register location
- Parameters
-
location | location to write to. |
data | the data to write. |
bool BaseI2CDevice::writeLong |
( |
uint8_t |
location, |
|
|
uint32_t |
data |
|
) |
| |
write four bytes (long) to the specified register location
- Parameters
-
location | location to write to. |
data | the data to write. |
bool BaseI2CDevice::writeRegisters |
( |
uint8_t |
start_register, |
|
|
uint8_t |
bytes_to_write, |
|
|
uint8_t * |
buffer = 0 |
|
) |
| |
write data bytes to the i2c device starting from the start register
- Parameters
-
start_register | location to write at. |
bytes_to_write | Number of bytes to write |
buffer | (optional) data buffer, if not supplied, data from internal buffer is used. |
uint8_t * BaseI2CDevice::_buffer = 0 |
|
static |
Buffer used for data that is returned from I2C commands
The documentation for this class was generated from the following files: