/* ----------------------------------------------------------------------------- Function name : _hwrtc_I2cSendStart Purpose :i2c bus write/read start program Input parameters :none Output parameters : none ----------------------------------------------------------------------------- */ static void _hwi2c_I2cSendStart(void) { SET_SDAEPR_HIGH; //发送起始条件的数据信号 SET_SCLEPR_HIGH; /* set SDA,SCL to high */ I2CEPR_DELAY; //起始条件建立时间大于4.7us延时 SET_SDAEPR_LOW; //发送起始信号 /* set SDA to low */ I2CEPR_DELAY; //起始条件锁定时间大于4us SET_SCLEPR_LOW; //钳住总线,准备发送或接收数据 /* set SCL to low */ I2CEPR_DELAY; }
/* ----------------------------------------------------------------------------- Function name : _hwrtc_I2cSendStop Purpose :i2c bus write/read stop program Input parameters :none Output parameters : none ----------------------------------------------------------------------------- */ static void _hwi2c_I2cSendStop(void) { SET_SDAEPR_LOW; /* set SDA to low */ I2CEPR_DELAY ; SET_SCLEPR_HIGH; /* set SCL to high */ I2CEPR_DELAY ; SET_SDAEPR_HIGH; /* set SDA to high */ I2CEPR_DELAY ; SET_SCLEPR_LOW; }
/* ----------------------------------------------------------------------------- Function name : _hwrtc_I2cSendNAck Purpose :Send NACK Signal Input parameters :none Output parameters : none ----------------------------------------------------------------------------- */ static void _hwi2c_I2cSendNAck(void) { SET_SDAEPR_HIGH; /* set SDA to high */ I2CEPR_DELAY ;
SET_SCLEPR_HIGH; /* set SCL to high */ I2CEPR_DELAY ;
SET_SCLEPR_LOW; /* set SCL to low */ I2CEPR_DELAY ; }
/* ----------------------------------------------------------------------------- Function name : _u1_hwrtc_I2cGetAck Purpose :Get ACK Signal Input parameters :none Output parameters : ACK Signal ----------------------------------------------------------------------------- */ static u1_t _u1_hwi2c_I2cGetAck(void) { u1_t __temp = TRUE, __i = 0xFF; // bool_t __b_ea ;
// __b_ea = _testbit_(EA) ;
SET_SDAEPR_HIGH; /* set SDA to high,Release SDA for ACK */ I2CEPR_DELAY ;
SET_SCLEPR_HIGH; /* set SCL to high,raise ACK clock */
if (__temp) /* if success return 0x01,else return 0x00 */ { return FALSE; } else { return TRUE; } }
/* ----------------------------------------------------------------------------- Function name : _u1_hwrtc_I2cSendByte Purpose :Send one byte to I2C interface Input parameters :value-the Byte that will be sent Output parameters : TRUE or FALSE ----------------------------------------------------------------------------- */ static u1_t _u1_hwi2c_I2cSendByte(u1_t value) { u1_t __i, __temp; // bool_t __b_ea ;
/* ----------------------------------------------------------------------------- Function name : _u1_hwrtc_I2cGetLastByte Purpose :Get the last byte form I2C interface Input parameters :none Output parameters : the last byte from I2C interface ----------------------------------------------------------------------------- */ static u1_t _u1_hwi2c_I2cGetLastByte(void) { u1_t __i, __temp, __temp1; // bool_t __b_ea ;
我嘀较早时发言: “对于串行EEPROM的写操作,建议采用ACKNOWLEDGE POLLING代替延时ACKNOWLEDGE POLLING: Once the internally-timed write cycle has started and the EEPROM inputs are disabled, acknowledge polling CAN be initiated. This involves sending a start condition followed by the device address word. The Read/Write bit is representative of the operation desired. Only if the internal write cycle has completed will the EEPROM respond with a “0”, allowing the read or write sequence to continue. 简单地说就是在串行EEPROM开始内部写操作过程到完成这段时间,不管你试图进行读或者写操作,芯片都不会响应。