arduino / ArduinoCore-mbed

330 stars 195 forks source link

Minimal example of peripheral SPI for Portenta H7 #644

Open Andres9713 opened 1 year ago

Andres9713 commented 1 year ago

Hello, I am trying to set up SPI communication between two Portenta H7's in order to facilitate fast data transfer between them. The code for setting up the Portenta in controller ('master') mode is easy to follow and works fine (https://github.com/arduino/ArduinoCore-mbed/issues/131) - however, I have not been able to find any examples (minimal or otherwise) on how to setup the Portenta H7 as a peripheral ('slave') SPI device. Does anyone know of such an example or resource?

alessandromrc commented 1 year ago

Hi @Andres9713, if I'm not mistaken the SPI library is implemented to only send data and not receive it

manchoz commented 1 year ago

Hi @Andres9713, You may want to experiment with the SPISlave class from the underlying MbedOS SPISlave. It might work if you don't initialize the default SPI bus.

Andres9713 commented 1 year ago

Thank you for your inputI might try @manchoz suggestion - though since I couldn't figure out the SPI interface I ended up 'bit-banging' a solution with 14 parallel wires (8 data wires, 3 address wires (telling the receiver what part of the signal is currently being sent), 1 interrupt signal, and 2 bit sum wires (though I'm thinking these might not be that beneficial)). The sender sets its output pins to the correct values, sends an interrupt telling the receiver that data is ready and then waits 6 to 10 microseconds (I'm still working this number out) for the receiver to be done reading. I originally had the receiver send a 'data received' signal but this really slowed things down. This homemade solution works well enough - I can send about 28k 32-bit float numbers per second this way - on the other hand it uses the majority of my useful pins. This is ok for now but is pretty limiting (since there are actually not that many useful pins left) and may become problematic later.

alessandromrc commented 1 year ago

Thank you for your inputI might try @manchoz suggestion - though since I couldn't figure out the SPI interface I ended up 'bit-banging' a solution with 14 parallel wires (8 data wires, 3 address wires (telling the receiver what part of the signal is currently being sent), 1 interrupt signal, and 2 bit sum wires (though I'm thinking these might not be that beneficial)). The sender sets its output pins to the correct values, sends an interrupt telling the receiver that data is ready and then waits 6 to 10 microseconds (I'm still working this number out) for the receiver to be done reading. I originally had the receiver send a 'data received' signal but this really slowed things down. This homemade solution works well enough - I can send about 28k 32-bit float numbers per second this way - on the other hand it uses the majority of my useful pins. This is ok for now but is pretty limiting (since there are actually not that many useful pins left) and may become problematic later.

This seems a really interesting way of dealing with it but surely GPIO consuming... keep us updated! 😊