I2C#
Modules#
Enumerations#
Enumeration for I2C bus speed.
Enumeration for I2C mode i.e., leader/follower.
Typedefs#
Renaming the I2C register set.
Functions#
Initialize the I2C i.e., set the parameters to the respective registers.
Reset the I2C peripheral.
Transmit one byte on SDA line.
Receive one byte on SDA line.
Configure the frequency of the I2C transmission.
Fetch the frequency of I2C peripheral clock.
Get the release, sqa and dev version of I2C.
Enable the I2C interface.
Disable the I2C interface.
Hold the SCL line low and stalls the leader until new command is available in TX FIFO.
Issue the STOP after completion of transfer irrespective of TX FIFO status.
Get the I2C IC status.
Disable the I2C interrupts.
Enable the I2C interrupts.
Set the interrupts i.e., unmask according to the flags passed in the parameter.
Clear the interrupts i.e., mask according to the flags passed in the parameter.
Get the pending interrupts.
Get the enabled interrupts.
Get the enabled and pending interrupts.
Wait till the process is completed.
Wait till the synchronization is completed.
Set the follower address when I2C is in leader mode.
Fetch the current follower address.
Update the address of leader when it is in follower mode.
Fetch the masked follower address i.e.
Generate NACK only when it is in follower-receiver mode.
Abort the transfer.
Clear the I2C bus.
Update the RX threshold values.
Update the TX threshold values.
Control the direction of the I2C interface.
Configure the SDA hold time.
Macros#
Macro function to assert the I2C instance.
Macro to validate I2C instance number.
Macro function to validate the user input and I2C instance.
I2C enable mask.
I2C write mask.
I2C read mask.
I2C clear mask.
SCL stuck timeout, used to clear the I2C bus.
SDA stick timeout, used to clear the I2C bus.
16 bit mask value
8 bit mask value
4 bit mask value
DMA enable.
DMA disable.
If processor attempts to read receive buffer when buffer is empty.
If receive buffer is full and another byte is received (extra bytes are lost)
When receive buffer is full up to the RX_TL threshold level.
If transmit buffer is full and user attempts to transmit another byte.
When transmit buffer is filled over the TX_TL threshold level.
SCL is on hold in follower mode when another leader attempts to read data.
Transmit is aborted, to validate the reason, read IC_TX_ABRT_SOURCE register.
In follower mode if leader does not acknowledge, happens on last byte.
Ongoing or previous activity was there on bus, to clear read IC_CLR_INTR / IC_CLR_ACTIVITY register.
Stop condition is detected on the bus (leader and follower both mode)
Start or Restart condition is detected on the bus (leader and follower both mode)
General call address is received, to clear read IC_CLR_GEN_CALL register.
Restart condition is detected on bus (follower mode)
Leader is holding the bus and FIFO is empty.
SCL line is stuck at low.
Address sent was not acknowledged by follower in 7-bit mode.
First 10-bit address byte sent was not acknowledged by follower.
Second 10-bit address byte sent was not acknowledged by follower.
Received acknowledgement for address bu did not receive acknowledgement for data.
No follower acknowledged General call.
Leader send general call but program was to read it from bus.
High speed leader call was acknowledged by follower.
Start byte was acknowledged by follower.
Restart is disabled and data transfer is in high speed mode.
Restart is disabled and user tries to send start byte.
Restart is disabled and 10-bit address read command is received.
Leader mode is disabled and leader mode operation is preformed.
Leader has lost arbitration.
Follower flushes old TX FIFO to respond new read command.
Follower lost the bus.
Follower requests for data and user writes 1 in CMD register.
Leader has detected transfer abort.
SDA is stuck at low.
No acknowledgement for Device ID transfer by leader.
No acknowledgement for follower address to leader.
Leader sends device ID transfer and TX FIFO has write command.
'OR' of Leader and Follower activity
Transmit FIFO is not full.
Transmit FIFO is completely empty.
Receive FIFO is not empty.
Receive FIFO is completely full.
Leader is not in idle state.
Follower is not in idle state.
Leader holds SCL as previous command did not have a STOP bit.
Leader holds SCL as RX FIFO is full and additional byte is received.
Follower holds SCL to request read data when TX FIFO is empty.
Follower holds SCL as RX FIFO is full and additional byte is received.
SDA is stuck at low and has not recovered.
Enumeration Documentation#
sl_i2c_clock_hlr_t#
sl_i2c_clock_hlr_t
Enumeration for I2C bus speed.
Enumerator | |
---|---|
SL_I2C_STANDARD_BUS_SPEED | Standard bus speed, 100 Kbps. |
SL_I2C_FAST_BUS_SPEED | Fast bus speed, 400 Kbps. |
SL_I2C_HIGH_BUS_SPEED | High bus speed, 3.4 Mbps. |
SL_I2C_FAST_PLUS_BUS_SPEED | Fast plus bus speed, 1 Mbps. |
sl_i2c_direction_t#
sl_i2c_direction_t
Enumeration for I2C direction i.e., read/write.
Enumerator | |
---|---|
SL_I2C_WRITE | I2C write operation mask. |
SL_I2C_READ | I2C read operation mask. |
sl_i2c_mode_t#
sl_i2c_mode_t
Enumeration for I2C mode i.e., leader/follower.
Enumerator | |
---|---|
SL_I2C_LEADER_MODE | I2C Leader mode. |
SL_I2C_FOLLOWER_MODE | I2C Follower mode. |
Function Documentation#
sl_si91x_i2c_init#
void sl_si91x_i2c_init (I2C_TypeDef * i2c, const sl_i2c_init_params_t * p_config)
Initialize the I2C i.e., set the parameters to the respective registers.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
const sl_i2c_init_params_t * | [in] | p_config | (sl_i2c_init_params_t) Pointer to the initialization parameters structure. |
It needs to be called at the beginning of the code. It sets the frequency as per the input given in freq_scl and chlr. It accepts the following members for initialization parameters:
mode (Leader/Follower) sl_i2c_mode_t.
freq_scl (I2C SCL frequency).
chlr (Bus Speed) sl_i2c_clock_hlr_t.
address (Follower address).
is_10bit_addr (pass true if address is of 10 bit).
Returns
none
sl_si91x_i2c_reset#
void sl_si91x_i2c_reset (I2C_TypeDef * i2c)
Reset the I2C peripheral.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It resets the initialization parameters to zero and clears all the interrupts. It resets the target and slave addresses.
Returns
none
sl_si91x_i2c_tx#
void sl_si91x_i2c_tx (I2C_TypeDef * i2c, uint8_t data)
Transmit one byte on SDA line.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint8_t | [in] | data | (uint8_t) Data that needs to be transmitted via I2C bus. |
Threshold needs to be set before calling this API sl_si91x_i2c_set_tx_threshold. Direction needs to be selected before calling this API sl_si91x_i2c_control_direction.
sl_si91x_i2c_init(); sl_si91x_i2c_set_tx_threshold(); sl_si91x_i2c_control_direction(); sl_si91x_i2c_enable();
Returns
none
sl_si91x_i2c_rx#
uint8_t sl_si91x_i2c_rx (I2C_TypeDef * i2c)
Receive one byte on SDA line.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
Threshold needs to be set before calling this API sl_si91x_i2c_set_rx_threshold. Direction needs to be selected before calling this API sl_si91x_i2c_control_direction.
sl_si91x_i2c_init(); sl_si91x_i2c_set_rx_threshold(); sl_si91x_i2c_control_direction(); sl_si91x_i2c_enable();
Returns
data (uint8_t) Data that is received on the I2C bus.
sl_si91x_i2c_set_frequency#
void sl_si91x_i2c_set_frequency (I2C_TypeDef * i2c, uint32_t ref_freq, uint32_t freq_scl, sl_i2c_clock_hlr_t clhr)
Configure the frequency of the I2C transmission.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint32_t | [in] | ref_freq | (uint32_t) SCL frequency. |
uint32_t | [in] | freq_scl | (sl_i2c_clock_hlr_t) Bus speed for I2C. |
sl_i2c_clock_hlr_t | N/A | clhr |
This API is called inside sl_si91x_i2c_init, but can be called separately to change the frequency. According the input of freq_scl frequency is calculated and filled in the register appropriately as the speed selected in chlr. The accepted parameters for chlr are: sl_i2c_clock_hlr_t.
SL_I2C_STANDARD_BUS_SPEED = 1, ///< Standard bus speed, 100 Kbps
SL_I2C_FAST_BUS_SPEED, ///< Fast bus speed, 400 Kbps
SL_I2C_FAST_PLUS_BUS_SPEED, ///< Fast plus bus speed, 1 Mbps
SL_I2C_HIGH_BUS_SPEED, ///< High bus speed, 3.4 Mbps
Returns
none
sl_si91x_i2c_get_frequency#
uint32_t sl_si91x_i2c_get_frequency (I2C_TypeDef * i2c)
Fetch the frequency of I2C peripheral clock.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It returns uint32_t value of the SystemCoreClock frequency.
Returns
frequency (uint32_t) The frequency of the System.
sl_si91x_i2c_get_version#
sl_i2c_version_t sl_si91x_i2c_get_version (void )
Get the release, sqa and dev version of I2C.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | [in] |
Returns
(sl_i2c_version_t) type structure
sl_si91x_i2c_enable#
__STATIC_INLINE void sl_si91x_i2c_enable (I2C_TypeDef * i2c)
Enable the I2C interface.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address |
It sets the register bit which enabled the I2C interface.
Returns
none
sl_si91x_i2c_disable#
__STATIC_INLINE void sl_si91x_i2c_disable (I2C_TypeDef * i2c)
Disable the I2C interface.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It clears the register bit which enabled the I2C interface.
Returns
none
sl_si91x_i2c_start_cmd#
__STATIC_INLINE void sl_si91x_i2c_start_cmd (I2C_TypeDef * i2c)
Hold the SCL line low and stalls the leader until new command is available in TX FIFO.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
STOP condition is not issued after completion of transfer irrespective of TX FIFO status.
Returns
none
sl_si91x_i2c_stop_cmd#
__STATIC_INLINE void sl_si91x_i2c_stop_cmd (I2C_TypeDef * i2c)
Issue the STOP after completion of transfer irrespective of TX FIFO status.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
If TX FIFO has data, leader sends start byte and starts the transmission.
Returns
none
sl_si91x_i2c_get_status#
__STATIC_INLINE uint32_t sl_si91x_i2c_get_status (I2C_TypeDef * i2c)
Get the I2C IC status.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
The bits of status are set according to the events. The macros are written in this file that can be directly used to mask the value of this register.
Returns
none
sl_si91x_i2c_disable_interrupts#
__STATIC_INLINE void sl_si91x_i2c_disable_interrupts (I2C_TypeDef * i2c, uint32_t flags)
Disable the I2C interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint32_t | N/A | flags |
It is mandatory to disable interrupts before configuring the I2C parameters.
Returns
none
sl_si91x_i2c_enable_interrupts#
__STATIC_INLINE void sl_si91x_i2c_enable_interrupts (I2C_TypeDef * i2c, uint32_t flags)
Enable the I2C interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint32_t | N/A | flags |
Returns
none
sl_si91x_i2c_set_interrupts#
__STATIC_INLINE void sl_si91x_i2c_set_interrupts (I2C_TypeDef * i2c, uint32_t flags)
Set the interrupts i.e., unmask according to the flags passed in the parameter.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint32_t | [in] | flags | (uint32_t) Interrupt flags which needs to be unmasked. |
Returns
none
sl_si91x_i2c_clear_interrupts#
__STATIC_INLINE void sl_si91x_i2c_clear_interrupts (I2C_TypeDef * i2c, uint32_t flags)
Clear the interrupts i.e., mask according to the flags passed in the parameter.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint32_t | [in] | flags | (uint32_t) Interrupt flags which needs to be masked. |
Returns
none
sl_si91x_i2c_get_pending_interrupts#
__STATIC_INLINE uint32_t sl_si91x_i2c_get_pending_interrupts (I2C_TypeDef * i2c)
Get the pending interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It returns the uint32_t type interrupt status register. The macros are written in this file that can be directly used to mask the value of this register.
Returns
status (uint32_t) Interrupts which are pending.
sl_si91x_i2c_get_enabled_interrupts#
__STATIC_INLINE uint32_t sl_si91x_i2c_get_enabled_interrupts (I2C_TypeDef * i2c)
Get the enabled interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It returns the uint32_t type interrupt mask register. The macros are written in this file that can be directly used to mask the value of this register.
Returns
status (uint32_t) Interrupts which are unmasked.
sl_si91x_i2c_get_enabled_pending_interrupts#
__STATIC_INLINE uint32_t sl_si91x_i2c_get_enabled_pending_interrupts (I2C_TypeDef * i2c)
Get the enabled and pending interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It returns the uint32_t type value which is bitwise end of enabled interrupts and pending interrupts. The macros are written in this file that can be directly used to mask the value of this register.
Returns
status (uint32_t) Interrupts which are unmasked and pending.
sl_si91x_i2c_wait_ready#
__STATIC_INLINE void sl_si91x_i2c_wait_ready (I2C_TypeDef * i2c, uint32_t mask)
Wait till the process is completed.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint32_t | [in] | mask | (uint32_t) Interrupt mask for that it waits. |
Mask takes the interrupt flags and waits until it is triggered. Interrupt is cleared once it is triggered.
Returns
none
sl_si91x_i2c_wait_sync#
__STATIC_INLINE void sl_si91x_i2c_wait_sync (I2C_TypeDef * i2c)
Wait till the synchronization is completed.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It checks whether the I2C interface is enabled and the bus is free i.e., no activity is pending on the bus.
Returns
none
sl_si91x_i2c_set_follower_address#
__STATIC_INLINE void sl_si91x_i2c_set_follower_address (I2C_TypeDef * i2c, uint16_t addr, bool is_10bit_addr)
Set the follower address when I2C is in leader mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint16_t | [in] | addr | (uint16_t) Follower address. |
bool | [in] | is_10bit_addr | (bool) boolean value for the 10 bit address. |
It validates the is_10bit_addr parameter and sets the 10 bit address register. It updates the register of follower address with the value passed in the parameter. This API is called in sl_si91x_i2c_init function sl_si91x_i2c_init It can also be called separately from to update the follower address.
Returns
none
sl_si91x_i2c_get_follower_address#
__STATIC_INLINE uint16_t sl_si91x_i2c_get_follower_address (I2C_TypeDef * i2c)
Fetch the current follower address.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It returns uint8_t value as the current follower address.
Returns
address(uint8_t) address of the follower.
sl_si91x_i2c_set_follower_mask_address#
__STATIC_INLINE void sl_si91x_i2c_set_follower_mask_address (I2C_TypeDef * i2c, uint16_t mask)
Update the address of leader when it is in follower mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint16_t | N/A | mask |
It updates the register of follower address with the value passed in the parameter. This API is called in sl_si91x_i2c_init function sl_si91x_i2c_init It can also be called separately from to update the address.
Returns
none
sl_si91x_i2c_get_follower_mask_address#
__STATIC_INLINE uint16_t sl_si91x_i2c_get_follower_mask_address (I2C_TypeDef * i2c)
Fetch the masked follower address i.e.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
leader address when it is in follower mode. It returns uint8_t value as the current masked follower address.
Returns
address(uint8_t) leader's address when it is in follower mode
sl_si91x_i2c_send_nack#
__STATIC_INLINE void sl_si91x_i2c_send_nack (I2C_TypeDef * i2c)
Generate NACK only when it is in follower-receiver mode.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address |
It generates NACK after a byte is received and the transfer will be aborted.
sl_si91x_i2c_enable(); sl_si91x_i2c_inti();
Returns
none
sl_si91x_i2c_abort_transfer#
__STATIC_INLINE void sl_si91x_i2c_abort_transfer (I2C_TypeDef * i2c)
Abort the transfer.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It disables the interrupts, I2C interface and waits till the abort is completed. Abort issues the stop condition and flushes the TX FIFO and sets the SL_I2C_EVENT_TRANSMIT_ABORT interrupt after the operation is completed. For abort it is necessary to keep to I2C instance in enable mode.
Returns
none
sl_si91x_i2c_clear_bus#
__STATIC_INLINE void sl_si91x_i2c_clear_bus (I2C_TypeDef * i2c)
Clear the I2C bus.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
It disables the I2C interface, loads the SCL and SDA timeout values and again enabled the I2C interface.
Returns
none
sl_si91x_i2c_set_rx_threshold#
__STATIC_INLINE void sl_si91x_i2c_set_rx_threshold (I2C_TypeDef * i2c, uint8_t threshold)
Update the RX threshold values.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint8_t | [in] | threshold | (uint8_t) Threshold value which need to be filled in FIFO. |
Returns
none
sl_si91x_i2c_set_tx_threshold#
__STATIC_INLINE void sl_si91x_i2c_set_tx_threshold (I2C_TypeDef * i2c, uint8_t threshold)
Update the TX threshold values.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
uint8_t | [in] | threshold | (uint8_t) Threshold value which need to be filled in FIFO. |
Returns
none
sl_si91x_i2c_control_direction#
__STATIC_INLINE void sl_si91x_i2c_control_direction (I2C_TypeDef * i2c, sl_i2c_direction_t direction)
Control the direction of the I2C interface.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
sl_i2c_direction_t | [in] | direction | (sl_i2c_direction_t) I2C direction for operation.
|
It updates the register with the read mask / write mask value sl_i2c_direction_t
Note
I2C instance should be enabled before calling this API.
Returns
none
sl_si91x_i2c_set_sda_hold_time#
__STATIC_INLINE void sl_si91x_i2c_set_sda_hold_time (I2C_TypeDef * i2c, sl_i2c_direction_t direction, uint32_t time)
Configure the SDA hold time.
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address. |
sl_i2c_direction_t | [in] | direction | (sl_i2c_direction_t) C direction for operation.
|
uint32_t | [in] | time | Time which needs to be filled in the SDA hold register. |
According to the direction sl_i2c_direction_t, it updates the registers with the time value which is passed as the function parameter. It holds the SDA in the units of clock period.
Returns
none
sl_si91x_i2c_send_ack#
__STATIC_INLINE void sl_si91x_i2c_send_ack (I2C_TypeDef * i2c, p_config)
Type | Direction | Argument Name | Description |
---|---|---|---|
I2C_TypeDef * | [in] | i2c | (I2C_TypeDef) Pointer to the I2C instance base address |
[in] | p_config | (sl_i2c_init_params_t) Pointer to the initialization parameters structure |
Returns
none