According to the Atmel site, the Atmega2560 has 5 SPI.
I'm not sure exactly what they mean by that. Do they mean 5 separate SPI ports?
Or just 5 pins that can be used to create one SPI port?
On the Arduino Mega there are 4 pins related to SPI, 50, 51, 52, and 53.
However, they all have specific SPI functions (MISO, MOSI, SCK, SS).
Does this mean the Arduino Mega is restricting the overall usefulness of the SPI?
Or is this what Atmel really means by 5 SPI, that 5 of the pins are somehow dedicated to creating one SPI port?
Datasheet shows 1 actual SPI port (SCK, MISO, MOSI, SS)
while the 4 USARTs can be run in SPI compliant mode.
See Sections 20 & 22 of the '2560 datasheet.
A lot of parametric tables etc quote things like "5 SPI" when in fact they are referring to 1 SPI and 4 USARTs that can be used in SPI mode as CR said.
Personally I think it's a bit of a con but all the chip people seem to do it. To be fair I suppose it's same as saying 40 IO pins and 16 ADC inputs, that's kind of true but not all at the same time.
The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) can be set to a master SPI compliant mode of operation. The Master SPI Mode (MSPIM) has the following features: ...
What is the penalty of using a USART as a SPI port?
You can only use it in Master mode for one thing. Clearly you lose a serial port since it is using the same USART resource.
As for the pins, judging by the data sheet, including the pins diagram, if you set the USART into SPI mode then you use the "serial" pins as SPI pins (ie. Tx, Rx) and also another adjacent pin for the clock (eg. pin 2 = RXD0, pin 3 = TXD0, pin 4 = XCK0). So you get completely separate pins for each SPI device.
You would also need to allocate a SS pin for each SPI device.
According to page 234 of the datasheet:
The UDORDn bit in UCSRnC sets the frame format used by the USART in MSPIM mode. The Receiver and Transmitter use the same setting. Note that changing the setting of any of these bits will corrupt all ongoing communication for both the Receiver and Transmitter.
Isn't the receiver and transmitter how the Arduino is programmed? If I change those pins into SPI ports, is there a possibility I will no longer be able to program the Arduino?
I've temporarily switched to using Arduino Duemilanove w/ Atmega328.
I've been using the SPI port with the clock rate select at 2MHz by using these settings:
SPI2X: 1 SPR1: 0 SPR0: 1
Now I want to use a USART port in MSPIM mode with the same clock settings.
According to 21.7 on page 205 in the datasheet:
The SPI double speed mode (SPI2X) bit is not included. However, the same effect is achieved by setting UBRRn accordingly.
Here's my guess about what to do.
On page 200 there's a table that gives equations for how to calculate baud UBRRn.
I'm assuming baud is equivalent to clock rate.
I'm also assuming U2Xn is set to 0, though I'm not entirely sure what effect it has.
If that's the case, and I want 2MHz, then:
UBRRn = fosc/2BAUD - 1
UBRRn = 16MHZ/2(2MHz) - 1= 3
Is this correct? If so, which registers do I need to set in UBRRnH and UBRRnL to make that happens?
Can you just explain why you want to do this? You can have the single (dedicated) SPI pins service multiple devices by giving each one a SS line. I don't really see what you achieve by, instead, using separate pins for each device by configuring the USART in this way. SPI at these speeds are not going to be able to keep up with talking to 4 devices at once unless I am mistaken.
are not going to be able to keep up with talking to 4 devices at once unless I am mistaken.
Correct, you will have trouble keeping up with a single port although I guess you've been doing so,but I can't see that you have a chance with 4 unless the data is very sporadic and you have time between bytes to deal with them.
I'm attempting to control multiple LED strips that can be controlled using SPI.
Here's the datasheet: http://www.sparkfun.com/datasheets/Components/LED/WS2801.pdf
They do not have a chip select. They only have clock and data.
I was considering faking chip select in some way using a demultiplexer but I thought I would explore how good atmega chips are at running multiple SPI ports.
I'd like to do this in parallel if at all possible.
Oh well, I suppose. But at those speeds you won't really get parallel, but I suppose it might work. However if you just ran the SCK line through some AND gates (or similar) per chip you could simulate a chip select.
They won't, I don't think. Running at 16 MHz that is only 4 clock cycles to shove something out at 4 MHz. And that is a single port. There's no way you are going to be able, at that speed, load multiple ports from memory (eg. indexed RAM access), place in the SPI buffer, and loop. There just isn't enough spare CPU for that.
I just want the option to run a bunch of strips for various art projects.
One of my friends was experimenting and thinks these are fast enough to get a decent persistence of vision effect, so high frame rates are preferable.
I'm not using 6 meters, I'm using 5 meters, it seems to work OK with one strip at 5 meters.
You won't be able to use any of the USARTs on the Aruino Mega in SPI mode because not a single one of them has all of their pins broken out. I think it was the SCK pin in particular. You'd need a 3rd party or custom board that gives you access to them.
not a single one of them has all of their pins broken out.
That's just typical of the lack of engineering thought put into the Arduino hardware designs.
if Atmel chips just can't handle pumping out 4MHz of data from multiple ports.
I think I guesstimated that you could do 8 parallel bits at 2MHz (effective 16MHz data rate) on that other thread, as long as the data is pre-prepared.
I just want the option to run a bunch of strips for various art projects.
At 4MHz SPI you can control 40,000 LEDs (13,333 3-color LEDs) with a 100Hz frame rate (seems like a lot, did I get the numbers right?).
If I did get those numbers right I'm having trouble seeing why a single link can't do it although there may be propagation issues with 40k chips in a row.
Again with pre-prepared data maintaining that rate would be easy as long as there isn't much else to do.