Report
4 years, 9 months ago.

LSM9DS0 library - import from arduino

Hello there,

I'm trying to import LSM9DS0 library from arduino to FRDM K64F mbed platform but I'm facing issues with that. I tried to import the following code:

uint8_t I2CreadByte(uint8_t address, uint8_t subAddress)
{
     uint8_t data; // `data` will store the register data	 
     Wire.beginTransmission(address);         // Initialize the Tx buffer
     Wire.write(subAddress);	                 // Put slave register address in Tx buffer 
     Wire.endTransmission(false);             // Send the Tx buffer, but send a restart to keep connection alive
     Wire.requestFrom(address, (uint8_t) 1);  // Read one byte from slave register address 
    data = Wire.read();                      // Fill Rx buffer with result
    return data;                             // Return data read from slave register
}

I translated into mbed as follows:

uint8_t I2CreadByte(uint8_t address, uint8_t subAddress)
{
        char output = 0xff;
	int wr = i2c.write(address << 1, (const char*)&subAddress, 1); // arduino addressing is 7-bit 
	int rd = i2c.read(address << 1, &output, 1);
        return output;
}

The write is ok and return success (wr = 0) while the read is not working properly (rd=1)!

What is wrong with my translated code?

PS: the arduino library can be found here https://github.com/sparkfun/LSM9DS0_Breakout/tree/master/Libraries/Arduino/SFE_LSM9DS0

how stupid I'm, I forgot to set the repeated flag !

the following code is working:

uint8_t I2CreadByte(uint8_t address, uint8_t subAddress)
{
        char output = 0xff;
    int wr = i2c.write(address << 1, (const char*)&subAddress, 1, 1); // arduino addressing is 7-bit 
    int rd = i2c.read(address << 1, &output, 1, 0);
        return output;
}
posted by mohamed ali 13 Jun 2014

I found your question today.

I'm interested in this project. Could you publish your project on the web?

posted by Hiroshi SAITO 25 Sep 2014
Comment on this question
Be the first to answer this question.

Assigned to mohamed ali 4 years, 9 months ago.

This means that the question has been accepted and is being worked on.

To post an answer, please log in.