/*------------------- W R I T E A T 2 4 C 2 5 6 -------------------- 【功能】:**** 【参数】:**** 【返回】:**** 【说明】:**** --------------作者:**** 2009年5月15日12:51:28-------------------------*/ void WriteAT24C256(u32 addr, u8 *ptr, u32 len) {
#ifndef I2C_REMMAP I2cInit(); #endif I2C_AcknowledgePolling(); for ( ; len!=0; len--) { I2C_GenerateSTART(I2C1,ENABLE); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)!=SUCCESS); I2C_Send7bitAddress(I2C1,AT24_DEVICE_ADDR,I2C_Direction_Transmitter); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)!=SUCCESS); I2C_SendData(I2C1,(addr>>8)); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)!=SUCCESS); I2C_SendData(I2C1,(addr&0xff)); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)!=SUCCESS); I2C_SendData(I2C1,*ptr++); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)!=SUCCESS); I2C_GenerateSTOP(I2C1,ENABLE); addr++; Delay_us(5000); // Wait at least 5 ms before value is written into EEPROM } #if 0 I2C_GenerateSTART(I2C1,ENABLE); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)!=SUCCESS); I2C_Send7bitAddress(I2C1,AT24_DEVICE_ADDR,I2C_Direction_Transmitter); while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)!=SUCCESS);
/*------------------- R E A D A T 2 4 C 2 5 6 -------------------- 【功能】:**** 【参数】:**** 【返回】:**** 【说明】:**** --------------作者:**** 2009年5月15日12:51:22-------------------------*/ void ReadAT24C256(u32 addr, u8 *ptr, u32 len) { // int i;