Is the procedure to setup interrupts on the Maple still valid? I tried to follow the steps... I was trying to get the interrupt from the ADC to work... basically every conversion, the ADC sends an interrupt out to signal a complete conversion.
I first initialized the ADC (initADC()). I then added an interrupt on the nvic, and the peripheral (in my case the ADC) (initInterrupts()), and then tried to overload the interrupt handlerADC_IRQHandler(). I didn't get it to work.... any input would be invaluable.
The full code:
// START CONSTANTS
const uint8 numMics = 6;
volatile int tic = 0;
// sampleRate = number of ADC cycles per read = ADC_SMPR_x + 12.5 =
// samples per cycle at 14 MHz. For ADC_SMPR_1_5, total conversion time = 1 microsec.
const adc_smp_rate sampleRate = ADC_SMPR_28_5;
const int sampleRateInt = 28.5;
// we're using raw adc channels via adcChans instead of micPins
const int micPins[6] = {D15, D16, D17, D18, D19, D20};
// below refers to channels according to ADC docs, and not to pins on maple
// 10-15 correspond to pins D15-D20 on maple
// the order of adcChans decides the order in which the channels are read
// (ie first one = chan0, etc)
const uint8 adcChans[6] = {10, 11, 12, 13, 14, 15};
HardwareTimer timer(1);
// END CONSTANTS
// Analog input pin. You may need to change this number if your board
// can't do analog input on pin 15.
const int analogStartPin = 15;
void setup() {
// Set up board LED to blink, useful for debugging
pinMode(BOARD_LED_PIN, OUTPUT);
// Declare analogInputPin as INPUT_ANALOG:
for(int i = 0; i < numMics; i++)
{
pinMode(micPins[i], INPUT_ANALOG);
}
initADC();
initInterrupts();
}
void initADC() {
// ADC register map
adc_reg_map *regs = ADC1->regs;
// below not needed, maplelib does it for us!
//adc_init(ADC1);
// if adc is on, turn it off so we can change settings
if(regs->CR2 | ADC_CR2_ADON) {
regs->CR2 ^= ADC_CR2_ADON;
}
adc_set_sample_rate(ADC1, sampleRate);
// set number of channels to read
adc_set_reg_seqlen(ADC1, numMics);
// set channel read sequence order (from adcChans)
uint32 channels = 0;
for (int i = 0; i < numMics; i++) {
channels |= (adcChans[i] << (i*4));
}
regs->SQR3 = channels;
// scan mode on
regs->CR1 |= ADC_CR1_SCAN;
// continuous mode on
regs->CR2 |= ADC_CR2_CONT;
// enable end_of_conversion interrupts
regs->CR1 |= ADC_CR1_EOCIE;
// calibrate ADC
adc_calibrate(ADC1);
// turn on ADC
regs->CR2 |= ADC_CR2_ADON;
// start adc read
regs->CR2 |= ADC_CR2_SWSTART;
}
void initInterrupts() {
// enable adc interrupt on the interrupt controller
nvic_globalirq_enable();
nvic_irq_enable(NVIC_ADC_1_2);
//enable adc interrupt on the adc
}
void ADC_IRQHandler(void) {
SerialUSB.print('x');
tic++;
if(tic == 60)
{
tic = 0;
toggleLED();
}
}
void loop() {
// use interrupts!
}