PAN1080 Peripheral API
Modules | Data Structures | Macros | Functions
I2c Interface

I2c Interface. More...

Collaboration diagram for I2c Interface:

Modules

 I2c rx threshold level
 I2c receive fifo threshold level.
 
 I2c tx transmit level
 I2c transmit fifo threshold level.
 
 I2c interrupts
 I2c raw interrupts flag.
 
 I2c state
 I2c device and fifo state flag.
 

Data Structures

struct  I2C_InitTypeDef
 Structure with i2c init feature. More...
 

Macros

#define PAN_I2C_MODE_MASTER   ((uint16_t)0x0021)
 
#define PAN_I2C_MODE_SLAVE   ((uint16_t)0x0000)
 
#define IS_I2C_MODE(MODE)
 
#define I2C_SPEED_STANDARD_MODE   (uint16_t)(0x0002)
 
#define I2C_SPEED_FAST_MODE   (uint16_t)(0x0004)
 
#define I2C_SPEED_HIGH_MODE   (uint16_t)(0x0006)
 
#define I2C_DutyCycle_16_9   ((uint16_t)0x4000)
 
#define I2C_DutyCycle_2   ((uint16_t)0xBFFF)
 
#define IS_I2C_DUTY_CYCLE(CYCLE)
 
#define I2C_AcknowledgedAddress_7bit   ((uint16_t)0x4000)
 
#define I2C_AcknowledgedAddress_10bit   ((uint16_t)0xC000)
 
#define I2C_CMD_WR   ((uint8_t)0x00)
 
#define I2C_CMD_RD   ((uint8_t)0x01)
 
#define I2C_CMD_STOP   ((uint8_t)0x02)
 
#define I2C_CMD_RESTART   ((uint8_t)0x04)
 
#define FLAG_MASK   ((uint32_t)0x007F0FFF)
 
#define ITEN_MASK   ((uint16_t)0x2FFF)
 
#define IT_FLAG_MASK   ((uint16_t)0x2FFF)
 

Functions

__STATIC_INLINE void I2C_SetMode (I2C_T *I2Cx, uint16_t Mode)
 Set I2C mode . More...
 
__STATIC_INLINE void I2C_SetTxTirggerLevel (I2C_T *I2Cx, uint8_t ThresholdValue)
 Set I2C Tx fifo threshold value . More...
 
__STATIC_INLINE void I2C_SetRxTirggerLevel (I2C_T *I2Cx, uint8_t ThresholdValue)
 Set I2C Rx fifo threshold value . More...
 
__STATIC_INLINE void I2C_Cmd (I2C_T *I2Cx, FunctionalState NewState)
 Enables or disables the specified I2C peripheral. More...
 
__STATIC_INLINE void I2C_GeneralCallCmd (I2C_T *I2Cx, FunctionalState NewState)
 Enables or disables the specified I2C general call feature. More...
 
__STATIC_INLINE void I2C_SendDataCmd (I2C_T *I2Cx, uint8_t Data, uint8_t Cmd)
 Sends a data byte through the I2Cx peripheral. More...
 
__STATIC_INLINE void I2C_SendCmd (I2C_T *I2Cx, uint8_t Cmd)
 Sends a data byte through the I2Cx peripheral. More...
 
__STATIC_INLINE uint8_t I2C_ReceiveData (I2C_T *I2Cx)
 Returns the most recent received data by the I2Cx peripheral. More...
 
__STATIC_INLINE void I2C_AbortTransfer (I2C_T *I2Cx)
 Aborting I2C Transfers. More...
 
__STATIC_INLINE void I2C_DMACmd (I2C_T *I2Cx, FunctionalState NewState)
 Enables or disables the specified I2C DMA requests. More...
 
__STATIC_INLINE void I2C_DMATransferDataLevel (I2C_T *I2Cx, uint8_t Level)
 DMA Transmit Data Level Register. More...
 
__STATIC_INLINE void I2C_DMAReceiveDataLevel (I2C_T *I2Cx, uint8_t Level)
 DMA Receive Data Level Register. More...
 
__STATIC_INLINE ITStatus I2C_GetITStatus (I2C_T *I2Cx, uint16_t I2C_IT)
 Checks whether the specified I2C interrupt has occurred or not. More...
 
__STATIC_INLINE ITStatus I2C_GetRawITStatus (I2C_T *I2Cx, uint16_t I2C_IT)
 Checks whether the specified I2C interrupt has occurred or not. More...
 
__STATIC_INLINE void I2C_ITConfig (I2C_T *I2Cx, uint16_t I2C_IT, FunctionalState NewState)
 Enables or disables the specified I2C interrupts. More...
 
__STATIC_INLINE void I2C_DisableAllIT (I2C_T *I2Cx)
 Enables or disables all the specified I2C interrupts. More...
 
__STATIC_INLINE void I2C_ClearAllITPendingBit (I2C_T *I2Cx)
 Clears all the I2Cx's interrupt pending bits. More...
 
__STATIC_INLINE bool I2C_AbortSrcCheck (I2C_T *I2Cx, uint32_t IC_MSK)
 Get the source of tx_abort. More...
 
__STATIC_INLINE void I2C_SetSlaveAddr (I2C_T *I2Cx, uint32_t addr)
 Set slave address. More...
 
bool I2C_Init (I2C_T *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
 Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct. More...
 
void I2C_Set7bitAddress (I2C_T *I2Cx, uint8_t Address)
 Configure the target address for any master transaction. More...
 
void I2C_Set10bitAddress (I2C_T *I2Cx, uint16_t Address)
 Configure the target address for any master transaction. More...
 
FlagStatus I2C_GetFlagStatus (I2C_T *I2Cx, uint32_t I2C_FLAG)
 Checks whether the specified I2C flag is set or not. More...
 
void I2C_ClearITPendingBit (I2C_T *I2Cx, uint16_t I2C_IT)
 Clears the I2Cx's interrupt pending bits. More...
 
void I2C_Write (I2C_T *I2Cx, uint8_t *WriteBuf, uint32_t Size)
 read data from the I2Cx peripheral. More...
 
void I2C_Read (I2C_T *I2Cx, uint8_t *ReadBuf, uint32_t Size)
 write data to the I2Cx peripheral. More...
 

Detailed Description

I2c Interface.

Macro Definition Documentation

◆ FLAG_MASK

#define FLAG_MASK   ((uint32_t)0x007F0FFF)

I2C flag mask

◆ I2C_AcknowledgedAddress_10bit

#define I2C_AcknowledgedAddress_10bit   ((uint16_t)0xC000)

I2C 10-bit acknowledged address enable

◆ I2C_AcknowledgedAddress_7bit

#define I2C_AcknowledgedAddress_7bit   ((uint16_t)0x4000)

I2C 7-bit acknowledged address enable

◆ I2C_CMD_RD

#define I2C_CMD_RD   ((uint8_t)0x01)

I2C read cmd

◆ I2C_CMD_RESTART

#define I2C_CMD_RESTART   ((uint8_t)0x04)

I2C restart cmd

◆ I2C_CMD_STOP

#define I2C_CMD_STOP   ((uint8_t)0x02)

I2C stop cmd

◆ I2C_CMD_WR

#define I2C_CMD_WR   ((uint8_t)0x00)

I2C write cmd

◆ I2C_DutyCycle_16_9

#define I2C_DutyCycle_16_9   ((uint16_t)0x4000)

I2C fast mode Tlow/Thigh = 16/9

◆ I2C_DutyCycle_2

#define I2C_DutyCycle_2   ((uint16_t)0xBFFF)

I2C fast mode Tlow/Thigh = 2

◆ I2C_SPEED_FAST_MODE

#define I2C_SPEED_FAST_MODE   (uint16_t)(0x0004)

I2C fast speed mode,speed less than 1MHz

◆ I2C_SPEED_HIGH_MODE

#define I2C_SPEED_HIGH_MODE   (uint16_t)(0x0006)

I2C high speed mode,speed larger than 1MHz

◆ I2C_SPEED_STANDARD_MODE

#define I2C_SPEED_STANDARD_MODE   (uint16_t)(0x0002)

I2C standard speed mode, speed less than 100KHz

◆ IS_I2C_DUTY_CYCLE

#define IS_I2C_DUTY_CYCLE (   CYCLE)
Value:
(((CYCLE) == I2C_DutyCycle_16_9) || \
((CYCLE) == I2C_DutyCycle_2))
#define I2C_DutyCycle_16_9
Definition: pan_i2c.h:68
#define I2C_DutyCycle_2
Definition: pan_i2c.h:69

I2C fast mode duty cycle check

◆ IS_I2C_MODE

#define IS_I2C_MODE (   MODE)
Value:
(((MODE) == PAN_I2C_MODE_MASTER) || \
((MODE) == PAN_I2C_MODE_SLAVE))
#define PAN_I2C_MODE_MASTER
Definition: pan_i2c.h:56
#define PAN_I2C_MODE_SLAVE
Definition: pan_i2c.h:57

I2C mode check

◆ IT_FLAG_MASK

#define IT_FLAG_MASK   ((uint16_t)0x2FFF)

I2C interrupt flag mask

◆ ITEN_MASK

#define ITEN_MASK   ((uint16_t)0x2FFF)

I2C interrupt enable mask

◆ PAN_I2C_MODE_MASTER

#define PAN_I2C_MODE_MASTER   ((uint16_t)0x0021)

I2C master mode

◆ PAN_I2C_MODE_SLAVE

#define PAN_I2C_MODE_SLAVE   ((uint16_t)0x0000)

I2C slave mode

Function Documentation

◆ I2C_AbortSrcCheck()

__STATIC_INLINE bool I2C_AbortSrcCheck ( I2C_T *  I2Cx,
uint32_t  IC_MSK 
)

Get the source of tx_abort.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Returns
true or false

◆ I2C_AbortTransfer()

__STATIC_INLINE void I2C_AbortTransfer ( I2C_T *  I2Cx)

Aborting I2C Transfers.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Returns
None

◆ I2C_ClearAllITPendingBit()

__STATIC_INLINE void I2C_ClearAllITPendingBit ( I2C_T *  I2Cx)

Clears all the I2Cx's interrupt pending bits.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Returns
None

◆ I2C_ClearITPendingBit()

void I2C_ClearITPendingBit ( I2C_T *  I2Cx,
uint16_t  I2C_IT 
)

Clears the I2Cx's interrupt pending bits.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
I2C_ITspecifies the interrupt pending bit to clear.
  • I2C_IT_RX_UNDER
  • I2C_IT_RX_OVER
  • I2C_IT_RX_FULL
  • I2C_IT_TX_OVER
  • I2C_IT_TX_EMPTY
  • I2C_IT_RD_REQ
  • I2C_IT_TX_ABRT
  • I2C_IT_RX_DONE
  • I2C_IT_ACTIVITY
  • I2C_IT_STOP_DET
  • I2C_IT_START_DET
  • I2C_IT_GEN_CALL
  • I2C_IT_MST_ON_HOLD
Returns
None

◆ I2C_Cmd()

__STATIC_INLINE void I2C_Cmd ( I2C_T *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the specified I2C peripheral.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
NewStatenew state of the I2Cx peripheral. This parameter can be: ENABLE or DISABLE.
Returns
None

◆ I2C_DisableAllIT()

__STATIC_INLINE void I2C_DisableAllIT ( I2C_T *  I2Cx)

Enables or disables all the specified I2C interrupts.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Returns
None

◆ I2C_DMACmd()

__STATIC_INLINE void I2C_DMACmd ( I2C_T *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the specified I2C DMA requests.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
NewStatenew state of the I2C DMA transfer. This parameter can be: ENABLE or DISABLE.
Returns
None

◆ I2C_DMAReceiveDataLevel()

__STATIC_INLINE void I2C_DMAReceiveDataLevel ( I2C_T *  I2Cx,
uint8_t  Level 
)

DMA Receive Data Level Register.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
LevelThis parameter controls the level at which a DMA request is made by the receive logic.
Returns
None

◆ I2C_DMATransferDataLevel()

__STATIC_INLINE void I2C_DMATransferDataLevel ( I2C_T *  I2Cx,
uint8_t  Level 
)

DMA Transmit Data Level Register.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
LevelThis parameter controls the level at which a DMA request is made by the transmit logic
Returns
None

◆ I2C_GeneralCallCmd()

__STATIC_INLINE void I2C_GeneralCallCmd ( I2C_T *  I2Cx,
FunctionalState  NewState 
)

Enables or disables the specified I2C general call feature.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
NewStatenew state of the I2C General call. This parameter can be: ENABLE or DISABLE.
Returns
None

◆ I2C_GetFlagStatus()

FlagStatus I2C_GetFlagStatus ( I2C_T *  I2Cx,
uint32_t  I2C_FLAG 
)

Checks whether the specified I2C flag is set or not.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
I2C_FLAGspecifies the flag to check. This parameter can be one of the following values:
  • I2C_FLAG_SLV_ACTIVITY
  • I2C_FLAG_MST_ACTIVITY
  • I2C_FLAG_RFF
  • I2C_FLAG_TFE
  • I2C_FLAG_TFNF
  • I2C_FLAG_ACTIVITY
  • I2C_FLAG_MST_ACTIVITY
Returns
The new state of I2C_FLAG (SET or RESET).

◆ I2C_GetITStatus()

__STATIC_INLINE ITStatus I2C_GetITStatus ( I2C_T *  I2Cx,
uint16_t  I2C_IT 
)

Checks whether the specified I2C interrupt has occurred or not.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
I2C_ITspecifies the interrupt source to check. This parameter can be one of the following values:
  • I2C_IT_RX_UNDER
  • I2C_IT_RX_OVER
  • I2C_IT_RX_FULL
  • I2C_IT_TX_OVER
  • I2C_IT_TX_EMPTY
  • I2C_IT_RD_REQ
  • I2C_IT_TX_ABRT
  • I2C_IT_RX_DONE
  • I2C_IT_ACTIVITY
  • I2C_IT_STOP_DET
  • I2C_IT_START_DET
  • I2C_IT_GEN_CALL
  • I2C_IT_MST_ON_HOLD
Returns
The new state of I2C_IT (SET or RESET).

◆ I2C_GetRawITStatus()

__STATIC_INLINE ITStatus I2C_GetRawITStatus ( I2C_T *  I2Cx,
uint16_t  I2C_IT 
)

Checks whether the specified I2C interrupt has occurred or not.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
I2C_ITspecifies the interrupt source to check. This parameter can be one of the following values:
  • I2C_IT_RX_UNDER
  • I2C_IT_RX_OVER
  • I2C_IT_RX_FULL
  • I2C_IT_TX_OVER
  • I2C_IT_TX_EMPTY
  • I2C_IT_RD_REQ
  • I2C_IT_TX_ABRT
  • I2C_IT_RX_DONE
  • I2C_IT_ACTIVITY
  • I2C_IT_STOP_DET
  • I2C_IT_START_DET
  • I2C_IT_GEN_CALL
  • I2C_IT_MST_ON_HOLD
Returns
The new state of I2C_IT (SET or RESET).

◆ I2C_Init()

bool I2C_Init ( I2C_T *  I2Cx,
I2C_InitTypeDef I2C_InitStruct 
)

Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.

Note
To use the I2C at 400 KHz (in fast mode), the PCLK1 frequency (I2C peripheral input clock) must be a multiple of 10 MHz.
Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
I2C_InitStructpointer to a I2C_InitTypeDef structure that contains the configuration information for the specified I2C peripheral.
Note
This function should be called before enabling the I2C Peripheral.
Return values
falseinit fail
trueinit succeed
:
I2C_InitTypeDef I2C_InitStructure;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVE_OWN_ADDRESS7;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED_100K;
I2C_Cmd(I2Cx, DISABLE);
bool ret = I2C_Init(I2Cx, &I2C_InitStructure);
#define I2C_AcknowledgedAddress_7bit
Definition: pan_i2c.h:75
__STATIC_INLINE void I2C_Cmd(I2C_T *I2Cx, FunctionalState NewState)
Enables or disables the specified I2C peripheral.
Definition: pan_i2c.h:202
bool I2C_Init(I2C_T *I2Cx, I2C_InitTypeDef *I2C_InitStruct)
Initializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
Structure with i2c init feature.
Definition: pan_i2c.h:45
uint16_t I2C_DutyCycle
Definition: pan_i2c.h:48
uint16_t I2C_OwnAddress1
Definition: pan_i2c.h:49
uint16_t I2C_AcknowledgedAddress
Definition: pan_i2c.h:50
uint32_t I2C_ClockSpeed
Definition: pan_i2c.h:46

◆ I2C_ITConfig()

__STATIC_INLINE void I2C_ITConfig ( I2C_T *  I2Cx,
uint16_t  I2C_IT,
FunctionalState  NewState 
)

Enables or disables the specified I2C interrupts.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
I2C_ITspecifies the I2C interrupts sources to be enabled or disabled. This parameter can be any combination of the following values:
  • I2C_IT_RX_UNDER
  • I2C_IT_RX_OVER
  • I2C_IT_RX_FULL
  • I2C_IT_TX_OVER
  • I2C_IT_TX_EMPTY
  • I2C_IT_RD_REQ
  • I2C_IT_TX_ABRT
  • I2C_IT_RX_DONE
  • I2C_IT_ACTIVITY
  • I2C_IT_STOP_DET
  • I2C_IT_START_DET
  • I2C_IT_GEN_CALL
NewStatenew state of the specified I2C interrupts. This parameter can be: ENABLE or DISABLE.
Returns
None

◆ I2C_Read()

void I2C_Read ( I2C_T *  I2Cx,
uint8_t *  ReadBuf,
uint32_t  Size 
)

write data to the I2Cx peripheral.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
ReadBufcache of stored writings.
Sizenumber of data read from I2C peripheral.
Returns
None.

◆ I2C_ReceiveData()

__STATIC_INLINE uint8_t I2C_ReceiveData ( I2C_T *  I2Cx)

Returns the most recent received data by the I2Cx peripheral.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Returns
The value of the received data.

◆ I2C_SendCmd()

__STATIC_INLINE void I2C_SendCmd ( I2C_T *  I2Cx,
uint8_t  Cmd 
)

Sends a data byte through the I2Cx peripheral.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Cmd: I2c operate command I2C_CMD_RD,I2C_CMD_WR,I2C_CMD_RESTART,I2C_CMD_STOP
Returns
None

◆ I2C_SendDataCmd()

__STATIC_INLINE void I2C_SendDataCmd ( I2C_T *  I2Cx,
uint8_t  Data,
uint8_t  Cmd 
)

Sends a data byte through the I2Cx peripheral.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
DataByte to be transmitted..
Cmd: I2c operate command I2C_CMD_RD,I2C_CMD_WR,I2C_CMD_RESTART,I2C_CMD_STOP
Returns
None

◆ I2C_Set10bitAddress()

void I2C_Set10bitAddress ( I2C_T *  I2Cx,
uint16_t  Address 
)

Configure the target address for any master transaction.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Addressspecifies the slave 10-bit address which will be transmitted
Returns
None.

◆ I2C_Set7bitAddress()

void I2C_Set7bitAddress ( I2C_T *  I2Cx,
uint8_t  Address 
)

Configure the target address for any master transaction.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Addressspecifies the slave 7-bit address which will be transmitted
Returns
None.

◆ I2C_SetMode()

__STATIC_INLINE void I2C_SetMode ( I2C_T *  I2Cx,
uint16_t  Mode 
)

Set I2C mode .

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
Moderole of the I2Cx peripheral. This parameter can be: PAN_I2C_MODE_MASTER or PAN_I2C_MODE_SLAVE.
Note
This function should be called before enabling the I2C Peripheral.
Returns
None

◆ I2C_SetRxTirggerLevel()

__STATIC_INLINE void I2C_SetRxTirggerLevel ( I2C_T *  I2Cx,
uint8_t  ThresholdValue 
)

Set I2C Rx fifo threshold value .

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
ThresholdValueReceive FIFO Threshold Level This parameter can be I2c rx threshold level.
Note
Controls the level of entries (or below) that trigger the RX_FULL interrupt (bit 2 in IC_RAW_INTR_STAT register). The valid range is 0-8, with the additional restriction that it may not be set to value larger than the depth of the buffer. If an attempt is made to do that, the actual value set will be the maximum depth of the buffer.A value of 0 sets the threshold for 0 entries, and a value of 8 sets the threshold for 8 entries.
Returns
None

◆ I2C_SetSlaveAddr()

__STATIC_INLINE void I2C_SetSlaveAddr ( I2C_T *  I2Cx,
uint32_t  addr 
)

Set slave address.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
addrslave address.
Returns
true or false

◆ I2C_SetTxTirggerLevel()

__STATIC_INLINE void I2C_SetTxTirggerLevel ( I2C_T *  I2Cx,
uint8_t  ThresholdValue 
)

Set I2C Tx fifo threshold value .

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
ThresholdValueTransmit FIFO Threshold Level This parameter can be I2c tx transmit level.
Note
Controls the level of entries (or below) that trigger the TX_EMPTY interrupt (bit 4 in IC_RAW_INTR_STAT register). The valid range is 0-8, with the additional restriction that it may not be set to value larger than the depth of the buffer. If an attempt is made to do that, the actual value set will be the maximum depth of the buffer.A value of 0 sets the threshold for 0 entries, and a value of 8 sets the threshold for 8 entries.
Returns
None

◆ I2C_Write()

void I2C_Write ( I2C_T *  I2Cx,
uint8_t *  WriteBuf,
uint32_t  Size 
)

read data from the I2Cx peripheral.

Parameters
I2Cxwhere I2Cx is a i2c peripheral base address.
WriteBufcache of stored readings.
Sizenumber of data read from I2C peripheral.
Returns
none.