Author Topic: whats wrong with this little code?  (Read 2688 times)

0 Members and 1 Guest are viewing this topic.

Offline navidrctTopic starter

  • Regular Contributor
  • *
  • Posts: 117
  • Country: 00
whats wrong with this little code?
« on: June 14, 2015, 05:22:23 am »
hi
im new in ARM and Keil.
i want to work with adc of lpc1768 and i wrote this code . y does not working?
Code: [Select]
#include "LPC17xx.h"                    // Device header
#include "GPIO_LPC17xx.h"               // Keil::Device:GPIO

uint32_t voltaj = 0 ;

int main()
{
LPC_SC->PCONP |= ((1 << 12) | (1 << 15));  /* enable power to ADC & IOCON   */
LPC_ADC->ADCR    =  ( 1 <<  0) |            /* select AD0.0 pin              */
                      ( 1 <<  13) |          /*  freq=1M/33                   */
                      ( 1 << 21)|             /* enable ADC  */             
                      ( 1 << 24);              /*start conversion*/                 
LPC_ADC->ADINTEN =  ( 1 <<  8) | (1 << 0); /* global ADC enable interrupt   */
NVIC_EnableIRQ(ADC_IRQn);                  /* enable ADC Interrupt          */

while(1)
{
voltaj = LPC_ADC->ADDR0;
}
}
void ADC_IRQHandler(void)
{

}
 

Offline ttt

  • Regular Contributor
  • *
  • Posts: 90
  • Country: us
Re: whats wrong with this little code?
« Reply #1 on: June 14, 2015, 10:53:10 am »
See page 583 (Chapter 29) in the user manual which has the whole procedure outlined. Looks like you are not setting PINSEL to ADC mode. All pins are set to GPIO mode on init.
 

Offline navidrctTopic starter

  • Regular Contributor
  • *
  • Posts: 117
  • Country: 00
Re: whats wrong with this little code?
« Reply #2 on: June 14, 2015, 11:22:55 am »
See page 583 (Chapter 29) in the user manual which has the whole procedure outlined. Looks like you are not setting PINSEL to ADC mode. All pins are set to GPIO mode on init.
thanks alot that was helpful
 

Offline navidrctTopic starter

  • Regular Contributor
  • *
  • Posts: 117
  • Country: 00
Re: whats wrong with this little code?
« Reply #3 on: June 15, 2015, 05:53:25 am »
i did correct PCLKSEL now why it does not work?
when i put it in burst mode it work . why?

Code: [Select]
#include "LPC17xx.h"                    // Device header
#include "GPIO_LPC17xx.h"               // Keil::Device:GPIO

uint32_t voltaj = 0 ;
uint32_t voltaj2 = 0 ;

int main()
{
LPC_SC->PCONP |= ((1 << 12) | (1 << 15));  /* enable power to ADC & IOCON   */
LPC_ADC->ADCR    =  ( 1 <<  0) |            /* select AD0.0 pin              */
                      ( 1 <<  13) |          /*  freq=1M/33                   */
                      ( 1 << 21)|             /* enable ADC  */             
                      ( 1 << 24);              /*start conversion*/ 
LPC_SC->PCLKSEL0 =  ( 1 << 24 ) | (1 << 25);
LPC_ADC->ADINTEN =  ( 1 <<  8) | (1 << 0); /* global ADC enable interrupt   */
NVIC_EnableIRQ(ADC_IRQn);                  /* enable ADC Interrupt          */

while(1)
{

voltaj = LPC_ADC->ADDR0;
}
}
void ADC_IRQHandler(void)
{
voltaj2 = LPC_ADC->ADDR0;
}
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->