Electronics > Microcontrollers

Yikes! Exponential SPI weirdness

(1/4) > >>

andyturk:
I'm working on a project to read some analog sensors and display the results on an LCD screen. One of the issues I've run into is that the SPI traffic causes lots of noise on the board which throws off the ADC readings.

As part of minimizing the noise, I'm experimenting with interleaving ADC and SPI activity to make sure the two never occur at the same time. The ADC has to collect samples on a specific interval (currently ~6K times per second), so I've been disabling the SPI peripheral just before the ADC wakes up, and then re-enabling SPI after the data has been read. It seems to work and does reduce (some of) the noise being picked up by the ADC. The mcu is a STM32F103RG.

While poking around with my scope, I noticed this decidedly non-digital artifact on the MOSI (Master Out Slave In) line shown in blue:



The yellow trace is a GPIO that goes high just before SPI is being shut down. After the ADC is done, the yellow trace goes low, and SPI starts up shortly thereafter. The interesting part is the exponential ramp of the MOSI line while the SPI peripheral is disabled. My guess is that something goes high-Z internally and a weak pull-up on the I/O pad acts through some capacitance gradually ramps it up to VDD. The RC time constant looks to be about one division, or roughly 5uS.

This doesn't seem to cause any problems for the LCD I'm using (ST7735R from Adafruit), but having a floating SPI line can't be a good thing in general. Should I put an external pull down resistor on the next spin of the board?

Also, is there any general wisdom for keeping SPI noise away from an ADC on a mixed signal board? For now, I'm using a 2-layer design for prototyping since that's much cheaper than 4-layer.

svofski:
I think that your guess about something getting tristated is correct. How do you shut down SPI? Maybe before shutting it down you could reconfigure the SPI pins to become GPIO and set them to zero, then reconfigure them back again next time when you need SPI: thus you would avoid uncertainty on the pins.

amyk:
If the LCD /CS is inactive (is that the GPIO) then it shouldn't cause any problems as long as the voltage is within spec since the controller isn't reading what's on the MOSI while it's deselected.

andyturk:

--- Quote from: amyk on December 30, 2012, 07:33:23 am ---If the LCD /CS is inactive (is that the GPIO) then it shouldn't cause any problems as long as the voltage is within spec since the controller isn't reading what's on the MOSI while it's deselected.

--- End quote ---

As it turns out, the CS stays put through the entire ordeal... apparently the LCD doesn't care. I used a different GPIO for the yellow trace (with an LED on it), but you're right, I probably ought to toggle the chip select too.

MikeK:
Don't you need pullups on the SPI lines?

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod