I hate to be asking for your help agin but I seem to need it.
I am using a external quadrature encoder counter IC called LS7366R. I can't get it working on the ESP32 but when I hooked it up to the Raspberry Pi I had no problem getting it work properly so this tells me I am wiring it correctly and the chip does work.
Communication to the chip is via SPI, you write a command byte followed by 1 to 4 data bytes (can be either read or write depending on what set in command byte)
I have just hooked up the scope to the SPI pins while the program was running and the only pin that was rising and falling was the CS pin that I was driving so obviously I am doing something wrong with setting up and using the SPI.
Here is my code, it is very short
Code: Select all
from machine import Pin, SPI
import time
spi2 = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
spi2.init(baudrate=10000000)
cs = Pin(15, Pin.OUT)
cs.value(0)
spi2.write(b'\x20') #clear counter
cs.value(1)
cs.value(0)
spi2.write(b'\x30') #clear status
cs.value(1)
cs.value(0)
spi2.write(b'\x88\x03') #set MDR0 to 4 counts per cycle
cs.value(1)
time.sleep(1)
cs.value(0)
spi2.write(b'\x90\x00') #set MDR1 to 4 byte counter
cs.value(1)
while True:
cs.value(0)
spi2.write(b'\x60') #command to read counter
data = spi2.read(4) #read 4 bytes
cs.value(1)
print (data)