ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
mpu6050.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15
16#include "mpu6050.h"
17
19{
20 return (num >> 8) | (num << 8);
21}
22
24{
26}
27
29{
30 uint8_t ret;
31 I2C_Read(MPU6050_ADDR, addr, &ret, 1);
32 return ret;
33}
34
36{
37 uint16_t ret;
38 I2C_Read(MPU6050_ADDR, addr, (uint8_t *)&ret, 2);
39 return swap(ret); // swap high/low bits for correct order
40}
41
43{
44 uint8_t i;
46 for (i = 0; i < 7; i++)
47 {
48 *(buf + i) = swap(*(buf + i));
49 }
50}
51
52void MPU6050_Init(void) {
58}
59
60void MPU6050_Reset(void) {
62}
63
66}
67
70 MPU6050_Write(MPU6050_REG_PWR_MGMT_1, reg & ~0x08 | (state << 3));
71}
72
74 MPU6050_Write(MPU6050_REG_PWR_MGMT_1, 0x28); // 0010,1000 sleep:0, cycle:1, dis_temp:1
75 MPU6050_Write(MPU6050_REG_PWR_MGMT_2, freq << 6 | 0x03); // STBY_XG, STBY_YG, STBY_ZG -> 1
76}
77
81}
82
89{
91}
92
94{
96}
97
99{
101}
102
104{
106}
__CODE int8_t dat[20]
uint8_t I2C_Read(uint8_t devAddr, uint8_t memAddr, uint8_t *buf, uint16_t size)
Definition: fw_i2c.c:36
uint8_t I2C_Write(uint8_t devAddr, uint8_t memAddr, uint8_t *dat, uint16_t size)
Definition: fw_i2c.c:18
unsigned short uint16_t
Definition: fw_types.h:19
HAL_State_t
Definition: fw_types.h:69
unsigned char uint8_t
Definition: fw_types.h:18
uint8_t addr[8]
Definition: main.c:28
uint8_t __XDATA i
void MPU6050_DisableTemperature(HAL_State_t state)
Definition: mpu6050.c:68
void MPU6050_DisableLowPowerMode(void)
Definition: mpu6050.c:78
uint16_t MPU6050_ReadInt(uint8_t addr)
Definition: mpu6050.c:35
void MPU6050_Write(uint8_t addr, uint8_t dat)
Definition: mpu6050.c:23
void MPU6050_SetAccFullScaleRange(MPU6050_Acc_FullScaleRange_t range)
Definition: mpu6050.c:103
uint16_t swap(uint16_t num)
Definition: mpu6050.c:18
void MPU6050_SetDLPF(MPU6050_DLPF_t filter)
Definition: mpu6050.c:93
void MPU6050_ReadAll(uint16_t *buf)
Definition: mpu6050.c:42
void MPU6050_EnterSleepMode(void)
Definition: mpu6050.c:64
void MPU6050_EnableLowPowerMode(MPU6050_Wakeup_Freq_t freq)
Definition: mpu6050.c:73
void MPU6050_Reset(void)
Definition: mpu6050.c:60
void MPU6050_SetSampleRateDiv(uint8_t div)
Definition: mpu6050.c:88
uint8_t MPU6050_Read(uint8_t addr)
Definition: mpu6050.c:28
void MPU6050_Init(void)
Definition: mpu6050.c:52
void MPU6050_SetGyroFullScaleRange(MPU6050_Gyro_FullScaleRange_t range)
Definition: mpu6050.c:98
MPU6050_Wakeup_Freq_t
Definition: mpu6050.h:109
#define MPU6050_REG_ACCEL_XOUT_H
Definition: mpu6050.h:56
#define MPU6050_REG_CONFIG
Definition: mpu6050.h:30
#define MPU6050_REG_ACCEL_CONFIG
Definition: mpu6050.h:32
#define MPU6050_REG_SMPLRT_DIV
Definition: mpu6050.h:29
MPU6050_Acc_FullScaleRange_t
Definition: mpu6050.h:136
@ MPU6050_Acc_FullScaleRange_4g
Definition: mpu6050.h:138
#define MPU6050_REG_PWR_MGMT_2
Definition: mpu6050.h:102
#define MPU6050_REG_GYRO_CONFIG
Definition: mpu6050.h:31
#define MPU6050_ADDR
Definition: mpu6050.h:21
MPU6050_Gyro_FullScaleRange_t
Definition: mpu6050.h:128
@ MPU6050_Gyro_FullScaleRange_500dps
Definition: mpu6050.h:130
MPU6050_DLPF_t
Definition: mpu6050.h:117
@ MPU6050_DLPF_Delay2ms
Definition: mpu6050.h:119
#define MPU6050_REG_PWR_MGMT_1
Definition: mpu6050.h:101