mbed library sources

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

I2C Configuration Functions

I2C Configuration Functions

Functions

void i2c_init (i2c_t *obj, PinName sda, PinName scl)
 Initialize the I2C peripheral.
void i2c_frequency (i2c_t *obj, int hz)
 Configure the I2C frequency.
int i2c_start (i2c_t *obj)
 Send START command.
int i2c_stop (i2c_t *obj)
 Send STOP command.
int i2c_read (i2c_t *obj, int address, char *data, int length, int stop)
 Blocking reading data.
int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop)
 Blocking sending data.
void i2c_reset (i2c_t *obj)
 Reset I2C peripheral.
int i2c_byte_read (i2c_t *obj, int last)
 Read one byte.
int i2c_byte_write (i2c_t *obj, int data)
 Write one byte.

Function Documentation

int i2c_byte_read ( i2c_t obj,
int  last 
)

Read one byte.

Parameters:
objThe i2c object
lastAcknoledge
Returns:
The read byte
int i2c_byte_write ( i2c_t obj,
int  data 
)

Write one byte.

Parameters:
objThe i2c object
dataByte to be written
Returns:
1 if NAK was received, 0 if ACK was received, 2 for timeout.
void i2c_frequency ( i2c_t obj,
int  hz 
)

Configure the I2C frequency.

Parameters:
objThe i2c object
hzFrequency in Hz
void i2c_init ( i2c_t obj,
PinName  sda,
PinName  scl 
)

Initialize the I2C peripheral.

It sets the default parameters for I2C peripheral, and configure its specifieds pins.

Parameters:
objThe i2c object
sdaThe sda pin
sclThe scl pin
int i2c_read ( i2c_t obj,
int  address,
char *  data,
int  length,
int  stop 
)

Blocking reading data.

Parameters:
objThe i2c object
address7-bit address (last bit is 1)
dataThe buffer for receiving
lengthNumber of bytes to read
stopStop to be generated after the transfer is done
Returns:
Number of read bytes
void i2c_reset ( i2c_t obj )

Reset I2C peripheral.

TODO: The action here. Most of the implementation sends stop().

Parameters:
objThe i2c object
int i2c_start ( i2c_t obj )

Send START command.

Parameters:
objThe i2c object
int i2c_stop ( i2c_t obj )

Send STOP command.

Parameters:
objThe i2c object
int i2c_write ( i2c_t obj,
int  address,
const char *  data,
int  length,
int  stop 
)

Blocking sending data.

Parameters:
objThe i2c object
address7-bit address (last bit is 0)
dataThe buffer for sending
lengthNumber of bytes to wrte
stopStop to be generated after the transfer is done
Returns:
Number of written bytes