Go Down

Topic: Define multiple SPI pins? (Read 1 time) previous topic - next topic

dauntless89

I searched around and didn't find an answer.

I've got two SPI devices in use on this project. One SPI breakout is large and will have to be mounted off the main board, but the second is tiny and it would be ideal if it could just install into the Due's header. This would require defining two sets of SPI pins. Is it possible to declare duplicate pins on the same bus, or would I have to hack a library to use the second SPI bus to pull this off?

Thanks,
Tony

artisticforge

I searched around and didn't find an answer.

I've got two SPI devices in use on this project. One SPI breakout is large and will have to be mounted off the main board, but the second is tiny and it would be ideal if it could just install into the Due's header. This would require defining two sets of SPI pins. Is it possible to declare duplicate pins on the same bus, or would I have to hack a library to use the second SPI bus to pull this off?

Thanks,
Tony
the Arduino Due has 2 TWI/I2C/Wire declared.

On the Arduino Due
Above Pin 13 there are
SCL1
SCA1
AREF
GND

Pin 20 is SDA
Pin 21 is SCL

Getting started with the Arduino Due

https://www.arduino.cc/en/Reference/DueExtendedSPI

Serial Interfaces: SPI, I2C, UART Demystified

><>

ard_newbie

#2
Jan 29, 2018, 05:36 am Last Edit: Jan 29, 2018, 06:55 am by ard_newbie
@artisticforge: SPI and I2C (TWI) are different protocols.


@dauntless89: As mentionned above, the extended SPI Library for DUE allows you to have 3 SPI devices on the same SPI bus (pins 4, 10 and 52) and the Due will automatically handle the chip selection between multiple devices sharing the SPI bus.

Of course, you could also make manually the chip selection with "any" SPI device thru a GPIO.

With an external 4- to 16-bit decoder, you can select up to 12 spi devices thru NPCS0(PA28), NPCS1(PA29) and NPCS2(PB21) on the same bus.

Plus USART0 and USART1 can be programmed in SPI mode for 2 SPI devices.



artisticforge

@artisticforge: SPI and I2C (TWI) are different protocols.


@dauntless89: As mentionned above, the extended SPI Library for DUE allows you to have 3 SPI devices on the same SPI bus (pins 4, 10 and 52) and the Due will automatically handle the chip selection between multiple devices sharing the SPI bus.

Of course, you could also make manually the chip selection with "any" SPI device thru a GPIO.

With an external 4- to 16-bit decoder, you can select up to 12 spi devices thru NPCS0(PA28), NPCS1(PA29) and NPCS2(PB21) on the same bus.

Plus USART0 and USART1 can be programmed in SPI mode for 2 SPI devices.

Yes they are. it is obvious to the most casual observer that I did know that by including the third link.

Tell me are you always this condescending?
><>

dauntless89

I dug into this a little more and the libraries that go with these peripherals are bit-banging. The declaration tags each library looks for are different so I can easily have two independent soft SPI connections on two physically different sets of pins at the same time. Yeah, kind of a kludge code-wise, but it won't be any performance penalty for this application.

tito-t

#5
Feb 01, 2018, 11:41 am Last Edit: Feb 01, 2018, 11:50 am by tito-t
the Arduino Due has 2 TWI/I2C/Wire declared.

On the Arduino Due
Above Pin 13 there are
SCL1
SCA1
AREF
GND

Pin 20 is SDA
Pin 21 is SCL

@artisticforge :
your post is off-topic and misleading: you clearly refer to I²C (TWI), but the topic is about SPI.


As to SPI:
The Due has just 1 hardware SPI header available to Arduino users (MISO/MOSI/SCK pins 74-76 at old ICSP close to TX/RX pins).
There are also 3 different hardware CS pins available (4,10,52).
Additionally, multiple software SPI pin sets can be declared arbitrarily (e.g., like also for the MEGA by divergent ISCP pin numbers).
Just to mention that the SAM3X8E has actually 1 additional hardware SPI bus (at new ICSP close to power jack) but currently not available to arduino users unfortunately.

Go Up