i2c_master_v2 i2c_slave_v2
API Reference Manual  /  4 Model-to-Model Interfaces  / 

i2c_slave

Description
SIM_INTERFACE(i2c_slave) {
        void (*start_request)(conf_object_t *device, uint32 address);
        void (*read_request)(conf_object_t *device);
        void (*ack_read_request)(conf_object_t *device, i2c_status_t ack);
        void (*write_request)(conf_object_t *device, uint8 value);
        void (*stop)(conf_object_t *device, uint8 repeated_start);
};

#define I2C_SLAVE_INTERFACE "i2c_slave"

The i2c_slave interface is implemented by devices that may act as slaves on an I2C link. The start_request function is called by the I2C link to start a transaction. Bits 7 down to 1 of the address parameter are the address of the slave, and bit 0 is the write bit. The started transaction is a write transaction if the write bit is 0, and a read transaction otherwise. The I2C slave device accepts the transaction by calling the start_response function in the I2C link. The transaction consists of a number of calls to write_request (or read_request, depending on the write bit). The slave responds to each of these with a call to write_response (or read_response) in the I2C link. The ack_read_request function is called by the I2C link as response to the read_response function. The transfer can end in three ways:

  1. If a stop condition occurs (i.e., a master calls stop), stop(0) is called in the slave device.
  2. If a repeated start condition occurs, with the same device as slave, then the start message is relayed to the slave device as usual, and the first transmission is ended by this new call to the slave's start_request function.
  3. If a repeated start condition occurs, with a different device as slave, then the first transmission is ended by a stop(1) call in the first slave device.

Note that a call to stop doesn't necessarily represent an I2C stop condition: If the repeated_start parameter is 1, the call actually represents an I2C start condition, whose effect is similar to that of a stop condition.

Note that a call to ack_read_request always is followed by a call to read_request if ack is I2C_status_success, or by a call to either stop or start_request if ack is I2C_status_noack. Moreover, the interface calls to an i2c slave device always follow the regular expression (((R(ra)*rA)|(Ww*))+P)*, where R and W are calls to start_request with odd and even addresses, respectively; r is read_request; w is write_request; a and A are ack_read_request calls with ack set to I2C_status_success and I2C_status_noack, respectively; and P is a call to stop.

See the description for the i2c_link interface for more information how to call the *_response functions.

Execution Context
Cell Context for all methods.

i2c_master_v2 i2c_slave_v2