I have a weird problem. Using this code
I2C_HandleTypeDef* i2c;
MPU9250* mpu9250;
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
mpu9250 = new MPU9250(i2c);
// ...
}
I am getting error "undefined reference to 'i2c'" (in function main
). Based on what I was able to find about this error this code should work. Do you see anything that could cause this error?
edit:
Function MX_GPIO_Init()
. Same error with "undefined reference to i2c".
void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__GPIOB_CLK_ENABLE();
/*Configure GPIO pins : PB6 PB7 */
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
i2c = new I2C_HandleTypeDef;
i2c->Instance = I2C1;
i2c->Init.ClockSpeed = 100000;
i2c->Init.DutyCycle = I2C_DUTYCYCLE_2;
i2c->Init.OwnAddress1 = 0;
i2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
i2c->Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
i2c->Init.OwnAddress2 = 0;
i2c->Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
i2c->Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
HAL_I2C_Init(i2c);
}