CuVoodoo STM32F1 firmware template
Enumerations | Functions
i2c_master.h File Reference

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

Go to the source code of this file.

Enumerations

enum  i2c_master_rc {
  I2C_MASTER_RC_NONE = 0, I2C_MASTER_RC_START_STOP_IN_PROGESS, I2C_MASTER_RC_NOT_MASTER, I2C_MASTER_RC_NOT_TRANSMIT,
  I2C_MASTER_RC_NOT_RECEIVE, I2C_MASTER_RC_NOT_READY, I2C_MASTER_RC_NAK
}
 I2C return codes. More...
 

Functions

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...
 
void i2c_master_reset (uint32_t i2c)
 reset I2C peripheral, fixing any locked state More...
 
bool i2c_master_check_signals (uint32_t i2c)
 check if SDA and SCL signals are high 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 (API)

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.h.

Enumeration Type Documentation

◆ i2c_master_rc

I2C return codes.

Enumerator
I2C_MASTER_RC_NONE 

no error

I2C_MASTER_RC_START_STOP_IN_PROGESS 

a start or stop condition is already in progress

I2C_MASTER_RC_NOT_MASTER 

not in master mode

I2C_MASTER_RC_NOT_TRANSMIT 

not in transmit mode

I2C_MASTER_RC_NOT_RECEIVE 

not in receive mode

I2C_MASTER_RC_NOT_READY 

slave is not read (previous operations has been nacked)

I2C_MASTER_RC_NAK 

not acknowledge received

Definition at line 24 of file i2c_master.h.

Function Documentation

◆ 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 506 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 552 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 356 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

Note
to be used after failed start and stop
Parameters
[in]i2cI2C base address

Definition at line 235 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 287 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 448 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 477 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 265 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 425 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 391 of file i2c_master.c.