cancel
Showing results for 
Search instead for 
Did you mean: 

Preferred serial interface between 2+ STM32

LCE
Principal II

Heyho,

I have an application with an STM32H7x3, which might be talking to some other STM32 (type TBD, probably something <= G4) on another stacked PCB.

This is only a control interface, so no data streaming with a minimum data rate.

I am looking for the "best" interface, with that I mean "highest speed at lowest complexity"

 

Hardware limits:

  • trace length max 30 cm, probably over 1 or 2 connectors 
  • max. 4 pins (+1 chip select for each participant also okay)
  • max. 4 STM32x + STM32H7x3 on the "lines"

So, I2C or SPI - or anything else ?

For reliability I like the I2C's acknowledge, SPI is surely faster and has no address "overhead".

Thanks in advance for your input!

 

 

16 REPLIES 16
Andrew Neil
Super User

@LCE wrote:

I am looking for the "best" interface, with that I mean "highest speed at lowest complexity"


Give some actual numbers - what kind of speeds are you talking about ?

 


@LCE wrote:

So, I2C or SPI - or anything else ?


You could also consider UART in multiprocessor mode ...

These are all well-established standard interfaces, well-suited to such applications: the pros & cons are all well-known and widely-discussed - nothing specific to STM32 here.

 


@LCE wrote:

SPI ... has no address "overhead".


Maybe no software overhead, But SPI has the hardware overhead of requiring more data lines, and multiple select lines...

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
LCE
Principal II

Thanks @Andrew Neil !

UART in multi-processor mode, I'll have to check that, never used it.

Right now the main STM32H7 is talking to some slooow ATmegas via I2C (at 30 kHz...), and there are some dedicated spare pins which could be re-used for SPI chip select lines.

Compared to the ~ 30 kHz above, even I2C at 400 kHz would be an improvement. "Fast mode plus" at 1 MHz would definitely be good enough.

What I'd like about SPI is that no address is required, full duplex at least possible, and eventually the higher speed.

Choices...

TDK
Super User

highest speed at lowest complexity

Seems SPI is the winner based on those rules. I'm not convinced it's the best one for the job though, if the data rate is minimal.

> minimum data rate.

I would use I2C here, but it's considerably more complicated in terms of the protocol but signal count is way fewer.

UART is simpler but is more difficult with multi-drop.

CAN is another option, similar to I2C.

 

No doubt any of these could work so choose the one you're most comfortable with and meets the needs.

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Super User

@LCE wrote:

 

...  minimum data rate ...

... highest speed ..


These seem contradictory!

If you only want a "minimum data rate", then why does "highest speed" matter ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@TDK wrote:

UART is simpler but is more difficult with multi-drop.


It doesn't have to be complicated - simple open-drain drive with pullups should work in this scenario.

And (some?) STM32s support half-duplex ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I wasn't clear enough, what I meant that this is not for an interface which must have a certain minimum data rate.

Higher data rate would be nice as long as it doesn't complicate things.

Coming from our 30 kHz I2C something like the regular 400 kHz I2C would be acceptable.

 

LCE
Principal II

Also leaning towards SPI right now.

A challenge with SPI can be that the 2 directions happen simultaneously - which can make it difficult if you want the Master to send a command/request, and the Slave give some reply ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User

Another potential issue with SPI and I2C is that they give no way for the Slave(s) to initiate contact with the Master - you end up having to have some sort of "interrupt" or "attention" line, or the Master has to just keep polling.

 

That may or may not be significant in your particular application ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.