Jump to content
unknowsman

i2C Slave not working on MSP430FR5969

Recommended Posts

i try to use this example but nothing happened


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

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

// Created 29 March 2006

// This example code is in the public domain.


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

and this one

// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>

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

// Created 29 March 2006

// This example code is in the public domain.


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

with this pin

image.png.983fe755fe9aa6c2f5ed0195ec9a7d97.png

 

 

thank you

Share this post


Link to post
Share on other sites

What i2c device are you connecting? What does is do? What's the device address? (per device specs) Is it really 2?

Are you using pullups? I2c requires some type of pullup, and in general, the internal resistors on the '430 devices are not an appropriate value, so external are usually used.

Note: by default, i2c comms are on LP pins 9 (SCL) and 10 (SDA)  not 15 &&16 - P1.6 and P1.7, Energia defaults to spi on those pins.

Share this post


Link to post
Share on other sites

There is a bug for slave mode which has already been fixed in the git repo. You can work-around it with the following.

If you have the latest Energia release installed (1.8.7E21), then edit the file:

Linux: <Energia directory>hardware/energia/msp430/libraries/Wire/utility/twi.c
Windows: <Energia directory>hardware\energia\msp430\libraries\Wire\utility\twi.c
macOS: <Energia.app directory>/Contents/Java/hardware/energia/msp430/libraries/Wire/utility/twi.c

Got to line 1183 and replace:

1183                 } else if (twi_state == TWI_MRX) {      // Master receive mode
1184                         // copy data to output register
1185                         UCBzTXBUF = twi_txBuffer[twi_txBufferIndex++];


by this:

1183                 } else if (twi_state == TWI_STX) {      // Slave transmit mode
1184                         // copy data to output register
1185                         UCBzTXBUF = twi_txBuffer[twi_txBufferIndex++];

 

Share this post


Link to post
Share on other sites

@energia

When I send data over i2c but slave(MSP430FR5969) cannot read all the data with this code
Its look like just only 12 characters can send .

Pls give some advice.

Master Code ( Arduino Mega2560):

#include <Wire.h>
uint8_t greeting[35] = "Hello World! and How are you today!";
void setup() {
  Serial.begin(250000);
  Wire.begin();
}
void loop() {
  if (Serial.available() > 0) {
    byte inByte = Serial.read();
    if (inByte == '1') {
      Wire.beginTransmission(0x23); 
      Wire.write(greeting, 35);   
      Wire.endTransmission();    
    }
  }
}

Slave Code(MSP430FR5969) :

#include <Wire.h>
void setup()
{
  Wire.setModule(0);
  Wire.begin(0x23);             // join i2c bus with address #0x23
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(115200);         // 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 bytes)
{
  if (Wire.available() != 0) {
    for (int i = 0; i < bytes; i++) {
      Serial.write(Wire.read());
    }
    Serial.println();
  }
}

 

thank you very much

Share this post


Link to post
Share on other sites

The MSP430 Wire buffer length is set to 16. If you need a larger buffer, you can edit the file:

  • Linux: <Energia directory>hardware/energia/msp430/libraries/Wire/Wire.h
  • Windows: <Energia directory>hardware\energia\msp430\libraries\Wire\Wire.h
  • macOS: <Energia.app directory>/Contents/Java/hardware/energia/msp430/libraries/Wire/Wire.h

and in:

  • Linux: <Energia directory>hardware/energia/msp430/libraries/Wire/utility/twi.h
  • Windows: <Energia directory>hardware\energia\msp430\libraries\Wire\utility\twi.h
  • macOS: <Energia.app directory>/Contents/Java/hardware/energia/msp430/libraries/Wire/utility/twi.h

And set BUFFER_LENGTH / TWI_BUFFER_LENGTH to a larger number.

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

×