2013-12-21 04:35 AM
hello.
I want to write byte to the sensör with I2C so write this codevoid MPU6050_I2C_Init()
{
// RCC Configuration
RCC_HCLKConfig(RCC_SYSCLK_Div2);
RCC_PCLK1Config(RCC_HCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
// GPIO Configuration
GPIO_Config_Anahtari.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_Config_Anahtari.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Config_Anahtari.GPIO_Speed = GPIO_Speed_2MHz;GPIO_Init(GPIOB,&GPIO_Config_Anahtari);
GPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);
// I2C Configuration
I2C_Config_Anahtari.I2C_Mode = I2C_Mode_I2C;
I2C_Config_Anahtari.I2C_ClockSpeed = 400000;
I2C_Config_Anahtari.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_Config_Anahtari.I2C_Ack = ENABLE;
I2C_Config_Anahtari.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Config_Anahtari.I2C_OwnAddress1 = 0x10;
I2C_Init(I2C1,&I2C_Config_Anahtari);I2C_Cmd(I2C1,ENABLE);
}
void I2C_MonitorAndClear_ADDR()
{
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_ADDR)==RESET);
I2C_ReadRegister(I2C1,I2C_Register_SR1);
I2C_ReadRegister(I2C1,I2C_Register_SR2);}
void I2C_Clear_SB_Monitor_MSL()
{
I2C_ReadRegister(I2C1,I2C_Register_SR1);
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_MSL)==RESET);
}
void MPU6050_SingleByte_Write(uint8_t register_address,uint8_t data)
{
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)==SET);
I2C_GenerateSTART(I2C1,ENABLE);
I2C_Clear_SB_Monitor_MSL();
I2C_Send7bitAddress(I2C1,MPU6050_Default_Address,I2C_Direction_Transmitter);
I2C_MonitorAndClear_ADDR();
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_TRA)==RESET); I2C_SendData(I2C1,register_address); while(I2C_GetFlagStatus(I2C1,I2C_FLAG_TXE)==RESET); I2C_SendData(I2C1,data); while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BTF)==RESET); I2C_GenerateSTOP(I2C1,ENABLE);}here is my functions . In RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); line , BUSY flag is set and never reset. So code hangs in here. When I reset the I2C1 periph clock with RCC_APB2PeriphResetCmd command , busy flag is reset but I can't configure the I2C interface after reset cmd. So what is the problem ?
thanks for your answer.
2013-12-21 06:44 AM
The ReMap would require the AFIO clock enabled.
2013-12-21 12:23 PM
2013-12-21 01:27 PM
Can you help me in this issue ?
Not much I suppose.So, what address are you sending? Can you see the transaction on a scope?I'd supposed it would use address 0xD0 or 0xD2 depending on the part strapping. Make sure it is strapped for I2C operation, and what address you expect.2013-12-21 02:34 PM
2013-12-21 04:57 PM
No, I really think you're misinterpreting the data sheets wrt 7-bit addressing.
0x68 << 1 = 0xD0 The lack of an ACK indicates the part doesn't recognize the presented address. Try 0xD02013-12-22 03:05 AM
I try 0xD0 . I dont receive nack bit, but this time ADDR bit is not set.Program hangs in
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)==ERROR); . So I dont understand what is the problem. I dont have any solution. Why ADDR bit is not set ? thanks2013-12-22 03:26 AM
Now I try 0xD0 . but in debug mode I change breakout point location .
here is my screen.When I insert breakout point like this, program not hangs in while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)==ERROR); line. But I insert breakout point like this(below picture) , And step one line usin F11 , program hangs in while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)==ERROR); line. So can you interpret this situation ? thanks againPosted: Sunday, December 22, 2013 12:05 PMSubject: I2C Busy Flag problemI try 0xD0 . I dont receive nack bit, but this time ADDR bit is not set.Program hangs in
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)==ERROR); . So I dont understand what is the problem. I dont have any solution. Why ADDR bit is not set ? thanks