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.
Base_I2C_Device.cpp
- Committer:
- glansberry
- Date:
- 2015-05-06
- Revision:
- 0:fa683f936086
- Child:
- 1:700cce0a0ca8
File content as of revision 0:fa683f936086:
#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;
}