Page 1 of 2

Hardware SPI not working

Posted: Fri May 17, 2019 7:00 pm
by smith.randallscott
I am brand new to Micro Python, and I have not been successful in getting the Hardware SPI bus working on pins 23, 19, 18, and 5. So far I have been unable to get the clock signal on the output of pin18. Is there any one that has this working?

Re: Hardware SPI not working

Posted: Sat May 18, 2019 12:24 am
by jimmo
Hi,
Can you share the code you're using to construct and use the machine.SPI instance.
Thanks

Re: Hardware SPI not working

Posted: Mon May 20, 2019 7:14 pm
by smith.randallscott
Using a logic analyzer, it appears that the chip select line begins high, shifts low for 0.17ms, shifts high for 0.84ms, shifts low for 1.215ms then a 50kHz clock cycle is present for 0.31ms(on the chip select line), afterwards the chip select line remains low. Also I have not been able to determine the method for inserting a screenshot of the logic analyzer

from machine import Pin
from machine import SPI

cs = Pin(18, Pin.OUT)
cs.on()

miso = Pin(19, Pin.IN)
mosi = Pin(23, Pin.OUT)
sck = Pin(18, Pin.OUT)

spi = SPI(2, baudrate = 50000, sck = sck, mosi = mosi, miso = miso)

write80_buf = bytearray(2)
write80_buf[0] = 0x80
write80_buf[1] = 0x80

cs.off()

spi.write(write80_buf)

cs.on()

Re: Hardware SPI not working

Posted: Mon May 20, 2019 7:24 pm
by Roberthh
You used the same GPIO 18 for CS and clock in your script.

Re: Hardware SPI not working

Posted: Mon May 20, 2019 8:04 pm
by smith.randallscott
Thanks I found that problem shortly after I posted the reply. What I am noticing now is that the chip select line starts high, as it should, but once the chip select line goes low (for the first time) it stays low and then pulses high for transmission of data, then returns low; I believe this is opposite of what it should be. Thanks

Re: Hardware SPI not working

Posted: Mon May 20, 2019 8:06 pm
by Roberthh
I do not like the on() and off() notation, because I never know if on means low or high. I use cs(1) for high and cs(0) for low.

Re: Hardware SPI not working

Posted: Mon May 20, 2019 8:39 pm
by smith.randallscott
I have the same result when the on and off are changed to 1 and 0.

from machine import Pin
from machine import SPI

cs = Pin(5, Pin.OUT)
cs(1)

miso = Pin(19, Pin.IN)
mosi = Pin(23, Pin.OUT)
sck = Pin(18, Pin.OUT)

spi = SPI(2, baudrate = 50000, sck = sck, mosi = mosi, miso = miso)

write80_buf = bytearray(2)
write80_buf[0] = 0x80
write80_buf[1] = 0x80

cs(0)

spi.write(write80_buf)

cs(1)

cs(0)
spi.write(write80_buf)
cs(1)

Re: Hardware SPI not working

Posted: Mon May 20, 2019 9:27 pm
by jimmo
Out of curiosity does it work if you use software SPI instead? (i.e. just remove the `2` from the SPI constructor).

Re: Hardware SPI not working

Posted: Tue May 21, 2019 1:48 pm
by smith.randallscott
I had two of the test leads connected incorrectly on my logic analyzer. I appear to have it working with software SPI. Thank you all

Re: Hardware SPI not working

Posted: Wed May 22, 2019 2:51 pm
by smith.randallscott
After establishing what appears to SPI communication, the response from the MAX31865 does not seem to be corrected. I'm not sure how to trouble shoot this going forward. A work in progress I suppose.