The friendly Operating System for the Internet of Things
i2c.h File Reference

Low-level I2C peripheral driver interface definition. More...

Detailed Description

The I2C signal lines SDA/SCL need external pull-up resistors which connect the lines to the positive voltage supply Vcc. The I2C driver implementation should enable the pin's internal pull-up resistors. There are however some use cases for which the internal pull resistors are not strong enough and the I2C bus will show faulty behavior. This can for example happen when connecting a logic analyzer which will raise the capacitance of the bus. In this case you should make sure you connect external pull-up resistors to both I2C bus lines.

The minimum and maximum resistances are computed by:

\begin{eqnarray*} R_{min} &=& \frac{V_{DD} - V_{OL(max)}} {I_{OL}}\\ R_{max} &=& \frac{t_r} {(0.8473 \cdot C_b)} \end{eqnarray*}


where:
$ V_{DD} =$ Supply voltage, $ V_{OL(max)} =$ Low level voltage, $ I_{OL} =$ Low level output current, $ t_r =$ Signal rise time, $ C_b =$ Bus capacitance

The pull-up resistors depend on the bus speed. Some typical values are:
Normal mode: 10kΩ
Fast mode: 2kΩ
Fast plus mode: 2kΩ

For more details refer to section 7.1 in:
http://www.nxp.com/documents/user_manual/UM10204.pdf

Note
The current version of this interface only supports the 7-bit addressing mode.
Author
Hauke Petersen hauke.nosp@m..pet.nosp@m.ersen.nosp@m.@fu-.nosp@m.berli.nosp@m.n.de
Thomas Eichinger thoma.nosp@m.s.ei.nosp@m.ching.nosp@m.er@f.nosp@m.u-ber.nosp@m.lin..nosp@m.de

Definition in file i2c.h.

#include <stdint.h>
#include <limits.h>
#include "periph_cpu.h"
#include "periph/dev_enums.h"
+ Include dependency graph for i2c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define I2C_FLAG_WRITE   0
 Flag signaling a write operation on the bus. More...
 
#define I2C_FLAG_READ   1
 Flag signaling a read operation on the bus.
 
#define I2C_DEV(x)   (x)
 Default I2C device access macro.
 
#define I2C_UNDEF   (UINT_MAX)
 Default I2C undefined value.
 

Typedefs

typedef unsigned int i2c_t
 Default i2c_t type definition.
 

Enumerations

enum  i2c_speed_t {
  I2C_SPEED_LOW = 0x01, I2C_SPEED_NORMAL = TWI_FREQUENCY_FREQUENCY_K100, I2C_SPEED_FAST = TWI_FREQUENCY_FREQUENCY_K400, I2C_SPEED_FAST_PLUS = 0x02,
  I2C_SPEED_HIGH = 0x03, I2C_SPEED_LOW = 0, I2C_SPEED_NORMAL, I2C_SPEED_FAST,
  I2C_SPEED_FAST_PLUS, I2C_SPEED_HIGH
}
 Default mapping of I2C bus speed values. More...
 

Functions

int i2c_init_master (i2c_t dev, i2c_speed_t speed)
 Initialize an I2C device to run as bus master. More...
 
int i2c_acquire (i2c_t dev)
 Get mutually exclusive access to the given I2C bus. More...
 
int i2c_release (i2c_t dev)
 Release the given I2C device to be used by others. More...
 
int i2c_read_byte (i2c_t dev, uint8_t address, void *data)
 Read one byte from an I2C device with the given address. More...
 
int i2c_read_bytes (i2c_t dev, uint8_t address, void *data, int length)
 Read multiple bytes from an I2C device with the given address. More...
 
int i2c_read_reg (i2c_t dev, uint8_t address, uint8_t reg, void *data)
 Read one byte from a register at the I2C slave with the given address. More...
 
int i2c_read_regs (i2c_t dev, uint8_t address, uint8_t reg, void *data, int length)
 Read multiple bytes from a register at the I2C slave with the given address. More...
 
int i2c_write_byte (i2c_t dev, uint8_t address, uint8_t data)
 Write one byte to an I2C device with the given address. More...
 
int i2c_write_bytes (i2c_t dev, uint8_t address, const void *data, int length)
 Write multiple bytes to an I2C device with the given address. More...
 
int i2c_write_reg (i2c_t dev, uint8_t address, uint8_t reg, uint8_t data)
 Write one byte to a register at the I2C slave with the given address. More...
 
int i2c_write_regs (i2c_t dev, uint8_t address, uint8_t reg, const void *data, int length)
 Write multiple bytes to a register at the I2C slave with the given address. More...
 
void i2c_poweron (i2c_t dev)
 Power on the given I2C peripheral. More...
 
void i2c_poweroff (i2c_t dev)
 Power off the given I2C peripheral. More...