本帖最后由 feiyinglala 于 2016-4-7 12:36 编辑
目前在使用F051控制MPU6050,使用了官方提供的固件库函数,但实际运行程序时候一直卡死在
“while(I2C_GetFlagStatus(I2C2,I2C_ISR_TXIS) == RESET);”这句。硬件连接检查过了,模块的引脚和stm32的芯片引脚是联通的。
硬件联通关系:STM_PF6 - MPU6050_SCL ; STM_PF7 - MPU6050_SDA
请问我该如何解决这个问题,先谢过了
*************IO端口配置****************
static void I2C_GPIO_Config(void) //I2C2 I/O配置
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOF,ENABLE );
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;// SCL-PF6
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;// SDA-PF7
GPIO_Init(GPIOF, &GPIO_InitStructure);
//connect pin to Periph
GPIO_PinAFConfig(GPIOF, GPIO_PinSource6, GPIO_AF_0);
GPIO_PinAFConfig(GPIOF, GPIO_PinSource7, GPIO_AF_0);
}
<p>static void I2C_Mode_Config(void) //I2C ¹¤×÷ģʽÅäÖÃ
{
I2C_InitTypeDef I2C_InitStructure;
I2C_DeInit (I2C2);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStructure.I2C_DigitalFilter = 0x00;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_Timing = 0x00B01A4B;
I2C_Init(I2C2, &I2C_InitStructure);
I2C_Cmd (I2C2,ENABLE);
}
</p>
void I2C_ByteWrite(uint8_t Slave_Address,uint8_t REG_Address,uint8_t REG_Data) //дһ¸ö×Ö½Úµ½I2CÉ豸¼Ä´æÆ÷ÖÐ
{
uint32_t i;
while(I2C_GetFlagStatus(I2C2,I2C_FLAG_BUSY));
I2C_TransferHandling(I2C2,Slave_Address,1,I2C_AutoEnd_Mode,I2C_Generate_Start_Write); // I2C_AutoEnd_Mode
while(I2C_GetFlagStatus(I2C2,I2C_ISR_TXIS) == RESET);//
I2C_SendData(I2C2,REG_Address);
while(I2C_GetFlagStatus(I2C2,I2C_ISR_TC) == RESET);
I2C_TransferHandling(I2C2,Slave_Address,1,I2C_AutoEnd_Mode,I2C_No_StartStop); // I2C_Generate_Start_Write
while(I2C_GetFlagStatus(I2C2,I2C_ISR_TXIS) == RESET);
I2C_SendData(I2C2, REG_Data);
while(I2C_GetFlagStatus(I2C2,I2C_ISR_STOPF) == RESET);
}
说明:芯片是STM32F051R8 系统:win7 64位 开发环境:uVersion V5.11
下载器:J-LINK (USB口连到电脑,然后通过SWD连接电路板)
|