Mbed OS Reference
Loading...
Searching...
No Matches
I2C Configuration Functions

Modules

 I2C hal tests
 The I2C HAL tests ensure driver conformance to defined behaviour.
 

Functions

void i2c_init_direct (i2c_t *obj, const i2c_pinmap_t *pinmap)
 Initialize the I2C peripheral.
 
void i2c_init (i2c_t *obj, PinName sda, PinName scl)
 Initialize the I2C peripheral.
 
void i2c_free (i2c_t *obj)
 Release a I2C object.
 
void i2c_frequency (i2c_t *obj, int hz)
 Configure the I2C frequency.
 
int i2c_read (i2c_t *obj, int address, char *data, int length, int stop)
 Blocking read of data.
 
int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop)
 Blocking write of data.
 
int i2c_start (i2c_t *obj)
 Send START command.
 
int i2c_stop (i2c_t *obj)
 Send STOP command.
 
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.
 
const PinMapi2c_master_sda_pinmap (void)
 Get the pins that support I2C SDA.
 
const PinMapi2c_master_scl_pinmap (void)
 Get the pins that support I2C SCL.
 
const PinMapi2c_slave_sda_pinmap (void)
 Get the pins that support I2C SDA.
 
const PinMapi2c_slave_scl_pinmap (void)
 Get the pins that support I2C SCL.
 
i2c_capabilities_t const * i2c_get_capabilities ()
 Fills the given i2c_capabilities_t structure with the capabilities of the I2C peripheral.
 

Detailed Description

Defined behavior

Undefined behavior

Function Documentation

◆ i2c_init_direct()

void i2c_init_direct ( i2c_t obj,
const i2c_pinmap_t pinmap 
)

Initialize the I2C peripheral.

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

Parameters
objThe I2C object
pinmapPinmap pointer to structure which holds static pinmap

◆ i2c_init()

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

◆ i2c_free()

void i2c_free ( i2c_t obj)

Release a I2C object.

Return the pins owned by the I2C object to their reset state

Parameters
objThe I2C object to deinitialize

◆ i2c_frequency()

void i2c_frequency ( i2c_t obj,
int  hz 
)

Configure the I2C frequency.

Parameters
objThe I2C object
hzFrequency in Hz

◆ i2c_read()

int i2c_read ( i2c_t obj,
int  address,
char *  data,
int  length,
int  stop 
)

Blocking read of data.

This function may be called in these I2C states:

  • IDLE
  • HOLDING_BUS
  • BYTE_READ (to do a repeated start after a single byte transaction)
  • BYTE_WRITE (to do a repeated start after a single byte transaction)
Parameters
objThe I2C object
address8/11-bit address (last bit is 1)
dataThe buffer for receiving
lengthNumber of bytes to read. Allowed to be 0 only if the supports_zero_length_transfer_transaction capability is true.
stopStop to be generated after the transfer is done
Returns
Number of read bytes

◆ i2c_write()

int i2c_write ( i2c_t obj,
int  address,
const char *  data,
int  length,
int  stop 
)

Blocking write of data.

This function may be called in these I2C states:

  • IDLE
  • HOLDING_BUS
  • BYTE_READ (to do a repeated start after a single byte transaction)
  • BYTE_WRITE (to do a repeated start after a single byte transaction)
Parameters
objThe I2C object
address8/11-bit address (last bit is 0)
dataThe buffer for sending
lengthNumber of bytes to write. Allowed to be 0 only if the supports_zero_length_transfer_transaction capability is true.
stopStop to be generated after the transfer is done
Return values
zeroor non-zero - Number of written bytes
negative- I2C_ERROR_XXX status

◆ i2c_start()

int i2c_start ( i2c_t obj)

Send START command.

The I2C class guarantees that this will only be called at appropriate times (when the bus is idle or during an existing single-byte transaction to do a repeated start).

Note that some I2C peripherals (e.g. RP2xxx, newer STM32s) are not capable of sending a start condition until the address is known. On these MCUs, the start condition will not actually be sent until the first write_byte() call after the start().

This function may be called in these I2C states:

  • IDLE
  • HOLDING_BUS
  • ADDRESSED (to do a repeated start after a zero length transaction, if supported)
  • BYTE_READ
  • BYTE_WRITE
Parameters
objThe I2C object

◆ i2c_stop()

int i2c_stop ( i2c_t obj)

Send STOP command.

This function may be called in these I2C states:

  • ADDRESSED (to complete a zero length transaction, only allowed if the supports_zero_length_transfer_single_byte capability is enabled)
  • BYTE_READ
  • BYTE_WRITE
Parameters
objThe I2C object

◆ i2c_reset()

void i2c_reset ( i2c_t obj)

Reset I2C peripheral.

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

Parameters
objThe I2C object

◆ i2c_byte_read()

int i2c_byte_read ( i2c_t obj,
int  last 
)

Read one byte.

This function may be called in these I2C states:

  • ADDRESSED
  • BYTE_READ
Parameters
objThe I2C object
lastAcknoledge
Returns
The read byte

◆ i2c_byte_write()

int i2c_byte_write ( i2c_t obj,
int  data 
)

Write one byte.

This function may be called in these I2C states:

  • STARTED (to send the address byte)
  • ADDRESSED
  • BYTE_WRITE
Parameters
objThe I2C object
dataByte to be written
Returns
0 if NAK was received, 1 if ACK was received, 2 for timeout, or 3 for other error.

◆ i2c_master_sda_pinmap()

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

◆ i2c_master_scl_pinmap()

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

◆ i2c_slave_sda_pinmap()

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

◆ i2c_slave_scl_pinmap()

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

◆ i2c_get_capabilities()

i2c_capabilities_t const * i2c_get_capabilities ( )

Fills the given i2c_capabilities_t structure with the capabilities of the I2C peripheral.

Returns
Pointer to constant capabilities data