Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BMM150_HelloWorld2
Revision 1:9651fd7ee8f6, committed 2021-03-25
- 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 |
--- 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];
}
--- 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);