1

0 down vote favorite I am trying to build one sensor interface using Raspberry Pi over I2C. I have installed WiringPi. I am seeing limitations of wiringPi library, that supports only 1 or 2 bytes I2C read. reading single or double bytes at each shot is lagging my sensor data acquisition speed. My requirement is to read 6 bytes at one shot. Could anyone please suggest how to achieve this?

I have tried to modify the WiringPi library and rebuild for my requirement, But when I am using modified function in my application I am seeing "Undefined reference error. Please someone help me on this. Thanks in advance...

closed as too broad by goldilocks Jul 18 '18 at 17:40

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I removed your second question since 1) We prefer one at a time, 2) Saying you modified library source code and it didn't work then asking for help is like saying, "I am at sea, how do I get home?" No one can tell you without more information. But again: That is a separate question. – goldilocks Jul 18 '18 at 14:40
  • Since you could not accept this, your question has now been closed as too broad. Please take the tour to understand better how the site works, and read "What types of questions should I avoid asking?". – goldilocks Jul 18 '18 at 17:41
2

There is no need to modify the wiringPi source code to read or write multiple bytes.

wiringPi provides a simple wrapper around a few I2C/SMBus commands. If the commands are not sufficient you can use the underlying C read/write calls.

When you call wiringPiI2CSetup the return value is the standard Linux filehandle, say fd.

To write multiple bytes use write(fd, buf, count). To read multiple bytes use read(fd, buf, count)

See man 2 read, man 2 write for additional details.

  • While this obviously works, the recommended way to access an I²C host is through ioctl(fd, I2C_RDWR, &i2c_transfer); because you can do multiple transfers (e.g. register select, read) within one transaction with repeated start this way. – Janka Jul 18 '18 at 17:52
  • As per my understanding with this file pointer is it possible to write or read from the particular register address..? I don't think so.. – shivakumar Jul 19 '18 at 5:09
  • @shivakumar Don't you? Well I have done so and I wasn't dreaming. There are thousands of examples on the www. Perhaps check a few out? – joan Jul 19 '18 at 7:46
  • @joan could you please elaborate with one example. I am beginner for I2C. whenever we setup a I2C it will return a standard file pointer. how we can use this file pointer to read register from particular address? Eg: I have tried one example like this below. I2Csetup() returned a pointer , and its value is 0x04. then i Written register address to i2c bus using write() then I read it back using read() it was giving junk value. could you please explain me how it is or my understanding is correct? – shivakumar Jul 19 '18 at 12:47
  • @shivakumar abyz.me.uk/rpi/pigpio/examples.html#Misc_adxl345_c – joan Jul 19 '18 at 13:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.