-
AuthorPosts
-
-
Hi,
I wanted to kindly ask if you could provide us with an simple example of sending some data (for example a value that is incrementing) from MPU to MCU via SPi ? I am interested in this because for our project there is sensor data which is being processed in MPU and we would like to send it to MCU.
Thank you,
-
Hey hmarthens,
Sorry for the late response. I wrapped up a quick Python script to send data to MCU from MPU via SPI. You need to install the Spidev module to run the script – https://pypi.org/project/spidev/. The script simply asks for user input and transmits it to the MCU side.
On the MCU side, the template Simulink model already has the SPI transfer setup. You should be able to get the data from the MPU side via the pre-defined user variable SPIFromPi and watch the received SPI data in FreeMaster.
I’ve attached the Python script and some screenshots for your reference.
- This reply was modified 1 year, 1 month ago by Leo.
Attachments:
You must be logged in to view attached files. -
Hi Leo,
Thanks for your response. I have tried doing the implementation as suggested, however, when in FreeMaster, I am faced with the issue that the variable “spiFromPi” cannot remain the same and hold a value, I am only able to view it once when it is sent and then it is going back to its default value.
Below is a screenshot of the default value, and a screenshot of a time when it changed.
Is there any particular method you use for latching the value received ?
Attachments:
You must be logged in to view attached files. -
Hey Hmarthens,
Glad you got basic SPI transmission working in such a short time.
spiFromPi shouldn’t have any “default value”. I suspect your Flexbench already has an SPI broadcasting script running at startup. You can check this tutorial for more information – https://www.audesseinc.com/resources/python/
In order to confirm this, you can
1. First type – <ls /etc/systemd/system>, to check is the Python script(myScript.py) and the .service file are located there
2. Then type – <top>, to see if you can find the corresponding Python process that is running.
3. If so, you can type <sudo systemctl disable myScript.py> to disable the script from running at startupLet me know if you run into any more issues.
-
Hi Leo,
I checked and there were no other services for SPI, expect the default “spiComm.service”.
Also, in the processes that are running, only “spi0” is present which I guess is also default ?
Nonetheless, the issue I face is still the same. I have also ensured that before building the Simulink files, SPI is setup correctly as suggested on this page “https://www.audesseinc.com/resources/simulink-on-mpu/” but I guess this is more for the case where we want to use Simulink for MPU and is not related.
Please let me know if there could be another underlying issue.
Thanks -
However, one thing I noticed is that the variable “spiTx” is always changing, which confirms what you mentioned…but the only confusion I have is regarding whether the “spi0” service is the default one. Please also see the attached files below.
Attachments:
You must be logged in to view attached files. -
Hi Hmarthens,
I believe SPIComm.py/.service is the process that runs at startup that broadcasts the message to spi0, which keeps overriding your custom messages. U can either comment out the spidev.xfer2 part to mute the broadcasting or simply mv SPIComm.service out of /etc/systemd/system to stop the script from running at startup.
:)
-
-
AuthorPosts
- You must be logged in to reply to this topic.