MicroPython SPI code problems

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 4
Joined: Fri Feb 14, 2020 12:10 am

MicroPython SPI code problems

Post by fmentiplay » Fri Feb 14, 2020 12:44 am

I have an ESP32(WROOM) running latest MicroPython (MicroPython v1.12-119-g61f64c78a on 2020-02-01; ESP32 module with ESP32)
connected to a 2.8" 240x320 TFT with ili9341 driver chip, via SPI.

Using a ili9341 MicroPython driver ( e.g ili9341 from Adafruit or similar) I can draw shapes, text etc.

As an exercise I would like to "Read display identification information (04h)" without using the ili9341 Micropython driver, but I have not been successful.

Here is my code....
from machine import Pin, SPI
from time import sleep
# import ubinascii

vspi = SPI(2, baudrate=100000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(18), mosi=Pin(23), miso=Pin(19))

cs = Pin(5, Pin.OUT)

dc = Pin(17, Pin.OUT)
buf = bytearray(4)

rst = Pin(16, Pin.OUT)

while True:
# cs.value(0)
# dc.value(1)
#vspi.readinto(buf, 0x04)
a = vspi.read(3, 0x04)

Here is the output I have been getting ..
b'\xff\xff\xff' or b'\x00\x00\x00' which I consider is wrong

I assume I should be getting a 93 41 code

I have connected a logic analyser and I can see data on the MOSI line and clock activity on the sck(clock) line BUT I do not see any activity on the MISO line. I have tried different MicroPython SPI commands/combinations without any success.

Could someone show me some simply MicroPython code that might work or indicate what I am doing wrong.

Any help would be much appreciated.
Regards Frank

User avatar
Posts: 2089
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: MicroPython SPI code problems

Post by jimmo » Sat Feb 15, 2020 5:06 am

Some devices require you to use the CS line to start an operation.


- reset device (rst low, sleep, rst high)
- select command/data (dc high/low)
- start op (cs low)
- send / recv
- finish (cs high)

Do you see the correct data with the logic analyser on the MOSI and SCK lines? Is it definitely the correct polarity and phase?

Post Reply