SPI Import Question

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Andrew1234
Posts: 20
Joined: Sat Oct 16, 2021 3:58 pm

SPI Import Question

Post by Andrew1234 » Wed Jul 27, 2022 11:47 pm

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

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: SPI Import Question

Post by Roberthh » Thu Jul 28, 2022 6:17 am

use machine.SPI, which is the more recent style and portable across the various ports.

Post Reply