EEVblog® Electronics Community Forum

Electronics => Microcontrollers => Topic started by: sangar on June 13, 2017, 12:43:18 pm

Title: External Interrupt Callback function
Post by: sangar on June 13, 2017, 12:43:18 pm
Hello,

I am working on Project which have ADC to measure temperature. As my project is time critical,I am using ADC interrupt to read samples from ADC. For example, if I set ADC to 50 samples/sec, ADC will interrupt MCU for every 20ms(1/50) via a pin to read sample from DATA register. I want to read it in ISR callback function itself instead rising flag in ISR and read  sample from main if flag is true. ADC have SPI interface to MCU.



Thanks,
Sangar
Title: Re: External Interrupt Callback function
Post by: alexanderbrevig on June 13, 2017, 12:48:42 pm
You may want to, but you should not. What of SPI hangs and waits for a timeout or some such.
Btw actual adc and mcu will help us answer the question I'm guessing will come :)
Title: Re: External Interrupt Callback function
Post by: sangar on June 13, 2017, 12:53:45 pm
Hi,
Thanks. I am using AD7124-8 from Analog devices and SAML21J18B from ATMEL.




Thanks,
Sangar
Title: Re: External Interrupt Callback function
Post by: voltsandjolts on June 13, 2017, 01:52:53 pm
You should not wait in the interrupt for the transfers from ADC.
Do something like:

ADC sample ready > Ext Interrupt - start ADC read sample (SPI or whatever), Disable Ext Interrupt then return from interrupt

SPI Interrupt > Receive byte from ADC

SPI Interrupt > Receive byte from ADC

SPI Interrupt > Receive byte from ADC - transfer complete, restart ADC, Enable Ext Interrupt
Title: Re: External Interrupt Callback function
Post by: sangar on June 13, 2017, 05:45:17 pm
Hi,


Our actual project is acquiring samples from ADC and send it over RF module. I want to make this system as interrupt driven machine because it is very time critical. It means that both ADC and RF module will uses external interrupt to MCU. For example, Acquiring ADC samples in FIFO in ADC handler function as you said and handling this FIFO to RF MODULE handler function to send over air. Is it possible?.If so, what cares should I take when work  between handler functions?




Thanks,
Sangar