uStepper
|
Prototype of class for accessing the TWI (I2C) interface of the AVR (master mode only). More...
#include <uStepper.h>
Public Member Functions | |
i2cMaster (void) | |
Constructor. More... | |
bool | readByte (bool ack, uint8_t *data) |
Reads a byte from the I2C bus. More... | |
bool | read (uint8_t slaveAddr, uint8_t regAddr, uint8_t numOfBytes, uint8_t *data) |
sets up I2C connection to device, reads a number of data bytes and closes the connection More... | |
bool | start (uint8_t addr, bool RW) |
sets up connection between arduino and I2C device. More... | |
bool | restart (uint8_t addr, bool RW) |
Restarts connection between arduino and I2C device. More... | |
bool | writeByte (uint8_t data) |
Writes a byte to a device on the I2C bus. More... | |
bool | write (uint8_t slaveAddr, uint8_t regAddr, uint8_t numOfBytes, uint8_t *data) |
sets up I2C connection to device, writes a number of data bytes and closes the connection More... | |
bool | stop (void) |
Closes the I2C connection. More... | |
uint8_t | getStatus (void) |
Get current I2C status. More... | |
void | begin (void) |
Setup TWI (I2C) interface. More... | |
Private Member Functions | |
bool | cmd (uint8_t cmd) |
Sends commands over the I2C bus. More... | |
Private Attributes | |
uint8_t | status |
Prototype of class for accessing the TWI (I2C) interface of the AVR (master mode only).
This class enables the use of the hardware TWI (I2C) interface in the AVR (master mode only), which is used for interfacing with the encoder. This class is needed in this library, as arduino's build in "wire" library uses interrupts to access the TWI interface, and since the uStepper library needs to use the TWI interface within a timer interrupt, this library cannot be used. As a result of this, the "wire" library, cannot be used in sketches using the uStepper library, as this will screw with the setups, and make the sketch hang in the timer interrupt routine. Instead, if the programmer of the sketch needs to interface with external I2C devices, this class should be used. This library contains a predefined object called "I2C", which should be used for these purposes.
The functions "read()" and "write()", should be the only functions needed by most users of this library !
Definition at line 1210 of file uStepper.h.
i2cMaster::i2cMaster | ( | void | ) |
Constructor.
This is the constructor, used to instantiate an I2C object. Under normal circumstances, this should not be needed by the programmer of the arduino sketch, since this library already has a global object instantiation of this class, called "I2C".
Definition at line 2113 of file uStepper.cpp.
void i2cMaster::begin | ( | void | ) |
Setup TWI (I2C) interface.
This function sets up the TWI interface, and is automatically called in the instantiation of the uStepper encoder object.
Definition at line 2105 of file uStepper.cpp.
|
private |
Sends commands over the I2C bus.
This function is used to send different commands over the I2C bus.
cmd | - Command to be send over the I2C bus. |
Definition at line 1922 of file uStepper.cpp.
uint8_t i2cMaster::getStatus | ( | void | ) |
Get current I2C status.
This function returns the status of the I2C bus.
Definition at line 2100 of file uStepper.cpp.
bool i2cMaster::read | ( | uint8_t | slaveAddr, |
uint8_t | regAddr, | ||
uint8_t | numOfBytes, | ||
uint8_t * | data | ||
) |
sets up I2C connection to device, reads a number of data bytes and closes the connection
This function is used to perform a read transaction between the arduino and an I2C device. This function will perform everything from setting up the connection, reading the desired number of bytes and tear down the connection.
slaveAddr | - 7 bit address of the device to read from |
regAddr | - 8 bit address of the register to read from |
numOfBytes | - Number of bytes to read from the device |
data | - Address of the array/string to store the bytes read. Make sure enough space are allocated before calling this function ! |
Definition at line 1943 of file uStepper.cpp.
bool i2cMaster::readByte | ( | bool | ack, |
uint8_t * | data | ||
) |
Reads a byte from the I2C bus.
This function requests a byte from the device addressed during the I2C transaction setup. The parameter "ack" is used to determine whether the device should keep sending data or not after the reception of the currently requested data byte.
ack | - should be set to "ACK" if more bytes is wanted, and "NACK" if no more bytes should be send (without the quotes) |
data | - Address of the variable to store the requested data byte |
Definition at line 2022 of file uStepper.cpp.
bool i2cMaster::restart | ( | uint8_t | addr, |
bool | RW | ||
) |
Restarts connection between arduino and I2C device.
This function restarts the connection between the arduino and the I2C device desired to communicate with, by sending a start condition on the I2C bus, followed by the device address and a read/write bit.
addr | - Address of the device it is desired to communicate with |
RW | - Can be set to "READ" to setup a read transaction or "WRITE" for a write transaction (without the quotes) |
Definition at line 2072 of file uStepper.cpp.
bool i2cMaster::start | ( | uint8_t | addr, |
bool | RW | ||
) |
sets up connection between arduino and I2C device.
This function sets up the connection between the arduino and the I2C device desired to communicate with, by sending a start condition on the I2C bus, followed by the device address and a read/write bit.
addr | - Address of the device it is desired to communicate with |
RW | - Can be set to "READ" to setup a read transaction or "WRITE" for a write transaction (without the quotes) |
Definition at line 2046 of file uStepper.cpp.
bool i2cMaster::stop | ( | void | ) |
Closes the I2C connection.
This function is used to close down the I2C connection, by sending a stop condition on the I2C bus.
Definition at line 2086 of file uStepper.cpp.
bool i2cMaster::write | ( | uint8_t | slaveAddr, |
uint8_t | regAddr, | ||
uint8_t | numOfBytes, | ||
uint8_t * | data | ||
) |
sets up I2C connection to device, writes a number of data bytes and closes the connection
This function is used to perform a write transaction between the arduino and an I2C device. This function will perform everything from setting up the connection, writing the desired number of bytes and tear down the connection.
slaveAddr | - 7 bit address of the device to write to |
regAddr | - 8 bit address of the register to write to |
numOfBytes | - Number of bytes to write to the device |
data | - Address of the array/string containing data to write. |
Definition at line 1989 of file uStepper.cpp.
bool i2cMaster::writeByte | ( | uint8_t | data | ) |
Writes a byte to a device on the I2C bus.
This function writes a byte to a device on the I2C bus.
data | - Byte to be written |
Definition at line 2077 of file uStepper.cpp.
|
private |
Contains the status of the I2C bus
Definition at line 1214 of file uStepper.h.