JonasE
Posts: 24
Joined: Sun Nov 09, 2014 8:18 am

Re: MCP23017 problem

Wed Nov 12, 2014 10:07 pm

Interesting! But you only get 255 when it fails? In either case, that should not happen...

Thank you so much for testing this. Now I somehow feel better. ;)

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

Re: MCP23017 problem

Wed Nov 12, 2014 10:23 pm

JonasE wrote:Interesting! But you only get 255 when it fails? In either case, that should not happen...

Thank you so much for testing this. Now I somehow feel better. ;)
Seeing the 255 my initial thought was that the MCP23017 was busy so was stretching the clock. The Pi not supporting clock stretching was carrying on regardless to read all 1's.

However I can find no evidence that the MCP23017 uses clock stretching and have no idea how that idea could be tested.

ddahms
Posts: 67
Joined: Tue Mar 18, 2014 3:38 pm

Re: MCP23017 problem

Wed Nov 12, 2014 10:54 pm

Well Jonas, I think you deserve the award for weirdest problem of the month. You have conclusively proven it to be a problem in the MCP23017 chip, and Joan confirmed it.

Now that you understand the problem, you can plan your workaround. You could rewire your tester to use all the GPA7 and GPB7 pins for static signals, or use them as outputs, or not use them at all.

JonasE
Posts: 24
Joined: Sun Nov 09, 2014 8:18 am

Re: MCP23017 problem

Thu Nov 13, 2014 8:33 am

Yes. Now that it is confirmed I feel I can trust the rest of the pins some more. A simple reorganizing of used pins to my pod solves things for now.

A big "thank you" to Joan who spent time and energy to help me! And also thanks to everybody else that helped with comments.

Best regards, Jonas

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

Re: MCP23017 problem

Thu Nov 13, 2014 2:30 pm

While I had the breadboard set up I decided to do a final, slightly more rigorous test.

I cycled through 18 frequencies and spent 5 minutes at each recording the total number of bad reads.

All my bad reads were 255.

Code: Select all

#!/usr/bin/env python

# MCP23017

import time

import pigpio

A7=24 # gpio connected to port A7.

PWM=[10, 20, 40, 50, 80, 100, 160, 200, 250, 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000]

TIME=300

pi = pigpio.pi("tom") # Connect to tom.

chip = pi.i2c_open(0, 0x20) # tom is a Rev.1 board.

pi.set_PWM_dutycycle(A7, 128) # Square wave.

for p in PWM:

   freq = pi.set_PWM_frequency(A7, p)

   bad = 0
   reads = 0
   start = time.time()

   while (time.time() - start) < TIME:
      now = pi.i2c_read_byte_data(chip, 18)
      reads += 1
      if (now != 0) and (now != 128):
         bad += 1
         if now != 255:
            print(now)

   print("time {} frequency {} reads {} bad {}".format(TIME, freq, reads, bad))

pi.i2c_close(chip)

pi.stop()
Results

Code: Select all

time 300 frequency 10 reads 222992 bad 1
time 300 frequency 20 reads 222897 bad 2
time 300 frequency 40 reads 222799 bad 7
time 300 frequency 50 reads 222698 bad 6
time 300 frequency 80 reads 222728 bad 14
time 300 frequency 100 reads 222656 bad 15
time 300 frequency 160 reads 222732 bad 23
time 300 frequency 200 reads 222691 bad 31
time 300 frequency 250 reads 222843 bad 38
time 300 frequency 320 reads 222699 bad 45
time 300 frequency 400 reads 222726 bad 56
time 300 frequency 500 reads 222814 bad 58
time 300 frequency 800 reads 222826 bad 121
time 300 frequency 1000 reads 222585 bad 141
time 300 frequency 1600 reads 222821 bad 246
time 300 frequency 2000 reads 222706 bad 290
time 300 frequency 4000 reads 222924 bad 594
time 300 frequency 8000 reads 222932 bad 1128
mcp23017.png
mcp23017.png (20.43 KiB) Viewed 2042 times
There seems to be a clear correlation between PWM frequency and error rate.

JonasE
Posts: 24
Joined: Sun Nov 09, 2014 8:18 am

Re: MCP23017 problem

Thu Nov 13, 2014 2:38 pm

Beautiful! :D

JonasE
Posts: 24
Joined: Sun Nov 09, 2014 8:18 am

Re: MCP23017 problem

Thu Nov 13, 2014 8:31 pm

I hoked up the scope again, measuring the clock as the faulty 1:s are clocked out. The clock is ticking along nicely, not held low or anything by the MCP. So, no clock stretching as far as I can see.

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

Re: MCP23017 problem

Thu Nov 13, 2014 8:36 pm

JonasE wrote:I hoked up the scope again, measuring the clock as the faulty 1:s are clocked out. The clock is ticking along nicely, not held low or anything by the MCP. So, no clock stretching as far as I can see.
Time to contact Microchip I guess.

JonasE
Posts: 24
Joined: Sun Nov 09, 2014 8:18 am

Re: MCP23017 problem

Fri Nov 14, 2014 8:53 am

Yes, I filed a support ticket. I still hope you and I got some pirated version of the IC that has issues.

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

Re: MCP23017 problem

Fri Nov 14, 2014 3:55 pm

mahjongg wrote:
JonasE wrote:I added code for activating weak pullups, wrote 0xFF to 0x0C and 0x0D. I can see the effect on the pins but no, it did not solve the problem.

Best regards, Jonas
off course not! There are already external 1K8 pullups to 3V3 present, so adding the weak (~50K) pullups won't matter at all!

note that if you power this chip with 5V, the minimum high level voltage becomes 4V (0.8 x VCC) so 3V3 won't work, and thus you need a level converter. Solution, power the chip with 3V3, so Vih-min becomes 2,64V.
I have used MCP23017s powered by 5 volts. I have not had a single problem even at 1.7 mhz speeds. Yes I know that it is out of spec, but it still works on both the Rpi and the BBB.

It seems odd that you are connecting the output of the mcp23017 to a GPIO pin. I would have done something else.

Have you put in a decoupling cap for the IC?

I buy my MCP23017 chips from Digikey. About $1 each. Digikey's shipping is dirt cheap.
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

JonasE
Posts: 24
Joined: Sun Nov 09, 2014 8:18 am

Re: MCP23017 problem

Thu Nov 20, 2014 1:12 pm

Hi!

Yes, my decoupling should be fine... And I actually think your 1.7MHz is within spec. ;-)

I got a response from Microchip. They actually confirm there is a problem in the MCP23017. At least they have seen the problem before.

So, as a general advice, don't use GPA7 or GPB7 as inputs when using a MCP23017!

Best regards, Jonas

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