SPI use

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
BOB63
Posts: 58
Joined: Sat Jul 25, 2015 8:24 pm
Location: Monza , Italy

SPI use

Post by BOB63 » Fri Jun 29, 2018 2:11 pm

Hi, I'm trying to use SPI to communicate with a card connected to PyBoard, but seems that something is wrong .
This is a very simple code I'm using to send some data to the card connected , that tested with an Arduino works :

Code: Select all

import pyb
from pyb import LED
from pyb import SPI

spi=SPI.init(1,SPI.MASTER, baudrate=600000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB)

led = LED(1)
while True:
      spi.send(68)
      print('Done')
      led.toggle()
      pyb.delay(1000)
      

Image

Using a logic analyzer in the picture is what exit from the SPI :

On REPL I don't see any error and any print out as expected and led is not flashing.

I'm using the SPI 1 on X pins (5,6,7,8) but the same happen if I try with SPI2 on Y pins

Firmware version : MicroPython v1.9.2-123-gbdc6e86e on 2017-09-29; PYBv1.0 with STM32F405RG

What could be wrong ?
The code or the PyBoard damaged ?

Thanks for any help .
Roberto
Attachments
spi.JPG
spi.JPG (107.61 KiB) Viewed 1806 times
Thanks. Roberto

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: SPI use

Post by Damien » Sat Jun 30, 2018 6:36 am

You need to construct the SPI object, not call the init method. So you should do:

Code: Select all

spi = SPI(1,SPI.MASTER, baudrate=600000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB)
Note the lack of ".init". This will create and return an SPI object, which you can then use. Note also that the CS pin must be controlled by your script explicitly, it won't be controlled by the SPI object.

Post Reply