BeRTOS
Functions
Old I2C API
I2C driver

This is the old and deprecated I2C API. More...

Functions

bool i2c_send (const void *_buf, size_t count)
 Send a sequence of bytes in master transmitter mode to the selected slave device through the I2C bus.
bool i2c_recv (void *_buf, size_t count)
 Receive a sequence of one or more bytes from the selected slave device in master receive mode through the I2C bus.

I2C Backends.

Sometimes your cpu does not have a builtin i2c driver or you don't want, for some reason, to use that.

With this you can choose, at compile time, which backend to use. Set the CONFIG_I2C_BACKEND configuration variable in cfg_i2c.h

#define I2C_BACKEND_BUILTIN   0
 Uses cpu builtin i2c driver.
#define I2C_BACKEND_BITBANG   1
 Uses emulated bitbang driver.

I2c builtin prototypes.

Do NOT use these function directly, instead, you can call the ones named without "_builtin_" and specify in cfg_i2c.h (CONFIG_I2C_BACKEND) that you want the builtin backend.

bool i2c_builtin_start_w (uint8_t id)
 Send START condition and select slave for write.
bool i2c_builtin_start_r (uint8_t id)
 Send START condition and select slave for read.
void i2c_builtin_stop (void)
 Send STOP condition.
bool i2c_builtin_put (uint8_t _data)
 Put a single byte in master transmitter mode to the selected slave device through the TWI bus.
int i2c_builtin_get (bool ack)
 Get 1 byte from slave in master transmitter mode to the selected slave device through the TWI bus.

I2c bitbang prototypes.

Do NOT use these function directly, instead, you can call the ones named without "_bitbang_" and specify in cfg_i2c.h (CONFIG_I2C_BACKEND) that you want the bitbang backend.

bool i2c_bitbang_start_w (uint8_t id)
bool i2c_bitbang_start_r (uint8_t id)
void i2c_bitbang_stop (void)
bool i2c_bitbang_put (uint8_t _data)
int i2c_bitbang_get (bool ack)

Detailed Description

This is the old and deprecated I2C API.

It is maintained for backward compatibility only, don't use it in new projects.


Function Documentation

int i2c_builtin_get ( bool  ack)

Get 1 byte from slave in master transmitter mode to the selected slave device through the TWI bus.

If ack is true issue a ACK after getting the byte, otherwise a NACK is issued.

Returns:
the byte read if ok, EOF on errors.

Definition at line 187 of file i2c_avr.c.

bool i2c_builtin_put ( const uint8_t  data)

Put a single byte in master transmitter mode to the selected slave device through the TWI bus.

Returns:
true on success, false on error.

Definition at line 166 of file i2c_avr.c.

bool i2c_builtin_start_r ( uint8_t  id)

Send START condition and select slave for read.

id is the device id comprehensive of address left shifted by 1. The LSB of id is ignored and set to 1 for read operation.

Returns:
true on success, false otherwise.

Definition at line 133 of file i2c_avr.c.

bool i2c_builtin_start_w ( uint8_t  id)

Send START condition and select slave for write.

id is the device id comprehensive of address left shifted by 1. The LSB of id is ignored and reset to 0 for write operation.

Returns:
true on success, false otherwise.

Definition at line 93 of file i2c_avr.c.

bool i2c_recv ( void *  _buf,
size_t  count 
)

Receive a sequence of one or more bytes from the selected slave device in master receive mode through the I2C bus.

Received data is placed in buf.

Note:
a NACK is automatically given on the last received byte.
Returns:
true on success, false on error

Definition at line 76 of file i2c.c.

bool i2c_send ( const void *  _buf,
size_t  count 
)

Send a sequence of bytes in master transmitter mode to the selected slave device through the I2C bus.

Returns:
true on success, false on error.

Definition at line 52 of file i2c.c.