Hello all, first time poster here!
I am currently using Microchip's MRF24J40MA 802.15.4 Transceiver module (datasheet) with two Satshakits, which are "100% Arduino IDE and libraries compatible, fabbable and open source boards" that act as an Arduino Uno, both software-wise (e.g. when programming) and hardware-wise (e.g. pinout). I am doing so to send weather data from Adafruit's BME280 SPI Temperature Humidity Pressure Sensor connected to one Satshakit to the other wirelessly and display that information; this is all for my Fab Academy final project. I have been using karlp's MRF24J40 Arduino library that is used in many Arduino projects with the MRF24J40 wireless modules that I've seen on the web. I have been running various iterations of sample code found within the library's examples and elsewhere. To do so, I am basically keeping the PAN ID the same for both boards (which I understand is necessary to connect the two modules) and swapping the sending/receiving addresses between boards. As far as I can tell, both modules are sending data, but neither are receiving each others' transmissions.
The Setup
The wireless modules on each board is connected to the ATMega328P in the following manner (note that all signals, except for GND and VCC, are routed through a Logic Level Converter to shift the levels from 5V to 3.3V and back again since the wireless module operates on 3.3V; see attached photo & schematics for look at the modules and the LLCs, which are on the top left and bottom left of each board, respectively):
| MRF24J40MA Pin (in numerical order from datasheet) | Satshakit (Arduino Uno) Pin |
|---|---|
| GND | GND |
| RESET | 6 |
| WAKE | 2 |
| INT | 3 |
| SDI | 11 (MOSI) |
| SCK | 13 (SCK) |
| SDO | 12 (MISO) |
| CS | 9 |
| NC | - |
| VIN | VCC (via 3.3V LDO regulator) |
| GND | GND |
| GND | GND |
The Code
I began with the Basic_TwoWay example from the aforementioned library (original .ino file attached for reference), and I changed the pins at the top and the attachInterrupt line to reflect my setup, and then only swapped the addresses for sending/receiving on the two boards. The resulting, modified code:
/**
* Example code for using a microchip mrf24j40 module to send and receive
* packets using plain 802.15.4
* Requirements: 3 pins for spi, 3 pins for reset, chip select and interrupt
* notifications
* This example file is considered to be in the public domain
* Originally written by Karl Palsson, karlp@tweak.net.au, March 2011
*/
#include <SPI.h>
#include <mrf24j.h>
const int pin_reset = 6; // UPDATED for my setup!!
const int pin_cs = 9; // UPDATED for my setup!!
const int pin_interrupt = 3; // UPDATED for my setup!!
Mrf24j mrf(pin_reset, pin_cs, pin_interrupt);
long last_time;
long tx_interval = 1000;
void setup() {
Serial.begin(9600);
mrf.reset();
mrf.init();
mrf.set_pan(0xcafe);
// 0xcafe is our PAN (common ID)
mrf.address16_write(0x4202); // CHANGE DEPENDING ON BOARD --> 0x4201 is address on display, 0x4202 on sensor
// uncomment if you want to receive any packet on this channel
//mrf.set_promiscuous(true);
// uncomment if you want to enable PA/LNA external control
//mrf.set_palna(true);
// uncomment if you want to buffer all PHY Payload
//mrf.set_bufferPHY(true);
attachInterrupt(1, interrupt_routine, CHANGE); // UPDATED for my setup!! --> interrupt 0 equivalent to pin 3 (INT1) on ATmega328
last_time = millis();
interrupts();
}
void interrupt_routine() {
mrf.interrupt_handler(); // mrf24 object interrupt routine
}
void loop() {
mrf.check_flags(&handle_rx, &handle_tx);
unsigned long current_time = millis();
if (current_time - last_time > tx_interval) {
last_time = current_time;
Serial.println("txxxing...");
mrf.send16(0x4201, "abcd"); // CHANGE DEPENDING ON BOARD --> should be opposite of address stated in mrf.address16_write above ^^^
}
}
void handle_rx() {
Serial.print("received a packet ");Serial.print(mrf.get_rxinfo()->frame_length, DEC);Serial.println(" bytes long");
if(mrf.get_bufferPHY()){
Serial.println("Packet data (PHY Payload):");
for (int i = 0; i < mrf.get_rxinfo()->frame_length; i++) {
Serial.print(mrf.get_rxbuf()[i]);
}
}
Serial.println("\r\nASCII data (relevant data):");
for (int i = 0; i < mrf.rx_datalength(); i++) {
Serial.write(mrf.get_rxinfo()->rx_data[i]);
}
Serial.print("\r\nLQI/RSSI=");
Serial.print(mrf.get_rxinfo()->lqi, DEC);
Serial.print("/");
Serial.println(mrf.get_rxinfo()->rssi, DEC);
}
void handle_tx() {
if (mrf.get_txinfo()->tx_ok) {
Serial.println("TX went ok, got ack");
} else {
Serial.print("TX failed after ");Serial.print(mrf.get_txinfo()->retries);Serial.println(" retries\n");
}
}
When I run this code on one Satshakit and run the same code with swapped addresses on the other Satshakit and open serial monitor for one of the boards, I only get the "txxxing..." message. I am uncertain as to whether the modules are even sending anything at all (or how I could check that they are properly functioning) or why they aren't receiving each others' messages. I also un-commented the following line:
mrf.set_promiscuous(true);
which the comment preceding it indicates should show any message on the same channel, but to no avail.
I found another similar library here that has a neat ChannelScanner example that would at least help me figure out if the modules are functioning. However, none of the examples from that library include syntax that show me how to modify the defined SPI pins, which I need to change to match my setup. (I will look through the SPI library that is included in the code and see if I can change it that way, though I would prefer a manner that wouldn't change the entire library).
(continued...)
Basic_TwoWay.ino (2.5 KB)
