2009-12-28 03:32 AM
I2C
2011-05-17 04:35 AM
Hi
I have a problem with I2C(on I2C2).I have configured related parts, but I have not any output neither on data pin nor on clock pin whenever I send information via it.(oscilloscope does not show any activity,pins have external pull up resistors). I am using Ride7(7.20.09.0162) as a compiler and STM32F101 as a processor. The part of the program which is related to I2C configuration is as follow, and I will appreciate if anybody can help me to find my failure. #define Global_I2C2_Speed 350000 #define sysclock High //Reset and clock controll void RCC_Configuration(void) { RCC_DeInit();//RCC system reset(for debug purpose) RCC_HSEConfig(RCC_HSE_ON);//Enable HSE HSEStartUpStatus = RCC_WaitForHSEStartUp();//Wait till HSE is ready if(HSEStartUpStatus == SUCCESS) { RCC_PCLK2Config(RCC_HCLK_Div1);//APB2CLK = HCLK FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//Enable Prefetch Buffer #if(sysclock==High) RCC_HCLKConfig(RCC_SYSCLK_Div1);//AHBCLK = SYSCLK-36Mhz RCC_PCLK1Config(RCC_HCLK_Div2);//APB1CLK = AHBCLK/2-18Mhz FLASH_SetLatency(FLASH_Latency_2);//Flash 2 wait state RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9);//PLLCLK = 8MHz/2 * 9 = 36 MHz RCC_PLLCmd(ENABLE);//Enable PLL while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)//Wait till PLL is ready { } RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//Select PLL as system clock source while(RCC_GetSYSCLKSource() != 0x08)// Wait till PLL is used as system clock source { } #elif(sysclock==Low) RCC_HCLKConfig(RCC_SYSCLK_Div2);//AHBCLK = SYSCLK/2-8Mhz/2=4Mhz RCC_PCLK1Config(RCC_HCLK_Div1);//APB1CLK =AHBCLK-4Mhz FLASH_SetLatency(FLASH_Latency_0);//Flash 0 wait state RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); #endif } RCC_GetClocksFreq(&RCC_ClocksStatus); HCLK_Freq=(RCC_ClocksStatus.HCLK_Frequency/800000); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//TIM2 clock enable RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);//Enable GPIOA, GPIOB , GPIOD , GPIIOE and AFIO clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);//Enable GPIOD and AFIO clocks RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);//Enable I2C2 clock } void I2C_Configuration(void) { I2C_InitTypeDef I2C_InitStructure; // I2C2 configuration I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = Global_I2C2_Own_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = Global_I2C2_Speed; I2C_Cmd(I2C2, ENABLE);//I2C Peripheral Enable I2C_Init(I2C2, &I2C_InitStructure);//Apply I2C configuration after enabling it } void GPIO_Configuration(void) { // Configure I2C2 pins: SCL and SDA GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ; //SCL GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;//GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//GPIO_Mode_AF_OD GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //SDA GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;//GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); }2011-05-17 04:35 AM
You don't start any transaction, so when do you expect the communication? No start, no address, no data...
Try to use the I2C examples from FW library example directory as a base for your development. Btw. enabling GPIOA and AFIO twice has no use.2011-05-17 04:35 AM
Thanks for your reply.I didnt write transaction part in forum, but in my program it exist.