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: Low_Power_Long_Distance_IR_Vision_Robot MAX17055_EZconfig MAX17055_EZconfig_Sample Low_Power_Long_Distance_IR_Vision_Robot
Fork of max17055 by
Revision 1:a031f0c6a71e, committed 2017-09-21
- Comitter:
- fneirab
- Date:
- Thu Sep 21 22:35:39 2017 +0000
- Parent:
- 0:80c39eb8f3ba
- Child:
- 2:ff7db397b70f
- Commit message:
- working test of writ, read and write verify functions. Removed from private for access from main.cpp
Changed in this revision
| max17055.cpp | Show annotated file Show diff for this revision Revisions of this file |
| max17055.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/max17055.cpp Thu Sep 21 00:53:05 2017 +0000
+++ b/max17055.cpp Thu Sep 21 22:35:39 2017 +0000
@@ -45,76 +45,116 @@
{
//empty block
}
-
+///////////////////////////////////////////////////////////////////////////////
/**
* \brief Write a value to a MAX17055 register
* \par Details
* This function writes a value to a MAX17055 register
*
-* \param[in] Registers_e - register address
-* \param[in] reg_data - register data
+* \param[in] reg_addr - register address
+* \param[in] reg_data - register data
*
-* \retval true on success
+* \retval 1 on success
*/
int MAX17055::writeReg(Registers_e reg_addr, uint16_t reg_data)
{
- char add_plus_data[2] = {reg_addr, reg_data};
+
+ uint8_t dataLSB;
+ uint8_t dataMSB;
- if ( m_i2cBus.write(I2C_W_ADRS, add_plus_data, 2, false) == 0)
+ dataLSB = reg_data & 0x00FF;
+ dataMSB = (reg_data >> 8) & 0x00FF;
+
+ char add_plus_data[3] = {reg_addr, dataLSB, dataMSB};
+
+ if ( m_i2cBus.write(I2C_W_ADRS, add_plus_data, 3, false) == 0)
return 1;
else
return 0;
}
-
+///////////////////////////////////////////////////////////////////////////////
/**
* \brief Read a MAX17055 register
* \par Details
* This function reads a MAX17055 register
*
-* \param[in] uch_addr - register address
-* \param[out] puch_data - pointer that stores the register data
+* \param[in] reg_addr - register address
+* \param[out] &value - pointer that stores the register data
*
* \retval 1 on success
*/
-int32_t MAX17055::readReg(Registers_e reg_addr, uint8_t &value)
+int32_t MAX17055::readReg(Registers_e reg_addr, uint16_t &value)
{
int32_t result;
-
- char local_data[2];
+ //int16_t value2;
+ //int16_t twoBytes;
+ char local_data[1];
local_data[0] = reg_addr;
+ char read_data[2];
result = m_i2cBus.write(I2C_W_ADRS, local_data, 1);
if(result == 0)
{
- result = m_i2cBus.read(I2C_R_ADRS, (local_data + 1), 1);
- if (result == 0)
+ result = m_i2cBus.read(I2C_R_ADRS, read_data , 2, false);
+ if (result == 0)
{
- value = local_data[1];
- }
+ value = ( ((read_data[1] & 0x00FF) << 8) + (read_data[0]));
+ result = 1;
+ }
}
-
+
return result;
+
}
-//int MAX17055::write_and_verify_reg (MAX17055::Registers_e reg_addr, uint8_t reg_data)
-//{
-// uint8_t data;
-//
-// writeReg(reg_addr,reg_data);
-// data = readReg(reg_addr);
-//
-// if (data != reg_data) {
-// return -1;
-// }
-//
-// return E_NO_ERROR;
-//}
+
+/**
+* \brief Write and Verify a MAX17055 register
+* \par Details
+* This function wites and verifies if the writing process was successful
+*
+* \param[in] reg_addr - register address
+* \param[out] reg_data - the variable that contains the data to write
+* to the register address
+*
+* \retval 1 on success
+*/
+
+
+int MAX17055::write_and_verify_reg (MAX17055::Registers_e reg_addr, uint16_t reg_data)
+{
+ int retries = 8;
+ int ret;
+ int statusRead;
+ int statusWrite;
+ uint16_t read_data;
+
+ do {
+ statusWrite = writeReg(reg_addr, reg_data);
+ if (statusWrite != 1)
+ ret = -1;
+ wait_ms(3);
+ statusRead = readReg(reg_addr, read_data);
+ if (statusRead != 1)
+ ret = -2;
+ if (read_data != reg_data){
+ ret = -3;
+ retries--;
+ }
+ }while (retries && read_data != reg_data);
+
+ if (ret<0)
+ {
+ return ret;
+ } else
+ return 1;
+}
//
//int MAX17055::init()
//{
--- a/max17055.h Thu Sep 21 00:53:05 2017 +0000
+++ b/max17055.h Thu Sep 21 22:35:39 2017 +0000
@@ -247,7 +247,7 @@
-protected:
+//protected:
/**
* @brief Write Register
* @details Writes data to max17055 Register
@@ -263,7 +263,23 @@
*
* @parameters reg_addr Register to read
*/
- int32_t readReg(Registers_e reg_addr, uint8_t &value);
+ int32_t readReg(Registers_e reg_addr, uint16_t &value);
+
+ /**
+ * \brief Write and Verify a MAX17055 register
+ * \par Details
+ * This function wites and verifies if the writing process was successful
+ *
+ * \param[in] reg_addr - register address
+ * \param[out] reg_data - the variable that contains the data to write
+ * to the register address
+ *
+ * \retval 1 on success
+ * -1 if errors exist
+ */
+
+
+ int write_and_verify_reg(Registers_e reg_addr, uint16_t reg_data);
