FrankFromGermany
Posts: 4
Joined: Fri Feb 13, 2015 2:15 am
Location: Houston, TX

I2C MCP23017 crashes

Fri May 08, 2015 11:04 pm

Hi,

i am trying to access an MCP23017 I/O-expander through the I2C user-space driver.
Depending on the speed with which i send commands through the bus the chip seems to "crash" after a while - "crash" means that the i2cdetect utility does no longer report the address as occupied on the I2C-bus. There is nothing else connected to the RasPi, just the MCP23017:
RasPi -> MCP
pin2 -> pin9 (+5V)
pin3 -> pin13 (SDA)
pin5 -> pin14 (SCL)
pin6 -> pin10 (GND)
And the MCP-pins 15,16,17 are connected to GND, so that the I2C address of the chip is 0x20.
i2cdetect -y 1 prints:

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
When i run my little test-program:

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes ('sleep');
use Device::SMBus;

my $DevicePath = '/dev/i2c-1';
my $DeviceAddr = 0x20;
my $MCP        = Device::SMBus->new(I2CBusDevicePath => $DevicePath,I2CDeviceAddress => $DeviceAddr);

my $DELAY    = 0.1;
my @Patterns = (0x01,0x02,0x04,0x08,0x11,0x22,0x44,0x88,0x10,0x20,0x40,0x80,0x00);

my $rc = $MCP->writeByteData(0x00,0b00000000);  # All portbits output
printf("rc=%02x\n",$rc);
my $Counter = 0;

while (1) {
  foreach my $Pattern (@Patterns) {
    $Counter ++;
    $rc = $MCP->writeByteData(0x12,$Pattern);
    printf("rc=%02x counter=%d\n",$rc,$Counter);
    die "I2C error." if ($rc != 0);
    sleep($DELAY);
  }
}
It depends on the value of the $Delay variable how quickly it crashes, but it will crash:

Code: Select all

rc=00 counter=941
...
rc=00 counter=942
rc=00 counter=943
rc=ffffffffffffffff counter=944
I2C error. at test3.pl line 23.
And after a crash, the I/O expander is no longer visible:

Code: Select all

i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
To resolve this situation the power to the IC must be interrupted, even rebooting the Pi does not help.

I tried the same with a Python program with the same result, even using the i2cset utility will sooner or later crash the chip.

Is that a known issue? - If yes, is a workaround available?

Thank you very much in advance for your help.

Best regards from Houston (TX),
Frank/2

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

Re: I2C MCP23017 crashes

Sat May 09, 2015 8:17 am

I haven't looked at your code to see what it's doing.

This test viewtopic.php?p=639955#p639955 did about 4 million error free I2C operations. It did help confirm a fault within the MCP23017 but that is not related to what you appear to be doing.

User avatar
DougieLawson
Posts: 35805
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: I2C MCP23017 crashes

Sat May 09, 2015 11:01 am

I happened to have an MCP23017 with 16 LEDs wired to it so I ran your code (as posted).

It's not crashed at all.

rc=00 counter=2478
rc=00 counter=2479
rc=00 counter=2480
rc=00 counter=2481
rc=00 counter=2482

So I would suspect you've got a borked MCP23017 chip or something wired wrong.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

FrankFromGermany
Posts: 4
Joined: Fri Feb 13, 2015 2:15 am
Location: Houston, TX

Re: I2C MCP23017 crashes

Sat May 09, 2015 7:00 pm

DougieLawson wrote:So I would suspect you've got a borked MCP23017 chip or something wired wrong.
MERDE!!! :x

I bought 5 of them from a Chinese vendor for $1.25 each and they all show the same behavior. The one i bought from RadioShack works fine. - If it sounds too good to be true...

Thank you very much for your help!

FrankFromGermany
Posts: 4
Joined: Fri Feb 13, 2015 2:15 am
Location: Houston, TX

Re: I2C MCP23017 crashes

Sat May 09, 2015 7:08 pm

joan wrote:It did help confirm a fault within the MCP23017 but that is not related to what you appear to be doing.
Very interesting stuff! :o

I'm writing a Perl module to comfortably access my LCD1602 Pi Plate from Adafruit. They only offer a Python module, which needs to be ran with root access... I prefer to write in Perl or C and i try to avoid running anything as root.

Thank you very much for your help!

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: I2C MCP23017 crashes

Sat May 09, 2015 7:12 pm

FrankFromGermany wrote:
DougieLawson wrote:So I would suspect you've got a borked MCP23017 chip or something wired wrong.
MERDE!!! :x

I bought 5 of them from a Chinese vendor for $1.25 each and they all show the same behavior. The one i bought from RadioShack works fine. - If it sounds too good to be true...

Thank you very much for your help!
It's a shame you are experiencing this problem, as a workaround you could interrupt the power to the defective MCP23017's (using a GPIO to switch a transistor) at a fixed interval.
Doug.
Building Management Systems Engineer.

FrankFromGermany
Posts: 4
Joined: Fri Feb 13, 2015 2:15 am
Location: Houston, TX

Re: I2C MCP23017 crashes

Tue May 12, 2015 3:32 pm

BMS Doug wrote:It's a shame you are experiencing this problem, as a workaround you could interrupt the power to the defective MCP23017's (using a GPIO to switch a transistor) at a fixed interval.
Yep! You're right it is shameful to sell defect stuff to others. - On the other hand i blame myself for hitting the "BUY" button without checking the seller more thoroughly: The shop no longer exists on AliExpress...
I too thought about a workaround, using a GPIO to cut and restore the power to the chip, but dismissed it as too unpredictable. The MCP needs a bit more than just setting up the data-direction registers, i'd like to use the interrupt on-change functionality and all chips crash immediately upon writing into the INTCON register.
Maybe i build some art[ificial] lifeforms from those defect ICs in the future, four this [http://www.crookedbrains.net/2007/02/ic ... w-use.html] as an example recently... ;)

Best regards from Houston (TX),
Frank/2

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: I2C MCP23017 crashes

Sat May 16, 2015 10:20 am

Why would you buy a counterfeit from China ? Genuine MCP23017 chips are available from Digikey for $1.20 each in lots of 10. Cheap shipping too. The are $1 each in lots of 25 pcs.

http://www.digikey.com/product-search/e ... ageSize=25
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

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