Mini51 BSP  V3.02.002
The Board Support Package for Mini51 Series
Macros | Functions
I2C Exported Functions

Macros

#define I2C_SET_CONTROL_REG(i2c, u8Ctrl)   ( (i2c)->I2CON = ((i2c)->I2CON & ~0x3c) | u8Ctrl )
 This macro sets the I2C control register at one time. More...
 
#define I2C_START(i2c)   ( (i2c)->I2CON = ((i2c)->I2CON & ~I2C_I2CON_SI_Msk) | I2C_I2CON_STA_Msk )
 This macro only set START bit to the control register of I2C module. More...
 
#define I2C_STOP(i2c)
 This macro only set STOP bit to the control register of I2C module. More...
 
#define I2C_WAIT_READY(i2c)   while(!((i2c)->I2CON & I2C_I2CON_SI_Msk))
 This macro will return when I2C module is ready. More...
 
#define I2C_DISABLE_FIFO(i2c)   ( (i2c)->I2CON2 &= ~I2C_I2CON2_TWOFF_EN_Msk )
 This macro disables the FIFO function. More...
 
#define I2C_ENABLE_FIFO(i2c)   ( (i2c)->I2CON2 |= I2C_I2CON2_TWOFF_EN_Msk )
 This macro enables the FIFO function. More...
 
#define I2C_DISABLE_CLOCK_STRETCH(i2c)   ( (i2c)->I2CON2 |= I2C_I2CON2_NOSTRETCH_Msk )
 This macro disables clock stretch function. More...
 
#define I2C_ENABLE_CLOCK_STRETCH(i2c)   ( (i2c)->I2CON2 &= ~I2C_I2CON2_NOSTRETCH_Msk )
 This macro enables clock stretch function. More...
 
#define I2C_DISABLE_OVERRUN_INT(i2c)   ( (i2c)->I2CON2 &= ~I2C_I2CON2_OVER_INTEN_Msk )
 This macro disables over-run interrupt. More...
 
#define I2C_ENABLE_OVERRUN_INT(i2c)   ( (i2c)->I2CON2 |= I2C_I2CON2_OVER_INTEN_Msk )
 This macro enables over-run interrupt. More...
 
#define I2C_ENABLE_UNDERRUN_INT(i2c)   ( (i2c)->I2CON2 |= I2C_I2CON2_UNDER_INTEN_Msk )
 This macro enables under-run interrupt. More...
 
#define I2C_DISABLE_UNDERRUN_INT(i2c)   ( (i2c)->I2CON2 &= ~I2C_I2CON2_UNDER_INTEN_Msk )
 This macro disables under-run interrupt. More...
 
#define I2C_GET_DATA(i2c)   ( (i2c)->I2CDAT )
 This macro returns the data stored in data register of I2C module. More...
 
#define I2C_SET_DATA(i2c, u8Data)   ( (i2c)->I2CDAT = u8Data )
 This macro writes the data to data register of I2C module. More...
 
#define I2C_GET_STATUS(i2c)   ( (i2c)->I2CSTATUS )
 This macro returns the status of I2C module. More...
 
#define I2C_GET_TIMEOUT_FLAG(i2c)   ( ((i2c)->I2CTOC & I2C_I2CTOC_TIF_Msk) == I2C_I2CTOC_TIF_Msk ? 1:0 )
 This macro returns timeout flag. More...
 
#define I2C_GET_WAKEUP_FLAG(i2c)   ( ((i2c)->I2CSTATUS2 & I2C_I2CSTATUS2_WAKEUP_Msk) == I2C_I2CSTATUS2_WAKEUP_Msk ? 1:0 )
 This macro returns wakeup flag. More...
 
#define I2C_CLEAR_WAKEUP_FLAG(i2c)   ((i2c)->I2CSTATUS2 |= I2C_I2CSTATUS2_WAKEUP_Msk )
 This macro clears wakeup flag. More...
 

Functions

uint32_t I2C_Open (I2C_T *i2c, uint32_t u32BusClock)
 This function make I2C module be ready and set the wanted bus clock. More...
 
void I2C_Close (I2C_T *i2c)
 This function closes the I2C module. More...
 
void I2C_ClearTimeoutFlag (I2C_T *i2c)
 This function clears the timeout flag. More...
 
void I2C_Trigger (I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack)
 This function sets the control bit of the I2C module. More...
 
void I2C_DisableInt (I2C_T *i2c)
 This function disables the interrupt (EI bit) of I2C module. More...
 
void I2C_EnableInt (I2C_T *i2c)
 This function enables the interrupt (EI bit) of I2C module. More...
 
uint32_t I2C_GetBusClockFreq (I2C_T *i2c)
 This function returns the real bus clock of I2C module. More...
 
uint32_t I2C_SetBusClockFreq (I2C_T *i2c, uint32_t u32BusClock)
 This function enables the interrupt (EI bit) of I2C module. More...
 
uint32_t I2C_GetIntFlag (I2C_T *i2c)
 This function gets the interrupt flag (SI bit) of I2C module. More...
 
uint32_t I2C_GetStatus (I2C_T *i2c)
 This function returns the status of I2C module. More...
 
uint32_t I2C_GetData (I2C_T *i2c)
 This function returns the data stored in data register of I2C module. More...
 
void I2C_SetData (I2C_T *i2c, uint8_t u8Data)
 This function writes the data to data register of I2C module. More...
 
void I2C_SetSlaveAddr (I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode)
 Configure slave address and enable GC mode. More...
 
void I2C_SetSlaveAddrMask (I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask)
 Configure the mask of slave address. The corresponding address bit is "Don't Care". More...
 
void I2C_EnableTimeout (I2C_T *i2c, uint8_t u8LongTimeout)
 This function enables timeout function and configures DIV4 function to support long timeout. More...
 
void I2C_DisableTimeout (I2C_T *i2c)
 This function disables timeout function. More...
 
void I2C_EnableWakeup (I2C_T *i2c)
 This function enables the wakeup function of I2C module. More...
 
void I2C_DisableWakeup (I2C_T *i2c)
 This function disables the wakeup function of I2C module. More...
 

Detailed Description

Macro Definition Documentation

◆ I2C_CLEAR_WAKEUP_FLAG

#define I2C_CLEAR_WAKEUP_FLAG (   i2c)    ((i2c)->I2CSTATUS2 |= I2C_I2CSTATUS2_WAKEUP_Msk )

This macro clears wakeup flag.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 180 of file i2c.h.

◆ I2C_DISABLE_CLOCK_STRETCH

#define I2C_DISABLE_CLOCK_STRETCH (   i2c)    ( (i2c)->I2CON2 |= I2C_I2CON2_NOSTRETCH_Msk )

This macro disables clock stretch function.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 98 of file i2c.h.

◆ I2C_DISABLE_FIFO

#define I2C_DISABLE_FIFO (   i2c)    ( (i2c)->I2CON2 &= ~I2C_I2CON2_TWOFF_EN_Msk )

This macro disables the FIFO function.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 84 of file i2c.h.

◆ I2C_DISABLE_OVERRUN_INT

#define I2C_DISABLE_OVERRUN_INT (   i2c)    ( (i2c)->I2CON2 &= ~I2C_I2CON2_OVER_INTEN_Msk )

This macro disables over-run interrupt.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 112 of file i2c.h.

◆ I2C_DISABLE_UNDERRUN_INT

#define I2C_DISABLE_UNDERRUN_INT (   i2c)    ( (i2c)->I2CON2 &= ~I2C_I2CON2_UNDER_INTEN_Msk )

This macro disables under-run interrupt.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 133 of file i2c.h.

◆ I2C_ENABLE_CLOCK_STRETCH

#define I2C_ENABLE_CLOCK_STRETCH (   i2c)    ( (i2c)->I2CON2 &= ~I2C_I2CON2_NOSTRETCH_Msk )

This macro enables clock stretch function.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 105 of file i2c.h.

◆ I2C_ENABLE_FIFO

#define I2C_ENABLE_FIFO (   i2c)    ( (i2c)->I2CON2 |= I2C_I2CON2_TWOFF_EN_Msk )

This macro enables the FIFO function.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 91 of file i2c.h.

◆ I2C_ENABLE_OVERRUN_INT

#define I2C_ENABLE_OVERRUN_INT (   i2c)    ( (i2c)->I2CON2 |= I2C_I2CON2_OVER_INTEN_Msk )

This macro enables over-run interrupt.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 119 of file i2c.h.

◆ I2C_ENABLE_UNDERRUN_INT

#define I2C_ENABLE_UNDERRUN_INT (   i2c)    ( (i2c)->I2CON2 |= I2C_I2CON2_UNDER_INTEN_Msk )

This macro enables under-run interrupt.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 126 of file i2c.h.

◆ I2C_GET_DATA

#define I2C_GET_DATA (   i2c)    ( (i2c)->I2CDAT )

This macro returns the data stored in data register of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
Data.

Definition at line 140 of file i2c.h.

◆ I2C_GET_STATUS

#define I2C_GET_STATUS (   i2c)    ( (i2c)->I2CSTATUS )

This macro returns the status of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
Status.

Definition at line 155 of file i2c.h.

◆ I2C_GET_TIMEOUT_FLAG

#define I2C_GET_TIMEOUT_FLAG (   i2c)    ( ((i2c)->I2CTOC & I2C_I2CTOC_TIF_Msk) == I2C_I2CTOC_TIF_Msk ? 1:0 )

This macro returns timeout flag.

Parameters
i2cis the base address of I2C module.
Returns
Status.
Return values
0Flag is not set.
1Flag is set.

Definition at line 164 of file i2c.h.

◆ I2C_GET_WAKEUP_FLAG

#define I2C_GET_WAKEUP_FLAG (   i2c)    ( ((i2c)->I2CSTATUS2 & I2C_I2CSTATUS2_WAKEUP_Msk) == I2C_I2CSTATUS2_WAKEUP_Msk ? 1:0 )

This macro returns wakeup flag.

Parameters
i2cis the base address of I2C module.
Returns
Status.
Return values
0Flag is not set.
1Flag is set.

Definition at line 173 of file i2c.h.

◆ I2C_SET_CONTROL_REG

#define I2C_SET_CONTROL_REG (   i2c,
  u8Ctrl 
)    ( (i2c)->I2CON = ((i2c)->I2CON & ~0x3c) | u8Ctrl )

This macro sets the I2C control register at one time.

Parameters
i2cis the base address of I2C module.
u8Ctrlis the register value of I2C control register.
Returns
none

Definition at line 52 of file i2c.h.

◆ I2C_SET_DATA

#define I2C_SET_DATA (   i2c,
  u8Data 
)    ( (i2c)->I2CDAT = u8Data )

This macro writes the data to data register of I2C module.

Parameters
i2cis the base address of I2C module.
u8Datais the data which will be write to data register of I2C module.
Returns
none

Definition at line 148 of file i2c.h.

◆ I2C_START

#define I2C_START (   i2c)    ( (i2c)->I2CON = ((i2c)->I2CON & ~I2C_I2CON_SI_Msk) | I2C_I2CON_STA_Msk )

This macro only set START bit to the control register of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 59 of file i2c.h.

◆ I2C_STOP

#define I2C_STOP (   i2c)
Value:
do { \
(i2c)->I2CON |= (I2C_I2CON_SI_Msk | I2C_I2CON_STO_Msk); \
while((i2c)->I2CON & I2C_I2CON_STO_Msk); \
} while(0)
#define I2C_I2CON_STO_Msk
#define I2C_I2CON_SI_Msk

This macro only set STOP bit to the control register of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 66 of file i2c.h.

◆ I2C_WAIT_READY

#define I2C_WAIT_READY (   i2c)    while(!((i2c)->I2CON & I2C_I2CON_SI_Msk))

This macro will return when I2C module is ready.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 77 of file i2c.h.

Function Documentation

◆ I2C_ClearTimeoutFlag()

void I2C_ClearTimeoutFlag ( I2C_T i2c)

This function clears the timeout flag.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 66 of file i2c.c.

◆ I2C_Close()

void I2C_Close ( I2C_T i2c)

This function closes the I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 51 of file i2c.c.

◆ I2C_DisableInt()

void I2C_DisableInt ( I2C_T i2c)

This function disables the interrupt (EI bit) of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 101 of file i2c.c.

◆ I2C_DisableTimeout()

void I2C_DisableTimeout ( I2C_T i2c)

This function disables timeout function.

Parameters
i2cis the base address of I2C module.
Returns
none.

Definition at line 265 of file i2c.c.

◆ I2C_DisableWakeup()

void I2C_DisableWakeup ( I2C_T i2c)

This function disables the wakeup function of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none.

Definition at line 285 of file i2c.c.

◆ I2C_EnableInt()

void I2C_EnableInt ( I2C_T i2c)

This function enables the interrupt (EI bit) of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none

Definition at line 111 of file i2c.c.

◆ I2C_EnableTimeout()

void I2C_EnableTimeout ( I2C_T i2c,
uint8_t  u8LongTimeout 
)

This function enables timeout function and configures DIV4 function to support long timeout.

Parameters
i2cis the base address of I2C module.
u8LongTimeoutEnable timeout counter input clock is divide by 4.
Returns
none.

Definition at line 250 of file i2c.c.

◆ I2C_EnableWakeup()

void I2C_EnableWakeup ( I2C_T i2c)

This function enables the wakeup function of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
none.

Definition at line 275 of file i2c.c.

◆ I2C_GetBusClockFreq()

uint32_t I2C_GetBusClockFreq ( I2C_T i2c)

This function returns the real bus clock of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
Actual I2C bus clock frequency.

Definition at line 121 of file i2c.c.

◆ I2C_GetData()

uint32_t I2C_GetData ( I2C_T i2c)

This function returns the data stored in data register of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
Data.

Definition at line 171 of file i2c.c.

◆ I2C_GetIntFlag()

uint32_t I2C_GetIntFlag ( I2C_T i2c)

This function gets the interrupt flag (SI bit) of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
Interrupt flag.
Return values
0Flag is not set.
1Flag is set.

Definition at line 151 of file i2c.c.

◆ I2C_GetStatus()

uint32_t I2C_GetStatus ( I2C_T i2c)

This function returns the status of I2C module.

Parameters
i2cis the base address of I2C module.
Returns
Status.

Definition at line 161 of file i2c.c.

◆ I2C_Open()

uint32_t I2C_Open ( I2C_T i2c,
uint32_t  u32BusClock 
)

This function make I2C module be ready and set the wanted bus clock.

Parameters
i2cis the base address of I2C module.
u32BusClockis the target bus speed of I2C module.
Returns
Actual I2C bus clock frequency.

Definition at line 33 of file i2c.c.

◆ I2C_SetBusClockFreq()

uint32_t I2C_SetBusClockFreq ( I2C_T i2c,
uint32_t  u32BusClock 
)

This function enables the interrupt (EI bit) of I2C module.

Parameters
i2cis the base address of I2C module.
u32BusClockis the target bus speed of I2C module.
Returns
Actual I2C bus clock frequency.

Definition at line 134 of file i2c.c.

◆ I2C_SetData()

void I2C_SetData ( I2C_T i2c,
uint8_t  u8Data 
)

This function writes the data to data register of I2C module.

Parameters
i2cis the base address of I2C module.
u8Datais the data which will be write to data register of I2C module.
Returns
none

Definition at line 182 of file i2c.c.

◆ I2C_SetSlaveAddr()

void I2C_SetSlaveAddr ( I2C_T i2c,
uint8_t  u8SlaveNo,
uint8_t  u8SlaveAddr,
uint8_t  u8GCMode 
)

Configure slave address and enable GC mode.

Parameters
i2cis the base address of I2C module.
u8SlaveNois the set number of salve address.
u8SlaveAddris the slave address.
u8GCModeenable GC mode.
Returns
none

Definition at line 195 of file i2c.c.

◆ I2C_SetSlaveAddrMask()

void I2C_SetSlaveAddrMask ( I2C_T i2c,
uint8_t  u8SlaveNo,
uint8_t  u8SlaveAddrMask 
)

Configure the mask of slave address. The corresponding address bit is "Don't Care".

Parameters
i2cis the base address of I2C module.
u8SlaveNois the set number of salve address.
u8SlaveAddrMaskis the slave address mask.
Returns
none

Definition at line 223 of file i2c.c.

◆ I2C_Trigger()

void I2C_Trigger ( I2C_T i2c,
uint8_t  u8Start,
uint8_t  u8Stop,
uint8_t  u8Si,
uint8_t  u8Ack 
)

This function sets the control bit of the I2C module.

Parameters
i2cis the base address of I2C module.
u8Startsets START bit to I2C module.
u8Stopsets STOP bit to I2C module.
u8Sisets SI bit to I2C module.
u8Acksets ACK bit to I2C module.
Returns
none

Definition at line 80 of file i2c.c.