Functions which simplify handling of register based twi-slaves. More...
Modules | |
Advanced informations | |
Enumerations | |
enum | eTwiWrapperError |
Functions for simplified access to register-like TWI devices. More... | |
Bit-Access Functions | |
enum eTwiWrapperError | twiWrapper_readBit (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data) |
Read a single bit from an 8-bit device register. More... | |
enum eTwiWrapperError | twiWrapper_readBits (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t bitLength, uint8_t *data) |
Read multiple bits from an 8-bit device register. More... | |
enum eTwiWrapperError | twiWrapper_writeBit (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data) |
Write a single bit in an 8-bit device register. More... | |
enum eTwiWrapperError | twiWrapper_writeBits (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t bitLength, uint8_t data) |
Write multiple bits in an 8-bit device register. More... | |
Byte Access Functions | |
enum eTwiWrapperError | twiWrapper_readByte (uint8_t devAddr, uint8_t regAddr, uint8_t *data) |
Read single byte from an 8-bit device register. More... | |
enum eTwiWrapperError | twiWrapper_readBytes (uint8_t devAddr, uint8_t regAddr, uint8_t byteCount, uint8_t *data) |
Read multiple bytes from an 8-bit device register. More... | |
enum eTwiWrapperError | twiWrapper_writeByte (uint8_t devAddr, uint8_t regAddr, uint8_t data) |
Write single byte to an 8-bit device register. More... | |
enum eTwiWrapperError | twiWrapper_writeBytes (uint8_t devAddr, uint8_t regAddr, uint8_t byteCount, uint8_t *data) |
Write multiple bytes to an 8-bit device register. More... | |
Functions which simplify handling of register based twi-slaves.
enum eTwiWrapperError |
Functions for simplified access to register-like TWI devices.
All these functions use the TWI api to directly address one or more register of a single TWI device. Hence, reading or manipulating whole registers or single bits, is done by a single a function call.
Since, the TUC-Bot api may constantly communicate to the driving module or the integrated IMU, all twiWrapper functions need to block this internal communication. Therefore, wrapper functions will wait until the currently ongoing transfer on the twi bus is done and block future transfer. This may take some time. Afterwards the lock will be removed.
Always keep these szenarios in mind:
Enumerator | |
---|---|
kTwiWrapperErrorNone | constant (0): no error |
kTwiWrapperErrorLock | constant (1): TWI is locked by the library |
kTwiWrapperErrorBusy | constant (2): TWI is currently used by the TWI-Wrapper |
kTwiWrapperErrorTimeOut | constant (3): timeout of the TWI Wrapper |
kTwiWrapperErrorRead | constant (4): internal error during reading |
kTwiWrapperErrorWrite | constant (5): internal error during writing |
enum eTwiWrapperError twiWrapper_readBit | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | bitNum, | ||
uint8_t * | data | ||
) |
Read a single bit from an 8-bit device register.
devAddr | TWI slave device address |
regAddr | Register address to read from |
bitNum | Bit position to read (0-7) |
data | Result of read operation (0xFF if bit was set, otherwise 0x00) |
example:
# byte in register : 01101001 # bit numbers : 76543210 # wanted bit : x # ==> bitNum = 3 # masked bit : 1 # ----------------------------- # ==> data (result) : 11111111
enum eTwiWrapperError twiWrapper_readBits | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | bitStart, | ||
uint8_t | bitLength, | ||
uint8_t * | data | ||
) |
Read multiple bits from an 8-bit device register.
devAddr | TWI slave device address |
regAddr | Register address to read from |
bitStart | First bit position to read (0-7) |
bitLength | Number of bits to read (not more than 8) |
data | Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05) |
example:
# byte in register : 01101001 # bit numbers : 76543210 # wanted bits : xxx # ==> bitStart = 2 # ==> bitLength = 3 # masked bits : 010 # shifted bits : 010 # ----------------------------- # ==> data (result) : 00000010
enum eTwiWrapperError twiWrapper_readByte | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t * | data | ||
) |
Read single byte from an 8-bit device register.
devAddr | TWI slave device address |
regAddr | Register address to read from |
data | Container for byte value read from device |
enum eTwiWrapperError twiWrapper_readBytes | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | byteCount, | ||
uint8_t * | data | ||
) |
Read multiple bytes from an 8-bit device register.
devAddr | TWI slave device address |
regAddr | First register address to read from |
byteCount | Number of bytes to read |
data | Buffer to store read data in |
enum eTwiWrapperError twiWrapper_writeBit | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | bitNum, | ||
uint8_t | data | ||
) |
Write a single bit in an 8-bit device register.
devAddr | TWI slave device address |
regAddr | Register address to write to |
bitNum | Bit position to write (0-7) |
data | New bit value to be written (0x00: bit is cleared; otherwise bit is set) |
example:
# byte in register : 01101001 # bit numbers : 76543210 # wanted bit : x # ==> bitNum = 4 # new bit value : 1 # ----------------------------- # ==> data : 11111111 # (all non-zero values will also work, e.g. 00000110
enum eTwiWrapperError twiWrapper_writeBits | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | bitStart, | ||
uint8_t | bitLength, | ||
uint8_t | data | ||
) |
Write multiple bits in an 8-bit device register.
devAddr | TWI slave device address |
regAddr | Register address to write to |
bitStart | First bit position to write (0-7) |
bitLength | Number of bits to write (not more than 8) |
data | Right-aligned value to write |
example:
# byte in register : 01101001 # bit numbers : 76543210 # wanted bits : xxx # ==> bitStart = 2 # ==> bitLength = 3 # new bit values : 101 # shifted bits : 101 # ----------------------------- # ==> data : 00000101
enum eTwiWrapperError twiWrapper_writeByte | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | data | ||
) |
Write single byte to an 8-bit device register.
devAddr | TWI slave device address |
regAddr | Register address to write to |
data | New byte value to write |
enum eTwiWrapperError twiWrapper_writeBytes | ( | uint8_t | devAddr, |
uint8_t | regAddr, | ||
uint8_t | byteCount, | ||
uint8_t * | data | ||
) |
Write multiple bytes to an 8-bit device register.
devAddr | TWI slave device address |
regAddr | First register address to write to |
byteCount | Number of bytes to write |
data | Buffer to copy new data from |