48 u32ClkDiv = (uint32_t) ((((((u32Pclk/2U)*10U)/(u32BusClock))+5U)/10U)-1U);
51 ui2c->
CTL &= ~UI2C_CTL_FUNMODE_Msk;
56 ui2c->
LINECTL &= ~UI2C_LINECTL_DWIDTH_Msk;
60 ui2c->
LINECTL &= ~UI2C_LINECTL_LSB_Msk;
63 ui2c->
BRGEN &= ~UI2C_BRGEN_CLKDIV_Msk;
67 return ( u32Pclk / ((u32ClkDiv+1U)<<1U) );
82 ui2c->
CTL &= ~UI2C_CTL_FUNMODE_Msk;
114 uint32_t u32Reg = 0U;
134 ui2c->
PROTCTL = u32Val | u32Reg;
161 ui2c->
PROTIEN &= ~UI2C_PROTIEN_TOIEN_Msk;
167 ui2c->
PROTIEN &= ~UI2C_PROTIEN_STARIEN_Msk;
173 ui2c->
PROTIEN &= ~UI2C_PROTIEN_STORIEN_Msk;
179 ui2c->
PROTIEN &= ~UI2C_PROTIEN_NACKIEN_Msk;
185 ui2c->
PROTIEN &= ~UI2C_PROTIEN_ARBLOIEN_Msk;
191 ui2c->
PROTIEN &= ~UI2C_PROTIEN_ERRIEN_Msk;
197 ui2c->
PROTIEN &= ~UI2C_PROTIEN_ACKIEN_Msk;
288 return ( u32Pclk / ((u32Divider+1U)<<1U) );
315 u32ClkDiv = (uint32_t) ((((((u32Pclk/2U)*10U)/(u32BusClock))+5U)/10U)-1U);
318 ui2c->
BRGEN &= ~UI2C_BRGEN_CLKDIV_Msk;
321 return ( u32Pclk / ((u32ClkDiv+1U)<<1U) );
345 uint32_t u32IntFlag = 0U;
346 uint32_t u32TmpValue;
474 return ( ui2c->
RXDAT );
489 ui2c->
TXDAT = u8Data;
517 ui2c->
PROTCTL = (ui2c->
PROTCTL & ~UI2C_PROTCTL_GCFUNC_Msk) |u8GCMode;
571 ui2c->
PROTCTL &= ~UI2C_PROTCTL_TOCNT_Msk;
572 ui2c->
BRGEN &= ~UI2C_BRGEN_TMCNTEN_Msk;
603 ui2c->
WKCTL &= ~UI2C_WKCTL_WKEN_Msk;
622 uint8_t u8Xfering = 1U, u8Err = 0U, u8Ctrl = 0U;
677 return (u8Err | u8Xfering);
696 uint8_t u8Xfering = 1U, u8Ctrl = 0U;
697 uint32_t u32txLen = 0U;
716 if (u32txLen < u32wLen)
765 uint8_t u8Xfering = 1U, u8Err = 0U, u8Ctrl = 0U;
766 uint32_t u32txLen = 0U;
790 else if (u32txLen == 1U)
824 return (u8Err | u8Xfering);
845 uint8_t u8Xfering = 1U, u8Ctrl = 0U;
846 uint32_t u32txLen = 0U;
874 if (u32txLen < u32wLen)
924 uint8_t u8Xfering = 1U, u8Err = 0U, u8Ctrl = 0U;
925 uint32_t u32txLen = 0U;
946 UI2C_SET_DATA(ui2c, (uint8_t)((u16DataAddr & 0xFF00U) >> 8U));
949 else if (u32txLen == 1U)
954 else if (u32txLen == 2U)
988 return (u8Err | u8Xfering);
1009 uint8_t u8Xfering = 1U, u8Addr = 1U, u8Ctrl = 0U;
1010 uint32_t u32txLen = 0U;
1033 UI2C_SET_DATA(ui2c, (uint8_t)((u16DataAddr & 0xFF00U) >> 8U));
1045 if (u32txLen < u32wLen)
1094 uint8_t u8Xfering = 1U, u8Err = 0U, rdata = 0U, u8Ctrl = 0U;
1172 uint8_t u8Xfering = 1U, u8Ctrl = 0U;
1173 uint32_t u32rxLen = 0U;
1203 if (u32rxLen < (u32rLen - 1U))
1255 uint8_t u8Xfering = 1U, u8Err = 0U, rdata = 0U, u8Ctrl = 0U;
1361 uint8_t u8Xfering = 1U, u8Ctrl = 0U;
1362 uint32_t u32rxLen = 0U;
1414 if (u32rxLen < u32rLen - 1U)
1465 uint8_t u8Xfering = 1U, u8Err = 0U, rdata = 0U, u8Addr = 1U, u8Ctrl = 0U;
1498 UI2C_SET_DATA(ui2c, (uint8_t)((u16DataAddr & 0xFF00U) >> 8U));
1578 uint8_t u8Xfering = 1U, u8Addr = 1U, u8Ctrl = 0U;
1579 uint32_t u32rxLen = 0U;
1612 UI2C_SET_DATA(ui2c, (uint8_t)((u16DataAddr & 0xFF00U) >> 8U));
1637 if (u32rxLen < u32rLen - 1U)
NuMicro peripheral access layer header file.
uint32_t CLK_GetPCLK1Freq(void)
Get PCLK1 frequency.
uint32_t CLK_GetPCLK0Freq(void)
Get PCLK0 frequency.
#define UI2C_LINECTL_DWIDTH_Pos
#define UI2C_BRGEN_TMCNTEN_Msk
#define UI2C_BRGEN_CLKDIV_Msk
#define UI2C_PROTIEN_STARIEN_Msk
#define UI2C_PROTSTS_STARIF_Msk
#define UI2C_PROTCTL_STA_Msk
#define UI2C_PROTSTS_NACKIF_Msk
#define UI2C_PROTSTS_ARBLOIF_Msk
#define UI2C_PROTCTL_STO_Msk
#define UI2C_PROTIEN_ACKIEN_Msk
#define UI2C_WKCTL_WKEN_Msk
#define UI2C_BRGEN_CLKDIV_Pos
#define UI2C_PROTIEN_TOIEN_Msk
#define UI2C_PROTSTS_ACKIF_Msk
#define UI2C_PROTCTL_PTRG_Msk
#define UI2C_PROTIEN_ARBLOIEN_Msk
#define UI2C_PROTIEN_STORIEN_Msk
#define UI2C_PROTSTS_TOIF_Msk
#define UI2C_PROTCTL_AA_Msk
#define UI2C_PROTCTL_PROTEN_Msk
#define UI2C_PROTIEN_NACKIEN_Msk
#define UI2C_PROTSTS_ERRIF_Msk
#define UI2C_PROTIEN_ERRIEN_Msk
#define UI2C_PROTSTS_STORIF_Msk
#define UI2C_CTL_FUNMODE_Pos
#define UI2C_PROTCTL_TOCNT_Pos
#define UI2C_NACK_INT_MASK
#define UI2C_ACK_INT_MASK
#define UI2C_STAR_INT_MASK
#define UI2C_ERR_INT_MASK
#define UI2C_STOR_INT_MASK
#define UI2C_ARBLO_INT_MASK
@ MASTER_SEND_H_RD_ADDRESS
@ MASTER_SEND_REPEAT_START
void UI2C_EnableInt(UI2C_T *ui2c, uint32_t u32Mask)
This function enables the interrupt of USCI_I2C module.
#define UI2C_START(ui2c)
This macro only set START bit to protocol control register of USCI_I2C module.
uint32_t UI2C_GetIntFlag(UI2C_T *ui2c, uint32_t u32Mask)
This function gets the interrupt flag of USCI_I2C module.
uint32_t UI2C_Open(UI2C_T *ui2c, uint32_t u32BusClock)
This function makes USCI_I2C module be ready and set the wanted bus clock.
void UI2C_DisableWakeup(UI2C_T *ui2c)
This function disables the wakeup function of USCI_I2C module.
uint32_t UI2C_GetData(UI2C_T *ui2c)
This function returns the data stored in data register of USCI_I2C module.
void UI2C_SetSlaveAddr(UI2C_T *ui2c, uint8_t u8SlaveNo, uint16_t u16SlaveAddr, uint8_t u8GCMode)
Configure slave address and enable GC mode.
uint8_t UI2C_WriteByte(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t data)
Write a byte to Slave.
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.
void UI2C_DisableTimeout(UI2C_T *ui2c)
This function disables time-out function.
uint8_t UI2C_ReadByteTwoRegs(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint16_t u16DataAddr)
Specify two bytes register address and read a byte from Slave.
void UI2C_SetData(UI2C_T *ui2c, uint8_t u8Data)
This function writes a byte data to data register of USCI_I2C module.
uint8_t UI2C_ReadByteOneReg(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t u8DataAddr)
Specify a byte register address and read a byte from Slave.
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.
void UI2C_EnableTimeout(UI2C_T *ui2c, uint32_t u32TimeoutCnt)
This function enables time-out function and configures timeout counter.
void UI2C_EnableWakeup(UI2C_T *ui2c, uint8_t u8WakeupMode)
This function enables the wakeup function of USCI_I2C module.
uint32_t UI2C_WriteMultiBytes(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t *data, uint32_t u32wLen)
Write multi bytes to Slave.
void UI2C_DisableInt(UI2C_T *ui2c, uint32_t u32Mask)
This function disables the interrupt of USCI_I2C module.
void UI2C_ClearIntFlag(UI2C_T *ui2c, uint32_t u32Mask)
This function clears the interrupt flag of USCI_I2C module.
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.
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.
#define UI2C_GET_PROT_STATUS(ui2c)
This macro gets USCI_I2C protocol interrupt flag or bus status.
#define UI2C_SET_CONTROL_REG(ui2c, u8Ctrl)
This macro sets the USCI_I2C protocol control register at one time.
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.
#define UI2C_CLR_PROT_INT_FLAG(ui2c, u32IntTypeFlag)
This macro clears specified protocol interrupt flag.
uint8_t UI2C_ReadByte(UI2C_T *ui2c, uint8_t u8SlaveAddr)
Read a byte from Slave.
uint32_t UI2C_GetBusClockFreq(UI2C_T *ui2c)
This function returns the real bus clock of USCI_I2C module.
void UI2C_ClearTimeoutFlag(UI2C_T *ui2c)
This function clears the time-out flag.
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.
#define UI2C_SET_DATA(ui2c, u8Data)
This macro writes the data to data register of USCI_I2C module.
void UI2C_Close(UI2C_T *ui2c)
This function closes the USCI_I2C module.
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.
#define UI2C_GET_DATA(ui2c)
This macro returns the data stored in data register of USCI_I2C module.
void UI2C_SetSlaveAddrMask(UI2C_T *ui2c, uint8_t u8SlaveNo, uint16_t u16SlaveAddrMask)
Configure the mask bit of slave address.
uint32_t UI2C_SetBusClockFreq(UI2C_T *ui2c, uint32_t u32BusClock)
This function sets bus clock frequency of USCI_I2C module.
uint32_t UI2C_ReadMultiBytes(UI2C_T *ui2c, uint8_t u8SlaveAddr, uint8_t *rdata, uint32_t u32rLen)
Read multi bytes from Slave.