TM STM32F4xx Libraries  v1.0.0
Libraries for STM32F4xx devices from Tilen Majerle
TM_I2C_Functions

Library Functions. More...

Functions

void TM_I2C_Init (I2C_TypeDef *I2Cx, TM_I2C_PinsPack_t pinspack, uint32_t clockSpeed)
 Initializes I2C. More...
 
uint8_t TM_I2C_Read (I2C_TypeDef *I2Cx, uint8_t address, uint8_t reg)
 Reads single byte from slave. More...
 
void TM_I2C_ReadMulti (I2C_TypeDef *I2Cx, uint8_t address, uint8_t reg, uint8_t *data, uint16_t count)
 Reads multi bytes from slave. More...
 
uint8_t TM_I2C_ReadNoRegister (I2C_TypeDef *I2Cx, uint8_t address)
 Reads byte from slave without specify register address. More...
 
void TM_I2C_ReadMultiNoRegister (I2C_TypeDef *I2Cx, uint8_t address, uint8_t *data, uint16_t count)
 Reads multi bytes from slave without setting register from where to start read. More...
 
void TM_I2C_Write (I2C_TypeDef *I2Cx, uint8_t address, uint8_t reg, uint8_t data)
 Writes single byte to slave. More...
 
void TM_I2C_WriteMulti (I2C_TypeDef *I2Cx, uint8_t address, uint8_t reg, uint8_t *data, uint16_t count)
 Writes multi bytes to slave. More...
 
void TM_I2C_WriteNoRegister (I2C_TypeDef *I2Cx, uint8_t address, uint8_t data)
 Writes byte to slave without specify register address. More...
 
void TM_I2C_WriteMultiNoRegister (I2C_TypeDef *I2Cx, uint8_t address, uint8_t *data, uint16_t count)
 Writes multi bytes to slave without setting register from where to start write. More...
 
uint8_t TM_I2C_IsDeviceConnected (I2C_TypeDef *I2Cx, uint8_t address)
 Checks if device is connected to I2C bus. More...
 
int16_t TM_I2C_Start (I2C_TypeDef *I2Cx, uint8_t address, uint8_t direction, uint8_t ack)
 I2C Start condition. More...
 
uint8_t TM_I2C_Stop (I2C_TypeDef *I2Cx)
 Stop condition on I2C. More...
 
uint8_t TM_I2C_ReadNack (I2C_TypeDef *I2Cx)
 Reads byte without ack. More...
 
uint8_t TM_I2C_ReadAck (I2C_TypeDef *I2Cx)
 Reads byte with ack. More...
 
void TM_I2C_WriteData (I2C_TypeDef *I2Cx, uint8_t data)
 Writes to slave. More...
 
void TM_I2C_InitCustomPinsCallback (I2C_TypeDef *I2Cx, uint16_t AlternateFunction)
 Callback for custom pins initialization. More...
 

Detailed Description

Library Functions.

Function Documentation

void TM_I2C_Init ( I2C_TypeDef *  I2Cx,
TM_I2C_PinsPack_t  pinspack,
uint32_t  clockSpeed 
)

Initializes I2C.

Parameters
*I2CxI2C used
pinspackPins used. This parameter can have a value of TM_I2C_PinsPack_t enumeration
clockSpeedClock speed for SCL in Hertz
Return values
None
void TM_I2C_InitCustomPinsCallback ( I2C_TypeDef *  I2Cx,
uint16_t  AlternateFunction 
)

Callback for custom pins initialization.

When you call TM_I2C_Init() function, and if you pass TM_I2C_PinsPack_Custom to function, then this function will be called where you can initialize custom pins for I2C peripheral.

Parameters
*I2CxI2C for which initialization will be set
AlternateFunctionAlternate function which should be used for GPIO initialization
Return values
None
Note
With __weak parameter to prevent link errors if not defined by user
uint8_t TM_I2C_IsDeviceConnected ( I2C_TypeDef *  I2Cx,
uint8_t  address 
)

Checks if device is connected to I2C bus.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
Return values
Devicestatus:
  • 0: Device is not connected
  • > 0: Device is connected
uint8_t TM_I2C_Read ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t  reg 
)

Reads single byte from slave.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
regregister to read from
Return values
Datafrom slave
uint8_t TM_I2C_ReadAck ( I2C_TypeDef *  I2Cx)

Reads byte with ack.

Parameters
*I2CxI2C used
Return values
Bytefrom slave
Note
For private use
void TM_I2C_ReadMulti ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t  reg,
uint8_t *  data,
uint16_t  count 
)

Reads multi bytes from slave.

Parameters
*I2CxI2C used
uint8_taddress: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
uint8_treg: register to read from
uint8_t*data: pointer to data array to store data from slave
uint8_tcount: how many bytes will be read
Return values
None
void TM_I2C_ReadMultiNoRegister ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t *  data,
uint16_t  count 
)

Reads multi bytes from slave without setting register from where to start read.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
*datapointer to data array to store data from slave
counthow many bytes will be read
Return values
None
uint8_t TM_I2C_ReadNack ( I2C_TypeDef *  I2Cx)

Reads byte without ack.

Parameters
*I2CxI2C used
Return values
Bytefrom slave
Note
For private use
uint8_t TM_I2C_ReadNoRegister ( I2C_TypeDef *  I2Cx,
uint8_t  address 
)

Reads byte from slave without specify register address.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
Return values
Datafrom slave
int16_t TM_I2C_Start ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t  direction,
uint8_t  ack 
)

I2C Start condition.

Parameters
*I2CxI2C used
addressslave address
directionmaster to slave or slave to master
ackack enabled or disabled
Return values
Startcondition status
Note
For private use
uint8_t TM_I2C_Stop ( I2C_TypeDef *  I2Cx)

Stop condition on I2C.

Parameters
*I2CxI2C used
Return values
Stopcondition status
Note
For private use
void TM_I2C_Write ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t  reg,
uint8_t  data 
)

Writes single byte to slave.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
regregister to write to
datadata to be written
Return values
None
void TM_I2C_WriteData ( I2C_TypeDef *  I2Cx,
uint8_t  data 
)

Writes to slave.

Parameters
*I2CxI2C used
datadata to be sent
Return values
None
Note
For private use
void TM_I2C_WriteMulti ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t  reg,
uint8_t *  data,
uint16_t  count 
)

Writes multi bytes to slave.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
regregister to write to
*datapointer to data array to write it to slave
counthow many bytes will be written
Return values
None
void TM_I2C_WriteMultiNoRegister ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t *  data,
uint16_t  count 
)

Writes multi bytes to slave without setting register from where to start write.

Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
*datapointer to data array to write data to slave
counthow many bytes you want to write
Return values
None
void TM_I2C_WriteNoRegister ( I2C_TypeDef *  I2Cx,
uint8_t  address,
uint8_t  data 
)

Writes byte to slave without specify register address.

Useful if you have I2C device to read like that:

  • I2C START
  • SEND DEVICE ADDRESS
  • SEND DATA BYTE
  • I2C STOP
Parameters
*I2CxI2C used
address7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used
datadata byte which will be send to device
Return values
None