This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553: MSP430G2553 + ADXL345 over SPI

Part Number: MSP430G2553


Hi

I was trying to post my question in this thread, however, it is locked!

I am connecting the MSP430G2553 to the ADXL345 accelerometer over SPI and using this code to set the ADXL345:

///////////////////////////////////////////////////////////////////
void SPI_write(void){

P3OUT &= ~CS;               // BIT 3.7 is CS

while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x2D; // We want to write to the power register

while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x00; // Write the 0x00 to the power register (put the ADXL345 in standby mode)
///--------------------------------------------------------
while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x31; // We want to write to the data format register while the ADXL345 is in stanby mode

while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x09; // Write the 0x01 to the data format register (4g range)
///--------------------------------------------------------
while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x2C; // We want to write to the BW_RATE register

while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x09; // Write 0x09 to the BW_RATE register to set the ACC to 25Hz data rate (table 7, p#14 of datasheet)
// setting the ACC to this acceleration sampling rate should makes it consume 90microAmp.
//see note 7 on page 5 of the data sheet about the wake up time
///---------------------------------------------------------
while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x2D; // We want to write to the power register

while (!(IFG2&UCA0TXIFG)); // Wait for TXBUF ready
UCA0TXBUF = 0x08; // Write the 0x08 to the power register to put it in measure mode
///---------------------------------------------------------
delay_ms(10);
while (!(UCB0STAT&UCBUSY)==0);
IFG2 &= ~UCA0RXIFG;

P3OUT |= CS;
}
////////////////////////////////////////////////////////////////////////

I am getting back the data. But it is different from when the ADXL345 is connected to the Arduino.

For example, when he accelerometer is still on the table, then I get 0.79 G rather than 1 G for the z-axis

anyone can help me with this

thank you

  • This could be related to a number of reasons outside of the MCU / sensor. Things to consider are: is the table is perfectly flat, even, or is the sensor's Z-axis orthogonal to the center of earth?

  • Hi,

    As Mike pointed out, this is likely due to the different orientations of the accelerometer when it is connected to each MCU. One other thing to check though is if the SPI phase and polarity on each MCU is the same. Please see the User's Guide and the sample code on the MSP430G2553 product page for details on this.

    Regards,
    Nathan
  • The orientation and the placement of the sensor are the same with both MCUs. i.e. I only disconnect the wires from one MCU and connect it to the other one without moving the sensor.

    One thing to add is: the raw data I am getting from the Arduino is different from the one of MSP430!

  • Hi,

    Again, if the raw data is different, then I would check the SPI phase and polarity. Also, do you have a logic analyzer or oscilloscope that you could use to probe the lines to see if the data is really different, or if the MCUs are just interpreting it differently?

    Regards,
    Nathan
  • Hi
    I am trying to find another pin to use instead of the 1.4 on MSP430G2553 as a clock for SPI on USCI A. However, I see that is the only one available for that purpose. Is there another way to use another pin? and how to achive that?

    Thank you
  • Hi,

    No, that is the only pin that will work for the USCI A module on this device. This device does not contain a port map controller or any other way to change the function of the pins.

    Regards,
    Nathan
  • Thank you for your reply

    One more thing. I would like to reduce the power consumption as much as possible.  As such, I am setting the pins like this:

    P1IE &= ~(RXD | TXD | SCL);
    P1SEL |= (RXD | TXD | SCL); // 1.1: SDO, 1.2: SDA, 1.4: SCL //we need this and the P1SEL2
    P1SEL2 |= (RXD | TXD | SCL);
    P1DIR |= (TXD | SCL); // Set as output
    P1REN &= ~(TXD | SCL); // Disable pullup/pulldown resistor
    P1OUT |= (TXD | SCL); //P1OUT &= ~TXD;
    
    P3REN &= ~(CS); // Disable pullup/pulldown resistor
    P3OUT &= ~CS;
    P3DIR = CS; // 3.7: CS
    P3OUT |= CS;
    

    And then set them back like this:

                    P1SEL &= (~RXD);
                    P1SEL &= (~TXD); 
           		P1SEL &= (~SCL); 
           		P3SEL &= (~CS); 
           		P1DIR |= RXD; 
           		P1OUT |= RXD; 
           		P1DIR |= TXD; 
           		P1OUT |= TXD; 
           		P1DIR |= SCL; 
           		P1OUT |= SCL; 
           		P3DIR |= CS; 
           		P3OUT |= CS; 

    Is that correct? 




  • Hi,

    Yes, that should reduce your power consumption.

    Regards,
    Nathan

**Attention** This is a public forum