I2C API I2C Slave Mode Transmit/Receive

In slave mode, polled routines are intended for testing purposes. It is up to the user to decide whether to use the polled or interrupt driven mode. While operating the Slave driver in polled mode can be useful for program development and debugging, most applications will need the interrupt-driven versions of Slave Receive and Transmit in the final software.

The following routines are polled routines:

	err_code i2c_slave_receive_poll(I2C_HANDLE_T*,I2C_PARAM*, I2C_RESULT*)-->
	err_code i2c_slave_transmit_poll(I2C_HANDLE_T*,I2C_PARAM*, I2C_RESULT*)-->

The following routines are interrupt driven routines:

	err_code i2c_slave_receive_intr(I2C_HANDLE_T*,I2C_PARAM*, I2C_RESULT*)-->
	err_code i2c_slave_transmit_intr(I2C_HANDLE_T*,I2C_PARAM*, I2C_RESULT*)-->


To initiate a master-mode write/read the I2C_PARAM has to be setup. The I2C_PARAM is a structure with various variables needed by the I2C ROM Driver to operate correctly. The structure contains the following:

  • Number of bytes to be transmitted.
  • Number of bytes to be received.
  • Pointer to the transmit buffer.
  • Pointer to the receive buffer.
  • Pointer to callback function.
  • Stop flag.

The RESULT structure contains the results after the function executes. The structure contains the following:

  • Number of bytes transmitted.
  • Number of bytes received.
Note: The number of bytes transmitted is updated only for i2c_slave_send_poll() and i2c_slave_send_intr(). The number of bytes received is updated only for i2c_slave_receive_poll() and i2c_slave_receive_intr().

To initiate a slave mode communication, the receive function is called. This can be either the polling or interrupt driven function, i2c_slave_receive_poll() or i2c_slave_receive_intr(), respectively. The receive buffer should be as large or larger than any data or command that will be received. If the amount of data exceed the receive buffer size, an error code will be returned.

In slave-receive mode, the driver receives data until one of the following are true:

  • Address matching set in the set_slave_addr() function with the R/W bit set to 1
  • STOP or repeated START is received
  • An error condition is detected

When using the interrupt function calls, the callback functions must be define. Upon the completion of a read/write as specified by the PARAM structure, the callback functions will be invoked.