Jump to content
sol25

I2C 2 msp430g2553 simple example Help.

Recommended Posts

Hello everyone! im here again for the 3rd time to ask for some advice/help. This forum has been so helpful!

 

Recently i've implemented some code on a msp430g2553 to read a 7 segment LED display. My next step is to send that reading to another msp430 or maybe a c2000 micro-controller.

 

End goal: Msp430-1 decodes the LED display and sends 2 digit number to the Msp430-2 then i display the numbers on my monitor.
 

 

I was looking at the "wire" master write and slave read examples. I have implemented them but they seem not to work, i'm not sure of a couple of things. How do i address SCL and SDA ? how do i rout them to the specific pin? 

 

  Wire.begin(4);                // join i2c bus with address #4
 
is 4 the pin for SDA? where do i tell energia where my SCL pin is?
I am attaching the examples i'm using in order to get more familiar with this "wire" method.
 
Do I have to change the orientation of the TX and RX jumpers?(see picture)
 
PS. is there any other communication protocol that i could use for my application? maybe something easier? or something where i could see a clear example of??
 
 
Thanks in advance for all the help and comments.
// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

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

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop()
{
  Wire.beginTransmission(4); // transmit to device #4
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte  
  Wire.endTransmission();    // stop transmitting

  x++;
  delay(500);
}

//======================================================================================//======================================================================================
//this goes in the other msp430

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}
 
 

 

post-38121-0-43173000-1409708660_thumb.png

Share this post


Link to post
Share on other sites

SCL and SDA are pins P1_6 and P1_7 respectively.

That said, for a number from 0-99 I would just use normal old serial. Connect the sensor board's TX to the receiving board's RX, and use Serial.write(variable) to send the info, then Serial.read on the other end.

Do note that the RX lines will be connected to both the PC (via the debug side of the launchpad) and to the other launchpad, so I think you'll want to disconnect the RX jumper on the receiving launchpad to prevent "interesting" issues, possibly including MCU death if they have differing ideas on whether the line should be HIGH or LOW and are willing to put some grunt into it.

Which jumper is actually TX and which is RX I don't know, it's not as simple as it at first appears. Checking which pin of the four involved in those two jumpers connects directly to the RX pin on the MCU itself would be a good idea.

 

Serial.write sends the variable as data, if it contains the number 45 it sends a single byte containing "45".

Serial.print sends the variable as text, if the variable contains 45 it sends a byte containing "52" and then a second byte containing "53", "4" and "5" respectively in ASCII code.

 

That said, this is a solid use for i2c as well. For it, connect SDA to SDA and SCL to SCL. You will also need to connect a 2.2k-4.7k resistor from each line to VCC.

Learning how to use i2c is probably a good idea, as it is very useful for some things. For one it can be safely shared with one master (or multiple, if they're careful about timing) and multiple slaves, where normal serial really shouldn't be shared.

Share this post


Link to post
Share on other sites

@@bobnova

Hi thanks again for your help! I am using this.

//code for Sending
void setup() {

  Serial.begin(9600);
  
}

void loop() {

 Serial.write(52); 
 delay(500);
  
}
//code for Receiving

void setup() {
  
  Serial.begin(9600);
  
}

void loop() {
  
  if (Serial.available()) {
    int inByte = Serial.read();
    if(inByte==52){pinMode(5,OUTPUT);}else{digitalWrite(5, LOW);}
    Serial.print(inByte); 
  }
}

I cant see anything on the serial monitor so i added the code to light up an LED if i get "52" which is what the other launchap id sending. Nothing seems to work.

I have connected pin 3(TXD) of launchpad 1 to pin 4 (RXD)of launchpad 2 and all the way around.

 

have tried all configurations of jumperpins for rx and tx and still no luck.

 

I feel a bit discouraged.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...