Page 1 of 1
SPI not working
Posted: Sat Jan 23, 2016 8:54 pm
by PCA
Hello, trying to connect an SPI device.
using GP14, GP15, GP16 as SCLK, MOSI, MISO.
Code: Select all
from machine import SPI
spi = SPI(0, SPI.MASTER, baudrate=2000000, polarity=0, phase=0, firstbit=SPI.MSB)
for i in range(3) :
mydata = bytearray([1,2,3,4])
spi.write(mydata)
time.sleep(2)
checked with a scope :
MOSI seems OK but no activity on SCLK (High level)
tried to add a pull up/down resistor : no change
firmware is v1.5.2-71-gcb4fbc8
no more idea ...
Can you help ?
Pascal
Re: SPI not working
Posted: Sat Jan 23, 2016 9:10 pm
by danicampora
Hi,
I see that this is missing from the docs. The default SPI pins are GP14, GP16 and GP30. In order to select other pins you need to add the 'pins' tuple to the constructor:
Code: Select all
spi.init(mode, baudrate=1000000, *, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(CLK, MOSI, MISO))
Example:
Code: Select all
spi = SPI(0, SPI.MASTER, baudrate=2000000, polarity=0, phase=0, firstbit=SPI.MSB, pins=('GP14', 'GP16', 'GP15'))
The PinOUT is here:
https://raw.githubusercontent.com/wipy/ ... PinOUT.png
Cheers,
Daniel
Re: SPI not working
Posted: Sat Jan 23, 2016 9:33 pm
by PCA
Hi Daniel, thank you for the ultra fast answer!
Unhappily the issue is not solved.
My new code :
Code: Select all
from machine import SPI
from machine import Pin
cs = Pin('GP17',mode=Pin.ALT, alt = 7)
spi = SPI(0, SPI.MASTER, baudrate=200000, polarity=0, phase=0, firstbit=SPI.MSB, pins=('GP14', 'GP16', 'GP15'))
for i in range(3) :
mydata = bytearray([1,2,3,4])
spi.write(mydata)
time.sleep(2)
MOSI is OK. CS is OK (due to my line cs = Pin('GP17'... ))
But GP14 (SCLK) always stuck high.
I checked the GP30 pin : no activity.
Pascal
Re: SPI not working
Posted: Sat Jan 23, 2016 9:36 pm
by PCA
Daniel,
mistake : GP30 is MISO (by default) so an input. no activity is just normal...
ignore my remark on this point.
Pascal
Re: SPI not working
Posted: Tue Jan 26, 2016 1:11 pm
by PCA
@danicampora
I suspect an hardware problem on my Wipy module.
I've just ordered a new one and will test again as soon as it arrives.
Pascal