HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Raspberry Pi GPIO/SPI/I2C => Topic started by: funworld on February 10, 2015, 10:07:26 PM

Title: Raspberry 2 MCP23017 Error
Post by: funworld on February 10, 2015, 10:07:26 PM
CR: Read operation failed with BCM2835_I2C_REASON_ERROR_NACK status

Have Anyone a solution

THX
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 16, 2015, 08:35:11 PM
Hi funworld,

I know at least one reason for this error.
It happens to me when the electrical connections on the I2C bus is faulty.

I would check all my connection for bad contacts etc.

The error tells you that an I2C device is not answering.

Regards,
Wibo.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 17, 2015, 08:49:42 PM
It also could mean you're accessing an I2C device at the wrong address and that from the electrical perspective there's nothing wrong.

Regards,
Wibo.
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 19, 2015, 07:54:18 PM
Hello Wibo,

I try with putty with i2cdetect -y 1 bus find device 0x20 and 0x21
and i  can turn on and off,
With genie smartIC-MCP23017 get the error!
After update to r478 I get a different error
Error
×
    Object of type 'HomeGenie.Automation.Scripting.ScriptingInstance' doesn't match target type 'HomeGenie.Automation.Scripting.ScriptingInstance'

THX for replay
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 19, 2015, 08:09:39 PM
Hi funworld,

HomeGenie does not support Raspberry Pi 2 BCM2836 I2C, but RPi BCM2835 I2C.

Cheers,
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 19, 2015, 08:14:53 PM
Hi Gene,
Will raspi 2 supported in the future?
because the performance is great !

Regards,
funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 19, 2015, 08:33:38 PM
If the RaspberrySharp-IO library will be updated with Rpi2 support I will also update HG with it.
https://github.com/raspberry-sharp/raspberry-sharp-io
A couple of months ago  I've been adapting some code of the RaspberrySharp to make it compatible with CubieTruck and encountered the I2C issue already.
https://github.com/genielabs/raspberry-sharp-io
By then I thought I may write an "EmbeddedSharp" library based on the currently used RaspberrySharp library but compatible with any computer board by just editing an XML file that will contain the various memory addresses needed for direct access operations on GPIO/I2C/SPI/... pins.
Off course this needs more encouragement and donations :)

Cheers,
g.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 21, 2015, 07:38:44 PM
Hi Gene,

since 3 days I'm an owner of the RPi2
It's bloody fast and dies when I take picture with my Nikon D40.

Well I need I2C to work and it doesn't work.
I'm trying to find the cause of this problem.
I'm not asking you to fix the problem, but maybe you know something I don't know.

Some guy claims to have it working (check the replies):
http://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/ (http://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/)

Kinda stuck right now...
Any pointers are appreciated.

Regards,
Wibo.






Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 21, 2015, 08:40:15 PM
Wibo... try it with HG r480. What is Nikon D40?

Cheers,
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: bkenobi on February 22, 2015, 02:38:28 AM
The D40 is a pretty nice digital SLR camera.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 22, 2015, 03:19:01 AM
And what is the matter with D40 and Raspberry Pi 2? ;D

g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 22, 2015, 12:05:13 PM
Hi Gene,

The RPi 2 has a semiconductor (U16) on the PCB that is sensitive to light.

See this link: http://www.raspberrypi.org/xenon-death-flash-a-free-physics-lesson/ (http://www.raspberrypi.org/xenon-death-flash-a-free-physics-lesson/)
or this: http://www.raspberrypi.org/forums/viewtopic.php?t=99042 (http://www.raspberrypi.org/forums/viewtopic.php?t=99042)

You need a high intensity Xenon flash to reproduce it.
LED Flash isn't powerful enough, a 500 W halogen floodlight is also not capable of resetting it.

Problem can be "solved" by covering U16.

Regards,
Wibo.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 22, 2015, 01:15:05 PM
a shy pi!  ;D

g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 22, 2015, 02:16:01 PM
Hi Gene,

I tested with HG r480.
Got the homegenie_1_00_beta_r480.tgz from
https://sourceforge.net/projects/homegenie/files/testing/ (https://sourceforge.net/projects/homegenie/files/testing/)

Copied all content of the tgz onto the RPi2

GPIO is working from HG when I use GPIO23 as output, but I2C doesn't work.

Attached a picture of the error I get.

I wonder if I forget something to setup when starting with a fresh raspbian image?

Regards,
Wibo.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 22, 2015, 04:14:19 PM
Hi Wibo,

so the changes I applied to raspberry-sharp did not help  :-\
In case you would like to help with this, I'm showing you what I did.

First I changed raspberry-sharp-system library to recognize RPi2 board
https://github.com/genielabs/raspberry-sharp-system
If you download it, you can compile the test program and see if the output on the RPi2 is the one expected.

Then I changed the raspberry-sharp-io library in order to use a different memory base address for I2C when running on RPi2:
https://github.com/genielabs/raspberry-sharp-io/commit/89b796a774658db89df2f598442f25ba38c99a90

That's it. Probably the trick of changing the base address is not the only thing to be aware of in order to properly address I2C on RPi2.

Cheers,
g.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 22, 2015, 04:28:17 PM
Well... I found out that I applied corrections of base address only to the GPIO class but not to the I2C one (didn't notice of duplicated code for Interop.cs).
So I'm attacching the fix. These are changes I just made:

https://github.com/genielabs/raspberry-sharp-io/commit/1d5dce1dadd3f1bb3e5539909669a7495c816ad3

Hope it works!
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 22, 2015, 07:09:15 PM
Hi Gene,

Sorry but I get still  errors!
1. when I start inside the editor

Error
×
    Object of type 'HomeGenie.Automation.Scripting.ScriptingInstance' doesn't match target type 'HomeGenie.Automation.Scripting.ScriptingInstance'

2. when starting the modul smartIC mcp23017

CR: Read operation failed with BCM2835_I2C_REASON_ERROR_NACK status

THX
 funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 22, 2015, 07:52:46 PM
Did you restart HG after copying the new libraries? Try also recompiling the program.
Can you provide output of command
Code: [Select]
cat /proc/cpuinfo
from your RPi 2?

g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 22, 2015, 08:46:01 PM
Hello,
yes,  I make a restart and can command with putty!
my cpuinfo

processor       : 0
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 38.40
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

processor       : 1
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 38.40
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

processor       : 2
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 38.40
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

processor       : 3
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 38.40
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

Hardware        : BCM2709
Revision        : a01041
Serial          : 000000006e92fXXX

root@raspberrypi:~# i2cset -y 1 0x20 0x00 0x00
root@raspberrypi:~# i2cset -y 1 0x20 0x14 0x01
root@raspberrypi:~# i2cset -y 1 0x20 0x14 0x00
root@raspberrypi:~# i2cget -y 1 0x20 0x14
0x00
root@raspberrypi:~# i2cset -y 1 0x20 0x14 0x01
root@raspberrypi:~# i2cget -y 1 0x20 0x14
0x01
root@raspberrypi:~# i2cset -y 1 0x20 0x14 0x00

regards

Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 22, 2015, 09:53:28 PM
Hi all,

my CPU info is attached.

Going to investigate your changes Gene.

Where did you get the info about  different base address?

What url for svn should I use if I want to use the same code base as HG?
It's not clear to me where the master is.

Regards,
Wibo.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 22, 2015, 11:40:09 PM
Hi guys,

so the problem might be the wrong Revision I used to detect RPi2:

https://github.com/genielabs/raspberry-sharp-system/blob/master/Raspberry.System/Board.cs#L182 (https://github.com/genielabs/raspberry-sharp-system/blob/master/Raspberry.System/Board.cs#L182)

I got it from some forum, can't remember where... the reported revision in that forum was 0x1a01040.
The revision reported in your infos is different --> a01040.

@Wibo, the base address was get from a post on the raspberry forum site:
http://www.raspberrypi.org/forums/viewtopic.php?f=72&t=98400&p=701074&hilit=0x3F000000#p701074 (http://www.raspberrypi.org/forums/viewtopic.php?f=72&t=98400&p=701074&hilit=0x3F000000#p701074)

I will change the revision number used for detecting RPi2 later and post the update here.

It would be useful if some of you could verify RPi2 detection directly from source code by running the test program contained here:
https://github.com/genielabs/raspberry-sharp-system (https://github.com/genielabs/raspberry-sharp-system)

@Wibo raspberry-sharp libraries used in HG are two:
1) one is raspberry-sharp-system that just detect the board type and can be found at the above link
2) the second one is raspberryshar-io that contains all the class for working with gpio/i2c/spi and other components. this can be found here: https://github.com/genielabs/raspberry-sharp-io (https://github.com/genielabs/raspberry-sharp-io)

g.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 23, 2015, 12:20:24 AM
Hey guys,

thanks to your cpuinfo I finally made the raspberry-system detect RPi2.
I used Wibo file as input and so fixed to make it work.
Attacched the fixed dll (to be used with the previously attacched raspberry-sharp-io).

https://github.com/genielabs/raspberry-sharp-system/commit/fb2dc2a0d5de0b61b3055cc4b5384aaf357c17de

I'll keep finger crossed  ;)

Cheers,
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 23, 2015, 06:36:29 PM
HI gene,

thx for the info, I'm on it.

Regards,
Wibo.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 23, 2015, 07:26:14 PM
Output from the Test.Board.exe attached.

Already wandered where the Raspberry.System.dll came from.
High resolution timer was on my wishlist, nice!

Going to check if I can get I2C online.

Regards,
Wibo.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 23, 2015, 09:07:52 PM
Hi Gene,

did a fresh build from https://github.com/genielabs/raspberry-sharp-system r209
Checked Raspberry.System.dll, think nuget copied it into the solution.
It was the same(size: 11264)) as produced by the Test.Board.exe solution.
Copied all 7 dll's into the r480 folder on Pi2 and got same error in HG.

Replaced Raspberry.System.dll from Test.Board and rebuilded.
Copied and tested, error still lives.

Suddenly the Raspberry.System.dll was 11288 bytes, I didn't change anything, just a rebuild.
Is Nuget doing this?
Repeated the whole drill to no avail.

Downloaded your dll which was also 11288 bytes, repeated the whole drill and no results.

Going to do some debugging...

Regards,
Wibo.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 23, 2015, 11:43:38 PM
Hi Wibo,

I packed up all the patched raspberry-sharp dll into the new r480 deb and tgz (testing folder).
So you can try to run HG and see if I2C is now working without struggling with source code.

g.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 24, 2015, 12:22:01 AM
Hi Gene,

Going to sleep now, will try that tomorrow...

Is there any easy way to replace Raspberry.System.dll without modifying the raspberry-sharp solution and projects, they are all expecting the dll to be in the bin/debug.?

Your attempts to only use HG will be futile.
I'm a source guy and HG can never give me all I want, but I'm trying to do as much as integration as possible.

I'm a control freak, just like you.

Regards,
Wibo.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 24, 2015, 01:09:31 AM
All right source guy  :)
Yes, all dll are expected to be in the bin/debug.

Cheers,
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 24, 2015, 09:04:08 PM
Hi Gene,

have the I2C working on RPi2.

Your changes used the wrong base address.
bscBase: 0x20804000
gpioBase: 0x3F200000

I2cDriver.GetBscBase return the wrong address.
It gets a rev 3 from GpioConnectionSettings.BoardConnectorRevision
Your switch case 3 is the only case where you don't replace the base address.

When I change bscBase into 0x3F804000 it works.

Thank God for source code.  8)

Regards,
Wibo.


Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 24, 2015, 10:10:19 PM
Forgot some info...

If you want to cleanup all the experiments...

These are the pins used:
const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
const ConnectorPin sclPin = ConnectorPin.P1Pin05;

After calling ToProcessor() on the ConnectorPin they result in ProcessorPins.
sdaCpuPin: Pin02
sclCpuPin: Pin03

The processor pins go into the I2cDriver and that's what your testing in method GetBscBase()

All this info was gathered on RPi2, but the same testing code works on RPiB+ too (without the 0x3F804000 hack)

Regards,
Wibo.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 24, 2015, 10:22:16 PM
So if I fix this line:

https://github.com/genielabs/raspberry-sharp-io/blob/master/Raspberry.IO.InterIntegratedCircuit/I2cDriver.cs#L301
Code: [Select]
...
                case 3:
                    if (sdaPin == ProcessorPin.Pin2 && sclPin == ProcessorPin.Pin3)
                        return Board.Current.Model == '2' ? Interop.BCM2836_BSC1_BASE : Interop.BCM2835_BSC1_BASE;
                    throw new InvalidOperationException("No I2C device exist on the specified pins");
...
does it work?
Or also the base address here:

https://github.com/genielabs/raspberry-sharp-io/blob/master/Raspberry.IO.InterIntegratedCircuit/Interop.cs#L21

has to be changed?

Cheers,
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 24, 2015, 10:31:20 PM
I see that BCM2835_BSC1_BASE is matching  0x3F804000 (BCM2835_PERI_BASE + 0x804000).
So just fixing the switch (didn't notice it before, otherwise would have fixed! =)).
Glad to see it's working.
Thanks!
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 24, 2015, 10:39:25 PM
I think the output from GpioConnectionSettings.BoardConnectorRevision is right, it's all about the connector and that's rev3

In GetBscBase() shuffling the base address should probably only be done in case 3 and not in 1 and 2.

and yes, the modification you suggested works on RPi2 and you don't have to change the constants in the interop.

Regards,
Wibo.


Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 24, 2015, 10:41:13 PM
All right, so I'm changing it like this:

Code: [Select]

        private static uint GetBscBase(ProcessorPin sdaPin, ProcessorPin sclPin)
        {
            switch (GpioConnectionSettings.BoardConnectorRevision)
            {
                case 1:
                    if (sdaPin == ProcessorPin.Pin0 && sclPin == ProcessorPin.Pin1)
                    return Interop.BCM2835_BSC0_BASE;
                    throw new InvalidOperationException("No I2C device exist on the specified pins");

                case 2:
                    if (sdaPin == ProcessorPin.Pin28 && sclPin == ProcessorPin.Pin29)
                        return Interop.BCM2835_BSC0_BASE;
                    if (sdaPin == ProcessorPin.Pin2 && sclPin == ProcessorPin.Pin3)
                        return Interop.BCM2835_BSC1_BASE;
                    throw new InvalidOperationException("No I2C device exist on the specified pins");

                case 3:
                    if (sdaPin == ProcessorPin.Pin2 && sclPin == ProcessorPin.Pin3)
                        return Board.Current.Model == '2' ? Interop.BCM2836_BSC1_BASE : Interop.BCM2835_BSC1_BASE;
                    throw new InvalidOperationException("No I2C device exist on the specified pins");

                default:
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Board revision {0} is not supported", GpioConnectionSettings.BoardConnectorRevision));
            }
        }



g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 24, 2015, 10:54:32 PM
testing...
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 24, 2015, 10:55:54 PM
Done!

https://github.com/genielabs/raspberry-sharp-io/commit/5f0c86d4aa2edcdca850cc980995fa2b39ef1a77

also updated r480 packages with the fix.

https://sourceforge.net/projects/homegenie/files/testing/

Cheers,
g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 24, 2015, 11:03:11 PM
Works and double checked if I removed the hack.
will test your release now...

There was an issue with the imported Automation program GPIO for the B+ running on the RPi2, maybe it's fixed too, I'll let you know.

BTW: Is there any chance the GPIO automation program for the B+ is adde by default in the HG installs?

Regards,
Wibo.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 24, 2015, 11:24:32 PM
BTW: Is there any chance the GPIO automation program for the B+ is adde by default in the HG installs?

yes, where do I find the hgx for the GPIO B+ app?

g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 25, 2015, 12:00:52 AM
Checked your release at https://sourceforge.net/projects/homegenie/files/testing/

Only tested it on RPi2.
Have a test hgx to access I2c directly.
All hard coded and it never worked on RPi2, now it does :)

Will test HG GPIO tomorrow to see if there are any issues left.
Can't test SPI, since I have no SPI devices.

About the B+ and hopefully RPi2 GPIO hgx that are both rev3 connector.
You will get some lock violation if both casual and B+ are enabled, which is good, but not user friendly.
.

I use the attached hgx that was posted on the HG forum.

Regards,
Wibo.

Title: Re: Raspberry 2 MCP23017 Error
Post by: Wibo on February 25, 2015, 08:35:47 PM
Hi Gene,

just did some basic testing with GPIO, using your r480 testing release.
I used the GPIO hgx I posted yesterday.

Tested some pins in the GPIO rev2 range(26pins) and pins in the GPIO rev3 range(40pins).
The issue I had with my first tests never came back, it happened before you started to recognize the RPi2.

I didn't have other any other issues.

So it seems HG is working on RPi2 when it concerns GPIO and I2c.
I'm happy, because I have a sharp io library that works on RPi2.

Going to switch to HG raspberry-sharp-io fork for my own development.

Thanks for all the efforts and sharing info to make it work on RPi2.

Regards,
Wibo.



Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 25, 2015, 09:07:22 PM
Hi guys,

You all doing a great Job,Thanks for that.
I using your last r480 testing release.
and tested the GPIO rev3  that works on RPI 2,
but all I2C moduls still get an error,
  "Object of type 'HomeGenie.Automation.Scripting.ScriptingInstance' doesn't match target type 'HomeGenie.Automation.Scripting.ScriptingInstance'"

Regards,
funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on February 25, 2015, 09:16:47 PM
@Wibo you're welcome, thank you too.

@funworld, the error probably means that you've to recompile that automation program, can you share the code?

g.
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 25, 2015, 09:39:02 PM
Hello,
I use the standard SmartIC-MCP23017 but change low to high!

regards
funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on February 26, 2015, 10:02:02 PM
Hello, 

Now all work fine, I had connect a singel I2C device !

Thanks

Regards
Funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on October 26, 2015, 06:12:36 PM
Hi Gene,

In the new pre versions 497 and 498 the i2c with SmartIC - MCP23017 ditn´t work on Raspi 2
Read operation failed with BCM2835_I2C_REASON_ERROR_NACK status

Thanks

Regards
Funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on October 26, 2015, 08:22:32 PM
which is the last working version?

Title: Re: Raspberry 2 MCP23017 Error
Post by: funworld on October 27, 2015, 07:43:32 PM
with  version  r496 was working, but i will make more tests,
look´s like have problems with my system!

funworld
Title: Re: Raspberry 2 MCP23017 Error
Post by: Gene on October 27, 2015, 08:26:56 PM
nothing changed in the Raspberry-IO libraries since then.