Page 1 of 1

Does pyboard support 3-wire mode SPI bus?

Posted: Wed Jan 18, 2017 4:48 pm
by shaoziyang
Does pyboard support 3-wire mode SPI bus?

Standard SPI is 4-wire, MOSI, MISO, SCK and CS. But in some case, we use 3-wire mode SPI, does micropython support it?
3.jpg
3.jpg (25.34 KiB) Viewed 3203 times

Re: Does pyboard support 3-wire mode SPI bus?

Posted: Wed Jan 18, 2017 5:14 pm
by dhylands
MicroPython doesn't directly support this, but the reference Manual for the STM32F405 says that it is supported.

So I think that you can make it work by using the stm module to read/write the registers directly to tweak the SPI mode.

Here's an example of using the stm module to set the HDSEL bit in a UART:
https://github.com/dhylands/bioloid3/bl ... ort.py#L27

You should be able to do something similar to play with the SPI registers. The stm module has the following SPI constants:

Code: Select all

>>> import stm
>>> [x for x in dir(stm) if x.startswith('SPI')]
['SPI2', 'SPI3', 'SPI1', 'SPI_CR1', 'SPI_CR2', 'SPI_SR', 'SPI_DR', 'SPI_CRCPR', 'SPI_RXCRCR', 'SPI_TXCRCR', 'SPI_I2SCFGR', 'SPI_I2SPR']
SPI1, SPI2, and SPI3 are the SPI base register addresses and SPI_xxx are the offsets of the various registers.

Re: Does pyboard support 3-wire mode SPI bus?

Posted: Thu Jan 19, 2017 2:07 am
by shaoziyang
dhylands wrote:MicroPython doesn't directly support this, but the reference Manual for the STM32F405 says that it is supported.

So I think that you can make it work by using the stm module to read/write the registers directly to tweak the SPI mode.

Here's an example of using the stm module to set the HDSEL bit in a UART:
https://github.com/dhylands/bioloid3/bl ... ort.py#L27

You should be able to do something similar to play with the SPI registers. The stm module has the following SPI constants:

Code: Select all

>>> import stm
>>> [x for x in dir(stm) if x.startswith('SPI')]
['SPI2', 'SPI3', 'SPI1', 'SPI_CR1', 'SPI_CR2', 'SPI_SR', 'SPI_DR', 'SPI_CRCPR', 'SPI_RXCRCR', 'SPI_TXCRCR', 'SPI_I2SCFGR', 'SPI_I2SPR']
SPI1, SPI2, and SPI3 are the SPI base register addresses and SPI_xxx are the offsets of the various registers.
Thank you !