Hi,
I'm trying to generate an interrupt with the ADC but I just dont know how. My ADC is working well but right now im polling it.
I set the NVIC->ISER[0] =0x00000FFFF in order to make sure that interruptions are enabled. The AIEN bit is set in the ADC0->SC1[0] register.
How do I tell the compiler where to go (function to run)in case of interrupt occurs?
Any one has a example?
Jose
The Chip Manufacturer (Freescale?) - surely?
Thank you guys. I found the info at the freescale web site. I will post my code in case someone else hase same issue.
This Code works in case anyone needs it.
#include <MKL25Z4.H> #include "Delay.h" #include "Ports.h"
const uint32_t blue_mask = 1UL << 1; const uint32_t red_mask = 1UL <<18; const uint32_t green_mask = 1UL <<19;
const uint32_t mini_green = 1UL <<4; const uint32_t blue_green = 1UL <<5;
unsigned int temp3=0;
//---------------------------------------------------------------------------- //MAIN function //---------------------------------------------------------------------------- int main (void) {
unsigned int temp2=0;
SystemCoreClockUpdate(); /* Get Core Clock Frequency */ SysTick_Config(SystemCoreClock/1000); /* Generate interrupt each 1 ms */
/* SIM->SCGC5 |= (1UL << 12); Enable Clock to Port D */ // PORTA = 9, PORTB=10, PORTC=11, PORTD=12, PORTD=13 SIM->SCGC5 |= (1UL << 9) | (1UL << 10) | (1UL << 12); /* Enable Clock to Port A & B & D */
//*************************************************************** //ADC Configuration //**SCGC6 - System Clock Gating Control Register 6 (SIM_SCGC6) SIM->SCGC6 = (1UL << 27); // ADC0 Clock Gate Control - 1 Clock enabled
ADC0->SC1[0]=0x40; // 6- AIEN=1, 5-DIFF=0, 4-0-ADCH=00000 ADC0->SC1[1]=0x40; // 6- AIEN=1, 5-DIFF=0, 4-0-ADCH=00000
ADC0->SC2 = 0x00; // ADTRG:0, ACFE:0, ACFGT:0, ACREN:0, DMAEN:0, REFSEL:00 ADC0->SC3 = 0x00; //CAL:0, NA:0, NA:0, ADCO:0, AVGE:0, AVGS:0
ADC0->CFG1 = 0x0C; //ADLPC:0, ADIV:00, ADLSMP:0, MODE:11, ADICLK:00 ADC0->CFG2 = 0x00; //MUXSEL:0, ADACKEN:0, ADHSC:0, ADLSTS:00
//********************************************************************
//There is a PCR register for each pin of every port PORTB->PCR[0] = (1UL << 8); // Pin PTD1 is GPIO - This is the blue LED // PORTD->PCR[1] = (1UL << 8); // Pin PTD1 is GPIO - This is the blue LED PORTD->PCR[4] = (1UL << 8); // Pin PTD4 is GPIO - Pin 6 J1 connector PORTB->PCR[18] = (1UL << 8); // Pin PTB18 is GPIO - this is the red LED PORTB->PCR[19] = (1UL << 8); // Pin PTB18 is GPIO - This is the greel LED //****Prueba1 - Configurar el PTB0 como GPIO
PORTA->PCR [1] = (1UL << 8); // Pin PTA1 is GPIO - Pin 8 J1 connector PORTA->PCR [2] = (1UL << 8); // Pin PTA1 is GPIO - Pin 8 J1 connector PORTA->PCR [12] = (1UL << 8); // Pin PTA12 is GPIO - Pin 8 J1 connector
//Configure pins as outputs (1) //PORTA
//PORTB //FPTB->PDDR = 0X000C0000; /* 0X000C0000 enables PTB18 and PTB19 as Output */ FPTB->PDDR = (pin_18 | pin_19); //enables PTB18 and PTB19 as Output
//PORTC //No cofiguration will be done by now
//PORTD //FPTD->PDDR = 0X00000002; /* enable PTD1 as Output */ FPTD->PDDR = (pin_1 | pin_4); // enable PTD1 and PTD4 as Output
//Configure pins as inputs (0) //PORTA FPTA->PDDR = 0X00000000;//(pin_12 | pin_2 | pin_1); // Configure PTD2 and PTD12 as inputs
//PORTB //No cofiguration will be done by now
//PORTD //No cofiguration will be done by now
//******************************************************************* //Interrupt configuration //******************************************************************* //NVIC->ISER[0] = 0X00008000; //Configuracion del ADC0 // NVIC->ICPR[0] |= (1<<15); //Borra las interrupciones pendientes del ADC0 // NVIC->ISER[0] |= (1<<15); //habilita la interrupcion del ADC0 // NVIC->IP //ADC0_IRQn = 15, /**< ADC0 interrupt */ NVIC_ClearPendingIRQ(ADC0_IRQn); NVIC_EnableIRQ(ADC0_IRQn); //NVIC_SetPriority(ADC0_IRQn,1);
//******************************************************************8
//Turn off pins FPTA->PDOR = 0XFFFFFFFF; // Turn off PortA FPTB->PDOR = 0XFFFFFFFF; // Turn off PortB FPTD->PDOR = 0X00000002; // Turn off PortD 1 FPTD->PDOR = 0XFFFFFFFF; // Turn off PortD
while(1) {
// This part should lite as yellow FPTB->PCOR = 0X000C0000; // turns on green and red FPTD->PDOR = 0X00000002; // turns off blue Delay(1000);
ADC0->SC1[0]=0x48; // 6- AIEN=1, 5-DIFF=0, 4-0-ADCH=01000
// This part should lite as blue FPTD->PCOR = 0X00000002; // turns on blue FPTB->PDOR = 0X000C0000; // turns off red and green Delay(1000);
FPTD->PCOR = 0X00000002; // turns on blue FPTB->PDOR = 0X000C0000; // turns off red and green Delay(1000);
} } //************************************************ //ADC0 IRQ ISR //************************************************ void ADC0_IRQHandler(){
NVIC_ClearPendingIRQ(ADC0_IRQn); FPTB->PCOR = 0X00040000; // turns on red temp3 = ADC0->R[0];
}
When posting source code, please review the posting notes, and use PRE tags, otherwise all we see is a wall of code.