Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

I2C problem

Wed Aug 26, 2015 9:51 am

I have Raspberry made in 2011,12 and need to use I2C there. According to the docs, the Raspberry should use
/dev/i2c-0 (port I2C0).
However i2cdetect -y 0 can not detect my device
while "i2cdetect -y 1" can.

I use Python smbus utility like this
smbus.SMBus(1)
and
I can send /read a single byte
but I can not send more data.
From a logic analyzer I can see it should be possible to send via ONE write command at least 4bytes
D0,D1,D2,D3.
I tried to send 3 bytes but failed

I would like to send
D0=0x03,D1=0xAA,D2=0xBB
so I tried

Code: Select all

>>> bus.write_i2c_block_data(0x08,0x03,[0xAA,0xBB])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 5] Input/output error
where 0x08 is the address of my I2C device

When I check via a logic analyzer, I can see data bytes like these
D0 is 03
D1 is AA
but all others are empty, including D2, which I would expect to have 0xBB value

Has anyone found a solution to such a problem?Thank you

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 10:17 am

Until your device is seen on the bus (by i2cdetect) there is no point in sending it messages. It won't get them and the I2C driver software will abort the message.

The device is not connected properly.

Could you post a photo of the connections you have made between the Pi and the device? Could you also describe the connections in words?

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 10:42 am

Thanks for your reply.
I use
SDA pin 3
SCL pin 5
3.3V pin 1
GND pin 6

But if the device were not connected properly, I do not think I can send any byte.
But I CAN send a byte, but only ONE byte in one write command.

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 10:55 am

Jan1 wrote:Thanks for your reply.
I use
SDA pin 3
SCL pin 5
3.3V pin 1
GND pin 6

But if the device were not connected properly, I do not think I can send any byte.
But I CAN send a byte, but only ONE byte in one write command.
If it's not shown by i2cdetect the device is not connected to the bus. The I2C driver won't notice until the device fails to acknowledge a data byte.

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 11:10 am

Thank you for the reply.
The device is shown by
"i2cdetect -y 1"

as a device with address 0x08, which is correct.
So, the device is detected but on bus 1.
Do you think it is wrong and it should be detected on bus 0 ?

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 11:19 am

Jan1 wrote:Thank you for the reply.
The device is shown by
"i2cdetect -y 1"

as a device with address 0x08, which is correct.
So, the device is detected but on bus 1.
Do you think it is wrong and it should be detected on bus 0 ?
I think you have the Pi with the 26 pin expansion header plus the 8 (unpopulated) pin expansion header. In that case I2C bus 1 uses GPIOs 2 and 3 which happen to be on pins 3 and 5. So for you i2cdetect -y 1 is correct.

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 11:24 am

Thank you for the reply.
So, the hardware connection is correct, isn't it?
But can you please help me to find out a reason, why I can not send more bytes - see the description of my problem from the beginning of this post ?
Thank you

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 11:30 am

The simplest reason is that the device does not acknowledge the data it is being sent. Could you post a logic analyser trace of the transaction?

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 11:53 am

Here is the output, when trying to send more bytes with a command
bus.write_i2c_block_data(0x08,0x03,[0xAA,0xBB])
LAPicture2.jpg
LAPicture2.jpg (46.02 KiB) Viewed 2335 times
Thank you.

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 12:51 pm

The device hasn't acknowledged the byte (the RED bit). So the device does not expect the data. I guess the message is incorrect.

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 2:03 pm

Which message is incorrect?
IOError: [Errno 5] Input/output error ?
Is it possible that Raspbery ( IO chip) is slow? I made reversed engineering by using another USB/I2C bridge that uses 299kHz speed ( raspberry only 100kHz) and it was possible to write more bytes.
And is the syntax
>>> bus.write_i2c_block_data(0x08,0x03,[0xAA,0xBB])
correct?
Thank you for help

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 2:53 pm

The commands/data to be sent to the device will be specified in its datasheet.

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 3:03 pm

and do you think the small Raspberry's GPIO speed could be that problem?

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 3:28 pm

Jan1 wrote:and do you think the small Raspberry's GPIO speed could be that problem?
I have no idea, but I would have thought it unlikely. What is the device?

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Wed Aug 26, 2015 4:49 pm

It is MIPS CPU( 400Mhz) board . There is a program that works properly with that CPU and I used it during a reverse engineering.
The frequency was about 299kHz.
While Raspberry shows only 100 kHz.Is it possible to increase the I2C bus speed?

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Wed Aug 26, 2015 4:56 pm

Yes, you can change the bus speed. The method depends on whether you are using device tree or not.

Pre device tree you set the baud rate as a module parameter when you start i2c-bcm2708, e.g. modprobe i2c-bcm2708 baudrate=299000.

Post device tree you set an entry in /boot/config.txt, e.g. dtparam=i2c_arm_baudrate=299000

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Thu Aug 27, 2015 9:30 am

I added dtparam=i2c_arm_baudrate=299000 to in /boot/config.txt, but it did not help the speed is still the same (100kHz).
Can you please let me know:
- what a difference is between Pre device tree and Post device tree
-how to check if my Raspberry uses device tree or not

Meanwhile I browsed the forum and found out more people had a problem with Python when sending more bytes to I2C device e.g.
viewtopic.php?f=44&t=53680&p=800908&hil ... 67#p800908
post by LinuxCircle » Mon Aug 10, 2015 11:12 pm
Can anyone confirm it is a bug?

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Thu Aug 27, 2015 9:48 am

Do a uname -a to get your kernel version. I think device tree was >= 3.18.

No it is not a bug.

From memory LinuxCircle has a self inflicted problem. He got something working using wiringPi and C and tried to port it to Python. Rather than using the Python equivalents of the wiringPi calls he used inappropriate smbus calls. Just to cloud the issue further I seem to remember he was also using overlapping quick2wire and smbus calls (both are I2C libraries).

Jan1
Posts: 42
Joined: Tue Nov 13, 2012 7:22 pm

Re: I2C problem

Thu Aug 27, 2015 10:18 am

pi@raspberrypi ~/Python $ uname -a
Linux raspberrypi 3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013 armv6l GNU/Linux

Does it mean I use device tree?

I added dtparam=i2c_arm_baudrate=299000 to in /boot/config.txt, but it did not help the speed is still the same (100kHz).
What else shall I try?
What is a difference between Pre device tree and Post device tree ?
Thank you

User avatar
joan
Posts: 14747
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C problem

Thu Aug 27, 2015 10:28 am

Version 3.6.11 is earlier that 3.18.

Return to “Interfacing (DSI, CSI, I2C, etc.)”