PiperLarf
Posts: 2
Joined: Wed Mar 01, 2017 6:38 pm

Unexpected results on MOSI when using spi and pi4j on Strech

Sat May 26, 2018 11:01 pm

I've run into some very puzzling trouble using the spi bus via the pi4j lib. I get incoherent bytestreams off the mosi pin only when using pi4j.

The set up is a brand new pi3B+, running raspbian stretch, and the most recente snapshot (1.2) of pi4j.

My spi bus appears to be working well in all other cases: I can sue some c code that uses spi, all the spi tests look good, I can set up a loopback with pi4j and get the results I expect. I've also attached mosi to rx on an ftdi cable and using realterm I can see coherent bytestreams from some C code I have. By all accounts my spi setup is fine.

Here is the code using pi4j:

Code: Select all

spi = SpiFactory.getInstance(SpiChannel.CS0, 30000000, SpiMode.MODE_3);
byte[] reset = new byte[]{(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04};
while(true) {
	result = spi.write(reset);
	System.out.println(javax.xml.bind.DatatypeConverter.printHexBinary(result));
	sleep(10);
        }
I've used this in the past without a problem, and I said, on loopback this looks fine. However, I am unable to communicate with anything and when I use the ftdi/realtme debug this is the HEX output I see on the terminal:

Code: Select all

00000600000000000000040000000000010000000100110000000010000000000000000000000000
00010000020004000000200000000000010028000000800000000000000600000000000001000100
00000000000010000000000004000820000000000000000004000000000000000000000000000000
00000100000000000002000000000080008000000008000000000000010004000000000000000200
01001000000000000000000000002000000010000008000000000000000000000000000000000000
00000000000700000000000000000000040002000000000004000000000008000000080000002020
00030009000000000000010004000000000000000000010000000000000001000200000000000008
00000000000000000000000400000000000000000000000000000000000000000000004000000000
00000200000001000000800400000000000000000000000000000040000040000000000000000400
000000000000000200000000000000000C0000000000000600000010000000040000000000000000
00000000010005000000000000000100000004000800000000000008000100000010000000000000
00000000000000000000000000000000000000060008000000000000000000000400000000000008
00000200000000000003000000000000000600100000000002000400000000000000040000008000
00000000000000000000010000000000000000000004010004000000000006000200000005000000
44000000000000050000000600000000000000000000000000000008000000000000000000000000
00100000000000000000000000 


Can anyone give me some direction on what to check next? Is this a clock speed issue?

Are there any other ways to access the spi from java?

Thanks

Return to “Java”

Who is online

Users browsing this forum: No registered users and 5 guests