Why does this i2c example fail on the Grand Central M4

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Gary_J
 
Posts: 7
Joined: Mon Nov 08, 2021 5:10 pm

Why does this i2c example fail on the Grand Central M4

Post by Gary_J »

In migrating some old code over to the Grand Central M4, I ran into a curous i2c (wire.h) issue so I thought best to exit my code and jump into an example sketch from the wire library. I fired it up and tossed in some print statements to see how it progressed.

It doesn't..It won't run unless I comment out the line:
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2

I assumed the loop would plow on, regardless of an i2c request.

Currently the Grand Central is hanging out of my computer on a short cable with nothing connected.

Here is the code.. I have looked for this issue from others to no avail..

Code: Select all

// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Serial.begin(115200);  // start serial for output
  Wire.begin();        // join i2c bus (address optional for master)
}

void loop()
{
  Serial.println("Void Loop");
  Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2

 // while(Wire.available())    // slave may send less than requested
  { 
 //   char c = Wire.read(); // receive a byte as character
 //   Serial.println(c);         // print the character
  }
Serial.println("Last Line");
  delay(500);
}

Any idea why?
Gary

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Why does this i2c example fail on the Grand Central M4

Post by adafruit_support_bill »

Currently the Grand Central is hanging out of my computer on a short cable with nothing connected.
Nothing connected to the i2c bus? The Arduino Wire library is prone to hanging when there are problems on the bus. An unconnected cable is effectively an antenna for noise.

User avatar
Gary_J
 
Posts: 7
Joined: Mon Nov 08, 2021 5:10 pm

Re: Why does this i2c example fail on the Grand Central M4

Post by Gary_J »

Hi Bill,
This is what I mean (pic) with regards to the connection. I have a Mega 2560 and Grand central running the same code and the Mega runs the void loop and the Grand Central doesn't.
2021-11-10 08.11.29.jpg
2021-11-10 08.11.29.jpg (30.8 KiB) Viewed 373 times
Thanks, Gary

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Why does this i2c example fail on the Grand Central M4

Post by adafruit_support_bill »

The ATMEGA and ATSAMD processor architectures are different. And also the Mega has external pullups on the i2c lines, so it is not too surprising that they behave differently when not connected to anything.

User avatar
Gary_J
 
Posts: 7
Joined: Mon Nov 08, 2021 5:10 pm

Re: Why does this i2c example fail on the Grand Central M4

Post by Gary_J »

Hi Bill,
Ok..yes.. it was that easy. I had my pull up resistors on a part I had disconnected and took for granted there was enough pull-up in the Grand Central.
I added a couple of resistors and all is 'normal'
Thanks for the insight.
Gary

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”