Slave

group group_scb_i2c_slave_functions

Functions

void Cy_SCB_I2C_SlaveConfigReadBuf(CySCB_Type const *base, uint8_t *buffer, uint32_t size, cy_stc_scb_i2c_context_t *context)

Configures the buffer pointer and the read buffer size.

This is the buffer from which the master reads data. After this function is called, data transfer from the read buffer to the master is handled by Cy_SCB_I2C_Interrupt.

When the Read transaction is completed (master generated Stop, ReStart or error occurred), the CY_SCB_I2C_SLAVE_RD_BUSY status is cleared and the CY_SCB_I2C_SLAVE_RD_CMPLT is set. Also the CY_SCB_I2C_SLAVE_RD_CMPLT_EVENT event is generated.

note

  • The Read buffer must not be modified and stay allocated until it has been read by the master.

  • If this function has not been called, and the master tries to read data from the slave a CY_SCB_I2C_DEFAULT_TX is returned to the master.

  • If the master tries to read more bytes than available in the Read buffer, a CY_SCB_I2C_SLAVE_RD_BUF_EMPTY_EVENT event occurs. The CY_SCB_I2C_DEFAULT_TX is returned to the master if the buffer remains empty after an event notification.

Parameters
  • base: The pointer to the I2C SCB instance.

  • buffer: The pointer to the buffer with data to be read by the master.

  • size: Size of the buffer.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

void Cy_SCB_I2C_SlaveAbortRead(CySCB_Type *base, cy_stc_scb_i2c_context_t *context)

Aborts the configured slave read buffer to be read by the master.

If the master reads and “abort operation” is requested, the CY_SCB_I2C_SLAVE_RD_BUF_EMPTY_EVENT event occurs. The CY_SCB_I2C_DEFAULT_TX is returned to the master if the buffer remains empty after the event notification.

Side Effects

If the TX FIFO is used, this function clears it. The TX FIFO clear operation also clears the shift register, thus the shifter can be cleared in the middle of a data element transfer, corrupting it. The data element corruption means that all bits that have not been transmitted are transmitted as “ones” on the bus.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

void Cy_SCB_I2C_SlaveConfigWriteBuf(CySCB_Type const *base, uint8_t *buffer, uint32_t size, cy_stc_scb_i2c_context_t *context)

Configures the buffer pointer and size of the write buffer.

This is the buffer that the master writes data to. After this function is called data transfer from the master into the write buffer is handled by Cy_SCB_I2C_Interrupt.

When write transaction is completed (master generated Stop, ReStart or error occurred) the CY_SCB_I2C_SLAVE_WR_BUSY status is cleared and the CY_SCB_I2C_SLAVE_WR_CMPLT is set, also the CY_SCB_I2C_SLAVE_WR_CMPLT_EVENT event is generated.

note

  • The write buffer must not be modified and must stay allocated until it has been written by the master.

  • If this function has not been called and the master tries to write data, the first byte is NAKed and discarded.

  • If the master writes more bytes than the slave can store in the write buffer, the CY_SCB_I2C_SLAVE_WR_OVRFL status is set and the slave will NACK last byte, unless the RX FIFO is used. Then the slave will NAK only after RX FIFO becomes full.

  • If the RX FIFO is used, the minimum write buffer size is automatically the size of the RX FIFO. If a write buffer is less than the RX FIFO size, extra bytes are ACKed and stored into RX FIFO but ignored by firmware.

Parameters
  • base: The pointer to the I2C SCB instance.

  • buffer: The pointer to buffer to store data written by the master.

  • size: Size of the buffer.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

void Cy_SCB_I2C_SlaveAbortWrite(CySCB_Type *base, cy_stc_scb_i2c_context_t *context)

Aborts the configured slave write buffer to be written by the master.

If master writes and an “abort operation” is requested, the next incoming byte will be NAKed.

note

If the RX FIFO is used, the NAK will not be sent until RX FIFO becomes full, however bytes accepted after an abort request are ignored.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_I2C_SlaveGetStatus(CySCB_Type const *base, cy_stc_scb_i2c_context_t const *context)

Returns the current I2C slave status.

This status is a bit mask and the value returned may have multiple bits set.

Return

I2C Slave Status.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_I2C_SlaveClearReadStatus(CySCB_Type const *base, cy_stc_scb_i2c_context_t *context)

Clears the read status and error conditions flags and returns their values.

note

The CY_SCB_I2C_SLAVE_RD_BUSY flag is not cleared.

Return

I2C Slave Status.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_I2C_SlaveClearWriteStatus(CySCB_Type const *base, cy_stc_scb_i2c_context_t *context)

Clears the write status flags and error condition flags and returns their values.

note

The CY_SCB_I2C_SLAVE_WR_BUSY flag is not cleared.

Return

I2C Slave Status.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_I2C_SlaveGetReadTransferCount(CySCB_Type const *base, cy_stc_scb_i2c_context_t const *context)

Returns the number of bytes read by the master since the last time Cy_SCB_I2C_SlaveConfigReadBuf was called.

note

  • This function returns an invalid value if a read transaction was aborted or any listed event occurs during the transaction: CY_SCB_I2C_SLAVE_ARB_LOST, CY_SCB_I2C_SLAVE_BUS_ERR.

  • This number is updated only when a transaction completes, either through an error or successfully.

Return

The number of bytes read by the master.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.

uint32_t Cy_SCB_I2C_SlaveGetWriteTransferCount(CySCB_Type const *base, cy_stc_scb_i2c_context_t const *context)

Returns the number of bytes written by the master since the last time Cy_SCB_I2C_SlaveConfigWriteBuf was called.

note

  • This function returns an invalid value if write transaction was aborted or any listed event occurs during the transaction: CY_SCB_I2C_SLAVE_ARB_LOST, CY_SCB_I2C_SLAVE_BUS_ERR.

  • This number is updated only when the transaction completes, either through an error or successfully.

Return

Number of bytes written by the master.

Parameters
  • base: The pointer to the I2C SCB instance.

  • context: The pointer to the context structure cy_stc_scb_i2c_context_t allocated by the user. The structure is used during the I2C operation for internal configuration and data retention. The user must not modify anything in this structure.