2 SPI devices at different speeds

Discussion related to "under the hood" OpenMV topics.
User avatar
kwiley
Posts: 107
Joined: Fri Dec 21, 2018 5:22 pm

2 SPI devices at different speeds

Postby kwiley » Thu Jan 17, 2019 6:10 pm

I am successfully driving two devices off the M7's SPI interface, the LCD shield and a third party device controlled from Pin 9. However, the other device operates at a maximum speed of 2MHz. Configuring the bus for 2MHz reduces the main-loop framerate to 5 fps as the LCD takes much longer to update. I'm not sure I have any options here. The PyBoard has two buses, but the M7 (and the upcoming H7) only has one. Can anyone see a way to get what I want out of this setup. The LCD needs to use SPI at its desired faster speed (whatever speed lcd.init() sets the speed to, I'm not sure) and the other device needs to use SPI at 2MHz. Am I out of the luck here or is there a solution to this problem?

Thank you.
User avatar
kwagyeman
Posts: 3205
Joined: Sun May 24, 2015 2:10 pm

Re: 2 SPI devices at different speeds

Postby kwagyeman » Thu Jan 17, 2019 6:46 pm

Hi, just reinit the SPI bus when switching between the two devices. It doesn't take much time to reinit it. Only a few clock cycles.

Um, I'm still working on upgrading find_blobs() but I should be done by the end of the week on it. Then I just have to get in some fixes for drawing ellipses and your rotated text request and I will be able to redo the LCD code then such that it doesn't leave any traces behind that it uses the SPI bus. I.e. the redone code will capture the previous state, then set the bus to what it needs, send an image, and then restore the state.
Nyamekye,
User avatar
kwiley
Posts: 107
Joined: Fri Dec 21, 2018 5:22 pm

Re: 2 SPI devices at different speeds

Postby kwiley » Thu Jan 17, 2019 7:03 pm

I actually thought of that before writing my post, but the resulting framerate dropped from 5 to 2! It got considerably worse. In fact, even if I just call lcd.init() right before I call lcd.display() the framerate drops to 2, even if I don't bother setting the bus to the slower speed in between frames. Weird.

Are you sure you would expect that to work? I could try again.
Last edited by kwiley on Thu Jan 17, 2019 7:09 pm, edited 1 time in total.
User avatar
kwiley
Posts: 107
Joined: Fri Dec 21, 2018 5:22 pm

Re: 2 SPI devices at different speeds

Postby kwiley » Thu Jan 17, 2019 7:07 pm

BTW, the rotated text wasn't an explicit coding or effort request, although I appreciate your diligence. I was asking what was supported at the time, but not trying to make extra work for you.

Thanks.
User avatar
kwiley
Posts: 107
Joined: Fri Dec 21, 2018 5:22 pm

Re: 2 SPI devices at different speeds

Postby kwiley » Thu Jan 17, 2019 7:13 pm

Oooookay. I see. Instead of calling lcd.init() every time, I directly reset the bus speed. That actually seems to work:

Code: Select all

    pyb.SPI(2).init(pyb.SPI.MASTER, baudrate=15000000, polarity=0, phase=0)
    lcd.display(img)
    pyb.SPI(2).init(pyb.SPI.MASTER, baudrate=2000000, polarity=0, phase=0)
That leaves one question remaining. What is the correct bus speed to set it to for the LCD. I just "narrowed in" on 15MHz by finding the speed that reproduced the original framerate, but that probably isn't exactly correct. What speed would the LCD *like* me to set the bus to?
User avatar
kwagyeman
Posts: 3205
Joined: Sun May 24, 2015 2:10 pm

Re: 2 SPI devices at different speeds

Postby kwagyeman » Fri Jan 18, 2019 12:02 am

About 20 MHz. Don't worry however, the M7 can't actually do any freq. SO, it sets it to a freq below what you want to hit normally however.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests