EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: Pack34 on October 08, 2018, 07:17:51 pm

Title: Can interrupt firing corrupt a SPI Transfer?
Post by: Pack34 on October 08, 2018, 07:17:51 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?
Title: Re: Can interrupt firing corrupt a SPI Transfer?
Post by: mikerj on October 08, 2018, 07:22:47 pm
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 08, 2018, 09:30:56 pm
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, 01:37:35 am
 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, 01:47:50 am
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, 08:13:55 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?

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 12, 2018, 03:32:47 pm
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?