more G-Labs products

Author Topic: 2 x MCP23017 not working together  (Read 2702 times)

July 11, 2014, 12:30:44 AM
Read 2702 times

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi,


I keep getting problems trying to work with 2 MCP23017's together.

I duplicated the latest MPC23017 program of Gene, renamed the module domain name to .A and .B, and changed the ports to 0x20 and 0x21.
Both programs and ic's work fine if I enable them alone.
But when I try to run them both together, the program that is already running receives an error (CR:BCM2835_I2C_REASON_ERROR_DATA. 1 byte missing.)    and stops working, and the new program remains running... Only the ports of the new chip are working.

What am I missing here?
Can anyone help me please?
What can I do more than changing the moduleDomain name and port?

I think the wireing (parrallel) is good as both chips are working fine individually.
Also i2cdetect on raspbian shows me two devices connected, one on 0x20 and one on 0x21.

I'm out of ideas right now...


Thanks.



July 11, 2014, 05:52:52 PM
Reply #1

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
You need to make sure each named differently
You need to amend the first line
var moduleDomain = "Components.MCP23017";

to something like var moduleDomain = "Components.MCP23017-A";
and the other var moduleDomain = "Components.MCP23017B";




July 11, 2014, 08:24:23 PM
Reply #2

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi,


I renamed them just like Gene told me to do.
Instead of Components.MCP23017.1 and .2, I used .A and .B.

In the latest release r395 I can add 32 sensors (sensor 1-16 of MCP23017.A and sensor 1-16 of MCP23017.B) even tough the second program is not running :-s Even after a restart of the entire raspberry pi unit, homegenie starts with all 32 sensors available and the second program (MCP23017.B) has bever started (is this a bug in the new release?)
Of course only the sensors of A work.

Starting the second program results in crashing A and all the B sensors work...

Can the "." be a problem to recognize the difference?


Thanks

July 11, 2014, 10:56:34 PM
Reply #3

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
it could be... I'm on r395 also and added a seperator givng a name  "LED's "  but was not able to load the web page,
Then after I renamed it to LEDs (without the ' ) it was ok.
« Last Edit: July 11, 2014, 11:11:23 PM by baptist »

July 12, 2014, 01:11:49 AM
Reply #4

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi,


I renemed both domains to MCP23017_A and MCP23017_B.
Exactly the same problem happens :


STARTING PROGRAM B

Code: [Select]
01:02:59.403 Status.Level 0 16 Components.MCP23017_B
01:02:59.285 Status.Level 0 15 Components.MCP23017_B
01:02:59.167 Status.Level 0 14 Components.MCP23017_B
01:02:59.48 Status.Level 0 13 Components.MCP23017_B
01:02:58.929 Status.Level 0 12 Components.MCP23017_B
01:02:58.811 Status.Level 0 11 Components.MCP23017_B
01:02:58.692 Status.Level 0 10 Components.MCP23017_B
01:02:58.574 Status.Level 0 9 Components.MCP23017_B
01:02:58.442 Status.Level 0 8 Components.MCP23017_B
01:02:58.323 Status.Level 0 6 Components.MCP23017_B
01:02:58.206 Status.Level 0 5 Components.MCP23017_B
01:02:58.88 Status.Level 0 4 Components.MCP23017_B
01:02:57.970 Status.Level 0 3 Components.MCP23017_B
01:02:57.852 Status.Level 0 2 Components.MCP23017_B
01:02:57.734 Status.Level 0 1 Components.MCP23017_B
01:02:40.814 Runtime.Error CR: Read operation failed with BCM2835_I2C_REASON_ERROR_NACK status 1000 HomeAutomation.HomeGenie.Automation // PROGRAM A ERROR
01:02:39.798 Program.Status Disabled 1000 HomeAutomation.HomeGenie.Automation // PROGRAM A STOPS
01:02:39.518 Program.Status Running 1001 HomeAutomation.HomeGenie.Automation
01:02:37.161 Program.Status Enabled 1001 HomeAutomation.HomeGenie.Automation //STARTING PROGRAM B


STARTING PROGRAM A AGAIN

Code: [Select]
01:07:58.508 Runtime.Error CR: Read operation failed with BCM2835_I2C_REASON_ERROR_DATA status, missing 1 bytes 1001 HomeAutomation.HomeGenie.Automation // PROGRAM B ERROR
01:07:56.854 Program.Status Disabled 1001 HomeAutomation.HomeGenie.Automation // PROGRAM B STOPS
01:07:36.787 Program.Status Running 1000 HomeAutomation.HomeGenie.Automation
01:07:36.785 Program.Status Enabled 1000 HomeAutomation.HomeGenie.Automation // STARTING PROGRAM A

July 12, 2014, 01:14:24 PM
Reply #5

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi,


I hereby can confirm that running 2 programs of MCP23017 with a different domainname is not working (for me?)

Altough a previous post (http://www.homegenie.it/forum/index.php?topic=145.msg771#msg771) is confirming that creating 2 programs with a different domain, is working, I hardly doubt this is possible : for me it seems very logic, that when you run 2 programs asynchronically creating each a different Driver and a driverConnection, they will use the same bus together at the very same moment (not knowing of each other who comes first) which will result in conflicts.

For example :while one program is polling for data, the other might try to send configurations of a chip (startup). Of course they are targetting a different adres (driverConnection : 0x20 and 0x21) but they are using the same bus (Driver) which might be busy sending or receiving data from the other program.

Of course I poll every 100ms while the Original program polls only every 500ms. Maybe this generates more traffic on the bus but I hardly doubt that setting a poll rate of 500 ms will never result in conflicts....


So I did some duplications in Gene's code of the MCP23017 and now both chips are working fine and stable. In this code you only use one Driver and two driverConnections to a different adress (0x20 and 0x21) which seems more logic as in one program the code runs sequencely it is impossible to use both driverConnections at the same time (as long as you don't use an AsyncTask)


I also added a Get.Status tot the API so you can request the status of all 32 pins using API calls.


If there are still bugs in the new program, feel free to let me know.