Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 8 months ago.
MAX44000 programming Error- ( mbed assertation failed: )
I am trying to program MAX44000 PMB1 (Proximity Sensor) with MAX32630FTHR Board. But after running the sample program (file attached), I get the error -
"Initialized MAX44000 mbed assertation failed: stop != 0, file: C:\Jenkins\workspace\mbed-2-build-library\targets\TARGET_Maxim\TARGET_MAX32630\i2c_api.c, line 103 "
Please help me in programming MAX44000 peripheral module with MAX32630 FTHR Board.
/media/uploads/MahekDave/max44000.txt
1 Answer
8 years ago.
There seems to be a MBED OS5 compatibility with this library. I tested with the MAX32630FTHR and was able to observe the same issue. You should be able to replace the library with the following code.
MAX44000.h
#ifndef _MAX44000_H_
#define _MAX44000_H_
#include "mbed.h"
/**
* MAX44000 Ambient Light and Infrared Proximity Sensor
*
* @code
* #include <stdio.h>
* #include "mbed.h"
* #include "MAX44000.h"
*
* I2C i2c(P7_6, P7_7); //MAX32600MBED
* //I2C i2c(P3_4, P3_5); //MAX32630FTHR
* MAX44000 proximity(i2c, MAX44000::I2C_ADRS_SDO_HI);
*
*
* int main(void)
* {
* uint8_t reg_data;
*
*
* while(1) {
* if (proximity.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_1X, MAX44000::ALSPGA_128X, MAX44000::DRV_110) != 0) {
* printf("Error communicating with MAX44000\n");
* } else {
* printf("Initialized MAX44000\n");
* break;
* }
* wait(1);
* }
*
*
* while(1) {
*
* int alsValue = proximity.readALS();
* if(alsValue < 0) {
* printf("Error reading ALS value\n");
* }
*
* int proxValue = proximity.readRegister(MAX44000::REG_PRX_DATA, reg_data);
* if(proxValue < 0) {
* printf("Error reading proximity value\n");
* printf("proxValue = = 0x%02X\n", proxValue);
* }
*
* printf("ALS = 0x%04X Proximity = 0x%02X\n", alsValue, reg_data);
* wait(1);
*
* }
*
*
* }
* @endcode
*/
class MAX44000
{
public:
///MAX44000 default I2C address.
///8-bit write address
static const uint8_t I2C_ADRS_SDO_LO = 0x94;
///MAX44000 optional I2C address.
///7-bit write address
static const uint8_t I2C_ADRS_SDO_HI = 0x4A;
/**
* @brief Register Addresses
* @details Enumerated MAX44000 register addresses
*/
typedef enum {
REG_STATUS, ///< Interrupt Status
REG_MAIN_CONFIG, ///< Main Configuration
REG_RX_CONFIG, ///< Receive Configuration
REG_TX_CONFIG, ///< Transmit Configuration
REG_ALS_DATA_HIGH, ///< ADC High Byte (ALS)
REG_ALS_DATA_LOW, ///< ADC Low Byte (ALS)
REG_ALS_UPTHR_HIGH, ///< ALS Upper Threshold (High Byte)
REG_ALS_UPTHR_LOW, ///< ALS Upper Threshold (Low Byte)
REG_ALS_LOTHR_HIGH, ///< ALS Lower Threshold (High Byte)
REG_ALS_LOTHR_LOW, ///< ALS Lower Threshold (Low Byte)
REG_PST, ///< Threshold Persist Timer
REG_PRX_IND, ///< PROX Threshold Indicator
REG_PRX_THR, ///< PROX Threshold
REG_TRIM_GAIN_GREEN, ///< Digital Gain Trim of Green Channel
REG_TRIM_GAIN_IR = 0x0F, ///< Digital Gain Trim of Infrared Channel
REG_PRX_DATA = 0x16 ///< ADC Byte (PROX)
} registers_t;
/**
* @brief Operating Modes
* @details Enumerated MAX44000 operating modes
*/
typedef enum {
MODE_SHUTDOWN, ///< Analog circuits are shut down, but the digital register retains values
MODE_ALS_GMIR, ///< Standard ALS mode, stores difference between green and IR channels
MODE_ALS_G, ///< ALS green channel only
MODE_ALS_IR, ///< Infrared channel only
MODE_ALS_PROX, ///< ALS and PROX are interleaved continuously
MODE_PROX, ///< PROX only
MODE_RSVD_110, ///< Reserved, do not use
MODE_RSVD_111 ///< Reserved, do not use
} modes_t;
/**
* @brief ALS ADC Conversion Time
* @details MAX44000 Ambient Light Sensor ADC Conversion Time
*/
typedef enum {
ALSTIM_1X, ///< 100ms, 16,384 counts, 14 bit resolution
ALSTIM_4X, ///< 25ms, 4096 counts, 12 bit resolution
ALSTIM_16X, ///< 6.25ms, 1024 counts, 10 bit resolution
ALSTIM_64X ///< 1.5625ms, 256 counts, 8 bit resolution
} alstim_t;
/**
* alspga_t - MAX44000 Ambient Light Measurement Gain
*/
typedef enum {
ALSPGA_1X, ///< 0.03125 lux/lsb
ALSPGA_4X, ///< 0.125 lux/lsb
ALSPGA_16X, ///< 0.5 lux/lsb
ALSPGA_128X ///< 4 lux/lsb
} alspga_t;
/**
* @brief LED Driver Current
* @details MAX44000 LED Driver Current Settings
*/
typedef enum {
DRV_0, ///< LED driver disabled
DRV_10, ///< 10mA
DRV_20, ///< 20mA
DRV_30, ///< 30mA
DRV_40, ///< 40mA
DRV_50, ///< 50mA
DRV_60, ///< 60mA
DRV_70, ///< 70mA
DUP_40, ///< 40mA
DUP_50, ///< 50mA
DUP_60, ///< 60mA
DUP_70, ///< 70mA
DRV_80, ///< 80mA
DRV_90, ///< 90mA
DRV_100, ///< 100mA
DRV_110 ///< 110mA
} drive_t;
/**
* @brief Persist Times
* @details MAX44000 ALS/PROX Threshold Persist Timer Settings
*/
typedef enum {
PST_1, ///< 1 trigger before interrupt
PST_2, ///< 2 consecutive triggers before interrupt
PST_4, ///< 4 consecutive triggers before interrupt
PST_16 ///< 16 consecutive triggers before interrupt
} persist_t;
/**
* MAX44000 constructor.
*
* @param i2c I2C object to use.
*/
MAX44000(I2C &i2cBus, uint8_t i2cAdrs);
/**
* MAX44000 destructor.
*/
~MAX44000();
/**
* @brief Initialize MAX44000.
* @details Gets the device ID and saves the calibration values.
* @param mode Operating Mode
* @param alstim Ambient Light ADC Conversion Time
* @param alspga Ambient Light Measurement Gain
* @param drive LED Driver Current
* @returns 0 if no errors, -1 if error.
*/
int init(MAX44000::modes_t mode, MAX44000::alstim_t alstim, MAX44000::alspga_t alspga, MAX44000::drive_t drive);
/**
* @brief Write Register
* @details Writes data to MAX44000 register
*
* @param reg Register to write
* @param data Data to write
* @returns 0 if no errors, -1 if error.
*/
int32_t writeRegister(registers_t reg, const uint8_t data);
/**
* @brief Read Register
* @details Reads data from MAX44000 register
*
* @param reg Register to read
* @param &data Pointer to memorey location for data
* @returns data if no errors, -1 if error.
*/
int32_t readRegister(registers_t reg, uint8_t &data);
/**
* @brief Read ALS Data
* @details Reads both ALS data registers and returns combined value
*
* @returns data if no errors, -1 if error.
*/
int readALS(void);
private:
I2C &m_i2cBus;
uint8_t m_Wadrs, m_Radrs;
};
#endif /* _MAX44000_H_ */
MAX44000.cpp
#include "MAX44000.h"
//******************************************************************************
MAX44000::~MAX44000()
{
//empty function
}
//******************************************************************************
int MAX44000::init(MAX44000::modes_t mode, MAX44000::alstim_t alstim, MAX44000::alspga_t alspga, MAX44000::drive_t drive)
{
char data[2];
data[0] = REG_RX_CONFIG;
data[1] = 0xF0 | ((alstim & 0x03)<<2) | (alspga & 0x03);
if (m_i2cBus.write(m_Wadrs, data, 2) != 0) {
return -1;
}
data[0] = REG_TX_CONFIG;
data[1] = (drive & 0x0F);
if (m_i2cBus.write(m_Wadrs, data, 2) != 0) {
return -1;
}
data[0] = REG_MAIN_CONFIG;
data[1] = ((mode & 0x07)<<2) | (1<<5); // Set bit 5 to use factory trim data
if (m_i2cBus.write(m_Wadrs, data, 2) != 0) {
return -1;
}
return 0;
}
//*****************************************************************************
MAX44000::MAX44000(I2C &i2cBus, uint8_t i2cAdrs) //Function modified
:m_i2cBus(i2cBus), m_Wadrs(i2cAdrs << 1), m_Radrs((i2cAdrs << 1) | 1)
{
}
//*****************************************************************************
int32_t MAX44000::readRegister(registers_t reg, uint8_t &data) //fucntion modified
{
int32_t rtnVal;
char packet[1];
packet[0] = reg;
char read_data[1];
if(m_i2cBus.write(m_Wadrs, packet, 1) == 0) {
rtnVal = m_i2cBus.read(m_Radrs, read_data, 1, false);
if (rtnVal == 0) {
data = read_data[0];
}
}
return rtnVal;
}
//*****************************************************************************
int32_t MAX44000::writeRegister(registers_t reg, const uint8_t data) //Function modified
{
char packet[] = {static_cast<char>(reg), static_cast<char>(data)};
return m_i2cBus.write(m_Wadrs, packet, sizeof(packet));
}
//******************************************************************************
int MAX44000::readALS(void) //Function modified
{
int alsData;
uint8_t reg_data, data_2_write;
int32_t status;
data_2_write = 0;
status = writeRegister(REG_ALS_DATA_HIGH, data_2_write);
if (status != 0) {
return -1;
}
status = readRegister(REG_ALS_DATA_HIGH, reg_data);
if (status != 0) { // must use repeated start to protect low byte data
return -1;
}
if (reg_data & 0x40) { // if the overflow bit is set
return -1;
}
alsData = (reg_data << 8);
status = writeRegister(REG_ALS_DATA_LOW, data_2_write);
if (status != 0) {
return -1;
}
status = readRegister(REG_ALS_DATA_LOW, reg_data);
if (status != 0) { // must use repeated start to protect low byte data
return -1;
}
alsData += reg_data;
return alsData;
}