Christian Dupaty 03/2021 Library and demo for BMM150 see datasheet here : https://www.bosch-sensortec.com/products/motion-sensors/magnetometers-bmm150/ Adaptation of BOSCH driver https://github.com/BoschSensortec/BMM150-Sensor-API for ARM MBED and tested on NUCLEO-L073RZ and GEOMAGNETIC CLICK https://www.mikroe.com/geomagnetic-click

Dependents:   BMM150_HelloWorld2

Files at this revision

API Documentation at this revision

Comitter:
cdupaty
Date:
Thu Mar 25 13:08:05 2021 +0000
Parent:
0:ef20a9039c0c
Commit message:
New I2C functions

Changed in this revision

bmm150.cpp Show annotated file Show diff for this revision Revisions of this file
bmm150.h Show annotated file Show diff for this revision Revisions of this file
diff -r ef20a9039c0c -r 9651fd7ee8f6 bmm150.cpp
--- a/bmm150.cpp	Wed Mar 24 19:35:45 2021 +0000
+++ b/bmm150.cpp	Thu Mar 25 13:08:05 2021 +0000
@@ -321,62 +321,38 @@
 
 void BMM150::i2c_write(short address, short data) 
 {
-    i2c->start();
-    i2c->write(BMM150_I2C_Address);
-    i2c->write(address);
-    i2c->write(data);
-    i2c->stop();
+    char temp[2];
+    temp[0]=address;
+    temp[1]=data;
+    i2c->write(BMM150_I2C_Address,temp,2);
+}
+
+void BMM150::i2c_write(short address) 
+{
+    char temp[1];
+    temp[0]=address;
+    i2c->write(BMM150_I2C_Address,temp,1);
 }
 
 void BMM150::i2c_read(short address, uint8_t* buffer, short length) 
-{uint8_t i;
-    i2c->start();
-    i2c->write(BMM150_I2C_Address);
-    i2c->write(address);  
-    i2c->stop();
-    i2c->start();
-    i2c->write(BMM150_I2C_Address+1); 
-    for (i = 0; i <= length; i++)
-    {
-        buffer[i] = i2c->read(ACK);
-    }
-    i++;
-    buffer[i] = i2c->read(NACK);
-    i2c->stop();
+{
+     i2c_write(address);
+      i2c->read(BMM150_I2C_Address+1,(char *)buffer,length);
 }
 
 
 void BMM150::i2c_read(short address, int8_t* buffer, short length) 
 {
-uint8_t i;
-    i2c->start();
-    i2c->write(BMM150_I2C_Address);
-    i2c->write(address);
-    i2c->stop();
-    i2c->start();
-    i2c->write(BMM150_I2C_Address+1); 
-   for (i = 0; i <= length; i++)		// initialement i < length 
-    {
-        buffer[i] = i2c->read(ACK);
-    }
-    // ajout 
-    i++;
-    buffer[i] = i2c->read(NACK);
-    i2c->stop();
+	 i2c_write(address);
+	 i2c->read(BMM150_I2C_Address+1,(char *)buffer,length);
 }
 
 uint8_t BMM150::i2c_read(short address) 
 {
-uint8_t byte;
-    i2c->start();
-    i2c->write(BMM150_I2C_Address);
-    i2c->write(address);
-    i2c->stop();
-    i2c->start();
-    i2c->write(BMM150_I2C_Address+1); 
-    byte = i2c->read(NACK);				
-    i2c->stop();
-    return byte;
+char temp[1];
+	i2c_write(address);
+    i2c->read(BMM150_I2C_Address+1,temp,1);
+    return temp[0];
 }
 
 
diff -r ef20a9039c0c -r 9651fd7ee8f6 bmm150.h
--- a/bmm150.h	Wed Mar 24 19:35:45 2021 +0000
+++ b/bmm150.h	Thu Mar 25 13:08:05 2021 +0000
@@ -142,6 +142,7 @@
 
 
     void i2c_write(short address, short byte);
+    void i2c_write(short address) ;
     void i2c_read(short address, uint8_t* buffer, short length);
     void i2c_read(short address, int8_t* buffer, short length);
     uint8_t i2c_read(short address);