2008-04-22 09:06 PM
I2C START and master mode
2011-05-17 03:31 AM
Hello,
I'm using the USART1 and after the instruction to generate start I2C_GenerateSTART(I2C1, ENABLE); the I2C1 master mode seem not to be selected the program stop at this instruction while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); ---- #define ClockSpeed 400000 ---- .... .... /* GPIO configuration ------------------------------------------------------*/ /* Configure I2C1 pins: SCL and SDA ----------------------------------------*/ GPIO_InitStructure_i2c.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure_i2c.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure_i2c.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure_i2c); /* Enable I2C1 ----------------------------------------------------*/ I2C_Cmd(I2C1, ENABLE); /* I2C1 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = ClockSpeed; I2C_Init(I2C1, &I2C_InitStructure); /*----- First transmission Phase -----*/ /* Send I2C1 START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* Test on I2C1 EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); Thanks..2011-05-17 03:31 AM
you're not showing where you enable the clock to the macrocell.
I init like this: I2C_DeInit(i2c); I2C_InitTypeDef i = { I2C_Mode_I2C, I2C_DutyCycle_2, 0, I2C_Ack_Enable, I2C_AcknowledgedAddress_7bit, clock }; I2C_Init(i2c, &i); (no I2C_Cmd() call since it's embedded in I2C_Init()) then I do this: I2C_GenerateSTART(i2cInterface.getI2C(), ENABLE); // send start when bus becomes available i2cInterface.waitForEvent(I2C_FLAG_SB);2011-05-17 03:31 AM
in order to use the i2c in master mode it is enough to generate a start with the function I2C_GenerateSTART(I2C1, ENABLE); ?
thanks2011-05-17 03:31 AM
My clock configuration
---- RCC configuration : void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* PLLCLK = 12MHz * 6 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } /* Enable GPIOA and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); /* Enable USART1 clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* Enable I2C1 clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); }2011-05-17 03:31 AM
wich library do you use, I haven't functions getI2C() or waitForEvent() I'm using the um0427 library
2011-05-17 03:31 AM
hi,
you're not enabling clock to GPIOB. the resynchronization of the input pins is not working since the synchronizer gets no clock, so the input signals to the I2C macrocell are constant values. if they are constant low values, then the I2C will think that the bus is in use and wait forever for it to become free before sending the start event. that's probably what's happening. > wich library do you use not really a library: > it is enough to generate a start with the function I2C_GenerateSTART(I2C1, ENABLE); ? yes.2011-05-17 03:31 AM
Hi lanchon,
You are online :) Cheers, STOne-32.2011-05-17 03:31 AM
Thank you Lanchon,
It is necessary that I pay more attention, I'm student in a traning period... Thank you for reply..