/**************************************************************************//** * @brief Main function * This exmaple sets up the TIMER to trigger the ADC through PRS at a set * interval. The ADC then sets a DMA request and the DMA fetches each sample * until the a set number of samples have been received. *****************************************************************************/ int main(void) { /* Initialize chip */ CHIP_Init(); /* Configuring clocks in the Clock Management Unit (CMU) */ setupCmu(); /* Configure DMA transfer from ADC to RAM */ setupDma(); /* Configure ADC Sampling and TIMER trigger through PRS. Start TIMER as well */ setupAdc(); /* Enter EM1 while DMA transfer is active to save power. Note that * interrupts are disabled to prevent the ISR from being triggered * after checking the transferActive flag, but before entering * sleep. If this were to happen, there would be no interrupt to wake * the core again and the MCU would be stuck in EM1. While the * core is in sleep, pending interrupts will still wake up the * core and the ISR will be triggered after interrupts are enabled * again. */ while(1) { INT_Disable(); if ( transferActive ) { EMU_EnterEM1(); } INT_Enable(); /* Exit the loop if transfer has completed */ if ( !transferActive ) { break; } } /* Cleaning up after DMA transfers */ DMA_Reset(); /* Done */ while (1); }
static void setup(void) { // Port setup PORTD = KEY; //key pullup & led off DDRD = LED; // led output PORTB &= ~OUT1; DDRB = OUT2 | SS; TIMSK1 |= (1 << TOIE1); // Enable overflow interrupt TCCR1B |= (1 << CS11); // Start timer at Fcpu/8 setupLine(); #ifdef ADC_ENABLED setupAdc(); #endif //ADCENABLED #ifdef GPS_ENABLED setupGps(); #endif //GPS_ENABLED sei(); }