Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to address i2c slaves #46

Open
GoogleCodeExporter opened this issue Mar 25, 2015 · 1 comment
Open

How to address i2c slaves #46

GoogleCodeExporter opened this issue Mar 25, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

 It's not really a problem, but I'm rather perplexed as to how to talk to specific I2C slaves. I only saw the i2ceeprom example, which somehow doesn't seem like what I need.

 I basically have an I2C slave on address 0x48 (it's an A->D converter, but that doesn't really matter). Later on I'll also add another I2C slave on the same line, so I really need to specify the proper addresses to talk to them.

 So how could I do something like:

#define ADS1015_REG_POINTER_CONFIG      (0x01) 
#define ADS1015_REG_POINTER_CONVERT     (0x00)

 int Address=0x48;
 ioctl(i2cFile, I2C_SLAVE, Address);
 i2c_smbus_write_word_data(i2cFile,ADS1015_REG_POINTER_CONFIG,0x1122);
 i2c_smbus_read_word_data(i2cFile,ADS1015_REG_POINTER_CONVERT);

 with libmpsse?

Original issue reported on code.google.com by [email protected] on 10 Mar 2014 at 8:51

@GoogleCodeExporter
Copy link
Author

 Posting a solution if anyone else gets perplexed like me ...

 Basically, you have to start writing to I2C with the address of slave SHIFTED 1 bit to the left (last bit 0 for writes, or 1 for reads) so the above code would be something like:

//writing part
 char Data={"\0x90\0x01\x11\x22"};
 Start(context);
 Write (Context,Data,4);  //equals ioctl and i2c_smbus_write_word_data above
 Stop(context);

//reading part
 Start(Context);
 Data[1]=\0x00;           // ADS1015_REG_POINTER_CONVERT=0x00
 Write (Context,Data,2);  //set the register for read
 Stop(context);
 Start(Context);
 Data[0]=\0x91;
 Write (Context,Data,1);  //State you want to read from address 0x48 (0x48<<1)|1
 Read (Context,2);        //read the word (2 bytes) of data
 Stop(Context);

Original comment by [email protected] on 19 Mar 2014 at 5:24

  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant