HRI board firmware v2.1 Microcontroller firmware of the board used during the HRI labs.

Functions
Driver / I2C

Driver for the I2C bus communication peripheral. More...

## Functions
void | i2c_Init (void)
| Initializes the I2C bus. More...
void | i2c_WriteRegister (uint8_t slaveAddress, uint8_t registerAddress, uint8_t registerValue, bool *ok)
| Writes a 8-bit value to a register. More...
void | i2c_WriteMultiBytesRegister (uint8_t slaveAddress, uint8_t registerAddress, uint8_t const *registerValue, uint8_t registerSize, bool *ok)
| Writes several bytes to a register. More...
uint8_t | i2c_ReadRegister (uint8_t slaveAddress, uint8_t registerAddress, bool *ok)
| Reads a 8-bit value from a register. More...
void | i2c_ReadMultiBytesRegister (uint8_t slaveAddress, uint8_t registerAddress, uint8_t *readData, uint8_t registerSize, bool *ok)
| Reads a multi bytes value from a register. More...

## Detailed Description

Driver for the I2C bus communication peripheral.

This driver controls the I2C peripheral of the STM32, that is accessible from the digital extension connector of the HRI board.

Call i2c_Init() first in the initialization code. Then, the communication function i2c_readRegister() or i2c_writeRegister() can be used. Note that both functions are synchronous, hence blocking the execution until the operation completes.

## Function Documentation

## ◆ i2c_Init()

void i2c_Init | ( | void |  | ) |

Initializes the I2C bus.

## ◆ i2c_ReadMultiBytesRegister()

void i2c_ReadMultiBytesRegister | ( | uint8_t | slaveAddress,
|  | uint8_t | registerAddress,
|  | uint8_t * | readData,
|  | uint8_t | registerSize,
|  | bool * | ok
| ) |  |

Reads a multi bytes value from a register.

Parameters

  slaveAddress | 7-bit I2C slave address.
  registerAddress | 8-bit register address.
  readData | array that will hold the read data. Its size should be at least registerSize.
  registerSize | number of bytes to read.
  ok | the value pointed will be set to true if the operation completed successfully, or to false if an error occured. If a NULL pointer is given, then it is ignored.

## ◆ i2c_ReadRegister()

uint8_t i2c_ReadRegister | ( | uint8_t | slaveAddress,
|  | uint8_t | registerAddress,
|  | bool * | ok
| ) |  |

Reads a 8-bit value from a register.

Parameters

  slaveAddress | 7-bit I2C slave address.
  registerAddress | 8-bit register address.
  ok | the value pointed will be set to true if the operation completed successfully, or to false if an error occured. If a NULL pointer is given, then it is ignored.

Returns
  the register value. If the operation failed (*ok set to false), then 0 is returned.

## ◆ i2c_WriteMultiBytesRegister()

void i2c_WriteMultiBytesRegister | ( | uint8_t | slaveAddress,
|  | uint8_t | registerAddress,
|  | uint8_t const * | registerValue,
|  | uint8_t | registerSize,
|  | bool * | ok
| ) |  |

Writes several bytes to a register.

Parameters

  slaveAddress | 7-bit I2C slave address.
  registerAddress | 8-bit register address.
  registerValue | values array to write to the 8-bit register.
  registerSize | number of bytes to write.
  ok | the value pointed will be set to true if the operation completed successfully, or to false if an error occured. If a NULL pointer is given, then it is ignored.

## ◆ i2c_WriteRegister()

void i2c_WriteRegister | ( | uint8_t | slaveAddress,
|  | uint8_t | registerAddress,
|  | uint8_t | registerValue,
|  | bool * | ok
| ) |  |

Writes a 8-bit value to a register.

Parameters

  slaveAddress | 7-bit I2C slave address.
  registerAddress | 8-bit register address.
  registerValue | value to write to the 8-bit register.
  ok | the value pointed will be set to true if the operation completed successfully, or to false if an error occured. If a NULL pointer is given, then it is ignored.