curtis63 5 Posted November 7, 2016 Share Posted November 7, 2016 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; } Quote Link to post Share on other sites
Rickta59 589 Posted November 7, 2016 Share Posted November 7, 2016 did you try it without the Wire.write(1) ? Maybe some i2c device sees that and is waiting for more? curtis63 1 Quote Link to post Share on other sites
energia 485 Posted November 7, 2016 Share Posted November 7, 2016 @@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. 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. I would advice to use pins 15 and 15 for I2C by calling Wire.setModule(0) _before_ calling Wire.begin(); Make sure that you have pull-ups on the I2C line 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 Quote Link to post Share on other sites
curtis63 5 Posted November 7, 2016 Author Share Posted November 7, 2016 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? Quote Link to post Share on other sites
energia 485 Posted November 7, 2016 Share Posted November 7, 2016 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? Quote Link to post Share on other sites
curtis63 5 Posted November 8, 2016 Author Share Posted November 8, 2016 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. --=- Quote Link to post Share on other sites
energia 485 Posted November 8, 2016 Share Posted November 8, 2016 Thanks for reporting back! Happy to help and happy to hear you got it working. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.