şeriban
Üye
- Katılım
- 22 Nis 2018
- Mesajlar
- 20
- Puanları
- 1
- Yaş
- 26
Kod:
#include "main.h"
#include "stm32f4xx_hal.h"
uint8_t i2cBuff[8];
uint8_t Tx_buffer[8];
uint16_t ax ,ay, az;
uint8_t i;
#define MPU6050_Address 0xD0
I2C_HandleTypeDef hi2c1;
TIM_HandleTypeDef htim1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
static void MX_TIM1_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
MX_TIM1_Init();
if (HAL_I2C_IsDeviceReady (&hi2c1 , MPU6050_Address ,2 ,1000 ) == HAL_OK) {
HAL_GPIO_WritePin(GPIOD ,GPIO_PIN_13 ,GPIO_PIN_SET);
}
Tx_buffer[0]=0x10;
HAL_I2C_Master_Transmit(&hi2c1 , MPU6050_Address , Tx_buffer ,1 , 100);
HAL_Delay(200);
Tx_buffer[1]= 0x6B;
Tx_buffer[2]= 0x00;
HAL_I2C_Master_Transmit(&hi2c1 ,MPU6050_Address , Tx_buffer ,2 ,100);
Tx_buffer[3]=0x1B;//GYRO_CONFIG
Tx_buffer[4]=0x08;//FS_SEL +-250
HAL_I2C_Master_Transmit(&hi2c1 , MPU6050_Address , Tx_buffer ,2 , 100);
while (1)
{
i2cBuff[0]= 0x43;
HAL_I2C_Master_Transmit(&hi2c1, MPU6050_Address, i2cBuff, 1, 10);
i2cBuff[1] = 0x00;
HAL_I2C_Master_Receive(&hi2c1, MPU6050_Address, &i2cBuff[1], 6, 10);
ax = -(i2cBuff[1]<<8 | i2cBuff[2]);
ay = -(i2cBuff[3]<<8 | i2cBuff[4]);
az = -(i2cBuff[5]<<8 | i2cBuff[6]);
// Xaccel = ax/8192.0;
// Yaccel = ay/8192.0;
// Zaccel = az/8192.0;
/* USER CODE BEGIN 3 */
}
}