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
slaveAddress7-bit I2C slave address.
registerAddress8-bit register address.
readDataarray that will hold the read data. Its size should be at least registerSize.
registerSizenumber of bytes to read.
okthe 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
slaveAddress7-bit I2C slave address.
registerAddress8-bit register address.
okthe 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
slaveAddress7-bit I2C slave address.
registerAddress8-bit register address.
registerValuevalues array to write to the 8-bit register.
registerSizenumber of bytes to write.
okthe 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
slaveAddress7-bit I2C slave address.
registerAddress8-bit register address.
registerValuevalue to write to the 8-bit register.
okthe 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.