Jump to content
43oh

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

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.

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++];

 

Link to post
Share on other sites
  • 3 weeks later...

@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

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.

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...