在做完模拟的I2C后,现在改用硬件的I2C,一点反应都没有,在仿真的情况下用示波器检测,就连Start信号也看不到,仿真软件中看到寄存器的值又是正确的,同志们帮忙分析下原因,下面是代码,用的是ST的DEMO和库函数
#define I2C_Speed 35000
void I2cInit(void)
{
/* Optional: put here as example only */
I2C_DeInit();
/* I2C Peripheral Enable */
I2C_Cmd(ENABLE);
/* Apply I2C configuration after enabling it */
I2C_Init(I2C_Speed, 0x88, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 8);
}
void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u8 NumByteToRead)
{
/* While the bus is busy */
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
/* Generate start & wait event detection */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
/* Send slave Address in write direction & wait detection event */
I2C_Send7bitAddress(CP_Add, I2C_DIRECTION_TX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
/* Send Address of first byte to be read & wait event detection */
//I2C_SendData((u8)(ReadAddr >> 8)); /* MSB */
/* Test on EV8 and clear it */
//while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData((u8)(ReadAddr)); /* LSB */
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
/* Send slave Address in read direction & wait event */
I2C_Send7bitAddress(CP_Add, I2C_DIRECTION_RX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
/* While there is data to be read */
while(NumByteToRead)
{
if(NumByteToRead == 1)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_ACK_NONE);
/* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);
}
/* Test on EV7 and clear it */
if(I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData();
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_ACK_CURR);
}
设置I2C频率是35K,非标准的,输入给I2C的频率设为8M,我用的时钟是内部8M的时钟,用I2C这两个口做模拟I2C是可以用的,实在想不明白了 |