SPI not working

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
PCA
Posts: 10
Joined: Tue Oct 27, 2015 10:20 pm

SPI not working

Post by PCA » Sat Jan 23, 2016 8:54 pm

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

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: SPI not working

Post by danicampora » Sat Jan 23, 2016 9:10 pm

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

PCA
Posts: 10
Joined: Tue Oct 27, 2015 10:20 pm

Re: SPI not working

Post by PCA » Sat Jan 23, 2016 9:33 pm

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

PCA
Posts: 10
Joined: Tue Oct 27, 2015 10:20 pm

Re: SPI not working

Post by PCA » Sat Jan 23, 2016 9:36 pm

Daniel,
mistake : GP30 is MISO (by default) so an input. no activity is just normal...
ignore my remark on this point.
Pascal

PCA
Posts: 10
Joined: Tue Oct 27, 2015 10:20 pm

Re: SPI not working

Post by PCA » Tue Jan 26, 2016 1:11 pm

@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

Post Reply