Page 1 of 1

Lacking support for multiple spi devices on the same bus

Posted: Sat Aug 15, 2020 2:58 pm
by DanielRossinsky
Important: The platform Im working on is the Doit esp32 devkit v1.

Iv'e come from a c++/Arduino background where if I want to use multiple spi devices on the same bus i just need to manage their slave select pin and use SPI.beginTransaction to set various speeds. However, in micropython there is no such thing as SPI.beginTransaction and I didn't find any custom drivers that ported the Arduino core SPI to micropython. Therefore, Im stuck with using init and deinit to imitate SPI.beginTransaction and SPI.endTransaction and the problem is it doesn't work. the sensors stop working completely.

As for the reason I need such functionality:
I want to power an ili9341 TFT LCD and use both its touch and graphics capabilities and a MAX7219 seven segment display. In arduino I could just assign them the same spi bus(MISO, MOSI, SCK) for example vspi (23,19,18) and manually enable them through their slave select pin. However I dont see it possible with micropython.

Iv'e attached two examples for the max7219 7 segment I've ported from c++ 1 working without imitating SPI.beginTransaction and the other tries to imitate SPI.beginTransaction and doesn't work at all, the seven segment doesn't even light up.

Am I missing something obvious ? or does such a feature not exist in micropython ?

Re: Lacking support for multiple spi devices on the same bus

Posted: Sun Aug 16, 2020 11:26 am
by Roberthh
I did not look into your files yet, having problems to unpack them. But there is a common trap in using spi.init() and other init calls. When you use that, you have to specify ALL non-default parameters again. Parameters which had been specified by the constructor will be overwritten with the defaults. That is caused by the implementation, which uses the same code both for the instantiation of the spi object and the init call. Same for UART, I2C, ....

Re: Lacking support for multiple spi devices on the same bus

Posted: Sun Aug 16, 2020 3:38 pm
by pythoncoder
The normal example is correct. The application instantiates the interface and passes the instance to the constructor of each object that uses it. This should "just work" so long as each device can share the same bus properties, with each device having a separate CS line.

If they can't share bus properties, management is required - this can be easy or quite hard depending on the application and how much concurrency is involved.