Danial

I2c communication between two MSP432 Boards

11 posts in this topic

Hello,

I am having a problem using the the Wire examples in energia, master_writer and slave_receiver.

I have not modified the code in the examples and just want it to transfer the information across, so that I can work on from there. 

 

The two boards are connected together with sda to sda and scl to scl, it shares a common ground and both boards have a 5V supply to the 5V pins

 

However, every time i connect the boards and check the serial monitor on the slave board, all i see is weird unique characters. 

When i press reset button on the slave board, it will repeat and print the same weird character.

post-50096-0-59376700-1488631506_thumb.png

 

I'm fairly new to i2c communication and would appreciate any help provided here,

 

Thank you,

 

Danial.

 

 

Share this post


Link to post
Share on other sites

1) The "weird" display could be a serial comm mismatch between your PC serial port and the serial output from the boards. So, first check that your serial display is set to the same baud rate as the sketch.

 

2) I2C requires pullup resistors. While some sketches will use the internal resistors available on some msp devices, those internal resistors are often too "weak" - around 30K to work effectively, if at all. Typically, 1K - 10K work well.  Further, I would use the 3.3V supply for your pullups. The msp ports are not 5V tolerant,  as they are natively 3.3V devices.  The 5V pin is coming off of the USB connection.

 

3) Posting the actual code you are running is always important and useful to help others sort out issues. :)

 

Regarding I2C pullups - I wish that TI would offer a LP board with pads where I could add an "optional" pair of resistors. Tying-in external resistors is a pain... :(

Share this post


Link to post
Share on other sites

Hi, thanks for the response.

The baud rate is set up for 9600 and and is also set 9600 on the serial monitor.
 
The code i am using, is of the examples given by Energia.

 

Master_Writer

// 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);
} 

Slave_receiver

// 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
}

As for the pull up resistors, i tried using 10 k Ohm and switched the supply to 3.3V instead of 5V however the same screen characters are occurring.

I'll take further look also for the time being into the pull up resistors, but at this stage i'm fairly stumped with it. 

Thanks,

Danial.

Share this post


Link to post
Share on other sites

Hi,

I've looked into pull up resistors more and believe the setup to be correct, however it had no effect on the situation and the problem still occurs.

So i'm wondering also:

Do any jumpers have to be removed from the MSP 432 boards for I2C to work.

Thanks.

Danial.

Share this post


Link to post
Share on other sites

Depending on the length of wire between the master and slave you may need to decrease the pull-ups to about 4.7K or so. Also, your master is sending 4 characters and 1 byte continuously and your slave is looking for those in order. However, you have no synchronization to ensure that the slave is seeing the beginning of a transmission rather than something in the middle. For troubleshooting purposes you may want to simplify the data transmission to just bytes to eliminate that possibility.

 

If you can borrow a logic analyzer (e.g. Saleae) that can go a long way in figuring out what is actually happening on the I2C bus.

 

EDIT: You may also want to try sending some test messages in your code (unrelated to your I2C print routine) via serial.print to ensure that the problem isn't between the slave and the PC.

Share this post


Link to post
Share on other sites

I changed the code to to transfer only the one byte and brought the resistors down to 5k, however i'm still not getting a response.

 

I put serial prints of statements into the loop, receiveEvent function and setup of the slave_receiver. The serial print in loop comes up in the monitor, but the serial print in the recieveEvent does not come up. So i don't think its entering that function at all.

 

I setup and put a serial print into the loop of the master_writer and that wasn't being displayed continuously on the monitor either.

 

Also i ran an I2C scanner to check for addresses of any other device connected to the master board to which it displayed zero.

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {} 

Share this post


Link to post
Share on other sites

I found I could get the test code to run with a pair of msp430f5529s after importing the energia project to CCS 6.1.3, recompiling and uploading.  However, that approach was not successful with the '432 devices. :(

I see the communication attempts with the '432 in the logic analyzer all followed by NAK, rather than an ACK.

The successful comms are with the '430s.  I note that I could not get the code to work when compiled and loaded with Energia 18.  I haven't tried 17...

 

I'm using a pair of 2k2 resistors for the pullups. The setup in both cases is the same, except for the LP boards. SCL is to P6.5 on the '432 and P4.2 on the '430, and SDA is on P6.4 on the 432 and P4.1 on the '430, which is the BP standard.

post-35117-0-02634100-1488733826.jpg

post-35117-0-46202200-1488733841_thumb.jpg

post-35117-0-12966600-1488733855_thumb.jpg

post-35117-0-26911000-1488733865_thumb.jpg

Danial likes this

Share this post


Link to post
Share on other sites

Thank you for the information there Bob, its very helpful.

Would you have any ideas in how to overcome the NAK problem or should I just opt to use a different type of board in this case.

Share this post


Link to post
Share on other sites

On further investigation, I've managed to migrate a pair of msp432 driverlib examples from their P1/EUSCI_B0 to a P6/EUSCI_B1 implementation.

The code examples selected were:

msp432p401x_eusci0_i2c_10 (master) and msp432p401x_eusci0_i2c_11 (slave)

Basically, a find/replace of all "EUSCI_B0" instances with "EUSCI_B1", as well as editing the interrupt enable from "EUSCIB0_IRQn" to "EUSCIB1_IRQn", and the interrupt handler from "EUSCIB0_IRQHandler" to "EUSCIB1_IRQHandler".  Finally, the port assignments need to be updated from:

    // Configure GPIO
    P1->OUT &= ~BIT0;                       // Clear P1.0 output latch
    P1->DIR |= BIT0;                        // For LED
    P1->SEL0 |= BIT6 | BIT7;                // I2C pins

To:
    // Configure GPIO
    P1->OUT &= ~BIT0;                       // Clear P1.0 output latch
    P1->DIR |= BIT0;                        // For LED
    P6->SEL0 |= BIT4 | BIT5;                // I2C pins
 

As before, 2k2 pullups.

 

post-35117-0-03747900-1488751206_thumb.jpg

post-35117-0-88683900-1488751226_thumb.jpg

Share this post


Link to post
Share on other sites

Thank you for the information there Bob, its very helpful.

Would you have any ideas in how to overcome the NAK problem or should I just opt to use a different type of board in this case.

Danial,

 

I suspect the issues are more with Energia and the Wire library, rather than the board/mcu. Unfortunately, I don't have the time or skills to really delve deeply into the Wire/Energia code to better understand what is, or is not, happening.  The fact that the driverlib code works under CCS indicates it's not the hardware.

 

Bob

Share this post


Link to post
Share on other sites

One last note - The driverlib example runs at 100kHz and it appears that the Wire.cpp code sets the clock to 400kHz. I believe that the pullup resistors may need to be of lower values with the faster clock, but that's probably not all that's happening.

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