CuVoodoo STM32F1 firmware template
Functions
i2c_master.c File Reference

library to communicate using I2C as master (code) More...

Go to the source code of this file.

Functions

static uint32_t RCC_I2C (uint32_t i2c)
 get RCC for I2C based on I2C identifier More...
 
static uint32_t RCC_GPIO_PORT_SCL (uint32_t i2c)
 get RCC for GPIO port for SCL pin based on I2C identifier More...
 
static uint32_t RCC_GPIO_PORT_SDA (uint32_t i2c)
 get RCC for GPIO port for SDA pin based on I2C identifier More...
 
static uint32_t GPIO_PORT_SCL (uint32_t i2c)
 get GPIO port for SCL pin based on I2C identifier More...
 
static uint32_t GPIO_PORT_SDA (uint32_t i2c)
 get GPIO port for SDA pin based on I2C identifier More...
 
static uint32_t GPIO_PIN_SCL (uint32_t i2c)
 get GPIO pin for SCL pin based on I2C identifier More...
 
static uint32_t GPIO_PIN_SDA (uint32_t i2c)
 get GPIO pin for SDA pin based on I2C identifier More...
 
void i2c_master_setup (uint32_t i2c, uint16_t frequency)
 setup I2C peripheral More...
 
void i2c_master_release (uint32_t i2c)
 release I2C peripheral More...
 
bool i2c_master_check_signals (uint32_t i2c)
 check if SDA and SCL signals are high More...
 
void i2c_master_reset (uint32_t i2c)
 reset I2C peripheral, fixing any locked state More...
 
enum i2c_master_rc i2c_master_start (uint32_t i2c)
 send start condition More...
 
enum i2c_master_rc i2c_master_select_slave (uint32_t i2c, uint16_t slave, bool address_10bit, bool write)
 select I2C slave device More...
 
enum i2c_master_rc i2c_master_read (uint32_t i2c, uint8_t *data, size_t data_size)
 read data over I2C More...
 
enum i2c_master_rc i2c_master_write (uint32_t i2c, const uint8_t *data, size_t data_size)
 write data over I2C More...
 
enum i2c_master_rc i2c_master_stop (uint32_t i2c)
 sent stop condition More...
 
enum i2c_master_rc i2c_master_slave_read (uint32_t i2c, uint16_t slave, bool address_10bit, uint8_t *data, size_t data_size)
 read data from slave device More...
 
enum i2c_master_rc i2c_master_slave_write (uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t *data, size_t data_size)
 write data to slave device More...
 
enum i2c_master_rc i2c_master_address_read (uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t *address, size_t address_size, uint8_t *data, size_t data_size)
 read data at specific address from an I2C memory slave More...
 
enum i2c_master_rc i2c_master_address_write (uint32_t i2c, uint16_t slave, bool address_10bit, const uint8_t *address, size_t address_size, const uint8_t *data, size_t data_size)
 write data at specific address on an I2C memory slave More...
 

Detailed Description

library to communicate using I2C as master (code)

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2017-2018
Note
peripherals used: I2C

Definition in file i2c_master.c.

Function Documentation

◆ GPIO_PIN_SCL()

static uint32_t GPIO_PIN_SCL ( uint32_t  i2c)
static

get GPIO pin for SCL pin based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
GPIO address

Definition at line 133 of file i2c_master.c.

◆ GPIO_PIN_SDA()

static uint32_t GPIO_PIN_SDA ( uint32_t  i2c)
static

get GPIO pin for SDA pin based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
GPIO address

Definition at line 155 of file i2c_master.c.

◆ GPIO_PORT_SCL()

static uint32_t GPIO_PORT_SCL ( uint32_t  i2c)
static

get GPIO port for SCL pin based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
GPIO address

Definition at line 89 of file i2c_master.c.

◆ GPIO_PORT_SDA()

static uint32_t GPIO_PORT_SDA ( uint32_t  i2c)
static

get GPIO port for SDA pin based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
GPIO address

Definition at line 111 of file i2c_master.c.

◆ i2c_master_address_read()

enum i2c_master_rc i2c_master_address_read ( uint32_t  i2c,
uint16_t  slave,
bool  address_10bit,
const uint8_t *  address,
size_t  address_size,
uint8_t *  data,
size_t  data_size 
)

read data at specific address from an I2C memory slave

Parameters
[in]i2cI2C base address
[in]slaveI2C address of slave device to select
[in]address_10bitif the I2C slave address is 10 bits wide
[in]addressmemory address of slave to read from
[in]address_sizeaddress size in bytes
[out]dataarray to store bytes read
[in]data_sizenumber of bytes to read
Returns
I2C return code

Definition at line 551 of file i2c_master.c.

◆ i2c_master_address_write()

enum i2c_master_rc i2c_master_address_write ( uint32_t  i2c,
uint16_t  slave,
bool  address_10bit,
const uint8_t *  address,
size_t  address_size,
const uint8_t *  data,
size_t  data_size 
)

write data at specific address on an I2C memory slave

Parameters
[in]i2cI2C base address
[in]slaveI2C address of slave device to select
[in]address_10bitif the I2C slave address is 10 bits wide
[in]addressmemory address of slave to write to
[in]address_sizeaddress size in bytes
[in]dataarray of byte to write to slave
[in]data_sizenumber of bytes to write
Returns
I2C return code

Definition at line 597 of file i2c_master.c.

◆ i2c_master_check_signals()

bool i2c_master_check_signals ( uint32_t  i2c)

check if SDA and SCL signals are high

Parameters
[in]i2cI2C base address
Returns
SDA and SCL signals are high

Definition at line 225 of file i2c_master.c.

◆ i2c_master_read()

enum i2c_master_rc i2c_master_read ( uint32_t  i2c,
uint8_t *  data,
size_t  data_size 
)

read data over I2C

Warning
the slave device must be selected before this operation
Parameters
[in]i2cI2C base address
[out]dataarray to store bytes read
[in]data_sizenumber of bytes to read
Returns
I2C return code

Definition at line 389 of file i2c_master.c.

◆ i2c_master_release()

void i2c_master_release ( uint32_t  i2c)

release I2C peripheral

Parameters
[in]i2cI2C base address

Definition at line 211 of file i2c_master.c.

◆ i2c_master_reset()

void i2c_master_reset ( uint32_t  i2c)

reset I2C peripheral, fixing any locked state

Warning
the I2C peripheral needs to be re-setup
Note
to be used after failed start or stop, and bus error
Parameters
[in]i2cI2C base address

Definition at line 254 of file i2c_master.c.

◆ i2c_master_select_slave()

enum i2c_master_rc i2c_master_select_slave ( uint32_t  i2c,
uint16_t  slave,
bool  address_10bit,
bool  write 
)

select I2C slave device

Warning
a start condition should be sent before this operation
Parameters
[in]i2cI2C base address
[in]slaveI2C address of slave device to select
[in]address_10bitif the I2C slave address is 10 bits wide
[in]writethis transaction will be followed by a read (false) or write (true) operation
Returns
I2C return code

Definition at line 311 of file i2c_master.c.

◆ i2c_master_setup()

void i2c_master_setup ( uint32_t  i2c,
uint16_t  frequency 
)

setup I2C peripheral

Parameters
[in]i2cI2C base address
[in]frequencyfrequency to use in kHz (1-400)
Note
Standard mode (Sm) is used for frequencies up to 100 kHz, and Fast mode (Fm) is used for frequencies up to 400 kHz

Definition at line 173 of file i2c_master.c.

◆ i2c_master_slave_read()

enum i2c_master_rc i2c_master_slave_read ( uint32_t  i2c,
uint16_t  slave,
bool  address_10bit,
uint8_t *  data,
size_t  data_size 
)

read data from slave device

Warning
the slave device must be selected before this operation
Parameters
[in]i2cI2C base address
[in]slaveI2C address of slave device to select
[in]address_10bitif the I2C slave address is 10 bits wide
[out]dataarray to store bytes read
[in]data_sizenumber of bytes to read
Returns
I2C return code

Definition at line 493 of file i2c_master.c.

◆ i2c_master_slave_write()

enum i2c_master_rc i2c_master_slave_write ( uint32_t  i2c,
uint16_t  slave,
bool  address_10bit,
const uint8_t *  data,
size_t  data_size 
)

write data to slave device

Warning
the slave device must be selected before this operation
Parameters
[in]i2cI2C base address
[in]slaveI2C address of slave device to select
[in]address_10bitif the I2C slave address is 10 bits wide
[in]dataarray of byte to write to slave
[in]data_sizenumber of bytes to write
Returns
I2C return code

Definition at line 522 of file i2c_master.c.

◆ i2c_master_start()

enum i2c_master_rc i2c_master_start ( uint32_t  i2c)

send start condition

Parameters
[in]i2cI2C base address
Returns
I2C return code

Definition at line 284 of file i2c_master.c.

◆ i2c_master_stop()

enum i2c_master_rc i2c_master_stop ( uint32_t  i2c)

sent stop condition

Parameters
[in]i2cI2C base address
Returns
I2C return code

Definition at line 464 of file i2c_master.c.

◆ i2c_master_write()

enum i2c_master_rc i2c_master_write ( uint32_t  i2c,
const uint8_t *  data,
size_t  data_size 
)

write data over I2C

Warning
the slave device must be selected before this operation
Parameters
[in]i2cI2C base address
[in]dataarray of byte to write to slave
[in]data_sizenumber of bytes to write
Returns
I2C return code

Definition at line 427 of file i2c_master.c.

◆ RCC_GPIO_PORT_SCL()

static uint32_t RCC_GPIO_PORT_SCL ( uint32_t  i2c)
static

get RCC for GPIO port for SCL pin based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
RCC GPIO address

Definition at line 57 of file i2c_master.c.

◆ RCC_GPIO_PORT_SDA()

static uint32_t RCC_GPIO_PORT_SDA ( uint32_t  i2c)
static

get RCC for GPIO port for SDA pin based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
RCC GPIO address

Definition at line 73 of file i2c_master.c.

◆ RCC_I2C()

static uint32_t RCC_I2C ( uint32_t  i2c)
static

get RCC for I2C based on I2C identifier

Parameters
[in]i2cI2C base address
Returns
RCC address for I2C peripheral

Definition at line 39 of file i2c_master.c.