libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
I2C peripheral API

Access functions for the I2C Controller More...

Collaboration diagram for I2C peripheral API:

Functions

void i2c_enable (uint32_t i2c, uint32_t mode)
 Enable I2C peripheral. More...
 
void i2c_disable (uint32_t i2c)
 Disable I2C peripheral. More...
 
void i2c_start_tx (uint32_t i2c)
 Start I2C transmission. More...
 
void i2c_start_rx (uint32_t i2c)
 Start I2C reception. More...
 
void i2c_send_stop (uint32_t i2c)
 Signal stop on I2C line. More...
 
void i2c_set_fast_mode (uint32_t i2c)
 Select Fast (400kHz) mode. More...
 
void i2c_set_standard_mode (uint32_t i2c)
 Select Standard (100kHz) mode. More...
 
void i2c_set_frequency (uint32_t i2c, uint32_t freq)
 Set I2C frequency. More...
 
void i2c_send_data (uint32_t i2c, uint8_t data)
 Write Data to TXD register to be sent. More...
 
uint8_t i2c_get_data (uint32_t i2c)
 Read Data from RXD register. More...
 
void i2c_select_pins (uint32_t i2c, uint32_t scl_pin, uint32_t sda_pin)
 Select GPIO pins to be used by this peripheral. More...
 
void i2c_set_address (uint32_t i2c, uint8_t addr)
 Set 7bit I2C address of the device you wish to communicate with. More...
 
void i2c_resume (uint32_t i2c)
 Resume I2C transaction. More...
 
void i2c_set_shorts (uint32_t i2c, uint32_t shorts)
 Configure event -> task shortcuts. More...
 
void i2c_set_tx_buffer (uint32_t i2c, const uint8_t *buffer, uint8_t len)
 Configure I2C transmit buffer properties. More...
 
void i2c_set_rx_buffer (uint32_t i2c, uint8_t *buffer, uint8_t len)
 Configure I2C receive buffer properties. More...
 

Detailed Description

Access functions for the I2C Controller

LGPL License Terms libopencm3 License

Author
© 2016 Maxim Sloyko maxim.nosp@m.s@go.nosp@m.ogle..nosp@m.com
© 2021 - 2022 Eduard Drusa <ventyl86(at)netkosice(dot)sk>

Function Documentation

◆ i2c_disable()

void i2c_disable ( uint32_t  i2c)

Disable I2C peripheral.

Parameters
[in]i2ci2c peripheral base, see I2C instances

Definition at line 52 of file i2c_common.c.

References I2C_ENABLE.

◆ i2c_enable()

void i2c_enable ( uint32_t  i2c,
uint32_t  mode 
)

Enable I2C peripheral.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]modei2c I2C peripheral mode

Definition at line 43 of file i2c_common.c.

References I2C_ENABLE.

◆ i2c_get_data()

uint8_t i2c_get_data ( uint32_t  i2c)

Read Data from RXD register.

Reads one byte from reception buffer. This API is only available if I2C_MODE_LEGACY is activated.

Parameters
[in]i2ci2c peripheral base, see I2C instances
Returns
data from RXD register.

Definition at line 140 of file i2c_common.c.

References I2C_RXD.

◆ i2c_resume()

void i2c_resume ( uint32_t  i2c)

Resume I2C transaction.

This function is unusual, but required to implement i2c exchange with this peripheral.

Parameters
[in]i2ci2c peripheral base, see I2C instances

Definition at line 190 of file i2c_common.c.

References I2C_TASK_RESUME, and PERIPH_TRIGGER_TASK.

◆ i2c_select_pins()

void i2c_select_pins ( uint32_t  i2c,
uint32_t  scl_pin,
uint32_t  sda_pin 
)

Select GPIO pins to be used by this peripheral.

Configures GPIO pins assigned to SCL and SDA signals. These pins are only occupied by I2C peripheral whenever it is enabled using i2c_enable. It is possible to ignore any given signal and not map it to pin by using special value of GPIO_UNCONNECTED instead of GPIO Pin Identifiers values.

This needs to be configured when no transaction is in progress.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]scl_pinGPIO pin used for SCL signal
[in]sda_pinGPIO pin used for SDA signal

Definition at line 158 of file i2c_common.c.

References __GPIO2PIN, GPIO_UNCONNECTED, I2C_PSELSCL, and I2C_PSELSDA.

◆ i2c_send_data()

void i2c_send_data ( uint32_t  i2c,
uint8_t  data 
)

Write Data to TXD register to be sent.

Writes one byte into transmission buffer. This API is only available if I2C_MODE_LEGACY is activated.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]databyte to send next.

Definition at line 127 of file i2c_common.c.

References I2C_TXD.

◆ i2c_send_stop()

void i2c_send_stop ( uint32_t  i2c)

Signal stop on I2C line.

Parameters
[in]i2ci2c peripheral base, see I2C instances.

Definition at line 82 of file i2c_common.c.

References I2C_TASK_STOP.

◆ i2c_set_address()

void i2c_set_address ( uint32_t  i2c,
uint8_t  addr 
)

Set 7bit I2C address of the device you wish to communicate with.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]addrdevice address (7bit).

Definition at line 178 of file i2c_common.c.

References I2C_ADDRESS.

◆ i2c_set_fast_mode()

void i2c_set_fast_mode ( uint32_t  i2c)

Select Fast (400kHz) mode.

Parameters
[in]i2ci2c peripheral base, see I2C instances.

Definition at line 91 of file i2c_common.c.

References I2C_FREQUENCY, and I2C_FREQUENCY_400K.

◆ i2c_set_frequency()

void i2c_set_frequency ( uint32_t  i2c,
uint32_t  freq 
)

Set I2C frequency.

In addition to Standard (100kHz) and Fast (400kHz) modes this peripheral also supports 250kHz mode.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]freqfrequency constant. See I2C frequency constants for details and note that this is not actually a frequency in Hz or kHz.

Definition at line 114 of file i2c_common.c.

References I2C_FREQUENCY.

◆ i2c_set_rx_buffer()

void i2c_set_rx_buffer ( uint32_t  i2c,
uint8_t *  buffer,
uint8_t  len 
)

Configure I2C receive buffer properties.

Configures receive buffer for EasyDMA transaction. This API is only available if I2C_MODE_MASTER mode is activated.

Configures linear RX buffer for EasyDMA transmission.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]bufferaddress of buffer start
[in]lenlength of the buffer

Definition at line 54 of file i2c.c.

References I2C_RXDLIST, I2C_RXDMAXCNT, and I2C_RXDPTR.

◆ i2c_set_shorts()

void i2c_set_shorts ( uint32_t  i2c,
uint32_t  shorts 
)

Configure event -> task shortcuts.

Sets new shortcut configuration bitmask for I2C peripheral.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]shortsI2C event -> task shortcuts activated

Definition at line 202 of file i2c_common.c.

References I2C_SHORTS.

◆ i2c_set_standard_mode()

void i2c_set_standard_mode ( uint32_t  i2c)

Select Standard (100kHz) mode.

Parameters
[in]i2ci2c peripheral base, see I2C instances.

Definition at line 100 of file i2c_common.c.

References I2C_FREQUENCY, and I2C_FREQUENCY_100K.

◆ i2c_set_tx_buffer()

void i2c_set_tx_buffer ( uint32_t  i2c,
const uint8_t *  buffer,
uint8_t  len 
)

Configure I2C transmit buffer properties.

Configures transmit buffer for EasyDMA transaction. This API is only available if I2C_MODE_MASTER mode is activated.

Configures linear TX buffer for EasyDMA transmission.

Parameters
[in]i2ci2c peripheral base, see I2C instances
[in]bufferaddress of buffer start
[in]lenlength of data in the buffer

Definition at line 37 of file i2c.c.

References I2C_TXDLIST, I2C_TXDMAXCNT, and I2C_TXDPTR.

◆ i2c_start_rx()

void i2c_start_rx ( uint32_t  i2c)

Start I2C reception.

Parameters
[in]i2ci2c peripheral base, see I2C instances.

Definition at line 73 of file i2c_common.c.

References I2C_TASK_STARTRX.

◆ i2c_start_tx()

void i2c_start_tx ( uint32_t  i2c)

Start I2C transmission.

Starts STARTTX task, which generates start condition on I2C bus and transmits address previously configured by i2c_set_address.

Parameters
[in]i2ci2c peripheral base, see I2C instances.

Definition at line 64 of file i2c_common.c.

References I2C_TASK_STARTTX.