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.

MSP-EXP430F5438 Accelerometer

Other Parts Discussed in Thread: MSP430F5438

Hello,

I'm still new to TI products, so I beg your indulgence for my problems here.

I have an MSP-EXP430F5438 experimenter board, and I've been "playing" with it for a few days now, with the different features like the balance ball, USB-UART features. I've been trying to write a programme enabling the acquisition of the x y and z axis readings from the accelerometer (every 1s for example), and display the 3 values on the lcd screen.

I'm using primarily the halAccelerometerRead function, but it doesn't seem to read anything. Here's more or less my code:

 

void main (void) {

int accx, accy, accz;

char x_string[10];

char y_string[10];


halAccelerometerInit();

halLcdInit();

halLcdClearScreen();

while(1) {

halAdcStartRead();

halAccelerometerRead(&accX, &accY, &accZ);

sprintf(x_string, "%d", accX);

sprintf(y_string, "%d", accY);

halLcdPrintLine(x_string, 0, 0);

halLcdPrintLine(y_string, 4, 0);

}

}

 

the thing is that it displays only two 0 on the screen on lines 0 and 4, and nothing changes, even when I shake or tilt the board. The while loop works, as verified by a counter that I implemented later, sprintf and printline works as well. Somehow the ADC refuses to read or transmit the data.

Any idea here where you can help me ? Thanks a zillion...

  • Stan,

     halAdcStartRead() only initiates the ADC module to start sampling. You need to make sure the conversions are complete before performing and valid read. Otherwise any read from the halAccelerometerRead(&accX, &accY, &accZ) function will just give you blank data.

    Try the following piece of code instead. It starts the conversion process, goes to sleep and waits for the module to finish [triggered by an interrupt flag] and returns to active mode, when the values are ready.

      halAdcSetQuitFromISR( 1 );

      halAdcStartRead();

        __bis_SR_register(LPM3_bits + GIE);   

      __no_operation(); 

     the halAccelerometerRead(&accX, &accY, &accZ);

     

    Cheers!

    Dung

  • well, i actually saw that 3 lines in the example for "balance ball", and i thought that at first i don't necessarily need it to go to "sleep".

    so now with those lines, i can actually display the values on the lcd screen ? i mean, i don't need to have the pragmas vector __interrupt etc kind of stuff below ? i can write to the lcd screen with the lines below ?

    sprintf(x_string, "%d", accX);

     

    sprintf(y_string, "%d", accY);

    halLcdPrintLine(x_string, 0, 0);

    halLcdPrintLine(y_string, 4, 0);

    oh, one more question, do I need to add the lines:

    RTCPS0CTL &= ~RT0PSIE;  

    RTCExit64Hz = 0; 

    i saw them in the same files as balance ball, and i can't seem to understand what they mean (can't seem to find them in the datasheet of msp430f5438). i can't suppose that they're some sort of register ?

    (i know, i'm a beginner and new to this board, new to microcontroller programming, so i beg your indugence in this matter)

  • Stan,

    yep, you still need to include the __interrupt ISR for the ADC module. It's responsible for servicing the interrupt triggered when the ADC conversion is done. The ISR also stored the conversion results to the application's variables. It also executes the instruction that returns the device to active mode. 

    If you just want to a quick & dirty test with no optimization whatsoever, you can revert back to your original code, but this time with a while statement checking for the ADC conversion flag to be set before moving on to reading the values directly from registers. For this I highly recommend checking out some code examples to fully understand what the necessary steps are.

    The RTC lines of code are very specific to the User Experience application to manage & schedule the wake up events in order to periodically check for inputs/accelerometer/etc. They're global variables to configure the time & event management.

    Regards,

    Dung

  • gees, thanks dung. i've got it up and running.

    right now i'm doing the usb/serial communication, sending the accelerometer data to the pc via hyperterminal.

    thanks a zillion there !

**Attention** This is a public forum