SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By Leo Natan
#67980
Hey everyone! Need some urgent help... First I'll say I'm a software developer, and the embedded stuff is new to me, so please go gently on me. :)

I have an ADXL330 accelerometer connected to the board like so:

Image

To be more clear:
Code: Select all
P1 <-> GND
P2 <-> VDD
P3 <-> X (analog input A0)
P4 <-> Y (analog input A1)
P5 <-> Z (analog input A2)
I'm trying to read data from the analog inputs. This is my function:
Code: Select all
void getData(int* x, int* y, int* z)
{
  int degC;

  ADC10AE0 |= 0x01 ;  // analog input enable for A0
  ADC10CTL1 = INCH_0;                  // A0
  ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE + ADC10SR;
  for( degC = 240; degC > 0; degC-- );  // delay to allow reference to settle
  ADC10CTL0 |= ENC + ADC10SC;           // Sampling and conversion start
  __bis_SR_register(CPUOFF + GIE);      // LPM0 with interrupts enabled
  *x = ADC10MEM;
  ADC10CTL0 &= ~ENC;
  ADC10CTL0 &= ~(REFON + ADC10ON);      // turn off A/D to save power
 
  ADC10AE0 |= 0x04 ;  // analog input enable for A1
  ADC10CTL1 = INCH_1;                  // A1
  ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE + ADC10SR;
  for( degC = 240; degC > 0; degC-- );  // delay to allow reference to settle
  ADC10CTL0 |= ENC + ADC10SC;           // Sampling and conversion start
  __bis_SR_register(CPUOFF + GIE);      // LPM0 with interrupts enabled
  *y = ADC10MEM;
  ADC10CTL0 &= ~ENC;
  ADC10CTL0 &= ~(REFON + ADC10ON);      // turn off A/D to save power
 
  ADC10AE0 |= 0x08 ;  // analog input enable for A2
  ADC10CTL1 = INCH_2;                  // A2
  ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE + ADC10SR;
  for( degC = 240; degC > 0; degC-- );  // delay to allow reference to settle
  ADC10CTL0 |= ENC + ADC10SC;           // Sampling and conversion start
  __bis_SR_register(CPUOFF + GIE);      // LPM0 with interrupts enabled
  *z = ADC10MEM;
  ADC10CTL0 &= ~ENC;
  ADC10CTL0 &= ~(REFON + ADC10ON);      // turn off A/D to save power
}
It is based on the temperature sensor example from TI. For some reason, I do not get correct data... :( Anyone could shed some light on the problem?

Thanks in advance,
Leo Natan
By airpower
#68036
Hey, if you get this to work please let me know how you implemented it in code, i'm trying to do exactly what you are doing and I wanna know if you had any success..i'm surprised I stumbled upon someone else that's trying to attach an accelerometer to the pins.

The one i'm using is the ADXL320 +/- 5 g.

I was thinking about doing that same thing and modify the code..but I don't understand why are you are using all the Celsius temperature junk ....i mean isn't the accelerometer different than the temperature sensors on board the target board and application device??

I just wanna know how you code it..have you gotten any replies? TI instruments sucks big time.. I tried to call customer support and they practically ignored my request..

what's the point of buying their hardware if they example demo they give is so application specific..that's it nearly impossible to understand how to write your own programs? anywho....let me know if you ever figured this out..I really need to know how to get this to work for one of my projects..ASAP..if you want shoot me your e-mail.
User avatar
By leon_heller
#81529
Try the TI forums.

Leon
By elliotbriggs
#83120
you are probably getting stuck in low power mode.
make sure to service the interrupt that the ADC will produce when it is done with the conversion process. In the interrupt you must exit from low power mode so the CPU is alive again and can return from the ISR and continue to execute code in main. The easiest way to do this is to not go into low power mode in the first place and to just poll the ADC interrupt flag in your normal code execution. If you want to save battery, then the low power mode feature should be used.

This is where you kill your CPU and wait for the interrupt....

__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled

if you can't step past this statement in your code, your CPU is turned off and will not turn back on until you tell it to in an ISR.