I2C_Init(I2C_MAX_STANDARD_FREQ, 0x86,I2C_DutyCycle_2, I2C_Ack_Disable, I2C_AcknowledgedAddress_7bit);
UINT8 I2C_AM_Byte_Read(UINT8 device_address, UINT16 reg_add)
{
UINT8 readdata,Temp;
UINT8 add_H,add_L;
add_H = reg_add>>8;
add_L = reg_add & 0x00FF;
while(I2C->SR3&0x02);//BUS EMPTY
LED1ON;
//I2C_GenerateSTART(ENABLE);
I2C->CR2 |= 0x01; //发送起始位
//while(!(I2C->CR2&0x01)); 这句我注释掉了,但是不注释也过不去 手册上说是发送完成自动清0。 (数据手册说明:START: This bit is set and cleared by software and cleared by hardware when start is sent or PE=0.)
while(!(I2C->SR1&0x01));// 等待起始发送完成,但是在这儿一直卡着过不去。 ( 数据手册说明:SB: Start Bit (Master mode) 0: No Start condition1: Start condition generated.)
Temp = I2C->SR1;
LED2ON;
I2C_Send7bitAddress(device_address, I2C_Direction_Transmitter);
while(!(I2C->SR1&0x02));//ADDR==1
Temp = I2C->SR1;
Temp = I2C->SR3;
I2C_SendData(add_H);
while(!(I2C->SR1&0x84));//TXE==1
I2C_SendData(add_L);
while(!(I2C->SR1&0x84));
I2C_GenerateSTART(ENABLE);
while(!(I2C->SR1&0x01));//SB==1
I2C_Send7bitAddress(device_address, I2C_Direction_Receiver);
while(!(I2C->SR1&0x02));//ADDR==1
Temp = I2C->SR1;
Temp = I2C->SR3;
while(!(I2C->SR1&0x40));//RXE==1
readdata = I2C_ReceiveData();
I2C_GenerateSTOP(ENABLE);
} |