2019-07-10 05:27 AM
Hi,
I'm trying to interface with an MPU6050 with STM32F103C8T6 Blue pill board or the so called stm32duino board. I have code written as such:
/* USER CODE BEGIN 2 */
if(HAL_I2C_IsDeviceReady(&hi2c1, MPU6050_ADDRESS, 2, 10) == HAL_OK){
HAL_GPIO_TogglePin(SENSOR_OK_LED_GPIO_Port,SENSOR_OK_LED_Pin);
}
/* USER CODE END 2 */
It works no problem. The problem is when I put this code into a function like so:
/* USER CODE BEGIN PFP */
void MPU6050_Init(void);
/* USER CODE END PFP */
/* USER CODE BEGIN Init */
MPU6050_Init();
/* USER CODE END Init */
/* USER CODE BEGIN 4 */
void MPU6050_Init(void){
if(HAL_I2C_IsDeviceReady(&hi2c1, MPU6050_ADDRESS, 2, 10) == HAL_OK){
HAL_GPIO_TogglePin(SENSOR_OK_LED_GPIO_Port,SENSOR_OK_LED_Pin);
}
}
/* USER CODE END 4 */
Why? Am I doing something wrong? Does this have to do anything with pointers and functions that I don't know about? Because as far as I know, this should work just fine.
I'm using STM32CubeMX & Keil MDK v5.
2019-07-10 06:02 AM
The "USER CODE BEGIN Init" block is before the other peripherials are initialized, like the GPIO pin you're using for the sensor ok LED.
So move the MPU6050_Init() back to where you had the other code, ie in "USER CODE BEGIN 2" block.
2019-07-17 07:42 AM
thanks men. it fixed.