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:
To be more clear:
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:
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](ImageShack - Best place for all of your image hosting and image sharing needs)