STM32F303K8T6でLSM303D動かしてみた

Dependents:   GPS_STM32F303K8

Files at this revision

API Documentation at this revision

Comitter:
sashida_h
Date:
Tue Sep 08 06:34:37 2020 +0000
Parent:
2:8cd0c3c11b48
Commit message:
initial commit

Changed in this revision

LSM303D.cpp Show annotated file Show diff for this revision Revisions of this file
LSM303D.h Show annotated file Show diff for this revision Revisions of this file
--- a/LSM303D.cpp	Mon Feb 08 17:57:22 2016 +0000
+++ b/LSM303D.cpp	Tue Sep 08 06:34:37 2020 +0000
@@ -37,7 +37,6 @@
 #include "mbed.h"
 #include "LSM303D.h"
 
-
 const int addr_acc_mag = 0x3A;
 
 enum REG_ADDRS {
@@ -84,7 +83,6 @@
     _LSM303(sda, scl)
 {
     char reg_v;
-    _LSM303.frequency(200000);
         
     reg_v = 0;
     
@@ -94,7 +92,7 @@
 
     /* -- mag --- */
     reg_v = 0;
-    reg_v |= 0x78;     //M_RES = 11 (high resolution mode); M_ODR = 100 (50 Hz ODR)
+    reg_v |= 0x74;     //M_RES = 11 (high resolution mode); M_ODR = 100 (50 Hz ODR)
     write_reg(addr_acc_mag,CTRL5,reg_v);
 
  
@@ -102,20 +100,24 @@
     reg_v = 0;    
     reg_v |= 0x00;   //continuous mag
     write_reg(addr_acc_mag,CTRL7,reg_v);
+    
+    reg_v = 0;    
+    reg_v |= 0x00;   //+-2gauss
+    write_reg(addr_acc_mag,CTRL6,reg_v);
 }
 
 
-bool LSM303D::read(float *ax, float *ay, float *az, float *mx, float *my, float *mz) {
+bool LSM303D::read(float *aData,float *mData) {
     char acc[6], mag[6];
  
     if (recv(addr_acc_mag, OUT_X_A, acc, 6) && recv(addr_acc_mag, OUT_X_M, mag, 6)) {
-        *ax = float(short(acc[1] << 8 | acc[0]))*0.061;  //32768/4=8192
-        *ay =  float(short(acc[3] << 8 | acc[2]))*0.061;
-        *az =  float(short(acc[5] << 8 | acc[4]))*0.061;
-        //+-4gauss
-        *mx = float(short(mag[0] << 8 | mag[1]))*0.16;
-        *mz = float(short(mag[2] << 8 | mag[3]))*0.16;
-        *my = float(short(mag[4] << 8 | mag[5]))*0.16;
+        aData[0] = float(short(acc[1] << 8 | acc[0]))*0.061;  //32768/4=8192
+        aData[1] =  float(short(acc[3] << 8 | acc[2]))*0.061;
+        aData[2] =  float(short(acc[5] << 8 | acc[4]))*0.061;
+        //+-2gauss
+        mData[0] = float(short(mag[1] << 8 | mag[0]))*0.08;
+        mData[1] = float(short(mag[3] << 8 | mag[2]))*0.08;
+        mData[2] = float(short(mag[5] << 8 | mag[4]))*0.08;
  
         return true;
     }
--- a/LSM303D.h	Mon Feb 08 17:57:22 2016 +0000
+++ b/LSM303D.h	Tue Sep 08 06:34:37 2020 +0000
@@ -20,7 +20,7 @@
          * @param ax,ay,az is the accelerometer 3d vector, written by the function
          * @param mx,my,mz is the magnetometer 3d vector, written by the function
          */
-         bool read(float *ax, float *ay, float *az, float *mx, float *my, float *mz);
+         bool read(float *aData,float *mData);
 
 
     private: