6 years, 3 months ago.

SPI - Change SCLK pin on the fly


I'm wondering if it's possible to change the SCLK pin that an mbed SPI interface is configured with on the fly during runtime. I have two SPI devices; one does not support a chip select so writing data to one device may cause unknown behavior in the other.

To mitigate this, our PCB has two SCLK lines and the chips share MOSI and MISO.

Alternatively, I've read that you can have two SPI interfaces configured with shared pins and mbed can switch between the two, is this correct?

1 Answer

6 years, 3 months ago.

perhaps add a gate controlled by another pin that will apply the clock or not.

It should be possible to obtain this functionality in software. As this is for a product that is potentially going to be mass produced, adding unnecessary external parts isn't preferred.

posted by George Beckstein 15 Feb 2018

You will also have to disable the MISO pin or the slaves will likely shortcircuit eachother. If you cant disable one of the slave devices it would be best to use two different SPI ports mapped on different pins. In case your processor has no spare hardware SPI engine the alternative may be a bitbanged software SPI. Obviously both solutions cost you I/O pins on the processor. Remapping all pins of a single SPI is also possible.

posted by Wim Huiskamp 15 Feb 2018

The SPI device with no chip select also doesn't need to report data; it is a display driver IC. So the MISO line only interacts with the other device that has a chip select.

posted by George Beckstein 16 Feb 2018