I am using a PyBoard 1.1, with the latest 1.9.4 firmware:
MicroPython v1.9.4 on 2018-05-11; PYBv1.1 with STM32F405RG
I try to create an SPI object, but it does not seem to take my initialization.
Here is from REPL:
>>> spi=SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0, bits=16, firstbit=SPI.MSB)
>>> spi
SPI(1, SPI.MASTER, baudrate=328125, prescaler=256, polarity=1, phase=0, bits=16)
>>>
The baudrate is wrong, and there appears to be no firstbit attribute.
Checking on a scope, the baudrate is indeed around 330kHz.
What am I doing wrong?
SPI initialization not working
Re: SPI initialization not working
You imported the wrong SPI module.Gordon_Hardman wrote: ↑Wed Aug 29, 2018 4:24 pmI am using a PyBoard 1.1, with the latest 1.9.4 firmware:
MicroPython v1.9.4 on 2018-05-11; PYBv1.1 with STM32F405RG
I try to create an SPI object, but it does not seem to take my initialization.
Here is from REPL:
>>> spi=SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0, bits=16, firstbit=SPI.MSB)
>>> spi
SPI(1, SPI.MASTER, baudrate=328125, prescaler=256, polarity=1, phase=0, bits=16)
>>>
The baudrate is wrong, and there appears to be no firstbit attribute.
Checking on a scope, the baudrate is indeed around 330kHz.
What am I doing wrong?
You have to do
Code: Select all
from pyb import SPI
Import SPI uses "machine.SPI".
Re: SPI initialization not working
Note that STM32 SPI cannot provide all baudrates. In fact if a specific baudrate is requested, MPY selects the available baudrate <= requested baudrate. Also note that available baudrates vary with SYSCLK frequency.
All of the above is only true for HW SPI, SW SPI might give finer granularity at lower frequencies. But keep in mind that SW SPI usually consumes more power.
In the given example one could use a baudrate of 2*328125, which is closer to 600000 but obviously greater than 600000.
All of the above is only true for HW SPI, SW SPI might give finer granularity at lower frequencies. But keep in mind that SW SPI usually consumes more power.
In the given example one could use a baudrate of 2*328125, which is closer to 600000 but obviously greater than 600000.