EEVblog Electronics Community Forum

Electronics => Microcontrollers & FPGAs => Topic started by: Pack34 on October 09, 2018, 06:17:51 am

Title: Can interrupt firing corrupt a SPI Transfer?
Post by: Pack34 on October 09, 2018, 06:17:51 am
I'm working with a PIC24 and a SPI transfer from an ADC seems to intermittently return incorrect data on a specific channel. The voltages applied to the input of the ADC have been proven to be steady using a series of external ADCs at a greater sampling rate but the ADC itself could respond with what would correspond to a drop of 8V on a 24V circuit.

The SPI module is a dedicated module inside the PIC and an interrupt that pulls the PIC elsewhere shouldn't affect the data being read-in over the bus, correct?
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: mikerj on October 09, 2018, 06:22:47 am
Does the ADC error always correlate to the same bit in the SPI frame?
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: Pack34 on October 09, 2018, 08:30:56 am
It's always the same channel. The LSB tends to look mostly intact but the MSB is complete garbage.
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: JustMeHere on October 12, 2018, 12:37:35 pm
 Do you have a schematic and perhaps a board layout?
Is your SPI being shared? 
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: floobydust on October 12, 2018, 12:47:50 pm
Check with a scope for runts on the SPI clock. I've seen cascaded 8-bit transfer subroutines used for 16-bit transfers, where the last 8-bits (subroutine) leaves the clock low and then the clock is up right away for the next 8-bit transfer, so you get an extra clock pulse as a glitch.
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: mikeselectricstuff on October 12, 2018, 07:13:55 pm
I'm working with a PIC24 and a SPI transfer from an ADC seems to intermittently return incorrect data on a specific channel. The voltages applied to the input of the ADC have been proven to be steady using a series of external ADCs at a greater sampling rate but the ADC itself could respond with what would correspond to a drop of 8V on a 24V circuit.

The SPI module is a dedicated module inside the PIC and an interrupt that pulls the PIC elsewhere shouldn't affect the data being read-in over the bus, correct?

Scope the SPI, add some debug code to set a pin to trigger the scope on an obviously incorrect SPI value and see what the SPI is doing at the time. 
Check that you are clocking data in on the correct edge of the SPI clock
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: SiliconWizard on October 13, 2018, 02:32:47 am
Since we have no idea about your source code... nor any scope capture...

Have you considered that it may not be an SPI transfer problem per se but rather the way you store the samples?
Maybe it's a 16-bit ADC and you use an 8-bit mode SPI, and have some kind of issue with reading incomplete values due to the storage itself being interrupted while you read them?