Page 1 of 1

SPI Import Question

Posted: Wed Jul 27, 2022 11:47 pm
by Andrew1234
Should SPI be an import from pyb, or from machine? The document here indicates to import from machine:
https://docs.micropython.org/en/latest/ ... e.SPI.html

But the pyboard quick reference imports from pyb:
https://docs.micropython.org/en/latest/ ... ml#pyb-spi

The methods are different as well. When importing from machine, methods include SPI.read and SPI.write.
Whereas when importing from pyb, methods include SPI.send and SPI.recv.

My code only seems to run if I import from machine. I haven't successfully communicated with my peripheral, so by run I mean that there does not seem to be a coding error (a call to light an LED at the end of the program works when I import SPI from machine, but not when I import from pyb).

Thanks for any advice
Regards
Andy

Re: SPI Import Question

Posted: Thu Jul 28, 2022 6:17 am
by Roberthh
use machine.SPI, which is the more recent style and portable across the various ports.