cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Master/Slave Role Assignment between two MCUs?

DLin.3
Associate II

Hi there,

First of all, thank you for reading this post.

I have a system that has an ARM Cortex M4 MCU interfacing with STM32G4 via SPI. In the current design, STM32G4 takes care of motor commutation related tasks. So the question I have is that who should be the SPI master/slave? Or does it really matter? My hunch is to have STM32G4 as the master since it has more time critical tasks; however, the tasks are based on what the other MCU's commands.

The other ARM M4 MCU (32bit) is fairly powerful too, running at 100MHz. The main tasks in this MCU are to initiate communications with other devices in the system, and tell STM32G4 when and how to run the motors.

I did some research online hoping to get some ideas regarding SPI Master/Slave role assignment, but I was not able to find anything useful.

Thanks again for the advice, in advance.

Sincerely,

1 ACCEPTED SOLUTION

Accepted Solutions
Nikita91
Lead II

There is 2 different architecture:

G4 as master :

In this case the G4 must periodicallty poll the M4 to obtain the commands.

The M4 must prepare a NOP command if it has no command to send.

M4 as Master:

Since the G4 is a slave, all it has to do is configure for slave receive and wait.

When it has received a command, it executes it, then returns to receive and wait .

When the M4 needs to send a command, he does so.

IMO the M4 master / G4 slave is simpler to implement.

View solution in original post

3 REPLIES 3
Nikita91
Lead II

There is 2 different architecture:

G4 as master :

In this case the G4 must periodicallty poll the M4 to obtain the commands.

The M4 must prepare a NOP command if it has no command to send.

M4 as Master:

Since the G4 is a slave, all it has to do is configure for slave receive and wait.

When it has received a command, it executes it, then returns to receive and wait .

When the M4 needs to send a command, he does so.

IMO the M4 master / G4 slave is simpler to implement.

Hi!

Thanks for your comment!

If I were to move the code that determines when and how to run the motors to G4, leaving M4 as a communication bridge to other devices in the system; in this case, would you suggest making G4 the SPI Master then?

Sincerely,

Nikita91
Lead II

I think the SPI master should be the one who takes the initiative in sending the messages.