Question
SPI Issues in STM32F215
Posted on June 28, 2014 at 17:27
Hi,
I have configured I2C2 in stm32f215 like below mentioned code, as well as i tried to read the device id. But while i am running its hanging in while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); .Please help how to solve this. Below is my code. static void I2C_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // /* Reset I2C1 IP */ // RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE); // // /* Release reset signal of I2C1 IP */ // RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE); /* I2C1 SCL and SDA pins configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOB, &GPIO_InitStructure); // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // GPIO_Init(GPIOB, &GPIO_InitStructure); /* Alternate function remapping */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2); /* I2C De-initialize */ I2C_DeInit(I2C2); /* I2C configuration */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = 0xA0; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = 1000; /*!< I2C Initialize */ I2C_Init(I2C2, &I2C_InitStructure); I2C_Cmd(I2C2, ENABLE); /* I2C ENABLE */ } unsigned char I2C_ Pressure_Read(unsigned char Address) { unsigned char c,Add=0x5D<<1; I2C_AcknowledgeConfig(I2C2, ENABLE); while (I2C_GetFlagStatus(I2C2,I2C_FLAG_BUSY)); I2C_GenerateSTART(I2C2, ENABLE); while (!I2C_GetFlagStatus(I2C2,I2C_FLAG_SB)); I2C_Send7bitAddress(I2C2, Add, I2C_Direction_Transmitter); while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); //I2C_SendData(I2C2, WRITE_ADD); I2C_SendData(I2C2,Address); while (!I2C_GetFlagStatus(I2C2,I2C_FLAG_TXE)); I2C_GenerateSTART(I2C2, ENABLE); while (!I2C_GetFlagStatus(I2C2,I2C_FLAG_SB)); //I2C_SendData(I2C2,READ_ADD); I2C_Send7bitAddress(I2C2, Add, I2C_Direction_Receiver); while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); c=I2C_ReceiveData(I2C2); I2C_NACKPositionConfig(I2C2, I2C_NACKPosition_Current); I2C_AcknowledgeConfig(I2C2, DISABLE); I2C_GenerateSTOP(I2C2, ENABLE); while(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF)); return c; } Regards, Thirukkannan.P