Electronic – Multiplexing two SPI Master

spi

Is it possible to switch two master SPI lines using Quad 2:1 multiplexer like (74HC257)? I want my two Master devices to access a single SPI slave (Flash). Please see attached schematics. SPI speed is 4MHz.

The reason for this is that, I have an MP3 module (master2) which already has a flash that I want my MCU (master1) to access the data from. I don't have control on SPI lines of MP3 (Master2).

two SPI master

Best Answer

I'm assuming that you have no control over the functionality for the MP3 master (i. e. can't change its firmware). When you switch the mux away from the MP3 master, it has no way to know this and may try to access the flash anyway, getting garbage (or all 0/1) responses and do who-knows-what.

SPI, per spec, has no kind of multi-master arbitration.

About the only way to make this work is if your master can pause (stop the clock to) or hold in reset or power-down the MP3 master while you have control of the flash. BTW, I'm only guessing that it might work to stop the clock. If the MP3 master has any kind of dynamic memory, it may not react well to losing its clock.

Also, when taking control of the SPI, you need to make sure the MP3 master is not in the middle of talking to the flash.

All told, what you propose will be difficult at best.