How to use multiple SPI Master on Arduino DUE

Hi.

Because I have to control stp16cp05 by high speed, 30 MHz, and also have to use SD card, I use both them by SPI on Arduino DUE. But SD card signal interfere signal of stp16cp05 so I'm looking forward how to use two SPI masters on Arduino DUE.

Can I use two SPI masters on Arduino DUE?

I want to connect each them by other SPI pins.

The USART peripheral can be used as an SPI Master or Slave.

From Sam3x datasheet page 802:

35.7.7.1 Modes of Operation
The USART can operate in SPI Master Mode or in SPI Slave Mode.
Operation in SPI Master Mode is programmed by writing to 0xE the USART_MODE field in the Mode Register. In
this case the SPI lines must be connected as described below:
the MOSI line is driven by the output pin TXD
the MISO line drives the input pin RXD
the SCK line is driven by the output pin SCK
the NSS line is driven by the output pin RTS
...

An interesting thread:

https://forum.arduino.cc/index.php?topic=283766.0

And this:

If one device is interfering with another, it's usually the CS (chip select) lines between the arduino and devices that need fixing.
Unless you need to run both SPI devices at the same time, you don't need another SPI bus.

However, the stp16cp05 is not a SPI device! This is why it's not working on the bus as you expect. Looking at the datasheet, I think you can make it work but you can't use CS on the LE/DM1 pin, but you can overcome that by manually toggling it to latch in the data after the SPI transfer (the one intended for the stp16cp05). Data for the SD card will still go through the stp16cp05, which isn't a problem if you don't latch the data in during SD card transfers.

Also, why are you trying to run the stp16cp05 at 30 MHz? unless you have lots of these cascaded and need a fast update time, I can't see the point, is that really what you need?

weird_dave:
If one device is interfering with another, it's usually the CS (chip select) lines between the arduino and devices that need fixing.
Unless you need to run both SPI devices at the same time, you don't need another SPI bus.

However, the stp16cp05 is not a SPI device! This is why it's not working on the bus as you expect. Looking at the datasheet, I think you can make it work but you can't use CS on the LE/DM1 pin, but you can overcome that by manually toggling it to latch in the data after the SPI transfer (the one intended for the stp16cp05). Data for the SD card will still go through the stp16cp05, which isn't a problem if you don't latch the data in during SD card transfers.

Also, why are you trying to run the stp16cp05 at 30 MHz? unless you have lots of these cascaded and need a fast update time, I can't see the point, is that really what you need?

I know that the stp16cp05 is not a SPI device. Because I have to control it by very high speed like 30 MHz, so I use it by SPI. And why I have to run the stp16cp05 at 30 MHz is to control a dot matrix has 36 * 24 pixels. And I have to set brightness of each pixels differently, so I need to control the stp16cp05 in full speed.

And I use CS of the SD card and LE of the stp16cp05, but just after CS of the SD card is disabled, the data signal of the SD card does not disappear immediately. So the data signal of the stp16cp05 is interfered by it.

So I'm looking for multiple SPI masters on Arduino DUE.

neosarchizo:
I know that the stp16cp05 is not a SPI device. Because I have to control it by very high speed like 30 MHz, so I use it by SPI. And why I have to run the stp16cp05 at 30 MHz is to control a dot matrix has 36 * 24 pixels. And I have to set brightness of each pixels differently, so I need to control the stp16cp05 in full speed.

You PWM each output? OK, I think I understand why you need speed :slight_smile:

neosarchizo:
And I use CS of the SD card and LE of the stp16cp05, but just after CS of the SD card is disabled, the data signal of the SD card does not disappear immediately. So the data signal of the stp16cp05 is interfered by it.

But what have you connected to LE of the stp16cp05? a CS pin?

neosarchizo:
So I'm looking for multiple SPI masters on Arduino DUE.

You don't need to. connect LE to an output pin of your choice. When you want to set the stp16cp05, simply do a SPI Transfer then toggle the LE pin high then low to latch the data in. Don't use any CS pin for this SPI transfer. The SD card can't interfere with it if you do this.
The problem you currently have isn't that the SD card data doesn't disappear immediately, it's the start of the SD card transfer when it first goes wrong, because your LE pin is high, so during the entire SD card transfer, the output stages of the stp16cp05 are getting updated with crap.

ard_newbie:
The USART peripheral can be used as an SPI Master or Slave.

From Sam3x datasheet page 802:

35.7.7.1 Modes of Operation
The USART can operate in SPI Master Mode or in SPI Slave Mode.
Operation in SPI Master Mode is programmed by writing to 0xE the USART_MODE field in the Mode Register. In
this case the SPI lines must be connected as described below:
the MOSI line is driven by the output pin TXD
the MISO line drives the input pin RXD
the SCK line is driven by the output pin SCK
the NSS line is driven by the output pin RTS
...

An interesting thread:

Using USART0 and USART1 in SPI Master Mode or SPI Slave Mode - Arduino Due - Arduino Forum

And this:

Better SPI Bus Design | Hackaday

Thanks!. This is what I was looking for!

weird_dave:
You PWM each output? OK, I think I understand why you need speed :slight_smile:

But what have you connected to LE of the stp16cp05? a CS pin?
You don't need to. connect LE to an output pin of your choice. When you want to set the stp16cp05, simply do a SPI Transfer then toggle the LE pin high then low to latch the data in. Don't use any CS pin for this SPI transfer. The SD card can't interfere with it if you do this.
The problem you currently have isn't that the SD card data doesn't disappear immediately, it's the start of the SD card transfer when it first goes wrong, because your LE pin is high, so during the entire SD card transfer, the output stages of the stp16cp05 are getting updated with crap.

I didn't connect the LE pin to the CS pin. But I agree what you said.
And now I consider using an USB not SD card. In arduino, the speed of SD card is so slow.

How slow? Can you buffer the data you need from the SD card before you want to use it?