I2C Fails at higher clock speeds

247 views
Skip to first unread message

Viorel Dehelean

unread,
Sep 17, 2013, 1:13:02 PM9/17/13
to pi...@googlegroups.com
Hi,

i have a device that runs at 400Khz i2c, when trying the following:

byte[] packet = {0x10,0x03,0x01,0x00,0x00,0x0c};
device.write(packet, 0, packet.length);

i get an exception:
Exception in thread "main" java.io.IOException: Error writing to /dev/i2c-1 at address 0x60. Got -20001.
at com.pi4j.io.i2c.impl.I2CDeviceImpl.write(I2CDeviceImpl.java:90)
at com.test.main.main(main.java:127)

This does not happen at the default 100Khz, however, the device i have does not work with 100Khz.

Any suggestions ?

Regards,
Viorel

click

unread,
Sep 27, 2013, 9:46:20 AM9/27/13
to pi...@googlegroups.com
Hi Viorel,

Sorry for slightly later response - I was hoping that I would be able to return to you and say it is done now.

Anyway - current implementation of pi4j is using /dev/i2c-0 and /dev/i2c-1 devices (i2c module) to directly write or read to/from. By default that driver is configured to 100kHz. For bus to work on different frequency it needs, explicitly, to be set for such frequency.

One workaround I can see right now is to use modules parameter to change the frequency:

sudo modprobe -r i2c_bcm2708 && sudo modprobe i2c_bcm2708 baudrate=400000

(from http://hertaville.com/2013/04/01/interfacing-an-i2c-gpio-expander-mcp23017-to-the-raspberry-pi-using-c/)

After that you should be able to access your 400kHz device. But, if you have other devices on the same bus that can't use that frequency then you'll need to find some other solution.

HTH
Reply all
Reply to author
Forward
0 new messages