SPI communication between ESP32 and TLE5012B magnetic encoder #15164
-
from machine import SPI, Pin
spi = SPI(1, 40000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) #defining the SPI object
cs = Pin(19,mode=Pin.OUT, value=1) #defining chip select pin
rxdata = bytearray(4) #defining a 4 byte array
txdata = b'32801'
print(rxdata,"rxdata") #reading empty rx data as bit strings
print(txdata,"txdata") #reading tx data before sent as bit string
cs(0) # Select peripheral.
spi.write(txdata) # Write 8 bytes, and don't care about received data.
cs(1)
cs(0) # Select peripheral.
spi.readinto(rxdata)#, 0x42) # Read 8 bytes inplace while writing 0x42 for each byte.
cs(1)
print(rxdata,"rxdata") Here are all of the resources I have found helpful for this project but I'm not asking you to look through all of them: Code for someone who got it working on an Arduino Nano: Micropython SPI tutorials: Datasheet of component: Register settings: (gives the register to read the data: 1000000000100001) A website with the circuit of TLE5012B for SPI: If yall know what is wrong or have any advice for me, I would greatly appreciate it. If you need more information about the project, please let me know. If I did something stupid and obvious, its because I don't really know what I am doing. Thanks yall! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I managed to solve it myself so here is a super simple but functional program in micropython that gets the angle. It took me long enough.
|
Beta Was this translation helpful? Give feedback.
I managed to solve it myself so here is a super simple but functional program in micropython that gets the angle. It took me long enough.