Mistake on this page?
Report an issue in GitHub or email us
Functions
I2C Configuration Functions

Functions

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

Detailed Description

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
0 if NAK was received, 1 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 configures its specifieds pins.

Parameters
objThe I2C object
sdaThe sda pin
sclThe scl pin
const PinMap* i2c_master_scl_pinmap ( void  )

Get the pins that support I2C SCL.

Return a PinMap array of pins that support I2C SCL in master mode. The array is terminated with {NC, NC, 0}.

Returns
PinMap array
const PinMap* i2c_master_sda_pinmap ( void  )

Get the pins that support I2C SDA.

Return a PinMap array of pins that support I2C SDA in master mode. The array is terminated with {NC, NC, 0}.

Returns
PinMap array
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
const PinMap* i2c_slave_scl_pinmap ( void  )

Get the pins that support I2C SCL.

Return a PinMap array of pins that support I2C SCL in slave mode. The array is terminated with {NC, NC, 0}.

Returns
PinMap array
const PinMap* i2c_slave_sda_pinmap ( void  )

Get the pins that support I2C SDA.

Return a PinMap array of pins that support I2C SDA in slave mode. The array is terminated with {NC, NC, 0}.

Returns
PinMap array
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 write
stopStop to be generated after the transfer is done
Returns
zero or non-zero - Number of written bytes negative - I2C_ERROR_XXX status
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.