I2C Busy Flag problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-21 4: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-21 6:44 AM
The ReMap would require the AFIO clock enabled.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-21 12:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-21 1: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.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-21 2:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-21 4: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 0xD0Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-22 3: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 ? thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-12-22 3:26 AM
Now I try 0xD0 . but in debug mode I change breakout point location .
here is my screen.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 ? thanks