MINI51DE_BSP V3.02.003
The Board Support Package for Mini51DE Series MCU
i2c.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __I2C_H__
13#define __I2C_H__
14
15#ifdef __cplusplus
16extern "C"
17{
18#endif
19
20
34#define I2C_STA 0x20
35#define I2C_STO 0x10
36#define I2C_SI 0x08
37#define I2C_AA 0x04 /* end of group MINI51_I2C_EXPORTED_CONSTANTS */
40
41
52#define I2C_SET_CONTROL_REG(i2c, u8Ctrl) ( (i2c)->I2CON = ((i2c)->I2CON & ~0x3c) | u8Ctrl )
53
59#define I2C_START(i2c) ( (i2c)->I2CON = ((i2c)->I2CON & ~I2C_I2CON_SI_Msk) | I2C_I2CON_STA_Msk )
60
66#define I2C_STOP(i2c) \
67do { \
68 (i2c)->I2CON |= (I2C_I2CON_SI_Msk | I2C_I2CON_STO_Msk); \
69 while((i2c)->I2CON & I2C_I2CON_STO_Msk); \
70} while(0)
71
77#define I2C_WAIT_READY(i2c) while(!((i2c)->I2CON & I2C_I2CON_SI_Msk))
78
84#define I2C_DISABLE_FIFO(i2c) ( (i2c)->I2CON2 &= ~I2C_I2CON2_TWOFF_EN_Msk )
85
91#define I2C_ENABLE_FIFO(i2c) ( (i2c)->I2CON2 |= I2C_I2CON2_TWOFF_EN_Msk )
92
98#define I2C_DISABLE_CLOCK_STRETCH(i2c) ( (i2c)->I2CON2 |= I2C_I2CON2_NOSTRETCH_Msk )
99
105#define I2C_ENABLE_CLOCK_STRETCH(i2c) ( (i2c)->I2CON2 &= ~I2C_I2CON2_NOSTRETCH_Msk )
106
112#define I2C_DISABLE_OVERRUN_INT(i2c) ( (i2c)->I2CON2 &= ~I2C_I2CON2_OVER_INTEN_Msk )
113
119#define I2C_ENABLE_OVERRUN_INT(i2c) ( (i2c)->I2CON2 |= I2C_I2CON2_OVER_INTEN_Msk )
120
126#define I2C_ENABLE_UNDERRUN_INT(i2c) ( (i2c)->I2CON2 |= I2C_I2CON2_UNDER_INTEN_Msk )
127
133#define I2C_DISABLE_UNDERRUN_INT(i2c) ( (i2c)->I2CON2 &= ~I2C_I2CON2_UNDER_INTEN_Msk )
134
140#define I2C_GET_DATA(i2c) ( (i2c)->I2CDAT )
141
148#define I2C_SET_DATA(i2c, u8Data) ( (i2c)->I2CDAT = u8Data )
149
155#define I2C_GET_STATUS(i2c) ( (i2c)->I2CSTATUS )
156
164#define I2C_GET_TIMEOUT_FLAG(i2c) ( ((i2c)->I2CTOC & I2C_I2CTOC_TIF_Msk) == I2C_I2CTOC_TIF_Msk ? 1:0 )
165
173#define I2C_GET_WAKEUP_FLAG(i2c) ( ((i2c)->I2CSTATUS2 & I2C_I2CSTATUS2_WAKEUP_Msk) == I2C_I2CSTATUS2_WAKEUP_Msk ? 1:0 )
174
180#define I2C_CLEAR_WAKEUP_FLAG(i2c) ((i2c)->I2CSTATUS2 |= I2C_I2CSTATUS2_WAKEUP_Msk )
181
182uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock);
183void I2C_Close(I2C_T *i2c);
184void I2C_ClearTimeoutFlag(I2C_T *i2c);
185void I2C_Trigger(I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack);
186void I2C_DisableInt(I2C_T *i2c);
187void I2C_EnableInt(I2C_T *i2c);
188uint32_t I2C_GetBusClockFreq(I2C_T *i2c);
189uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock);
190uint32_t I2C_GetIntFlag(I2C_T *i2c);
191uint32_t I2C_GetStatus(I2C_T *i2c);
192uint32_t I2C_GetData(I2C_T *i2c);
193void I2C_SetData(I2C_T *i2c, uint8_t u8Data);
194void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode);
195void I2C_SetSlaveAddrMask(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask);
196void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout);
197void I2C_DisableTimeout(I2C_T *i2c);
198void I2C_EnableWakeup(I2C_T *i2c);
199void I2C_DisableWakeup(I2C_T *i2c);
200 /* end of group MINI51_I2C_EXPORTED_FUNCTIONS */
202 /* end of group MINI51_I2C_Driver */
204 /* end of group MINI51_Device_Driver */
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif //__I2C_H__
212
213/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
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".
Definition: i2c.c:223
void I2C_Close(I2C_T *i2c)
This function closes the I2C module.
Definition: i2c.c:51
uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock)
This function enables the interrupt (EI bit) of I2C module.
Definition: i2c.c:134
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.
Definition: i2c.c:80
void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout)
This function enables timeout function and configures DIV4 function to support long timeout.
Definition: i2c.c:250
void I2C_ClearTimeoutFlag(I2C_T *i2c)
This function clears the timeout flag.
Definition: i2c.c:66
void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode)
Configure slave address and enable GC mode.
Definition: i2c.c:195
void I2C_SetData(I2C_T *i2c, uint8_t u8Data)
This function writes the data to data register of I2C module.
Definition: i2c.c:182
uint32_t I2C_GetBusClockFreq(I2C_T *i2c)
This function returns the real bus clock of I2C module.
Definition: i2c.c:121
void I2C_EnableInt(I2C_T *i2c)
This function enables the interrupt (EI bit) of I2C module.
Definition: i2c.c:111
void I2C_DisableWakeup(I2C_T *i2c)
This function disables the wakeup function of I2C module.
Definition: i2c.c:285
uint32_t I2C_GetStatus(I2C_T *i2c)
This function returns the status of I2C module.
Definition: i2c.c:161
void I2C_DisableInt(I2C_T *i2c)
This function disables the interrupt (EI bit) of I2C module.
Definition: i2c.c:101
uint32_t I2C_GetData(I2C_T *i2c)
This function returns the data stored in data register of I2C module.
Definition: i2c.c:171
void I2C_EnableWakeup(I2C_T *i2c)
This function enables the wakeup function of I2C module.
Definition: i2c.c:275
uint32_t I2C_GetIntFlag(I2C_T *i2c)
This function gets the interrupt flag (SI bit) of I2C module.
Definition: i2c.c:151
uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock)
This function make I2C module be ready and set the wanted bus clock.
Definition: i2c.c:33
void I2C_DisableTimeout(I2C_T *i2c)
This function disables timeout function.
Definition: i2c.c:265