Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 9 months ago.
SPI - Change SCLK pin on the fly
Hello,
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, 9 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 15 Feb 2018You 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 15 Feb 2018