Using help from this forum, I managed to port an Arduino BMX160 Library DFRobot_BMX160.h to mbed. However, there’s one single error that happens when compiling the program:
Error: No matching member function for call to 'read' in "DFBot/DFBot/DFRobot_BMX160.cpp", Line: 317, Col: 9
The line: i2c.read(_addr << 1, pBuf, len);
The function:
void DFRobot_BMX160::readReg(uint8_t reg, uint8_t *pBuf, uint16_t len)
{
i2c.lock();
i2c.start();
// to indicate an i2c read, shift the 7 bit address up 1 bit and set bit 0 to a 1
i2c.write(_addr << 1 | 1);
int writeResult = i2c.write(reg);
i2c.stop();
i2c.unlock();
if(writeResult != 1) {
return;
}
i2c.read(_addr << 1, pBuf, len);
}
The error does not occur for any other i2c related functions (e.g. i2c.start(), i2c.lock(), i2c.write() etc.) i2c has been defined at the beginning of the library cpp file as: I2C i2c(PC_1,PC_0);
Included headers in “DFRobot_BMX160.h”:
#include “stdint.h”
#include “stdlib.h”
#include “mbed.h”
#include “platform/mbed_thread.h”
The entire code compiles when i comment out that single line.
Note that the I2C functions are being defined inside the library cpp file and not main file.