PSOC E8XXGP Device Support Library

| PSOC E8XXGP Device Support Library

Functions
General
PDL API Reference » SCB (Serial Communication Block) » I2C (SCB) » Functions

## General Description

## Functions
cy_en_scb_i2c_status_t | Cy_SCB_I2C_Init (CySCB_Type *base, cy_stc_scb_i2c_config_t const *config, cy_stc_scb_i2c_context_t *context)
| Initializes the SCB for the I2C operation. More...
void | Cy_SCB_I2C_DeInit (CySCB_Type *base)
| De-initializes the SCB block and returns register values to default. More...
__STATIC_INLINE void | Cy_SCB_I2C_Enable (CySCB_Type *base)
| Enables the SCB block for the I2C operation. More...
void | Cy_SCB_I2C_Disable (CySCB_Type *base, cy_stc_scb_i2c_context_t *context)
| Disables the SCB block and clears context statuses. More...
uint32_t | Cy_SCB_I2C_SetDataRate (CySCB_Type *base, uint32_t dataRateHz, uint32_t scbClockHz)
| Configures the SCB to work at the desired data rate. More...
uint32_t | Cy_SCB_I2C_GetDataRate (CySCB_Type const *base, uint32_t scbClockHz)
| Returns the data rate for the selected SCB block. More...
__STATIC_INLINE void | Cy_SCB_I2C_SlaveSetAddress (CySCB_Type *base, uint8_t addr)
| Sets the slave address for the I2C slave. More...
__STATIC_INLINE uint32_t | Cy_SCB_I2C_SlaveGetAddress (CySCB_Type const *base)
| Returns the slave address of the I2C slave. More...
__STATIC_INLINE void | Cy_SCB_I2C_SlaveSetAddressMask (CySCB_Type *base, uint8_t addrMask)
| Sets the slave address mask for the I2C slave. More...
__STATIC_INLINE uint32_t | Cy_SCB_I2C_SlaveGetAddressMask (CySCB_Type const *base)
| Returns the slave address mask. More...
__STATIC_INLINE bool | Cy_SCB_I2C_IsBusBusy (CySCB_Type const *base)
| Checks whether the I2C bus is busy. More...
__STATIC_INLINE void | Cy_SCB_I2C_MasterSetLowPhaseDutyCycle (CySCB_Type *base, uint32_t clockCycles)
| This function sets the number of SCB clock cycles in the low phase of SCL. More...
__STATIC_INLINE void | Cy_SCB_I2C_MasterSetHighPhaseDutyCycle (CySCB_Type *base, uint32_t clockCycles)
| This function sets the number of SCB clock cycles in the high phase of SCL. More...
void | Cy_SCB_I2C_SetStretchThreshold (CySCB_Type const *base, uint32_t value)
| Sets the stretch threshold value. More...
uint32_t | Cy_SCB_I2C_GetStretchCount (CySCB_Type const *base)
| Provides the stretch count. More...
bool | Cy_SCB_I2C_IsStretchDetected (CySCB_Type const *base)
| Checks if stretch is detected on I2C SCL. More...
bool | Cy_SCB_I2C_IsSyncDetected (CySCB_Type const *base)
| Checks if synchronization is detected on I2C SCL. More...
bool | Cy_SCB_I2C_IsStretching (CySCB_Type const *base)
| Checks if I2C SCL is stretched by the block. More...

## Function Documentation

## ◆ Cy_SCB_I2C_Init()

cy_en_scb_i2c_status_t Cy_SCB_I2C_Init | ( | CySCB_Type * | base,
|  | cy_stc_scb_i2c_config_t const * | config,
|  | cy_stc_scb_i2c_context_t * | context
| ) |  |

Initializes the SCB for the I2C operation.

Parameters

  base | The pointer to the I2C SCB instance.
  config | The pointer to the configuration structure cy_stc_scb_i2c_config_t.
  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.

Returns
  cy_en_scb_i2c_status_t

Note
  If SCB is already enabled, ensure that the SCB block is disabled Cy_SCB_I2C_Disable before calling this function.

## ◆ Cy_SCB_I2C_DeInit()

void Cy_SCB_I2C_DeInit | ( | CySCB_Type * | base | ) |

De-initializes the SCB block and returns register values to default.

Parameters

  base | The pointer to the I2C SCB instance.

Note
  Ensure that the SCB block is disabled Cy_SCB_I2C_Disable before calling this function.

## ◆ Cy_SCB_I2C_Enable()

__STATIC_INLINE void Cy_SCB_I2C_Enable | ( | CySCB_Type * | base | ) |

Enables the SCB block for the I2C operation.

Parameters

  base | The pointer to the I2C SCB instance.

Note
  Ensure SCB is initialized with Cy_SCB_I2C_Init before calling this function

## ◆ Cy_SCB_I2C_Disable()

void Cy_SCB_I2C_Disable | ( | CySCB_Type * | base,
|  | cy_stc_scb_i2c_context_t * | context
| ) |  |

Disables the SCB block and clears context statuses.

Note that after the block is disabled, the TX and RX FIFOs and hardware statuses are cleared. Also, the hardware stops driving the output and ignores the input.

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.

Note
  Calling this function when I2C is busy (master preforms transaction or slave was addressed and is communicating with master) may cause transaction corruption because the hardware stops driving the outputs and ignores the inputs. Ensure that I2C is not busy before calling this function.

## ◆ Cy_SCB_I2C_SetDataRate()

uint32_t Cy_SCB_I2C_SetDataRate | ( | CySCB_Type * | base,
|  | uint32_t | dataRateHz,
|  | uint32_t | scbClockHz
| ) |  |

Configures the SCB to work at the desired data rate.

Parameters

  base | The pointer to the I2C SCB instance.
  dataRateHz | The desired data Rate in Hz.
  scbClockHz | The frequency of the clock connected to the SCB in Hz.

Returns
  The achieved data rate in Hz.
  When zero value is returned there is an error in the input parameters: data rate or clk_scb is out of valid range.

Note
  This function does not change the values of the clock divider connected to the SCB, it changes only the SCB clock oversample registers. If this function is not able to achieve the desired data rate, then the clock divider must be adjusted. Call this function only while the SCB is disabled. For the slave, this function only checks that the attached clock is fast enough to meet the desired data rate. It does not change any registers.

## ◆ Cy_SCB_I2C_GetDataRate()

uint32_t Cy_SCB_I2C_GetDataRate | ( | CySCB_Type const * | base,
|  | uint32_t | scbClockHz
| ) |  |

Returns the data rate for the selected SCB block.

Parameters

  base | The pointer to the I2C SCB instance.
  scbClockHz | The frequency of the clock connected to the SCB in Hz.

Returns
  The data rate in Hz.
  For slave mode when zero value is returned the clk_scb is out of valid range.

## ◆ Cy_SCB_I2C_SlaveSetAddress()

__STATIC_INLINE void Cy_SCB_I2C_SlaveSetAddress | ( | CySCB_Type * | base,
|  | uint8_t | addr
| ) |  |

Sets the slave address for the I2C slave.

Parameters

  base | The pointer to the I2C SCB instance.
  addr | The 7-bit right justified slave address.

## ◆ Cy_SCB_I2C_SlaveGetAddress()

__STATIC_INLINE uint32_t Cy_SCB_I2C_SlaveGetAddress | ( | CySCB_Type const * | base | ) |

Returns the slave address of the I2C slave.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  The 7-bit right justified slave address.

## ◆ Cy_SCB_I2C_SlaveSetAddressMask()

__STATIC_INLINE void Cy_SCB_I2C_SlaveSetAddressMask | ( | CySCB_Type * | base,
|  | uint8_t | addrMask
| ) |  |

Sets the slave address mask for the I2C slave.

The LSBit must always be 0. In all other bit positions a 1 indicates that the incoming address must match the corresponding bit in the slave address. A 0 in the mask means that the incoming address does not need to match. Example Slave Address = 0x0C. Slave Address Mask = 0x08. This means that the hardware will accept both 0x08 and 0x0C as valid addresses.

Parameters

  base | The pointer to the I2C SCB instance.
  addrMask | The 8-bit address mask, the upper 7 bits correspond to the slave address. LSBit must always be 0.

## ◆ Cy_SCB_I2C_SlaveGetAddressMask()

__STATIC_INLINE uint32_t Cy_SCB_I2C_SlaveGetAddressMask | ( | CySCB_Type const * | base | ) |

Returns the slave address mask.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  The 8-bit address mask, the upper 7 bits correspond to the slave address. LSBit must always be 0.

## ◆ Cy_SCB_I2C_IsBusBusy()

__STATIC_INLINE bool Cy_SCB_I2C_IsBusBusy | ( | CySCB_Type const * | base | ) |

Checks whether the I2C bus is busy.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  A bus status: busy or not busy.

Note
  After the SCB block is enabled or reset, the valid bus busy-status returns after half of the SCL period.

## ◆ Cy_SCB_I2C_MasterSetLowPhaseDutyCycle()

__STATIC_INLINE void Cy_SCB_I2C_MasterSetLowPhaseDutyCycle | ( | CySCB_Type * | base,
|  | uint32_t | clockCycles
| ) |  |

This function sets the number of SCB clock cycles in the low phase of SCL.

If Cy_SCB_I2C_SetDataRate is called after this function, the values specified in this function are overwritten.

Parameters

  base | The pointer to the I2C SCB instance.
  clockCycles | The number of SCB clock cycles in the low phase of SCL. The valid range is 7 to 16.

Note
  This function should be used at your own risk. Changing the number of clock cycles in a phase of SCL may violate the I2C specification. Make this change only while the block is disabled.

Please refer to the section group_scb_i2c_mclk_sync for more information.

## ◆ Cy_SCB_I2C_MasterSetHighPhaseDutyCycle()

__STATIC_INLINE void Cy_SCB_I2C_MasterSetHighPhaseDutyCycle | ( | CySCB_Type * | base,
|  | uint32_t | clockCycles
| ) |  |

This function sets the number of SCB clock cycles in the high phase of SCL.

If Cy_SCB_I2C_SetDataRate is called after this function, the values specified in this function get overwritten.

Parameters

  base | The pointer to the I2C SCB instance.
  clockCycles | The number of SCB clock cycles in the high phase of SCL. The valid range is 5 to 16.

Note
  This function should be used at your own risk. Changing the number of clock cycles in a phase of SCL may violate the I2C specification. Make this change only while the block is disabled.

## ◆ Cy_SCB_I2C_SetStretchThreshold()

void Cy_SCB_I2C_SetStretchThreshold | ( | CySCB_Type const * | base,
|  | uint32_t | value
| ) |  |

Sets the stretch threshold value.

Parameters

  base | The pointer to the I2C SCB instance.
  value | The stretch threshold value to be set. Typically it is the SCL turaround delay (including IO cell delay, SCL rise time, analog filter delay), in number of clk_scb cycles.

Note
  - The STRETCH_THRESHOLD value is 0 by default. If there is no device stretching the SCL bus, the delay between SCL output and input are reported in STRETCH_COUNT Cy_SCB_I2C_GetStretchCount, in number of clk_scb cycles, which can then be set as the STRETCH_THRESHOLD value.
  - The STRETCH_THRESHOLD value should be less than or equal to 0xFUL.
  - When STRETCH_COUNT Cy_SCB_I2C_GetStretchCount is higher than this STRETCH_THRESHOLD, STRETCH_DETECTED Cy_SCB_I2C_IsStretchDetected will be set.

## ◆ Cy_SCB_I2C_GetStretchCount()

uint32_t Cy_SCB_I2C_GetStretchCount | ( | CySCB_Type const * | base | ) |

Provides the stretch count.

The count is started when the I2C device begins to drive high phase on internal SCL output signal and is stalled when it detects high level on SCL input signal.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  The stretch count.

## ◆ Cy_SCB_I2C_IsStretchDetected()

bool Cy_SCB_I2C_IsStretchDetected | ( | CySCB_Type const * | base | ) |

Checks if stretch is detected on I2C SCL.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  If true, stretch is detected; false otherwise.

## ◆ Cy_SCB_I2C_IsSyncDetected()

bool Cy_SCB_I2C_IsSyncDetected | ( | CySCB_Type const * | base | ) |

Checks if synchronization is detected on I2C SCL.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  If true, synchronization is detected; false otherwise.

## ◆ Cy_SCB_I2C_IsStretching()

bool Cy_SCB_I2C_IsStretching | ( | CySCB_Type const * | base | ) |

Checks if I2C SCL is stretched by the block.

Parameters

  base | The pointer to the I2C SCB instance.

Returns
  If true, I2C SCL is being stretch by the block, false otherwise.