Jump to content
curtis63

Energia hangs on Wire.endTransmission()

Recommended Posts

Good morning,

 

I'm using the latest Energia 18 build with Windows 10.

I'm plugged into an MSP430 Launchpad with an MSP430G2553 chip on the board.

 

The following code hangs on the Wire.endTransmission() statement..  

 

Can somebody throw me a bone here and tell me how to fix this?

 

 



int findAddress(int fromAddress, int toAddress)
{
  int address = 0;

  for (int a = fromAddress; a < toAddress; a++)
  {
    Serial.print(a);
    Serial.print(" - beginTransmission..  ");
    Wire.beginTransmission(a);
     //   delay(3);
     //   Wire.write(1);
    Serial.print("  endTransmission..  ");
    int endStatus = Wire.endTransmission();
    Serial.print("  Result:  ");


    if (endStatus == 0)
    {
      address = a;
      Serial.print("Found device at: ");
      Serial.println(address);
    }
    else
    {
      Serial.print("x");
    }
  }

  return address;
}

Share this post


Link to post
Share on other sites

@@curtis63, I was able to reproduce it but can not explain it yet. I was able to get this working however in the way you want it to work.

 

  1. Since Energia 17, we moved I2C to the BoosterPack standard I2C pins 9 and 10. Unfortunately the MSP2553 does not have I2C on those pins. To work around it, we went for a software implementation. This software implementation still has some issues. What I might do is to remove the software implementation in the future releases is to remove the software implementation and revert back to pins 14 and 15 for I2C. This will only apply to the MSP430G series however. All other LaunchPads will stay the same and have I2C on pins 9 and 10.
  2. I would advice to use pins 15 and 15 for I2C by calling Wire.setModule(0) _before_ calling Wire.begin();
  3. Make sure that you have pull-ups on the I2C line
  4. Given that you would like to scan the bus for devices present, you should remove the Wire.write(1); As you, I was expecting that if there is no device present at the current address, it would cause a NAK and move on to the next address. This is not the case as you have seen.

Conclusion, for what you are looking for, remove the Wire.write(1) and you should find all the devices present on the bus. I was able to successfully scan the bus and find a device present at address 4.

 

Robert

Share this post


Link to post
Share on other sites

I have 4.7k pullup resisters on the SCL and SDA pins of sensor.

I have tried running the code with and without 'Wire.write(1);'

I call 'Wire.setModule(0);' in my setup function.

 

Still, no luck..

 

Is there a patch to the Energia 18 build that I need to apply?

Share this post


Link to post
Share on other sites

I ran this with a stock Energia 18 downloaded from Energia.nu. Just to make sure did you call Wire.setModule(0) before Wire.begin()? And you do have I2C the sensor connected to pins 14 (SCL) and 15 (SDA)? Also, you might want to remove the green LED jumper.

 

Just so that we are working with the same code, can you post the offending Sketch please?

Share this post


Link to post
Share on other sites

I have no idea why, but now, everything works fine..

 

So for a summary:

 

1.  Use 4.7kohm pullup resisters on both SDA and SCL I2C pins.

2.  Use Wire.setModule(0) before Wire.begin();

3.  Make sure you don't have SDA and SCL pins reversed.

4.  Bang your head on the desk, wall, keyboard, and floor...

 

Again, I thought I had all of these set correctly, I undid and redid everything, Then it all worked.

I have no idea which step I did incorrectly.

 

Thanks for the help, and sorry for the frustration.

 

--=-

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×