Interrupts and SPI

Hello :smiley:

I am using SPI communication between Arduino and an ADC. The ADC has a pin that goes low when data is ready to be transferred. I was using polling to check the pin to know when data is ready so Arduino can send the sclks through SPI, but it is causing some glitches. So I would like to use interrupt instead.

How can I write an ISR for when data is ready?? I’ve read that an ISR must take no parameters and return nothing… Can I use SPI.transfer inside of it?!

jfer:
Hello :smiley:

I am using SPI communication between Arduino and an ADC. The ADC has a pin that goes low when data is ready to be transferred. I was using polling to check the pin to know when data is ready so Arduino can send the sclks through SPI, but it is causing some glitches.

Unfortunately we cannot know what you mean by 'glitches'

However, you would expect polling the pin to work, unless there is some specific requirement for whichever ADC you are using which was not specified either.

I would fix the basic problem first, i.e.polling does not work.

srnet:
Unfortunately we cannot know what you mean by 'glitches'

However, you would expect polling the pin to work, unless there is some specific requirement for whichever ADC you are using which was not specified either.

It doesn't work quite well because there's loss of data. The Arduino must send SCLKs as soon as the pin goes low. Polling is not fast enough. Interrupts would be a better approach but I don't know how to use it to transfer data through SPI.

"Polling is not fast enough. "

If that's the case then you probably have very inefficient code and it could use some refactoring either way.

jfer:
The Arduino must send SCLKs as soon as the pin goes low.

If the SCLKs must be sent 'as soon as' the pin goes low, then even interrupts wont be fast enough.

'as soon as' I got up this morning I made a cup of coffee. The reality was that it was around a minute before I actually started making it.

Only when you quantify how fast 'as soon as' actually is can you assume that polling is not fast enough.

But your keeping the identity of the ADC secret, so no-one can help you out.