| Nano100AN Series BSP V3.02.002 The Board Support Package for Nano100AN Series

Macros | Functions
I2C Exported Functions
NANO100 Device Driver » I2C Driver

## Macros
#define | I2C_SET_CONTROL_REG(i2c, u8Ctrl)
| This macro sets the I2C control register at one time. More...
#define | I2C_START(i2c)
| This macro only set START bit to the control register of I2C module. More...
#define | I2C_GET_DATA(i2c)
| This macro returns the data stored in data register of I2C module. More...
#define | I2C_SET_DATA(i2c, u8Data)
| This macro writes the data to data register of I2C module. More...
#define | I2C_GET_STATUS(i2c)
| This macro returns the status of I2C module. More...
#define | I2C_GET_TIMEOUT_FLAG(i2c)
| This macro returns timeout flag. More...
#define | I2C_CLEAR_TIMEOUT_FLAG(i2c)
| This macro clears timeout flag. More...

## Functions
static __INLINE void | I2C_STOP (I2C_T *i2c)
| This macro only set STOP bit to the control register of I2C module. More...
static __INLINE void | I2C_WAIT_READY (I2C_T *i2c)
| This macro will return when I2C module is ready. More...
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 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 sets bus frequency of I2C module. More...
uint32_t | I2C_GetIntFlag (I2C_T *i2c)
| This function gets the interrupt flag of I2C module. More...
void | I2C_ClearIntFlag (I2C_T *i2c)
| This function clears the interrupt flag 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)
void | I2C_DisableWakeup (I2C_T *i2c)

## Detailed Description

## Macro Definition Documentation

## ◆ I2C_CLEAR_TIMEOUT_FLAG

#define I2C_CLEAR_TIMEOUT_FLAG | ( |  | i2c | ) |

This macro clears timeout flag.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 130 of file i2c.h.

## ◆ I2C_GET_DATA

#define I2C_GET_DATA | ( |  | i2c | ) |

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

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  Data.

Definition at line 95 of file i2c.h.

## ◆ I2C_GET_STATUS

#define I2C_GET_STATUS | ( |  | i2c | ) |

This macro returns the status of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  Status.

Definition at line 112 of file i2c.h.

## ◆ I2C_GET_TIMEOUT_FLAG

#define I2C_GET_TIMEOUT_FLAG | ( |  | i2c | ) |

This macro returns timeout flag.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  Status.

Return values

  0 | Flag is not set.
  1 | Flag is set.

Definition at line 122 of file i2c.h.

## ◆ I2C_SET_CONTROL_REG

#define I2C_SET_CONTROL_REG | ( |  | i2c,
|  |  | u8Ctrl
| ) |  |

This macro sets the I2C control register at one time.

Parameters

  [in] | i2c | is the base address of I2C module.
  [in] | u8Ctrl | is the register value of I2C control register.

Returns
  none

Definition at line 55 of file i2c.h.

## ◆ I2C_SET_DATA

#define I2C_SET_DATA | ( |  | i2c,
|  |  | u8Data
| ) |  |

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

Parameters

  [in] | i2c | is the base address of I2C module.
  [in] | u8Data | is the data which will be write to data register of I2C module.

Returns
  none

Definition at line 104 of file i2c.h.

## ◆ I2C_START

#define I2C_START | ( |  | i2c | ) |

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

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 63 of file i2c.h.

## Function Documentation

## ◆ I2C_ClearIntFlag()

void I2C_ClearIntFlag | ( | I2C_T * | i2c | ) |

This function clears the interrupt flag of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 171 of file i2c.c.

## ◆ I2C_ClearTimeoutFlag()

void I2C_ClearTimeoutFlag | ( | I2C_T * | i2c | ) |

This function clears the timeout flag.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 75 of file i2c.c.

## ◆ I2C_Close()

void I2C_Close | ( | I2C_T * | i2c | ) |

This function closes the I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 52 of file i2c.c.

## ◆ I2C_DisableInt()

void I2C_DisableInt | ( | I2C_T * | i2c | ) |

This function disables the interrupt of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 111 of file i2c.c.

## ◆ I2C_DisableTimeout()

void I2C_DisableTimeout | ( | I2C_T * | i2c | ) |

This function disables timeout function.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 271 of file i2c.c.

## ◆ I2C_DisableWakeup()

void I2C_DisableWakeup | ( | I2C_T * | i2c | ) |

## ◆ I2C_EnableInt()

void I2C_EnableInt | ( | I2C_T * | i2c | ) |

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

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 121 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

  [in] | i2c | is the base address of I2C module.
  [in] | u8LongTimeout | Enable timeout counter input clock is divide by 4.

Returns
  none

Definition at line 256 of file i2c.c.

## ◆ I2C_EnableWakeup()

void I2C_EnableWakeup | ( | I2C_T * | i2c | ) |

## ◆ I2C_GetBusClockFreq()

uint32_t I2C_GetBusClockFreq | ( | I2C_T * | i2c | ) |

This function returns the real bus clock of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  Actual I2C bus clock frequency.

Definition at line 131 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

  [in] | i2c | is the base address of I2C module.

Returns
  Data.

Definition at line 191 of file i2c.c.

## ◆ I2C_GetIntFlag()

uint32_t I2C_GetIntFlag | ( | I2C_T * | i2c | ) |

This function gets the interrupt flag of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  Interrupt flag.

Return values

  0 | Flag is not set.
  1 | Flag is set.

Definition at line 161 of file i2c.c.

## ◆ I2C_GetStatus()

uint32_t I2C_GetStatus | ( | I2C_T * | i2c | ) |

This function returns the status of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  I2C status

Definition at line 181 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

  [in] | i2c | is the base address of I2C module.
  [in] | u32BusClock | is the target bus speed of I2C module.

Returns
  Actual I2C bus clock frequency.

Definition at line 34 of file i2c.c.

## ◆ I2C_SetBusClockFreq()

uint32_t I2C_SetBusClockFreq | ( | I2C_T * | i2c,
|  | uint32_t | u32BusClock
| ) |  |

This function sets bus frequency of I2C module.

Parameters

  [in] | i2c | is the base address of I2C module.
  [in] | u32BusClock | is the target bus speed of I2C module.

Returns
  Actual I2C bus clock frequency.

Definition at line 144 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

  [in] | i2c | is the base address of I2C module.
  [in] | u8Data | is the data which will be write to data register of I2C module.

Returns
  none

Definition at line 202 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

  [in] | i2c | is the base address of I2C module.
  [in] | u8SlaveNo | is the set number of salve address.
  [in] | u8SlaveAddr | is the slave address.
  [in] | u8GCMode | GC mode enable or not. Valid values are: I2C_GCMODE_ENABLE I2C_GCMODE_DISABLE

Returns
  none

Definition at line 217 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

  [in] | i2c | is the base address of I2C module.
  [in] | u8SlaveNo | is the set number of salve address.
  [in] | u8SlaveAddrMask | is the slave address mask.

Returns
  none

Definition at line 237 of file i2c.c.

## ◆ I2C_STOP()

static __INLINE void I2C_STOP | ( | I2C_T * | i2c | ) |
| static

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

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 71 of file i2c.h.

## ◆ 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

  [in] | i2c | is the base address of I2C module.
  [in] | u8Start | sets START bit to I2C module.
  [in] | u8Stop | sets STOP bit to I2C module.
  [in] | u8Si | sets SI bit to I2C module.
  [in] | u8Ack | sets ACK bit to I2C module.

Returns
  none

Definition at line 89 of file i2c.c.

## ◆ I2C_WAIT_READY()

static __INLINE void I2C_WAIT_READY | ( | I2C_T * | i2c | ) |
| static

This macro will return when I2C module is ready.

Parameters

  [in] | i2c | is the base address of I2C module.

Returns
  none

Definition at line 83 of file i2c.h.