Jump to content
43oh

MSP430G2553 WITH ADXL345 I2C DON´T WORKING


Recommended Posts

Hi everyone 

I am beginner and I want to use the adxl345 with msp430g2553 with I2C, but the example that I am using don´t working, always send 0 in the axes x,y and z. I use energia 1.6.10e18, the circuit have the pull'up resistor in SDA and SCL pines, and I remove the jumper of the green led. I used the same code but with arduino and it working but with enegia not, help me please.

My launchpad is MSP-EXP430G2  rev 1.5

The SCL is connected in pin 14 and the SDA in pin 15.

My OS is windows 7

When i put this function "Wire.setModule(0)" the mcu does make nothing, the uart don´t send nothing.

 

The code is the follow:


#include <Wire.h>

void setup()

  Serial.begin(9600);
  Serial.print("Iniciado");

  Wire.begin();        
  
  writeTo(DATA_FORMAT, 0x01);                                                                   //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT register.
  writeTo(POWER_CTL, 0x08);                                                                       //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.

}

void loop()
{
  uint8_t howManyBytesToRead = 6;
  readFrom( DATAX0, howManyBytesToRead, _buff);                                 //read the acceleration data from the ADXL345


  int X = (((int)_buff[1]) << 😎 | _buff[0];   
  int Y = (((int)_buff[3]) << 😎 | _buff[2];
  int Z = (((int)_buff[5]) << 😎 | _buff[4];

  Serial.print("x: ");
  Serial.print( X );
  Serial.print(" y: ");
  Serial.print( Y );
  delay(500);            
}

void writeTo(byte address, byte val) {
  Wire.beginTransmission(DEVICE);                                        // start transmission to device 
  Wire.write(address);                                                                // send register address
  Wire.write(val);                                                                         // send value to write
  Wire.endTransmission();                                                       // end transmission
}

void readFrom(byte address, int num, byte _buff[]) {
  Wire.beginTransmission(DEVICE);                                      // start transmission to device 
  Wire.write(address);                                                              // sends address to read from
  Wire.endTransmission();                                                      // end transmission
  
  Wire.beginTransmission(DEVICE); // start transmission to device
  Wire.requestFrom(DEVICE, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())         // device may send less than requested (abnormal)
  {   digitalWrite(RED_LED,HIGH); 

    _buff = Wire.read();    // receive a byte
    i++;
  }
  Wire.endTransmission();         // end transmission
}
 

Edited by jcjc
add information
Link to post
Share on other sites

Hi everyone, my proyect its working! 

I followed steps of this link:

https://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/529036?I2C-communication-does-not-appear-to-be-working-correctly-with-Energia-and-CCS-How-do-I-fix-it-

but in addition to replacing the files in the directory mentioned in the link above, I have to remplace the files in the energia1610E181\hardware\energia\msp430\libraries\Wire\utility

The files are available in the link.

thanks!

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