I2C Master Synchronous Driver

The functions in the Inter-Integrated Circuit (I2C) Master synchronous driver provide an interface to read/write the data from/to the slave device.

The stop condition is automatically controlled by the driver if the I/O write and read functions are used, but can be manually controlled by using the i2c_m_sync_transfer function.

Often a master accesses different information in the slave by accessing different registers in the slave. This is done by first sending a message to the target slave containing the register address, followed by a repeated start condition (no stop condition in between) ending with transferring the register data. This scheme is supported by the i2c_m_sync_cmd_write and i2c_m_sync_cmd_read function, but limited to 8-bit register addresses.

I2C Modes (standard mode/fastmode+/highspeed mode) can only be selected in START. If the SCL frequency (baudrate) has changed run-time, make sure to stick within the SCL clock frequency range supported by the selected mode. The requested SCL clock frequency is not validated by the i2c_m_sync_set_baudrate function against the selected I2C mode.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Register I/O descriptor

  • Enable or disable the I2C master

  • Set the address of the slave device

  • Read/Write message to/from the slave

Summary of Configuration Options

Below is a list of the main I2C master parameters that can be configured in START. Many of these parameters are used by the i2c_m_sync_init function when initializing the driver and underlying hardware. Most of the initial values can be overridden and changed runtime by calling the appropriate API functions, such as i2c_m_sync_set_baudrate.
  • Set I2C bus clock speed

  • Which clock source is used

Driver Implementation Description

After the I2C hardware initialization, the i2c_m_sync_get_io_descriptor function is needed to register an I/O descriptor. Then enable the I2C hardware, and use the i2c_m_sync_set_slaveaddr function to set the slave address. At the end, start the read/write operation.

Example of Usage

The following shows a simple example of using the I2C master. The I2C master must have been initialized by i2c_m_sync_init. This initialization will configure the operation of the I2C master.

Limitations

  • System Management Bus (SMBus) is not supported

  • Power Management Bus (PMBus) is not supported

  • The register value for the requested I2C speed is calculated and placed in the correct register, but not validated if it works correctly with the clock/prescaler settings used for the module. To validate the I2C speed setting use the formula found in the configuration file for the module. Selectable speed is automatically limited within the speed range defined by the I2C mode selected

The example enables the I2C master, and finally starts a writing operation to the slave.
void I2C_0_example(void){    struct io_descriptor *I2C_0_io;    i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);    i2c_m_sync_enable(&I2C_0);    i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN);    io_write(I2C_0_io, (uint8_t *)"Hello World!", 12);}

Dependencies

  • The I2C master peripheral and its related I/O lines and clocks