Hardware SPI not working
-
- Posts: 32
- Joined: Mon May 13, 2019 12:42 pm
Hardware SPI not working
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
Hi,
Can you share the code you're using to construct and use the machine.SPI instance.
Thanks
Can you share the code you're using to construct and use the machine.SPI instance.
Thanks
-
- Posts: 32
- Joined: Mon May 13, 2019 12:42 pm
Re: Hardware SPI not working
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()
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
You used the same GPIO 18 for CS and clock in your script.
-
- Posts: 32
- Joined: Mon May 13, 2019 12:42 pm
Re: Hardware SPI not working
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
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.
-
- Posts: 32
- Joined: Mon May 13, 2019 12:42 pm
Re: Hardware SPI not working
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)
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
Out of curiosity does it work if you use software SPI instead? (i.e. just remove the `2` from the SPI constructor).
-
- Posts: 32
- Joined: Mon May 13, 2019 12:42 pm
Re: Hardware SPI not working
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
-
- Posts: 32
- Joined: Mon May 13, 2019 12:42 pm
Re: Hardware SPI not working
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.