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.
Diff: Base_I2C_Device.cpp
- Revision:
- 0:fa683f936086
- Child:
- 1:700cce0a0ca8
diff -r 000000000000 -r fa683f936086 Base_I2C_Device.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Base_I2C_Device.cpp Wed May 06 02:49:13 2015 +0000
@@ -0,0 +1,48 @@
+#include "Base_I2C_Device.h"
+
+
+
+
+uint8_t Base_I2C_Device::ReadRegisterByte(uint8_t reg)
+{
+char temp_write[1];
+char temp_read[1];
+
+ temp_write[0] = reg;
+ i2c.write(m_address, temp_write, 1, false); // no stop (unsure)
+ i2c.read(m_address, temp_read, 1, 0);
+
+ return (uint8_t)temp_read[0];
+}
+uint16_t Base_I2C_Device::ReadRegisterWord(uint8_t reg)
+{
+char temp_write[1];
+char temp_read[2];
+
+ temp_write[0] = reg;
+ i2c.write(m_address, temp_write, 1, false); // no stop (unsure)
+ i2c.read(m_address, temp_read, 2, 0);
+
+ return (((uint16_t)temp_read[0]) << 8) | (uint16_t)temp_read[1];
+
+}
+int Base_I2C_Device::WriteRegister(uint8_t reg, uint8_t value)
+{
+ char temp_write[2];
+
+ temp_write[0] = reg;
+ temp_write[1] = value; //check order of these (endianness)
+ i2c.write(m_address, temp_write, 2, 0);
+ return 0;
+}
+
+int Base_I2C_Device::WriteRegister(uint8_t reg, uint16_t value)
+{
+ char temp_write[3];
+
+ temp_write[0] = reg;
+ temp_write[1] = value>>8;
+ temp_write[2] = (value & 0xFF);
+ i2c.write(m_address, temp_write, 3, 0);
+ return 0;
+}
\ No newline at end of file