So, after some trial and error I managed to interface the MRF24J40 modules with two Arduinos and have them exchange data.
This looks more complicated than it is. On the breadboard are two wireless transceiver modules, each one connected to an Arduino and an LED as a rudimentary status display. The Arduino communicates with the module over three SPI pins and three pins for reset, chip select and interrupt.
This represents the pin layout from the Arduino Nano, on the Mega the SPI pins are a little different. MOSI, MISO and SCK are on pins 51, 50 and 52 instead of 11, 12 and 13.
As a bonus I connected pin 9 (NC) to a LED, figuring that “not connected” in the data sheet means that this can be used as an indicator if the module has a connection. It seems that I was right, the LED lights up when I connect the Arduino to power and turns off shortly after initializing, when the other module is available. Shortly after turning one device off the LED on the other device turns on again, so I guess it detected the connection loss.
I used the Basic_TwoWay example from the library and changed just a few things:
const int pin_reset = 6; const int pin_cs = 7; const int pin_interrupt = 2;
I kept the default values for pin_reset and pin_cs but changed the pin_interrupt to 2 (which is the default interrupt 0 on both of my Arduinos.
mrf.set_pan(0xcafe); // This is _our_ address mrf.address16_write(0x4201);
I kept the PAN name 0xCAFE and just gave the devices different addresses. One stayed with the address 0x4201, the other got 0x4202. I don’t have much experience with these devices yet, but I guess you can define those address pretty freely, you only have to make sure every one is unique and they all use the same PAN id.
This is the last line I changed, making sure that 0x4201 sends to 0x4202 and vice versa.
Here is my working code, but I’d check the github repository for updated versions: MRF24J40MA_test001.ino
Here is the output from the serial console:
txxxing... TX went ok, got ack received a packet 15 bytes long ASCII data (relevant data): abcd LQI/RSSI=115/255
“abcd” is the transmitted data, LQI is a link quality indicator, RSSI is a signal strength indicator. I found a pretty good explanation about LQI and RSSI on the Texas Instruments support site.