MPU9255
MPU9255 Arduino Library
MPU9255_PowerControl.cpp
Go to the documentation of this file.
1 
6 // This file is a part of MPU9255 library.
7 // Copyright (c) 2017-2020 Krzysztof Adamkiewicz <kadamkiewicz835@gmail.com>
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy of
10 // this software and associated documentation files (the “Software”), to deal in the
11 // Software without restriction, including without limitation the rights to use, copy,
12 // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
13 // and to permit persons to whom the Software is furnished to do so, subject to the
14 // following conditions: THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
18 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 
20 #include "MPU9255.h"
21 #include "Arduino.h"
22 
23 // perform hard reset (all regesters will be restored to they default values )
24 void MPU9255::Hreset()
25 {
26  write_OR(MPU_address,PWR_MGMT_1,1<<7);//set reset bit in PWR_MGMT_1 register
27 }
28 
29 //enable sleep mode
30 void MPU9255::sleep_enable()
31 {
32  write_OR(MPU_address,PWR_MGMT_1, 1<<6);//set sleep bit in PWR_MGMT_1 register
33 }
34 
35 //disable sleep mode
36 void MPU9255::sleep_disable()
37 {
38  write_AND(MPU_address,PWR_MGMT_1, ~(1<<6));//clear sleep bit in PWR_MGMT_1 register
39 }
40 
41 //reset selected module
42 //parameters:
43 // * modules selected_module - selected module
44 void MPU9255::reset(modules selected_module)
45 {
46  switch(selected_module)
47  {
48  case accelerometer:
49  write_OR(MPU_address,SIGNAL_PATH_RESET, 1<<1);
50  break;
51 
52  case gyroscope:
53  write_OR(MPU_address,SIGNAL_PATH_RESET, 1<<2);
54  break;
55 
56  case thermometer:
57  write_OR(MPU_address,SIGNAL_PATH_RESET, 1<<0);
58  break;
59 
60  case signalPaths:
61  write_OR(MPU_address,USER_CTRL, 1<<0);
62  break;
63 
64  case magnetometer:
65  write_OR(MAG_address,CNTL2, 1<<0);
66  break;
67  }
68 }
69 
70 //disable selected_module
71 //parameters:
72 // * modules selected_module - selected module
73 void MPU9255::disable(modules selected_module)
74 {
75  switch (selected_module)
76  {
77  case Acc_X:
78  write_OR(MPU_address,PWR_MGMT_2, 1<<5);
79  break;
80 
81  case Acc_Y:
82  write_OR(MPU_address,PWR_MGMT_2, 1<<4);
83  break;
84 
85  case Acc_Z:
86  write_OR(MPU_address,PWR_MGMT_2, 1<<3);
87  break;
88 
89  case Gyro_X:
90  write_OR(MPU_address,PWR_MGMT_2, 1<<2);
91  break;
92 
93  case Gyro_Y:
94  write_OR(MPU_address,PWR_MGMT_2, 1<<1);
95  break;
96 
97  case Gyro_Z:
98  write_OR(MPU_address,PWR_MGMT_2, 1<<0);
99  break;
100 
101  case magnetometer:
102  write(MAG_address,CNTL, 0x00);
103  break;
104  }
105 }
106 
107 //enable selected_module
108 //parameters:
109 // * modules selected_module - selected module
110 void MPU9255::enable(modules selected_module)
111 {
112  switch (selected_module)
113  {
114  case Acc_X:
115  write_AND(MPU_address,PWR_MGMT_2, ~(1<<5));
116  break;
117 
118  case Acc_Y:
119  write_AND(MPU_address,PWR_MGMT_2, ~(1<<4));
120  break;
121 
122  case Acc_Z:
123  write_AND(MPU_address,PWR_MGMT_2, ~(1<<3));
124  break;
125 
126  case Gyro_X:
127  write_AND(MPU_address,PWR_MGMT_2, ~(1<<2));
128  break;
129 
130  case Gyro_Y:
131  write_AND(MPU_address,PWR_MGMT_2, ~(1<<1));
132  break;
133 
134  case Gyro_Z:
135  write_AND(MPU_address,PWR_MGMT_2, ~(1<<0));
136  break;
137 
138  case magnetometer:
139  write(MAG_address,CNTL, 0x16);
140  break;
141  }
142 }
modules
modules (for enable / disable / reset functions)
Definition: MPU9255.h:27
Main header of the library.