是不是在写偏移的时候,把那个偏移地址按照24C512的时序,把数据地址,写2遍,先写高8bit,再写低8bit。
我这样改了,好像还是不行。
/* send offset if needed *///对于24C512这里增加一个地址 if (offset != 0xffffffff) { HiByte=(offset>>8)&0xff; LiByte=offset&0xff; //先发高地址 I2C_SendData(I2Cx, HiByte); *(u32 *)0xe000e014 = SEND_DATA_TIMEOUT; //SysTick_SetReload(SEND_DATA_TIMEOUT); *(u32 *)0xe000e018 = 0; //SysTick_CounterCmd(SysTick_Counter_Clear); *(u32 *)0xe000e010 |= 1; //SysTick_CounterCmd(SysTick_Counter_Enable); while(!(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED) || I2C_OT)); *(u32 *)0xe000e010 &= 0xfffffffe; //SysTick_CounterCmd(SysTick_Counter_Disable); if (I2C_OT) { I2C_OT = FALSE; I2C_GenerateSTOP(I2Cx, ENABLE); while ((I2C1->CR1 & 0x200) == 0x200); //wait while stop bit not cleared if(I2C_GetFlagStatus(I2Cx, I2C_FLAG_AF)) I2C_ClearFlag(I2Cx, I2C_FLAG_AF); return DATA_TIMEOUT; }
//后发低地址 I2C_SendData(I2Cx, LiByte); *(u32 *)0xe000e014 = SEND_DATA_TIMEOUT; //SysTick_SetReload(SEND_DATA_TIMEOUT); *(u32 *)0xe000e018 = 0; //SysTick_CounterCmd(SysTick_Counter_Clear); *(u32 *)0xe000e010 |= 1; //SysTick_CounterCmd(SysTick_Counter_Enable); while(!(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED) || I2C_OT)); *(u32 *)0xe000e010 &= 0xfffffffe; //SysTick_CounterCmd(SysTick_Counter_Disable); if (I2C_OT) { I2C_OT = FALSE; I2C_GenerateSTOP(I2Cx, ENABLE); while ((I2C1->CR1 & 0x200) == 0x200); //wait while stop bit not cleared if(I2C_GetFlagStatus(I2Cx, I2C_FLAG_AF)) I2C_ClearFlag(I2Cx, I2C_FLAG_AF); return DATA_TIMEOUT; } } |