| M480 BSP V3.05.001 The Board Support Package for M480 Series

usci_i2c.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __USCI_I2C_H__
10 #define __USCI_I2C_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
30 /*---------------------------------------------------------------------------------------------------------*/
31 /* USCI_I2C master event definitions */
32 /*---------------------------------------------------------------------------------------------------------*/
33 enum UI2C_MASTER_EVENT
34 {
35 MASTER_SEND_ADDRESS = 10,
36 MASTER_SEND_H_WR_ADDRESS,
37 MASTER_SEND_H_RD_ADDRESS,
38 MASTER_SEND_L_ADDRESS,
39 MASTER_SEND_DATA,
40 MASTER_SEND_REPEAT_START,
41 MASTER_READ_DATA,
42 MASTER_STOP,
43 MASTER_SEND_START
44 };
45
46 /*---------------------------------------------------------------------------------------------------------*/
47 /* USCI_I2C slave event definitions */
48 /*---------------------------------------------------------------------------------------------------------*/
49 enum UI2C_SLAVE_EVENT
50 {
51 SLAVE_ADDRESS_ACK = 100,
52 SLAVE_H_WR_ADDRESS_ACK,
53 SLAVE_L_WR_ADDRESS_ACK,
54 SLAVE_GET_DATA,
55 SLAVE_SEND_DATA,
56 SLAVE_H_RD_ADDRESS_ACK,
57 SLAVE_L_RD_ADDRESS_ACK
58 };
59
60 /*---------------------------------------------------------------------------------------------------------*/
61 /* USCI_CTL constant definitions. */
62 /*---------------------------------------------------------------------------------------------------------*/
63 #define UI2C_CTL_PTRG 0x20UL
64 #define UI2C_CTL_STA 0x08UL
65 #define UI2C_CTL_STO 0x04UL
66 #define UI2C_CTL_AA 0x02UL
68 /*---------------------------------------------------------------------------------------------------------*/
69 /* USCI_I2C GCMode constant definitions. */
70 /*---------------------------------------------------------------------------------------------------------*/
71 #define UI2C_GCMODE_ENABLE (1U)
72 #define UI2C_GCMODE_DISABLE (0U)
74 /*---------------------------------------------------------------------------------------------------------*/
75 /* USCI_I2C Wakeup Mode constant definitions. */
76 /*---------------------------------------------------------------------------------------------------------*/
77 #define UI2C_DATA_TOGGLE_WK (0x0U << UI2C_WKCTL_WKADDREN_Pos)
78 #define UI2C_ADDR_MATCH_WK (0x1U << UI2C_WKCTL_WKADDREN_Pos)
80 /*---------------------------------------------------------------------------------------------------------*/
81 /* USCI_I2C interrupt mask definitions */
82 /*---------------------------------------------------------------------------------------------------------*/
83 #define UI2C_TO_INT_MASK (0x001U)
84 #define UI2C_STAR_INT_MASK (0x002U)
85 #define UI2C_STOR_INT_MASK (0x004U)
86 #define UI2C_NACK_INT_MASK (0x008U)
87 #define UI2C_ARBLO_INT_MASK (0x010U)
88 #define UI2C_ERR_INT_MASK (0x020U)
89 #define UI2C_ACK_INT_MASK (0x040U)
91 /* end of group USCI_I2C_EXPORTED_CONSTANTS */
92
93
109 #define UI2C_SET_CONTROL_REG(ui2c, u8Ctrl) ((ui2c)->PROTCTL = ((ui2c)->PROTCTL & ~0x2EU) | (u8Ctrl))
110
121 #define UI2C_START(ui2c) ((ui2c)->PROTCTL = ((ui2c)->PROTCTL & ~UI2C_PROTCTL_PTRG_Msk) | UI2C_PROTCTL_STA_Msk)
122
133 #define UI2C_STOP(ui2c) ((ui2c)->PROTCTL = ((ui2c)->PROTCTL & ~0x2E) | (UI2C_PROTCTL_PTRG_Msk | UI2C_PROTCTL_STO_Msk))
134
145 #define UI2C_GET_DATA(ui2c) ((ui2c)->RXDAT)
146
158 #define UI2C_SET_DATA(ui2c, u8Data) ((ui2c)->TXDAT = (u8Data))
159
171 #define UI2C_GET_TIMEOUT_FLAG(ui2c) (((ui2c)->PROTSTS & UI2C_PROTSTS_TOIF_Msk) == UI2C_PROTSTS_TOIF_Msk ? 1:0)
172
184 #define UI2C_GET_WAKEUP_FLAG(ui2c) (((ui2c)->WKSTS & UI2C_WKSTS_WKF_Msk) == UI2C_WKSTS_WKF_Msk ? 1:0)
185
196 #define UI2C_CLR_WAKEUP_FLAG(ui2c) ((ui2c)->WKSTS = UI2C_WKSTS_WKF_Msk)
197
208 #define UI2C_DISABLE_10BIT_ADDR_MODE(ui2c) ((ui2c)->PROTCTL &= ~(UI2C_PROTCTL_ADDR10EN_Msk))
209
220 #define UI2C_ENABLE_10BIT_ADDR_MODE(ui2c) ((ui2c)->PROTCTL |= UI2C_PROTCTL_ADDR10EN_Msk)
221
232 #define UI2C_GET_PROT_STATUS(ui2c) ((ui2c)->PROTSTS)
233
250 #define UI2C_CLR_PROT_INT_FLAG(ui2c,u32IntTypeFlag) ((ui2c)->PROTSTS = (u32IntTypeFlag))
251
268 #define UI2C_ENABLE_PROT_INT(ui2c, u32IntSel) ((ui2c)->PROTIEN |= (u32IntSel))
269
286 #define UI2C_DISABLE_PROT_INT(ui2c, u32IntSel) ((ui2c)->PROTIEN &= ~ (u32IntSel))
287
288
289 uint32_t UI2C_Open(UI2C_T *ui2c, uint32_t u32BusClock);
290 void UI2C_Close(UI2C_T *ui2c);
291 void UI2C_ClearTimeoutFlag(UI2C_T *ui2c);
292 void UI2C_Trigger(UI2C_T *ui2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Ptrg, uint8_t u8Ack);
293 void UI2C_DisableInt(UI2C_T *ui2c, uint32_t u32Mask);
294 void UI2C_EnableInt(UI2C_T *ui2c, uint32_t u32Mask);
295 uint32_t UI2C_GetBusClockFreq(UI2C_T *ui2c);
296 uint32_t UI2C_SetBusClockFreq(UI2C_T *ui2c, uint32_t u32BusClock);
297 uint32_t UI2C_GetIntFlag(UI2C_T *ui2c, uint32_t u32Mask);
298 void UI2C_ClearIntFlag(UI2C_T* ui2c, uint32_t u32Mask);
299 uint32_t UI2C_GetData(UI2C_T *ui2c);
300 void UI2C_SetData(UI2C_T *ui2c, uint8_t u8Data);
301 void UI2C_SetSlaveAddr(UI2C_T *ui2c, uint8_t u8SlaveNo, uint16_t u16SlaveAddr, uint8_t u8GCMode);
302 void UI2C_SetSlaveAddrMask(UI2C_T *ui2c, uint8_t u8SlaveNo, uint16_t u16SlaveAddrMask);
303 void UI2C_EnableTimeout(UI2C_T *ui2c, uint32_t u32TimeoutCnt);
304 void UI2C_DisableTimeout(UI2C_T *ui2c);
305 void UI2C_EnableWakeup(UI2C_T *ui2c, uint8_t u8WakeupMode);
306 void UI2C_DisableWakeup(UI2C_T *ui2c);
307 uint8_t UI2C_WriteByte(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t data);
308 uint32_t UI2C_WriteMultiBytes(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t *data, uint32_t u32wLen);
309 uint8_t UI2C_WriteByteOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr, uint8_t data);
310 uint32_t UI2C_WriteMultiBytesOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr, uint8_t *data, uint32_t u32wLen);
311 uint8_t UI2C_WriteByteTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr, uint8_t data);
312 uint32_t UI2C_WriteMultiBytesTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr, uint8_t *data, uint32_t u32wLen);
313 uint8_t UI2C_ReadByte(UI2C_T *ui2c, uint8_t u8SlaveAddr);
314 uint32_t UI2C_ReadMultiBytes(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t *rdata, uint32_t u32rLen);
315 uint8_t UI2C_ReadByteOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr);
316 uint32_t UI2C_ReadMultiBytesOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr, uint8_t *rdata, uint32_t u32rLen);
317 uint8_t UI2C_ReadByteTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr);
318 uint32_t UI2C_ReadMultiBytesTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr, uint8_t *rdata, uint32_t u32rLen);
319 /* end of group USCI_I2C_EXPORTED_FUNCTIONS */
321 /* end of group USCI_I2C_Driver */
323 /* end of group Standard_Driver */
325
326 #ifdef __cplusplus
327 }
328 #endif
329
330 #endif
331
332 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
MASTER_SEND_DATA
Definition: usci_i2c.h:39
UI2C_SetSlaveAddrMask
void UI2C_SetSlaveAddrMask(UI2C_T *ui2c, uint8_t u8SlaveNo, uint16_t u16SlaveAddrMask)
Configure the mask bit of slave address.
Definition: usci_i2c.c:532
MASTER_SEND_ADDRESS
Definition: usci_i2c.h:35
UI2C_SetData
void UI2C_SetData(UI2C_T *ui2c, uint8_t u8Data)
This function writes a byte data to data register of USCI_I2C module.
Definition: usci_i2c.c:487
SLAVE_ADDRESS_ACK
Definition: usci_i2c.h:51
UI2C_EnableWakeup
void UI2C_EnableWakeup(UI2C_T *ui2c, uint8_t u8WakeupMode)
This function enables the wakeup function of USCI_I2C module.
Definition: usci_i2c.c:587
UI2C_EnableInt
void UI2C_EnableInt(UI2C_T *ui2c, uint32_t u32Mask)
This function enables the interrupt of USCI_I2C module.
Definition: usci_i2c.c:218
UI2C_SLAVE_EVENT
UI2C_SLAVE_EVENT
Definition: usci_i2c.h:49
SLAVE_H_RD_ADDRESS_ACK
Definition: usci_i2c.h:56
UI2C_DisableWakeup
void UI2C_DisableWakeup(UI2C_T *ui2c)
This function disables the wakeup function of USCI_I2C module.
Definition: usci_i2c.c:601
UI2C_Trigger
void UI2C_Trigger(UI2C_T *ui2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Ptrg, uint8_t u8Ack)
This function sets the control bit of the USCI_I2C module.
Definition: usci_i2c.c:112
UI2C_ReadMultiBytesTwoRegs
uint32_t UI2C_ReadMultiBytesTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr, uint8_t *rdata, uint32_t u32rLen)
Specify two bytes register address and read multi bytes from Slave.
Definition: usci_i2c.c:1576
UI2C_WriteByteOneReg
uint8_t UI2C_WriteByteOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr, uint8_t data)
Specify a byte register address and write a byte to Slave.
Definition: usci_i2c.c:763
UI2C_WriteMultiBytes
uint32_t UI2C_WriteMultiBytes(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t *data, uint32_t u32wLen)
Write multi bytes to Slave.
Definition: usci_i2c.c:694
MASTER_SEND_H_WR_ADDRESS
Definition: usci_i2c.h:36
UI2C_WriteMultiBytesOneReg
uint32_t UI2C_WriteMultiBytesOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr, uint8_t *data, uint32_t u32wLen)
Specify a byte register address and write multi bytes to Slave.
Definition: usci_i2c.c:843
UI2C_GetBusClockFreq
uint32_t UI2C_GetBusClockFreq(UI2C_T *ui2c)
This function returns the real bus clock of USCI_I2C module.
Definition: usci_i2c.c:272
SLAVE_SEND_DATA
Definition: usci_i2c.h:55
SLAVE_H_WR_ADDRESS_ACK
Definition: usci_i2c.h:52
SLAVE_L_RD_ADDRESS_ACK
Definition: usci_i2c.h:57
UI2C_EnableTimeout
void UI2C_EnableTimeout(UI2C_T *ui2c, uint32_t u32TimeoutCnt)
This function enables time-out function and configures timeout counter.
Definition: usci_i2c.c:554
UI2C_SetSlaveAddr
void UI2C_SetSlaveAddr(UI2C_T *ui2c, uint8_t u8SlaveNo, uint16_t u16SlaveAddr, uint8_t u8GCMode)
Configure slave address and enable GC mode.
Definition: usci_i2c.c:506
UI2C_ReadByteTwoRegs
uint8_t UI2C_ReadByteTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr)
Specify two bytes register address and read a byte from Slave.
Definition: usci_i2c.c:1463
UI2C_ReadByte
uint8_t UI2C_ReadByte(UI2C_T *ui2c, uint8_t u8SlaveAddr)
Read a byte from Slave.
Definition: usci_i2c.c:1092
UI2C_GetIntFlag
uint32_t UI2C_GetIntFlag(UI2C_T *ui2c, uint32_t u32Mask)
This function gets the interrupt flag of USCI_I2C module.
Definition: usci_i2c.c:343
UI2C_ClearIntFlag
void UI2C_ClearIntFlag(UI2C_T *ui2c, uint32_t u32Mask)
This function clears the interrupt flag of USCI_I2C module.
Definition: usci_i2c.c:418
UI2C_Close
void UI2C_Close(UI2C_T *ui2c)
This function closes the USCI_I2C module.
Definition: usci_i2c.c:79
UI2C_DisableTimeout
void UI2C_DisableTimeout(UI2C_T *ui2c)
This function disables time-out function.
Definition: usci_i2c.c:569
UI2C_T
Definition: ui2c_reg.h:26
MASTER_SEND_REPEAT_START
Definition: usci_i2c.h:40
MASTER_STOP
Definition: usci_i2c.h:42
UI2C_GetData
uint32_t UI2C_GetData(UI2C_T *ui2c)
This function returns the data stored in data register of USCI_I2C module.
Definition: usci_i2c.c:472
UI2C_ReadMultiBytes
uint32_t UI2C_ReadMultiBytes(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t *rdata, uint32_t u32rLen)
Read multi bytes from Slave.
Definition: usci_i2c.c:1170
UI2C_Open
uint32_t UI2C_Open(UI2C_T *ui2c, uint32_t u32BusClock)
This function makes USCI_I2C module be ready and set the wanted bus clock.
Definition: usci_i2c.c:34
UI2C_MASTER_EVENT
UI2C_MASTER_EVENT
Definition: usci_i2c.h:33
SLAVE_L_WR_ADDRESS_ACK
Definition: usci_i2c.h:53
MASTER_SEND_L_ADDRESS
Definition: usci_i2c.h:38
SLAVE_GET_DATA
Definition: usci_i2c.h:54
UI2C_ReadMultiBytesOneReg
uint32_t UI2C_ReadMultiBytesOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr, uint8_t *rdata, uint32_t u32rLen)
Specify a byte register address and read multi bytes from Slave.
Definition: usci_i2c.c:1359
UI2C_ClearTimeoutFlag
void UI2C_ClearTimeoutFlag(UI2C_T *ui2c)
This function clears the time-out flag.
Definition: usci_i2c.c:94
MASTER_READ_DATA
Definition: usci_i2c.h:41
UI2C_DisableInt
void UI2C_DisableInt(UI2C_T *ui2c, uint32_t u32Mask)
This function disables the interrupt of USCI_I2C module.
Definition: usci_i2c.c:156
UI2C_WriteMultiBytesTwoRegs
uint32_t UI2C_WriteMultiBytesTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr, uint8_t *data, uint32_t u32wLen)
Specify two bytes register address and write multi bytes to Slave.
Definition: usci_i2c.c:1007
UI2C_WriteByteTwoRegs
uint8_t UI2C_WriteByteTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr, uint8_t data)
Specify two bytes register address and Write a byte to Slave.
Definition: usci_i2c.c:922
MASTER_SEND_H_RD_ADDRESS
Definition: usci_i2c.h:37
UI2C_SetBusClockFreq
uint32_t UI2C_SetBusClockFreq(UI2C_T *ui2c, uint32_t u32BusClock)
This function sets bus clock frequency of USCI_I2C module.
Definition: usci_i2c.c:301
UI2C_ReadByteOneReg
uint8_t UI2C_ReadByteOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr)
Specify a byte register address and read a byte from Slave.
Definition: usci_i2c.c:1253
MASTER_SEND_START
Definition: usci_i2c.h:43
UI2C_WriteByte
uint8_t UI2C_WriteByte(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t data)
Write a byte to Slave.
Definition: usci_i2c.c:620