i2c Port Help!!

hi to all...it's possibel to any help me with read 2 bytes of data in the i2c port...in the old librarys i read the data but in the new hal library no work...

i use this in arduplane 2.68 code with librarys ; my sensor address is  0X75...and put in the i2c line 2 byte of data when is request ...

#include <I2C.h>

#define addr 0x75

void setup()
{
   I2c.begin();
 delay(10);
  Serial.begin(115200);
 
}

void loop()

{

 

int  x = 0;

uint8_t buff[2]; 

I2c.read(addr,2,buff);

x = buff[1] << 8;

x |= buff[0];

Serial.println(x,DEC);

}

i tried with news hal  librarys ,,,the code compile ok...but not read the i2c port...i read the i2c driver and the old library have more functions and the new not...its posible to error in the driver inside the AP_halavr???

#include <AP_Common.h>

#include <AP_Math.h>

#include <AP_Param.h>

#include <AP_Progmem.h>

#include <AP_HAL_AVR.h>

#include <AP_HAL.h>

const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;

 

#define addr  0x75

void setup()

{  

hal.i2c->begin();

  hal.scheduler->delay(10);

}

void loop()

{   

int x =0;    

uint8_t buff[2];   

hal.i2c->read(addr, 2, buff);        

x= buff[1] << 8 | buff[0];

 hal.console->printf_P(PSTR("value= %d \r\n"),x,DEC);  

hal.scheduler->delay(10);        

}

AP_HAL_MAIN();

 

 

thank you very much for your attention to all and sorry my bad english...

best regards.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –