Using same pins for SPI and ADC...

Working libraries, libraries being ported and related hardware
Post Reply
Angr77
Posts: 11
Joined: Sat Dec 01, 2018 9:05 pm

Using same pins for SPI and ADC...

Post by Angr77 » Sun Feb 17, 2019 10:58 am

Hi!

I am doing a small project with the blue pill board, 2.8” ILI9341 touch screen+SD reader...(built on the GUI for stm32 using GUI slice builder https://impulseadventure.com/elec/guislice-gui.html. Works fantastic!

In my project I will also use some ADC ports. But, what is the story here...if I have used some pins for SPI communication...are these pins blocked in the case they are shared as ADC ports? (Can SPI and ADC use the same pins?)

Best regards

Anders

User avatar
BennehBoy
Posts: 886
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Using same pins for SPI and ADC...

Post by BennehBoy » Sun Feb 17, 2019 4:27 pm

If you don't use any of the pins which SPI requires then ADC & SPI will co-exist just fine. If you need more ADC's then just use the 2nd spi instance which sits on different pins, or remap spi1... All the info is in the forum..
Last edited by BennehBoy on Mon Feb 18, 2019 3:40 pm, edited 1 time in total.
-------------------------------------
https://github.com/BennehBoy

User avatar
mrburnette
Posts: 3001
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Using same pins for SPI and ADC...

Post by mrburnette » Sun Feb 17, 2019 4:44 pm

And refer to the multiplexing graphic for the uC:

http://stm32duinoforum.com/forum/index.php?ti ... pinout.gif

And refer to the API section here:
http://stm32duinoforum.com/forum/index.php?title=API
Pin Modes
OUTPUT: Basic digital output: when the pin is HIGH, the voltage is held at +3.3v (Vcc) and when it is LOW, it is pulled down to ground.
OUTPUT_OPEN_DRAIN: In open drain mode, the pin indicates “low” by accepting current flow to ground and “high” by providing increased impedance.
INPUT: Basic digital input.
INPUT_ANALOG: This is a special mode for when the pin will be used for analog (not digital) reads.
INPUT_PULLUP: The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gently “pulled up” towards +3.3v.
INPUT_PULLDOWN: The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gently “pulled down” towards 0v.
INPUT_FLOATING: Synonym for INPUT.
PWM: This is a special mode for when the pin will be used for PWM output (a special case of digital output).
PWM_OPEN_DRAIN: Like PWM, except that instead of alternating cycles of LOW and HIGH, the voltage on the pin consists of alternating cycles of LOW and floating (disconnected).
And from the original LeafLabs site:
On Maple, pinMode() supports the INPUT and OUTPUT modes in the same way as Arduino (however, remember that the Maple, as a 3.3V device, will only drive 3.3V to an OUTPUT pin that has been set HIGH, instead of 5V like on Arduino).

INPUT_ANALOG and PWM modes were added because the Maple doesn’t separate the analog and digital pins the same way Arduino does. Unlike on Arduino, you must call pinMode() to set up a pin for these purposes before a call to, e.g., analogRead(). This should only add a few lines to your setup() function.

Angr77
Posts: 11
Joined: Sat Dec 01, 2018 9:05 pm

Re: Using same pins for SPI and ADC...

Post by Angr77 » Tue Feb 19, 2019 5:29 am

Hi
I am guessing that You are saying that IF i used the SPI 1 pins...which natively also share some of the ADC ports/pins...these ADC ports can’t be used. Better to remap to spi 2 or remap these SPI pins.

True or false?

Best regards

Anders

ag123
Posts: 1322
Joined: Thu Jul 21, 2016 4:24 pm

Re: Using same pins for SPI and ADC...

Post by ag123 » Tue Feb 19, 2019 8:08 am

below is a pinouts for maple mini (and clones)
i've used PA0 - PA3 for adc and PA4-PA7 for SPI prior, there are no conflicts, it works so long as you configure the ports and spi appropriately.
obviously i'd guess if you are already using PA4-PA7 for SPI you won't be using PA4-PA7 for adc at the same time (that sounds like common sense)? ;)
my guess is it may still be possible if one insists but that programming would likely be complicated and that one would need to switch configurations for the port on the fly which would probably get one on the toes, and you are on your own for that feat
Image

Post Reply