3
\$\begingroup\$

I'm using an AVR chip (i.e. Arduino Uno) to monitor SPI traffic on an external device and I'm running into a problem due to the fact that the external device periodically restarts itself (by design). This results in a momentary drop in voltage across the CLK pin which my AVR mistakes for an extra bit. Net result is that the SPI shift register goes out of sync to the incoming data stream by 1 bit every time the device restarts.

I can detect these restart events due to the start-up delay where no SPI traffic is being sent, is there any easy way to reset the shift register when this happens to cause SPI reads to restart at bit 0?

\$\endgroup\$

migrated from stackoverflow.com Jan 7 '15 at 14:20

This question came from our site for professional and enthusiast programmers.

  • \$\begingroup\$ Have you tried to reset SPE and MSTR bits? Alternatively you could try to pull-up CLK line to VCC to avoid the glitch. I'm not sure if the internal pull-up resistors will work if you configure pin as CLK, but I'd check it. \$\endgroup\$ – ezaquarii Jan 4 '15 at 20:31
1
\$\begingroup\$

There seems to be little information on how you use the arduino to monitor the communication. But, you should probably also monitor the \$\overline{\textrm{CS}}\$ pin. When \$\overline{\textrm{CS}}\$ goes low SPI communication is at the start of each transmission therefore you should be able to use that to synchronize on each 'packet' and reset the input shift register. When \$\overline{\textrm{CS}}\$ goes high communication is over, so you should flush your output even if you didn't get a complete byte. (\$\overline{\textrm{CS}}\$ is also known as \$\overline{\textrm{SS}}\$).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.