学前班
最后登录1970-1-1
在线时间 小时
注册时间2017-5-16
|
楼主 |
发表于 2017-5-17 16:51:30
|
显示全部楼层
多谢回复,我看视频里是有两套程序,不过光盘里的源码对6050的基本数据采集只有一个工程。iic.c里第一个函数是这个,这是初始化硬件吗?不好意思我不太懂,麻烦了。
/******************************* Function ************************************/
/**
* @brief 初始化I2C总线,使用I2C前需要调用
* @param 无
* @retval 无
*/
void I2cMaster_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
/* Enable I2Cx clock */
RCC_APB1PeriphClockCmd(SENSORS_I2C_RCC_CLK, ENABLE);
/* Enable I2C GPIO clock */
RCC_AHB1PeriphClockCmd(SENSORS_I2C_SCL_GPIO_CLK | SENSORS_I2C_SDA_GPIO_CLK, ENABLE);
/* Configure I2Cx pin: SCL ----------------------------------------*/
GPIO_InitStructure.GPIO_Pin = SENSORS_I2C_SCL_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
/* Connect pins to Periph */
GPIO_PinAFConfig(SENSORS_I2C_SCL_GPIO_PORT, SENSORS_I2C_SCL_GPIO_PINSOURCE, SENSORS_I2C_AF);
GPIO_Init(SENSORS_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
/* Configure I2Cx pin: SDA ----------------------------------------*/
GPIO_InitStructure.GPIO_Pin = SENSORS_I2C_SDA_GPIO_PIN;
/* Connect pins to Periph */
GPIO_PinAFConfig(SENSORS_I2C_SDA_GPIO_PORT, SENSORS_I2C_SDA_GPIO_PINSOURCE, SENSORS_I2C_AF);
GPIO_Init(SENSORS_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
I2C_DeInit(SENSORS_I2C);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C_OWN_ADDRESS;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
/* Enable the I2C peripheral */
I2C_Cmd(SENSORS_I2C, ENABLE);
/* Initialize the I2C peripheral */
I2C_Init(SENSORS_I2C, &I2C_InitStructure);
return;
}
|
|