ADC LPC1768 simple

0

this is my code

#include "LPC17xx.h"                    // Device header
#include "GPIO_LPC17xx.h"               // Keil::Device:GPIO
uint32_t voltag1 = 0 ;
uint32_t voltag2 = 0 ;
volatile uint32_t adstat;
int blink=1;
int main()
{
    //Config timer
    LPC_TIM1->MCR=2;                         
    LPC_TIM1->MR0=20000000;                 //Match Resgister
    LPC_TIM1->TCR=1; 
    LPC_TIM1->EMR = 0x00000030 ;

    //Config ADC
    LPC_PINCON->PINSEL1 |= (1 << 14) | (1 << 16);    // connect pin to ADC
    LPC_SC->PCONP |= ((1 << 12));                    //enable power of ADC  
    LPC_ADC->ADCR    =  0x06202001;                  //initialaze ADC
    LPC_ADC->ADINTEN =  0x00000100;                  // global interup      
    NVIC_EnableIRQ(ADC_IRQn);
    GPIO_SetDir(3,25,GPIO_DIR_OUTPUT);   
    while(1) {}
}

void ADC_IRQHandler(void) 
{
    adstat = LPC_ADC->ADSTAT;       /* Read ADC clears interrupt  */    
    blink++;
    GPIO_PinWrite(3,25,blink%2);
    voltag1 = (LPC_ADC->ADGDR >> 4) & 0xFFF; 
    //voltag2 = (LPC_ADC->ADDR1 >> 4) & 0xFFF; 
}

when i use LPC_ADC->ADGDR it work fine but when i use LPC_ADC->ADDR1 its not working , why?
i used MAT for ADC interup
and when i use LPC_ADC->ADGDR everything works fine
but when i use LPC_ADC->ADDR1 for reading its not working and not change with MAT edge

arm
keil
adc
asked on Stack Overflow Jun 16, 2015 by navid ansari • edited Jun 16, 2015 by Pathik Vejani

2 Answers

0

There are way too many magic numbers in your code. Please use the corresponding defines for all those bits. This code is unreadable as is.

There is a wrong comment in your code, the interrupt flag for ADGDR is not cleared on ADSTAT read. Only a read of ADGDR clears it, and thats why your code does not work with ADDR1.

Had you used the definition to set ADINTEN, you might have spotted your error sooner. That flag is named ADGDINTEN and corresponds to the flag in ADGDR only.

answered on Stack Overflow Jun 19, 2015 by Turbo J
0

You should enable IRQ of ch1 by:

LPC_ADC->ADINTEN =  1 << 1;  //0x0002  
answered on Stack Overflow Sep 3, 2015 by rundekugel

User contributions licensed under CC BY-SA 3.0