32#define I2C_EEPROM I2C1
33#define I2C_EEPROM_IRQn I2C1_IRQn
38uint8_t g_u8DeviceAddr = 0x50;
39uint8_t g_au8TxData[3];
42volatile uint8_t g_u8EndFlag = 0;
43typedef void (*I2C_FUNC)(uint32_t u32Status);
44static I2C_FUNC s_I2CHandlerFn =
NULL;
62 SYS->IPRST_CTL2 &= ~SYS_IPRST_CTL2_I2C1_RST_Msk;
78 u32Status = I2C_EEPROM->STATUS;
87 if (s_I2CHandlerFn !=
NULL)
88 s_I2CHandlerFn(u32Status);
106 I2C_EEPROM->DIV = u8Divider;
110 NVIC_EnableIRQ(I2C_EEPROM_IRQn);
123 if (u32Status == 0x08)
125 I2C_EEPROM->DATA = g_u8DeviceAddr << 1;
128 else if (u32Status == 0x18)
130 I2C_EEPROM->DATA = g_au8TxData[g_u8DataLen++];
133 else if (u32Status == 0x20)
137 else if (u32Status == 0x28)
139 if (g_u8DataLen != 2)
141 I2C_EEPROM->DATA = g_au8TxData[g_u8DataLen++];
149 else if (u32Status == 0x10)
151 I2C_EEPROM->DATA = ((g_u8DeviceAddr << 1) | 0x01);
154 else if (u32Status == 0x40)
158 else if (u32Status == 0x58)
160 g_u8RxData = I2C_EEPROM->DATA;
164 else if (u32Status == 0xF8)
186 if (u32Status == 0x08)
188 I2C_EEPROM->DATA = g_u8DeviceAddr << 1;
191 else if (u32Status == 0x18)
193 I2C_EEPROM->DATA = g_au8TxData[g_u8DataLen++];
196 else if (u32Status == 0x20)
200 else if (u32Status == 0x28)
202 if (g_u8DataLen != 3)
204 I2C_EEPROM->DATA = g_au8TxData[g_u8DataLen++];
213 else if (u32Status == 0xF8)
236 g_au8TxData[0] = u16Address >> 8;
237 g_au8TxData[1] = u16Address & 0xFF;
238 g_au8TxData[2] = u8Data;
250 while (g_u8EndFlag == 0);
262 g_au8TxData[0] = u16Address >> 8;
263 g_au8TxData[1] = u16Address & 0xFF;
275 while (g_u8EndFlag == 0);
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
#define I2C_CON_INTEN_Msk
#define I2C_INTSTS_INTSTS_Msk
#define SYS_IPRST_CTL2_I2C1_RST_Msk
#define I2C_INTSTS_TIF_Msk
NuEdu-Basic01_I2C_EEPROM I2C driver header file for NuEdu-SDK-Nano130.
#define CLK_APBCLK_I2C1_EN
#define I2C_SET_CONTROL_REG(i2c, u8Ctrl)
This macro sets the I2C control register at one time.
#define CLK
Pointer to CLK register structure.
#define I2C1
Pointer to I2C1 register structure.
#define SYS
Pointer to SYS register structure.
#define SYS_PA_H_MFP_PA10_MFP_I2C1_SDA
#define SYS_PA_H_MFP_PA11_MFP_I2C1_SCL
#define NULL
NULL pointer.
uint8_t I2C_EEPROM_Read(uint16_t u16Address)
This function do the I2C data reading from EEPROM device.
void I2C_MasterTx(uint32_t u32Status)
This function checks the status of I2C, sets the related control bit and data if needed when this I2C...
void I2C_EEPROM_Write(uint16_t u16Address, uint8_t u8Data)
This function do the I2C data writing to EEPROM device.
void I2C1_IRQHandler(void)
I2C interrupt handler. Checks the I2C interrupt flag, clears the corresponding event flag and calls t...
__INLINE void I2C_PIN_Init(void)
Open GPIO port for I2C interface and enable this I2C controller clock and reset it.
void I2C_EEPROM_Init(uint8_t u8Divider)
This function initializes the I2C module, bit-rate = 100 kHz and enable the corresponding interrupt.
void I2C_MasterRx(uint32_t u32Status)
This function checks the status of I2C, sets the related control bit and data if needed when this I2C...