SPI not in sync

I made a communication between two boards using digitals pins would it be faster than SPI in your opinion?

I want to try setting 8 digital pins representing a uint8_t and a two flag so 10 pins in total

the 8 data pins will be raised in a boolean type order before raising 1 flag to the other MCU to say a message is ready to be read. once the other device has read the message it can raise a flag to say im done with that message you can lower the data pins now.

This in my mind sounds faster than SPI that uses 4 pins however i am not sure and would like other peoples opinions.

Try both and time them. We would like to know.

flintloque:
This in my mind sounds faster than SPI that uses 4 pins

We all await the result of your experiment with interest.

Using more pins you can make faster communication.
Using more complicated protocol you can get faster communication with the same amount of pins.
SPI is a very simple protocol which is a great advantage by itself. For a given application it is possible to imagine better protocol. However in many situations SPI is "nearly as good" and works well for all of them so it is an "industry standard".

My guess is that a parallel bus would always be faster than a serial bus in absolute terms.

I see in your cross-post that you use a Mega (5volt logic) and a Nucleo (3.3volt logic).
The (needed) bi-directional logic level translators could be the weakest link.
Leo…

Edit: just tested sending over a 16-bit int with SPI.transfer16().
About 3200us for 1000 integers in a for() loop, with SPI clock set to 8Mhz.
How fast do you need.

#include <SPI.h>

void setup() {
  Serial.begin(115200);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.begin();
}

void loop() {
  unsigned long start = micros();
  for (int i = 0; i < 1000; i++) SPI.transfer16 (12345678);
  Serial.println(micros() - start);
  delay(1000);
}

Were you planning to do 10x digitalWrite() ? That may be slower than using the arduino SPI library, properly configured…

Hi,
How far apart are the boards?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Right now, default SPI takes 32 cycles to transmit 1 byte. It can run faster using a smaller clock divider.

And here's a bit to think about, once the byte gets received you still have to do something with it to be useful.

https://gammon.com.au/spi

SPI speeds

The default setting for SPI is to use the system clock speed divided by four, that is, one SPI clock pulse every 250 nS. You can change the clock divider by using setClockDivider like this:

SPI.setClockDivider(divider);

Where "divider" is one of:

SPI_CLOCK_DIV2
SPI_CLOCK_DIV4
SPI_CLOCK_DIV8
SPI_CLOCK_DIV16
SPI_CLOCK_DIV32
SPI_CLOCK_DIV64
SPI_CLOCK_DIV128

The fastest rate is "divide by 2" or one SPI clock pulse every 125 nS. This would therefore take 8 * 125 nS or 1 uS to transmit one byte.

However empirical testing shows that it is necessary to have two clock pulses between bytes, so the maximum rate at which bytes can be clocked out is 1.125 uS each (with a clock divider of 2).

To transfer data this fast you can't afford the time taken to check the "completed" register, so a timed loop is better, eg.

....... snip

To summarize, each byte can be sent at a maximum rate of one per 1.125 uS (with a 16 MHz clock) giving a theoretical maximum transfer rate of 1/1.125 uS, or 888,888 bytes per second (excluding overhead like setting SS low and so on).

This is achievable with both the "normal" SPI hardware and the MSPIM mode described above.

Parallel can beat that but at a cost in cycles to do something useful with the data and a lot of pins.

Is the thread title correct? No. Compare strawberries to salmon while you're at it.

GoForSmoke:
Is the thread title correct? No. Compare strawberries to salmon while you're at it.

Both are shades of red? :slight_smile:

Like both SPI and parallel move data, use pins, and still too different in uses to judge one on the basis of the other.

Apples to Peppers.....

For what it's worth there exists an "enhanced SPI" (eSPI) standard developed by Intel that is similar to SPI, but with up to 4 data lines: https://www.intel.com/content/dam/support/us/en/documents/software/chipset-software/327432-004_espi_base_specification_rev1.0_cb.pdf

The voltage levels are different so there's no applicability to Arduino-class microcontrollers.

@flintloque

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

Could you send me the other sketch you used for receiving i am struggling to get data from my nucleo to my arduino and im very unfirmiliar with arduino.

Wawa:
I see in your cross-post that you use a Mega (5volt logic) and a Nucleo (3.3volt logic).
The (needed) bi-directional logic level translators could be the weakest link.
Leo…

Edit: just tested sending over a 16-bit int with SPI.transfer16().
About 3200us for 1000 integers in a for() loop, with SPI clock set to 8Mhz.
How fast do you need.

#include <SPI.h>

void setup() {
  Serial.begin(115200);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.begin();
}

void loop() {
  unsigned long start = micros();
  for (int i = 0; i < 1000; i++) SPI.transfer16 (12345678);
  Serial.println(micros() - start);
  delay(1000);
}

AJLElectronics:
My guess is that a parallel bus would always be faster than a serial bus in absolute terms.

Just wondering why we don't use parallel harddisk interfaces anymore in PCs :slight_smile:

sterretje:
Just wondering why we don't use parallel harddisk interfaces anymore in PCs :slight_smile:

Hardware limitations and the fact that serial rates are generally more than adequate. Monitor modules still come with parallel as well as serial busses.

Parallel interfaces in some high speed applications suffer from skew and RF limitations in the data transfer, and hardware design starts to become more complex.
Synchronous serial can make it easier to minimise these issues.

I have a MCU that i have connected to my arduino mega however the i cannot seem to synchronise, how do i need to modify my code in or to have them sync. The other MCU is the master and the arduino is the slave.

#include <SPI.h>

void setup() {
  Serial.begin(115200);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.begin();
}

uint8_t stat[256];

void loop() {;
  for (int i = 0; i < 256; i++){
    stat[i] = SPI.transfer(0);
    Serial.println(stat[i]);
  }
  delay(1000);
}

Is that other MCU an Arduino UNO or NANO that is working as a SPI Master? If not, what kind of MCU it is?

Also please explain what you mean, "in sync".