-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #338: Add support for SPI on Pi5 using /dev/spidev. #390
base: develop
Are you sure you want to change the base?
Conversation
…tested. JNA is introduced as a dependency.
Hi, that means in the 2.7.1-SNAPSHOT you implemented it for the Pigpio-spi? I have a device were i could test it. |
You can pull the code from my fork and give it a test. I jumped off to a different project for a bit but writing to an SPI display was working for me with this implementation. |
Hi, as i am quite new to git, can you please advice me how to do this?
Do you have any idea what i am doing wrong? |
You can simply clone my branch directly and then follow the normal pi4j build instructions. My branch is behind pi4j but if you're just interested in testing SPI that shouldn't matter.
|
Hi, |
Hi, is there a reason for binding it directly to SPI 0? i changed it accordinlgy
and my pi4j context is
Do you have any idea why it is not working to call the create? |
You're probably correct that the code mixes up bus and channel in the device name. I was only using bus 0, channel 0 so it didn't matter. I can't say what might be wrong with your code. I tested it with the code below using a simple LED display:
That would use channel 0, mode 0, and baud 9600. It's possible other modes or channels aren't working correctly. I only had a RaspberryPi5 and a single LED display to test with so I definitely didn't test many variations. You can see that the code in |
Hi again, |
There's nothing Pi5 specific in this SPI code. It just uses kernel ioctl calls to talk to the /dev/spidev device. There's no native code other than the JNA core that maps the Java calls to native C calls. I suspect you'd get an exception from JNA if it didn't support your platform/architecture. Do you have SPI working on the device outside of your Java app? Like some kind of simple python or C test code? It's possible there's an issue at the OS/SPI level that isn't directly related to Java/Pi4J. For example, something like this or this. I don't have a CM4 to test with but if you're not getting any errors from the Pi4j SPI code, then it is probably opening the device successfully but probably not successfully talking to any SPI device. |
Hi, yes i tested it with a python script and spidev, so it is all running fine. With the Java app i already managed to get it partly working as i need the mode 1 for the SPI6 bus i tried your code. I get no error message at all that is strange. The program exits when i call the create method of the pi4j context. I also tried to switch this part and initialize the plugin directly
without success. |
Oh, ok. I didn't realize your application was exiting vs just not getting any SPI data. I'm guessing that the native SPI code is causing the JVM to crash. Usually the JVM will generate an hs_err_pid.log file when this happens but it may be JVM specific. Because you're already compiling pi4j yourself, you can try adding some System.out or configure SLF4J logging and add some If you find the specific call that causes the JVM to crash, you can look at the value's being passed to the native call. It's possible (likely) that there's a native data type or structure field layout mismatch. |
I implemented SPI support on the Pi5 using /dev/spidev. This change introduces a dependency on JNA. I implemented it in the existing LinuxFS plugin because it uses /dev/spidev, but I'm not sure if that's the intent of the existing plugin. I tested it with an OLED display using write operations, but I didn't test any read operations as I don't have an SPI device to work with. Use the code as you like.