SPI hardware

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
monk65
Posts: 5
Joined: Wed Jun 05, 2019 6:32 pm

SPI hardware

Post by monk65 » Wed Jun 05, 2019 6:45 pm

hello,

i use the spi in mode hardware , so i must configure the pin cs on the pin 15 as a chip select , but unfortunately my transfer don't work

hspi.init(baudrate=400000,sck=Pin(14), mosi=Pin(13), miso=Pin(12),firstbit=SPI.MSB )
cs.off()
hspi.write_readinto(b'\xE0\x00\x00\x00\x00\x00\x00\x00',buf)
cs.on()

but when i make the same function with Arduino C++, it works !
digitalWrite(m_ss, LOW);
m_spi.beginTransaction(SPISettings(400000, SPI_MSBFIRST, SPI_MODE0));
m_spi.transferBytes(const_cast<uint8_t*>(req.data()), resp.data(), req.size());
digitalWrite(m_ss, HIGH);


i don-t understand the problem :?

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: SPI hardware

Post by OutoftheBOTS_ » Wed Jun 05, 2019 8:44 pm

I am not sure what port of MP your using but check if the CS pin is going low or not as the main supported method for pin control is cs.value(0) or cs.value(1)

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

Re: SPI hardware

Post by jimmo » Thu Jun 06, 2019 10:10 am

Also check that the cs pin is initialized with Pin.OUT.

monk65
Posts: 5
Joined: Wed Jun 05, 2019 6:32 pm

Re: SPI hardware

Post by monk65 » Thu Jun 13, 2019 7:36 pm

yes it is initialise and i checked with a analyser logic, it's strange
cs = Pin(15, Pin.OUT)
some parameters are not accsessible (dma channel)

With Arduino IDE, my peripheral answer to the transfert

I don't see any example in micropython except
fork
https://github.com/loboris/MicroPython_ ... o/wiki/spi

but arguments are different !

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

Re: SPI hardware

Post by jimmo » Thu Jun 13, 2019 10:08 pm

What do you see on the analyser? Do you see your data going out? Is the problem that you never get a result stored in buf? (How is buf initialised?)

monk65
Posts: 5
Joined: Wed Jun 05, 2019 6:32 pm

Re: SPI hardware

Post by monk65 » Sun Aug 11, 2019 3:38 pm

i found my problem, my fpga was a response with decoded specific
thank for your reply, i finish this work, and micropython is a wonderful
programmation language
here's the simple code , i like this syntax , very clean

buf= bytearray(size)
self.hspi.init(baudrate=400000,sck=Pin(14), mosi=Pin(13), miso=Pin(12),firstbit=SPI.MSB ) # set the baudrate*
self.cs.off()
self.hspi.write_readinto(cmd,buf)
self.cs.on()


i close this post

Post Reply