Page 1 of 1

SPI use

Posted: Fri Jun 29, 2018 2:11 pm
by BOB63
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

Re: SPI use

Posted: Sat Jun 30, 2018 6:36 am
by Damien
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.