Jump to content

Recommended Posts

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
}

WhatsApp Image 2019-05-09 at 10.18.51 AM.jpeg

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

@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!

Share this post


Link to post
Share on other sites

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.

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

×