-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharduino_mpu9250_i2c.cpp
49 lines (42 loc) · 1.45 KB
/
arduino_mpu9250_i2c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/******************************************************************************
arduino_mpu9250_i2c.cpp - MPU-9250 Digital Motion Processor Arduino Library
Jim Lindblom @ SparkFun Electronics
original creation date: November 23, 2016
https://github.com/sparkfun/SparkFun_MPU9250_DMP_Arduino_Library
This library implements motion processing functions of Invensense's MPU-9250.
It is based on their Emedded MotionDriver 6.12 library.
https://www.invensense.com/developers/software-downloads/
Development environment specifics:
Arduino IDE 1.6.12
SparkFun 9DoF Razor IMU M0
Supported Platforms:
- ATSAMD21 (Arduino Zero, SparkFun SAMD21 Breakouts)
******************************************************************************/
#include "arduino_mpu9250_i2c.h"
#include <Arduino.h>
#include <Wire.h>
int arduino_i2c_write(unsigned char slave_addr, unsigned char reg_addr,
unsigned char length, unsigned char * data)
{
Wire.beginTransmission(slave_addr);
Wire.write(reg_addr);
for (unsigned char i = 0; i < length; i++)
{
Wire.write(data[i]);
}
Wire.endTransmission(true);
return 0;
}
int arduino_i2c_read(unsigned char slave_addr, unsigned char reg_addr,
unsigned char length, unsigned char * data)
{
Wire.beginTransmission(slave_addr);
Wire.write(reg_addr);
Wire.endTransmission(false);
Wire.requestFrom(slave_addr, length);
for (unsigned char i = 0; i < length; i++)
{
data[i] = Wire.read();
}
return 0;
}