Hi again,
I am still trying to create some kind of "minichat" thru console window between two Raspberry Pi, using SPI.
I have activated the SPI on both Rasp's tested with spidev_test on each.
Now I am on stage of writing Java code for it with help of wiringPi libraries but I am totally confused if it's right direction
import com.pi4j.wiringpi.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ChatSPI
{
public static void main(String[] args) throws Exception
{
int fd = Spi.wiringPiSPISetup(0, 10000000);
if (fd <= -1)
{
System.out.println(" ==>> SPI SETUP FAILED");
return;
}
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String msgout=br.readLine();
byte[] data = msgout.getBytes();
write(data);
}
public static void write(byte [] data) throws Exception
{
byte packet[] = data;
System.out.println("-----------------------------------------------");
System.out.println("[TX] " + packet);
Spi.wiringPiSPIDataRW(0, packet);
String str = new String(packet, "UTF-8");
System.out.println("[RX] " + str);
System.out.println("-----------------------------------------------");
}
}
If I connect MOSI MISO on only one Pi it''s printing our console message, but when I connect Pi's together and run the program on them I do not receive any message on second side. (line [RX] empty).
I assumed that there is lack of read method or/and perhaps I didn't set up connection correctly (no pins definition).
But if I understood it correctly method "wiringPiSPIDataRW" is responsible for write/read and wiringPi take over the definig pins stage.
I'll be grateful if somone could give me some hints how to overcome this problem.
Thanks in advance.