Anshikajain 0 Posted May 9, 2019 Share Posted May 9, 2019 I2c not working with energia. Below is the code attached. Please help Master Reader #include <Wire.h> void setup() { Wire.setModule(0); Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output } 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.print(c); // print the character } delay(500); } Slave Sender . #include <Wire.h> void setup() { Wire.setModule(0); Wire.begin(2); // join i2c bus with address #2 Wire.onRequest(requestEvent); // register event } void loop() { delay(100); } // function that executes whenever data is requested by master // this function is registered as an event, see setup() void requestEvent() { Wire.write("hello "); // respond with message of 6 bytes // as expected by master } Quote Link to post Share on other sites
NurseBob 111 Posted May 10, 2019 Share Posted May 10, 2019 Take a look at this youtube, it may help... Quote Link to post Share on other sites
Dani123 0 Posted May 10, 2019 Share Posted May 10, 2019 Checking it now... Quote Link to post Share on other sites
Anshikajain 0 Posted May 10, 2019 Author Share Posted May 10, 2019 @NurseBob the coding here is in C. If you could help me out with energia, it would be great. Thanks! Quote Link to post Share on other sites
Anshikajain 0 Posted May 10, 2019 Author Share Posted May 10, 2019 @Dani123 thankyou! PFA the zipped folder which contains three different codes that I've tried. Each folder contains two codes, one for each, the master and the slave. The folders named, '2' and '3' contain codes for lighting up a LED. Although, I haven't made a LED connection in the image of the circuit. The I2C bus connections however remain the same I'd be obliged if you could help me out with this. i2c.rar Quote Link to post Share on other sites
NurseBob 111 Posted May 12, 2019 Share Posted May 12, 2019 @Anshikajain Sorry, I've been offline for a couple of days. Not really sure what your question was, but FWIW, I rarely use Energia. That said, when I2C fails in Energia, it's almost always a configuration problem. My suggestion with the video was focused on how they configured the '430 jumpers. The G25 devices were significantly different from the later versions, and many have tripped over jumpers incorrectly configured. In your photo it appears you have the jumper P1.6 placed for the LED, and that was the very first comment in the video - the device will not work in I2C mode if that jumper is placed (at least on the older boards). Looking at the docs, pins P2.1 and P2.2 are designated as SCL and SDA (sw), which I presume means software, not hardware I2C? It's difficult to see in your photo, but it looks like you're using P1.6 and P1.7. So, the video's comments, and this from Energia docs: " When using I2C When using the Hardware I2C (Wire library) with SCL on P1.6 and SDA on P1.7 on the MSP-EXP430G2 you should remove the P1.6 jumper (GREEN LED) so that the LED doesn’t interfere with the I2C SCL signal... " Energia reference I don't know if I'm able to help much further. Please check your jumpers! Anshikajain 1 Quote Link to post Share on other sites
Rei Vilo 695 Posted May 12, 2019 Share Posted May 12, 2019 Please refer to the pins maps as the MSP430 LaunchPad exposés two I²C ports: one software master only, another hardware master and slave. Quote Link to post Share on other sites
Anshikajain 0 Posted May 12, 2019 Author Share Posted May 12, 2019 @Rei Vilo I don't understand. Could you please explain this a little further? Quote Link to post Share on other sites
energia 484 Posted May 13, 2019 Share Posted May 13, 2019 P2.1 and P2.2 are S/W I2C slave (module -1) and does not support I2C Slave. In your Sketch you call Wire.setModule(0) to select hardware I2C. However, looking at the picture you wired the 2 LaunchPad's together on P2.1/P2.2. This is not correct, the hardware I2C module is on P1.7(SDA) and P1.6(SCL). Rewire it to use those pins and that should solve the issue. Quote Link to post Share on other sites
Anshikajain 0 Posted May 13, 2019 Author Share Posted May 13, 2019 It works now. Thank you! @NurseBob @Rei Vilo @energia 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.