Wanted to move a ADC10-prog that read p1.5 from g2231 to g2553 but it seem to not read.
Using debugger it seem to hang waiting "adc to finish reading" "while (!(ADC10CTL0 & ADC10IFG));"
Asume that the use of ADC10CTL0 and ADC10IGF is different. Appresiate if someone could explain the dif and where to find the info. Have looked in slau144i. Are there other doc that explain the dif.
This is part of the prog to ((c) B. Nollmeyer 01/2011 #### ---- */
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz
// ---- initialise the GPIO's ----
P1SEL |= TXD;
P1DIR |= LED1 + LED2 + TXD; // LED1, LED2, TXD as Output
P1OUT &= ~ (LED1 + LED2); // LED's = OFF
// ---- Soft. UART Timer Setup ----
CCTL0 = OUT; // TXD Idle as Mark = '1'
TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode
// ---- initialise the ADC ----
ADC10CTL1 |= INCH_5; // ADC IN @ P1.5
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REF2_5V + REFON + ADC10ON; // SHT 16x ADC10CLKs, VREF 2.5V, ADC ON
ADC10AE0 |= AdcInput; // ADC Input Enable @ P1.5
__bis_SR_register (GIE); // interrupts enabled
for (;;) {
AdcValOut (getAdcValue ());
__delay_cycles (500000); // ~ 2x per Second
}
}
// ---- ADC Oversampling 12 BIT, Linearization, ADC Low Pass Filter, Offset + Gain Compensation ----
uint16_t getAdcValue (void)
{
uint16_t AvgCount = 0, measVal = 0;
uint32_t AvgSum = 0;
for (AvgCount = 0; AvgCount < 1024; AvgCount ++) {
ADC10CTL0 &= ~ADC10IFG;
ADC10CTL0 |= ENC + ADC10SC; // Start the ADC conversion
while (!(ADC10CTL0 & ADC10IFG)); // ADC busy ?
AvgSum += ADC10MEM; // Build an ADC average
}
measVal = ((((AvgSum >> 8) * Factor) + Offset) >> 16); // Scale the ADC -> 12 BIT